1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/BrowserHost.h"
#include "mozilla/ProcessPriorityManager.h"
#include "mozilla/dom/BrowsingContextGroup.h"
#include "mozilla/dom/CancelContentJSOptionsBinding.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/WindowGlobalParent.h"
#include "nsIObserverService.h"
namespace mozilla::dom {
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(BrowserHost)
NS_INTERFACE_MAP_ENTRY(nsIRemoteTab)
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, RemoteBrowser)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTION_WEAK(BrowserHost, mRoot)
NS_IMPL_CYCLE_COLLECTING_ADDREF(BrowserHost)
NS_IMPL_CYCLE_COLLECTING_RELEASE(BrowserHost)
BrowserHost::BrowserHost(BrowserParent* aParent)
: mId(aParent->GetTabId()),
mRoot(aParent),
mEffectsInfo{EffectsInfo::FullyHidden()} {
mRoot->SetBrowserHost(this);
}
BrowserHost* BrowserHost::GetFrom(nsIRemoteTab* aRemoteTab) {
return static_cast<BrowserHost*>(aRemoteTab);
}
TabId BrowserHost::GetTabId() const { return mId; }
mozilla::layers::LayersId BrowserHost::GetLayersId() const {
return mRoot->GetLayersId();
}
BrowsingContext* BrowserHost::GetBrowsingContext() const {
return mRoot->GetBrowsingContext();
}
nsILoadContext* BrowserHost::GetLoadContext() const {
RefPtr<nsILoadContext> loadContext = mRoot->GetLoadContext();
return loadContext;
}
bool BrowserHost::CanRecv() const { return mRoot && mRoot->CanRecv(); }
a11y::DocAccessibleParent* BrowserHost::GetTopLevelDocAccessible() const {
return mRoot ? mRoot->GetTopLevelDocAccessible() : nullptr;
}
void BrowserHost::LoadURL(nsDocShellLoadState* aLoadState) {
MOZ_ASSERT(aLoadState);
mRoot->LoadURL(aLoadState);
}
void BrowserHost::ResumeLoad(uint64_t aPendingSwitchId) {
mRoot->ResumeLoad(aPendingSwitchId);
}
void BrowserHost::DestroyStart() { mRoot->Destroy(); }
void BrowserHost::DestroyComplete() {
if (!mRoot) {
return;
}
mRoot->SetOwnerElement(nullptr);
mRoot->Destroy();
mRoot->SetBrowserHost(nullptr);
mRoot = nullptr;
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
if (os) {
os->NotifyObservers(NS_ISUPPORTS_CAST(nsIRemoteTab*, this),
"ipc:browser-destroyed", nullptr);
}
}
bool BrowserHost::Show(const OwnerShowInfo& aShowInfo) {
return mRoot->Show(aShowInfo);
}
void BrowserHost::UpdateDimensions(const LayoutDeviceIntRect& aRect,
const LayoutDeviceIntSize& aSize) {
mRoot->UpdateDimensions(aRect, aSize);
}
void BrowserHost::UpdateEffects(EffectsInfo aEffects) {
if (!mRoot || mEffectsInfo == aEffects) {
return;
}
mEffectsInfo = aEffects;
(void)mRoot->SendUpdateEffects(mEffectsInfo);
}
/* attribute boolean renderLayers; */
NS_IMETHODIMP
BrowserHost::GetRenderLayers(bool* aRenderLayers) {
if (!mRoot) {
*aRenderLayers = false;
return NS_OK;
}
*aRenderLayers = mRoot->GetRenderLayers();
return NS_OK;
}
NS_IMETHODIMP
BrowserHost::SetRenderLayers(bool aRenderLayers) {
if (!mRoot) {
return NS_OK;
}
mRoot->SetRenderLayers(aRenderLayers);
return NS_OK;
}
/* readonly attribute boolean hasLayers; */
NS_IMETHODIMP
BrowserHost::GetHasLayers(bool* aHasLayers) {
*aHasLayers = mRoot && mRoot->GetHasLayers();
return NS_OK;
}
/* attribute boolean priorityHint; */
NS_IMETHODIMP
BrowserHost::SetPriorityHint(bool aPriorityHint) {
if (!mRoot) {
return NS_OK;
}
mRoot->SetPriorityHint(aPriorityHint);
return NS_OK;
}
NS_IMETHODIMP
BrowserHost::GetPriorityHint(bool* aPriorityHint) {
*aPriorityHint = mRoot && mRoot->GetPriorityHint();
return NS_OK;
}
/* void resolutionChanged (); */
NS_IMETHODIMP
BrowserHost::NotifyResolutionChanged() {
if (!mRoot) {
return NS_OK;
}
VisitAll([](BrowserParent* aBrowserParent) {
aBrowserParent->NotifyResolutionChanged();
});
return NS_OK;
}
/* void deprioritize (); */
NS_IMETHODIMP
BrowserHost::Deprioritize() {
if (!mRoot) {
return NS_OK;
}
auto* bc = GetBrowsingContext()->Canonical();
ProcessPriorityManager::BrowserPriorityChanged(bc,
/* aPriority = */ false);
return NS_OK;
}
/* void preserveLayers (in boolean aPreserveLayers); */
NS_IMETHODIMP
BrowserHost::PreserveLayers(bool aPreserveLayers) {
if (!mRoot) {
return NS_OK;
}
VisitAll([&](BrowserParent* aBrowserParent) {
aBrowserParent->PreserveLayers(aPreserveLayers);
});
return NS_OK;
}
/* readonly attribute uint64_t tabId; */
NS_IMETHODIMP
BrowserHost::GetTabId(uint64_t* aTabId) {
*aTabId = mId;
return NS_OK;
}
/* readonly attribute uint64_t contentProcessId; */
NS_IMETHODIMP
BrowserHost::GetContentProcessId(uint64_t* aContentProcessId) {
if (!mRoot) {
*aContentProcessId = 0;
return NS_OK;
}
*aContentProcessId = GetContentParent()->ChildID();
return NS_OK;
}
/* readonly attribute int32_t osPid; */
NS_IMETHODIMP
BrowserHost::GetOsPid(int32_t* aOsPid) {
if (!mRoot) {
*aOsPid = 0;
return NS_OK;
}
*aOsPid = GetContentParent()->Pid();
return NS_OK;
}
/* readonly attribute BrowsingContext browsingContext; */
NS_IMETHODIMP
BrowserHost::GetBrowsingContext(BrowsingContext** aBc) {
if (!mRoot) {
*aBc = nullptr;
return NS_OK;
}
RefPtr<BrowsingContext> bc = mRoot->GetBrowsingContext();
bc.forget(aBc);
return NS_OK;
}
/* readonly attribute boolean hasPresented; */
NS_IMETHODIMP
BrowserHost::GetHasPresented(bool* aHasPresented) {
if (!mRoot) {
*aHasPresented = false;
return NS_OK;
}
*aHasPresented = mRoot->GetHasPresented();
return NS_OK;
}
/* void transmitPermissionsForPrincipal (in nsIPrincipal aPrincipal); */
NS_IMETHODIMP
BrowserHost::TransmitPermissionsForPrincipal(nsIPrincipal* aPrincipal) {
if (!mRoot) {
return NS_OK;
}
return GetContentParent()->TransmitPermissionsForPrincipal(aPrincipal);
}
/* void createAboutBlankDocumentViewer(in nsIPrincipal aPrincipal, in
* nsIPrincipal aPartitionedPrincipal); */
NS_IMETHODIMP
BrowserHost::CreateAboutBlankDocumentViewer(
nsIPrincipal* aPrincipal, nsIPrincipal* aPartitionedPrincipal) {
if (!mRoot) {
return NS_OK;
}
// Before creating the viewer in-content, ensure that the process is allowed
// to load this principal.
if (NS_WARN_IF(!mRoot->Manager()->ValidatePrincipal(aPrincipal))) {
ContentParent::LogAndAssertFailedPrincipalValidationInfo(
aPrincipal, "BrowserHost::CreateAboutBlankDocumentViewer");
return NS_ERROR_DOM_SECURITY_ERR;
}
// Ensure the content process has permisisons for the new document we're about
// to create in it.
nsresult rv = GetContentParent()->TransmitPermissionsForPrincipal(aPrincipal);
if (NS_FAILED(rv)) {
return rv;
}
// Ensure that UsesOriginAgentCluster has been initialized for this
// BrowsingContextGroup/principal pair before creating the document in
// content.
mRoot->GetBrowsingContext()->Group()->EnsureUsesOriginAgentClusterInitialized(
aPrincipal);
(void)mRoot->SendCreateAboutBlankDocumentViewer(aPrincipal,
aPartitionedPrincipal);
return NS_OK;
}
NS_IMETHODIMP
BrowserHost::MaybeCancelContentJSExecutionFromScript(
nsIRemoteTab::NavigationType aNavigationType,
JS::Handle<JS::Value> aCancelContentJSOptions, JSContext* aCx) {
// If we're in the process of creating a new window (via window.open), then
// the load that called this function isn't a "normal" load and should be
// ignored for the purposes of cancelling content JS.
if (!mRoot || mRoot->CreatingWindow()) {
return NS_OK;
}
dom::CancelContentJSOptions cancelContentJSOptions;
if (!cancelContentJSOptions.Init(aCx, aCancelContentJSOptions)) {
return NS_ERROR_INVALID_ARG;
}
GetContentParent()->CancelContentJSExecutionIfRunning(mRoot, aNavigationType,
cancelContentJSOptions);
return NS_OK;
}
} // namespace mozilla::dom
|