2019-05-07 00:04:34 +03:00
|
|
|
/* -*- 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"
|
|
|
|
|
2019-05-15 23:26:25 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2019-05-07 00:04:34 +03:00
|
|
|
#include "mozilla/dom/CancelContentJSOptionsBinding.h"
|
2020-10-28 15:31:35 +03:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2019-05-07 00:04:34 +03:00
|
|
|
#include "mozilla/dom/WindowGlobalParent.h"
|
|
|
|
|
2019-07-07 19:02:11 +03:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
namespace mozilla::dom {
|
2019-05-07 00:04:34 +03:00
|
|
|
|
2019-05-15 00:28:10 +03:00
|
|
|
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
|
|
|
|
|
2020-02-25 22:44:39 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WEAK(BrowserHost, mRoot)
|
2019-05-15 00:28:10 +03:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(BrowserHost)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(BrowserHost)
|
2019-05-08 19:45:23 +03:00
|
|
|
|
2019-05-15 20:34:14 +03:00
|
|
|
BrowserHost::BrowserHost(BrowserParent* aParent)
|
2019-05-15 23:26:25 +03:00
|
|
|
: mId(aParent->GetTabId()),
|
|
|
|
mRoot(aParent),
|
|
|
|
mEffectsInfo{EffectsInfo::FullyHidden()} {
|
2019-05-15 18:34:03 +03:00
|
|
|
mRoot->SetBrowserHost(this);
|
|
|
|
}
|
2019-05-07 00:04:34 +03:00
|
|
|
|
2019-05-08 22:34:47 +03:00
|
|
|
BrowserHost* BrowserHost::GetFrom(nsIRemoteTab* aRemoteTab) {
|
|
|
|
return static_cast<BrowserHost*>(aRemoteTab);
|
|
|
|
}
|
|
|
|
|
2019-06-02 20:42:03 +03:00
|
|
|
TabId BrowserHost::GetTabId() const { return mId; }
|
|
|
|
|
2019-05-07 00:04:34 +03:00
|
|
|
mozilla::layers::LayersId BrowserHost::GetLayersId() const {
|
2019-06-01 00:00:57 +03:00
|
|
|
return mRoot->GetLayersId();
|
2019-05-07 00:04:34 +03:00
|
|
|
}
|
|
|
|
|
2019-05-08 19:27:49 +03:00
|
|
|
BrowsingContext* BrowserHost::GetBrowsingContext() const {
|
|
|
|
return mRoot->GetBrowsingContext();
|
|
|
|
}
|
2019-05-07 00:04:34 +03:00
|
|
|
|
2019-05-08 19:27:49 +03:00
|
|
|
nsILoadContext* BrowserHost::GetLoadContext() const {
|
|
|
|
RefPtr<nsILoadContext> loadContext = mRoot->GetLoadContext();
|
|
|
|
return loadContext;
|
|
|
|
}
|
2019-05-07 00:04:34 +03:00
|
|
|
|
2019-05-08 22:34:47 +03:00
|
|
|
a11y::DocAccessibleParent* BrowserHost::GetTopLevelDocAccessible() const {
|
|
|
|
return mRoot->GetTopLevelDocAccessible();
|
|
|
|
}
|
|
|
|
|
2020-08-28 20:20:30 +03:00
|
|
|
void BrowserHost::LoadURL(nsDocShellLoadState* aLoadState) {
|
|
|
|
MOZ_ASSERT(aLoadState);
|
|
|
|
mRoot->LoadURL(aLoadState);
|
2020-05-19 23:22:34 +03:00
|
|
|
}
|
2019-05-07 00:04:34 +03:00
|
|
|
|
2019-05-08 19:27:49 +03:00
|
|
|
void BrowserHost::ResumeLoad(uint64_t aPendingSwitchId) {
|
|
|
|
mRoot->ResumeLoad(aPendingSwitchId);
|
|
|
|
}
|
2019-05-07 00:04:34 +03:00
|
|
|
|
2019-05-08 19:27:49 +03:00
|
|
|
void BrowserHost::DestroyStart() { mRoot->Destroy(); }
|
2019-05-07 00:04:34 +03:00
|
|
|
|
2019-05-08 19:27:49 +03:00
|
|
|
void BrowserHost::DestroyComplete() {
|
|
|
|
if (!mRoot) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mRoot->SetOwnerElement(nullptr);
|
|
|
|
mRoot->Destroy();
|
2019-07-07 19:02:11 +03:00
|
|
|
mRoot->SetBrowserHost(nullptr);
|
2019-05-08 19:27:49 +03:00
|
|
|
mRoot = nullptr;
|
2019-07-07 19:02:11 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
|
|
|
|
if (os) {
|
|
|
|
os->NotifyObservers(NS_ISUPPORTS_CAST(nsIRemoteTab*, this),
|
|
|
|
"ipc:browser-destroyed", nullptr);
|
|
|
|
}
|
2019-05-08 19:27:49 +03:00
|
|
|
}
|
2019-05-07 00:04:34 +03:00
|
|
|
|
2020-01-13 14:30:36 +03:00
|
|
|
bool BrowserHost::Show(const OwnerShowInfo& aShowInfo) {
|
|
|
|
return mRoot->Show(aShowInfo);
|
2019-05-07 00:04:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserHost::UpdateDimensions(const nsIntRect& aRect,
|
2019-05-08 19:27:49 +03:00
|
|
|
const ScreenIntSize& aSize) {
|
|
|
|
mRoot->UpdateDimensions(aRect, aSize);
|
|
|
|
}
|
2019-05-07 00:04:34 +03:00
|
|
|
|
2019-05-15 23:26:25 +03:00
|
|
|
void BrowserHost::UpdateEffects(EffectsInfo aEffects) {
|
|
|
|
if (!mRoot || mEffectsInfo == aEffects) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mEffectsInfo = aEffects;
|
|
|
|
Unused << mRoot->SendUpdateEffects(mEffectsInfo);
|
|
|
|
}
|
|
|
|
|
2019-05-08 19:45:23 +03:00
|
|
|
/* attribute boolean docShellIsActive; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
BrowserHost::GetDocShellIsActive(bool* aDocShellIsActive) {
|
2019-05-15 20:34:14 +03:00
|
|
|
if (!mRoot) {
|
|
|
|
*aDocShellIsActive = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-05-08 23:47:18 +03:00
|
|
|
*aDocShellIsActive = mRoot->GetDocShellIsActive();
|
|
|
|
return NS_OK;
|
2019-05-08 19:45:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
BrowserHost::SetDocShellIsActive(bool aDocShellIsActive) {
|
2019-05-15 20:34:14 +03:00
|
|
|
if (!mRoot) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-05-09 00:12:26 +03:00
|
|
|
VisitAll([&](BrowserParent* aBrowserParent) {
|
|
|
|
aBrowserParent->SetDocShellIsActive(aDocShellIsActive);
|
|
|
|
});
|
2019-05-08 23:47:18 +03:00
|
|
|
return NS_OK;
|
2019-05-08 19:45:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* attribute boolean renderLayers; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
BrowserHost::GetRenderLayers(bool* aRenderLayers) {
|
2019-05-15 20:34:14 +03:00
|
|
|
if (!mRoot) {
|
|
|
|
*aRenderLayers = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-05-08 23:47:18 +03:00
|
|
|
*aRenderLayers = mRoot->GetRenderLayers();
|
|
|
|
return NS_OK;
|
2019-05-08 19:45:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
BrowserHost::SetRenderLayers(bool aRenderLayers) {
|
2019-05-15 20:34:14 +03:00
|
|
|
if (!mRoot) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-05-15 23:29:22 +03:00
|
|
|
mRoot->SetRenderLayers(aRenderLayers);
|
2019-05-08 23:47:18 +03:00
|
|
|
return NS_OK;
|
2019-05-08 19:45:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute boolean hasLayers; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
BrowserHost::GetHasLayers(bool* aHasLayers) {
|
2019-05-15 20:34:14 +03:00
|
|
|
if (!mRoot) {
|
|
|
|
*aHasLayers = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-05-08 23:47:18 +03:00
|
|
|
*aHasLayers = mRoot->GetHasLayers();
|
|
|
|
return NS_OK;
|
2019-05-08 19:45:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void resolutionChanged (); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
BrowserHost::NotifyResolutionChanged(void) {
|
2019-05-15 20:34:14 +03:00
|
|
|
if (!mRoot) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-05-09 00:12:26 +03:00
|
|
|
VisitAll([](BrowserParent* aBrowserParent) {
|
|
|
|
aBrowserParent->NotifyResolutionChanged();
|
|
|
|
});
|
2019-05-08 23:47:18 +03:00
|
|
|
return NS_OK;
|
2019-05-08 19:45:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void deprioritize (); */
|
|
|
|
NS_IMETHODIMP
|
2019-05-08 23:47:18 +03:00
|
|
|
BrowserHost::Deprioritize(void) {
|
2019-05-15 20:34:14 +03:00
|
|
|
if (!mRoot) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-05-09 00:12:26 +03:00
|
|
|
VisitAll(
|
|
|
|
[](BrowserParent* aBrowserParent) { aBrowserParent->Deprioritize(); });
|
2019-05-08 23:47:18 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-05-08 19:45:23 +03:00
|
|
|
|
|
|
|
/* void preserveLayers (in boolean aPreserveLayers); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
BrowserHost::PreserveLayers(bool aPreserveLayers) {
|
2019-05-15 20:34:14 +03:00
|
|
|
if (!mRoot) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-05-09 00:12:26 +03:00
|
|
|
VisitAll([&](BrowserParent* aBrowserParent) {
|
|
|
|
aBrowserParent->PreserveLayers(aPreserveLayers);
|
|
|
|
});
|
2019-05-08 23:47:18 +03:00
|
|
|
return NS_OK;
|
2019-05-08 19:45:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute uint64_t tabId; */
|
|
|
|
NS_IMETHODIMP
|
2019-05-08 23:47:18 +03:00
|
|
|
BrowserHost::GetTabId(uint64_t* aTabId) {
|
2019-05-15 20:34:14 +03:00
|
|
|
*aTabId = mId;
|
2019-05-08 23:47:18 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-05-08 19:45:23 +03:00
|
|
|
|
|
|
|
/* readonly attribute uint64_t contentProcessId; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
BrowserHost::GetContentProcessId(uint64_t* aContentProcessId) {
|
2019-05-15 20:34:14 +03:00
|
|
|
if (!mRoot) {
|
|
|
|
*aContentProcessId = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-05-08 23:47:18 +03:00
|
|
|
*aContentProcessId = GetContentParent()->ChildID();
|
|
|
|
return NS_OK;
|
2019-05-08 19:45:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute int32_t osPid; */
|
|
|
|
NS_IMETHODIMP
|
2019-05-08 23:47:18 +03:00
|
|
|
BrowserHost::GetOsPid(int32_t* aOsPid) {
|
2019-05-15 20:34:14 +03:00
|
|
|
if (!mRoot) {
|
|
|
|
*aOsPid = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-05-08 23:47:18 +03:00
|
|
|
*aOsPid = GetContentParent()->Pid();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-05-08 19:45:23 +03:00
|
|
|
|
|
|
|
/* readonly attribute boolean hasPresented; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
BrowserHost::GetHasPresented(bool* aHasPresented) {
|
2019-05-15 20:34:14 +03:00
|
|
|
if (!mRoot) {
|
|
|
|
*aHasPresented = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-05-08 23:47:18 +03:00
|
|
|
*aHasPresented = mRoot->GetHasPresented();
|
|
|
|
return NS_OK;
|
2019-05-08 19:45:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void transmitPermissionsForPrincipal (in nsIPrincipal aPrincipal); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
BrowserHost::TransmitPermissionsForPrincipal(nsIPrincipal* aPrincipal) {
|
2019-05-15 20:34:14 +03:00
|
|
|
if (!mRoot) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-05-08 23:47:18 +03:00
|
|
|
return GetContentParent()->TransmitPermissionsForPrincipal(aPrincipal);
|
2019-05-08 19:45:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* boolean startApzAutoscroll (in float aAnchorX, in float aAnchorY, in nsViewID
|
|
|
|
* aScrollId, in uint32_t aPresShellId); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
BrowserHost::StartApzAutoscroll(float aAnchorX, float aAnchorY,
|
|
|
|
nsViewID aScrollId, uint32_t aPresShellId,
|
|
|
|
bool* _retval) {
|
2019-05-15 20:34:14 +03:00
|
|
|
if (!mRoot) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-05-08 23:47:18 +03:00
|
|
|
*_retval =
|
|
|
|
mRoot->StartApzAutoscroll(aAnchorX, aAnchorY, aScrollId, aPresShellId);
|
|
|
|
return NS_OK;
|
2019-05-08 19:45:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void stopApzAutoscroll (in nsViewID aScrollId, in uint32_t aPresShellId); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
BrowserHost::StopApzAutoscroll(nsViewID aScrollId, uint32_t aPresShellId) {
|
2019-05-15 20:34:14 +03:00
|
|
|
if (!mRoot) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-05-08 23:47:18 +03:00
|
|
|
mRoot->StopApzAutoscroll(aScrollId, aPresShellId);
|
|
|
|
return NS_OK;
|
2019-05-08 19:45:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
BrowserHost::MaybeCancelContentJSExecutionFromScript(
|
|
|
|
nsIRemoteTab::NavigationType aNavigationType,
|
|
|
|
JS::Handle<JS::Value> aCancelContentJSOptions, JSContext* aCx) {
|
2019-06-04 19:19:27 +03:00
|
|
|
// 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()) {
|
2019-05-15 20:34:14 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-05-08 23:47:18 +03:00
|
|
|
dom::CancelContentJSOptions cancelContentJSOptions;
|
|
|
|
if (!cancelContentJSOptions.Init(aCx, aCancelContentJSOptions)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
if (StaticPrefs::dom_ipc_cancel_content_js_when_navigating()) {
|
|
|
|
GetContentParent()->CancelContentJSExecutionIfRunning(
|
|
|
|
mRoot, aNavigationType, cancelContentJSOptions);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2019-05-08 19:45:23 +03:00
|
|
|
}
|
|
|
|
|
2020-11-04 20:04:01 +03:00
|
|
|
} // namespace mozilla::dom
|