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"
|
|
|
|
#include "mozilla/dom/WindowGlobalParent.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
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
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION(BrowserHost, mRoot)
|
|
|
|
|
|
|
|
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-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();
|
|
|
|
}
|
|
|
|
|
2019-05-08 19:27:49 +03:00
|
|
|
void BrowserHost::LoadURL(nsIURI* aURI) { mRoot->LoadURL(aURI); }
|
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();
|
|
|
|
mRoot = nullptr;
|
|
|
|
}
|
2019-05-07 00:04:34 +03:00
|
|
|
|
|
|
|
bool BrowserHost::Show(const ScreenIntSize& aSize, bool aParentIsActive) {
|
2019-05-08 19:27:49 +03:00
|
|
|
return mRoot->Show(aSize, aParentIsActive);
|
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 forceRepaint (); */
|
|
|
|
NS_IMETHODIMP
|
2019-05-08 23:47:18 +03:00
|
|
|
BrowserHost::ForceRepaint(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->ForceRepaint(); });
|
2019-05-08 23:47:18 +03:00
|
|
|
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 hasContentOpener; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
BrowserHost::GetHasContentOpener(bool* aHasContentOpener) {
|
2019-05-15 20:34:14 +03:00
|
|
|
if (!mRoot) {
|
|
|
|
*aHasContentOpener = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-05-08 23:47:18 +03:00
|
|
|
*aHasContentOpener = mRoot->GetHasContentOpener();
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute boolean hasBeforeUnload; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
BrowserHost::GetHasBeforeUnload(bool* aHasBeforeUnload) {
|
2019-05-15 20:34:14 +03:00
|
|
|
if (!mRoot) {
|
|
|
|
*aHasBeforeUnload = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-05-30 22:01:29 +03:00
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
VisitAll([&result](BrowserParent* aBrowserParent) {
|
|
|
|
result |= aBrowserParent->GetHasBeforeUnload();
|
|
|
|
});
|
|
|
|
|
|
|
|
*aHasBeforeUnload = result;
|
2019-05-08 23:47:18 +03:00
|
|
|
return NS_OK;
|
2019-05-08 19:45:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* readonly attribute Element ownerElement; */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
BrowserHost::GetOwnerElement(mozilla::dom::Element** aOwnerElement) {
|
2019-05-15 20:34:14 +03:00
|
|
|
if (!mRoot) {
|
|
|
|
*aOwnerElement = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-05-08 19:45:23 +03:00
|
|
|
*aOwnerElement = mRoot->GetOwnerElement();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
|
|
}
|
|
|
|
|
|
|
|
/* bool saveRecording (in AString aFileName); */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
BrowserHost::SaveRecording(const nsAString& aFileName, bool* _retval) {
|
2019-05-15 20:34:14 +03:00
|
|
|
if (!mRoot) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-05-08 23:47:18 +03:00
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
nsresult rv = NS_NewLocalFile(aFileName, false, getter_AddRefs(file));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return GetContentParent()->SaveRecording(file, _retval);
|
2019-05-08 19:45:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Promise getContentBlockingLog (); */
|
|
|
|
NS_IMETHODIMP
|
2019-05-08 23:47:18 +03:00
|
|
|
BrowserHost::GetContentBlockingLog(::mozilla::dom::Promise** aPromise) {
|
2019-05-15 20:34:14 +03:00
|
|
|
if (!mRoot) {
|
|
|
|
*aPromise = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2019-05-08 23:47:18 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aPromise);
|
|
|
|
|
|
|
|
*aPromise = nullptr;
|
|
|
|
if (!mRoot->GetOwnerElement()) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ErrorResult rv;
|
|
|
|
RefPtr<Promise> jsPromise = Promise::Create(
|
|
|
|
mRoot->GetOwnerElement()->OwnerDoc()->GetOwnerGlobal(), rv);
|
|
|
|
if (rv.Failed()) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<Promise> copy(jsPromise);
|
|
|
|
copy.forget(aPromise);
|
|
|
|
|
|
|
|
auto cblPromise = mRoot->SendGetContentBlockingLog();
|
|
|
|
cblPromise->Then(
|
|
|
|
GetMainThreadSerialEventTarget(), __func__,
|
|
|
|
[jsPromise](Tuple<nsCString, bool>&& aResult) {
|
|
|
|
if (Get<1>(aResult)) {
|
|
|
|
NS_ConvertUTF8toUTF16 utf16(Get<0>(aResult));
|
|
|
|
jsPromise->MaybeResolve(std::move(utf16));
|
|
|
|
} else {
|
|
|
|
jsPromise->MaybeRejectWithUndefined();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[jsPromise](ResponseRejectReason&& aReason) {
|
|
|
|
jsPromise->MaybeRejectWithUndefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-05-07 00:04:34 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|