2019-01-23 19:38:09 +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/. */
|
|
|
|
|
2019-03-05 05:15:58 +03:00
|
|
|
#include "mozilla/dom/BrowserBridgeParent.h"
|
2019-01-23 19:38:09 +03:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
|
|
|
#include "mozilla/dom/ContentProcessManager.h"
|
2019-03-14 21:50:45 +03:00
|
|
|
#include "mozilla/dom/CanonicalBrowsingContext.h"
|
|
|
|
#include "mozilla/dom/BrowsingContextGroup.h"
|
2019-01-23 19:38:09 +03:00
|
|
|
|
|
|
|
using namespace mozilla::ipc;
|
|
|
|
using namespace mozilla::layout;
|
2019-03-05 05:15:58 +03:00
|
|
|
using namespace mozilla::hal;
|
2019-01-23 19:38:09 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2019-03-05 05:15:58 +03:00
|
|
|
BrowserBridgeParent::BrowserBridgeParent() : mIPCOpen(false) {}
|
2019-01-23 19:38:09 +03:00
|
|
|
|
2019-04-17 03:52:53 +03:00
|
|
|
BrowserBridgeParent::~BrowserBridgeParent() { Destroy(); }
|
2019-01-23 19:38:09 +03:00
|
|
|
|
2019-03-05 05:15:58 +03:00
|
|
|
nsresult BrowserBridgeParent::Init(const nsString& aPresentationURL,
|
2019-03-14 21:50:47 +03:00
|
|
|
const nsString& aRemoteType,
|
2019-04-09 00:22:58 +03:00
|
|
|
CanonicalBrowsingContext* aBrowsingContext,
|
|
|
|
const uint32_t& aChromeFlags) {
|
2019-01-23 19:40:08 +03:00
|
|
|
mIPCOpen = true;
|
|
|
|
|
|
|
|
// FIXME: This should actually use a non-bogus TabContext, probably inherited
|
|
|
|
// from our Manager().
|
|
|
|
OriginAttributes attrs;
|
|
|
|
attrs.mInIsolatedMozBrowser = false;
|
|
|
|
attrs.SyncAttributesWithPrivateBrowsing(false);
|
|
|
|
MutableTabContext tabContext;
|
|
|
|
tabContext.SetTabContext(false, 0, UIStateChangeType_Set,
|
|
|
|
UIStateChangeType_Set, attrs, aPresentationURL);
|
|
|
|
|
|
|
|
ProcessPriority initialPriority = PROCESS_PRIORITY_FOREGROUND;
|
|
|
|
|
|
|
|
// Get our ConstructorSender object.
|
2019-02-25 23:04:47 +03:00
|
|
|
RefPtr<ContentParent> constructorSender =
|
2019-01-23 19:40:08 +03:00
|
|
|
ContentParent::GetNewOrUsedBrowserProcess(
|
|
|
|
nullptr, aRemoteType, initialPriority, nullptr, false);
|
|
|
|
if (NS_WARN_IF(!constructorSender)) {
|
|
|
|
MOZ_ASSERT(false, "Unable to allocate content process!");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2019-03-14 21:50:45 +03:00
|
|
|
// Ensure that our content process is subscribed to our newly created
|
|
|
|
// BrowsingContextGroup.
|
2019-03-14 21:50:47 +03:00
|
|
|
aBrowsingContext->Group()->EnsureSubscribed(constructorSender);
|
|
|
|
aBrowsingContext->SetOwnerProcessId(constructorSender->ChildID());
|
2019-03-14 21:50:45 +03:00
|
|
|
|
2019-01-23 19:40:08 +03:00
|
|
|
ContentProcessManager* cpm = ContentProcessManager::GetSingleton();
|
|
|
|
TabId tabId(nsContentUtils::GenerateTabId());
|
|
|
|
cpm->RegisterRemoteFrame(tabId, ContentParentId(0), TabId(0),
|
|
|
|
tabContext.AsIPCTabContext(),
|
|
|
|
constructorSender->ChildID());
|
|
|
|
|
2019-04-10 00:38:15 +03:00
|
|
|
// Construct the BrowserParent object for our subframe.
|
|
|
|
RefPtr<BrowserParent> browserParent(
|
|
|
|
new BrowserParent(constructorSender, tabId, tabContext, aBrowsingContext,
|
|
|
|
aChromeFlags, this));
|
2019-01-23 19:40:08 +03:00
|
|
|
|
2019-04-17 03:51:38 +03:00
|
|
|
// Open a remote endpoint for our PBrowser actor. DeallocPBrowserParent
|
|
|
|
// releases the ref taken.
|
|
|
|
ManagedEndpoint<PBrowserChild> childEp =
|
2019-04-10 00:38:15 +03:00
|
|
|
constructorSender->OpenPBrowserEndpoint(do_AddRef(browserParent).take());
|
2019-04-17 03:51:38 +03:00
|
|
|
if (NS_WARN_IF(!childEp.IsValid())) {
|
|
|
|
MOZ_ASSERT(false, "Browser Open Endpoint Failed");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tell the content process to set up its PBrowserChild.
|
|
|
|
bool ok = constructorSender->SendConstructBrowser(
|
|
|
|
std::move(childEp), tabId, TabId(0), tabContext.AsIPCTabContext(),
|
|
|
|
aBrowsingContext, aChromeFlags, constructorSender->ChildID(),
|
2019-01-23 19:40:08 +03:00
|
|
|
constructorSender->IsForBrowser());
|
2019-04-17 03:51:38 +03:00
|
|
|
if (NS_WARN_IF(!ok)) {
|
2019-01-23 19:40:08 +03:00
|
|
|
MOZ_ASSERT(false, "Browser Constructor Failed");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2019-04-10 00:38:15 +03:00
|
|
|
// Set our BrowserParent object to the newly created browser.
|
|
|
|
mBrowserParent = browserParent.forget();
|
|
|
|
mBrowserParent->SetOwnerElement(Manager()->GetOwnerElement());
|
|
|
|
mBrowserParent->InitRendering();
|
2019-01-23 19:40:08 +03:00
|
|
|
|
2019-04-10 00:38:15 +03:00
|
|
|
RenderFrame* rf = mBrowserParent->GetRenderFrame();
|
2019-01-23 20:04:26 +03:00
|
|
|
if (NS_WARN_IF(!rf)) {
|
|
|
|
MOZ_ASSERT(false, "No RenderFrame");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send the newly created layers ID back into content.
|
|
|
|
Unused << SendSetLayersId(rf->GetLayersId());
|
2019-01-23 19:38:09 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-04-17 03:52:53 +03:00
|
|
|
void BrowserBridgeParent::Destroy() {
|
2019-04-10 00:38:15 +03:00
|
|
|
if (mBrowserParent) {
|
|
|
|
mBrowserParent->Destroy();
|
|
|
|
mBrowserParent = nullptr;
|
2019-04-17 03:52:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-05 05:15:58 +03:00
|
|
|
IPCResult BrowserBridgeParent::RecvShow(const ScreenIntSize& aSize,
|
|
|
|
const bool& aParentIsActive,
|
|
|
|
const nsSizeMode& aSizeMode) {
|
2019-04-10 00:38:15 +03:00
|
|
|
RenderFrame* rf = mBrowserParent->GetRenderFrame();
|
2019-01-23 20:04:26 +03:00
|
|
|
if (!rf->AttachLayerManager()) {
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
|
|
|
|
2019-04-10 00:38:15 +03:00
|
|
|
Unused << mBrowserParent->SendShow(aSize, mBrowserParent->GetShowInfo(),
|
|
|
|
aParentIsActive, aSizeMode);
|
2019-01-23 20:04:26 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-03-05 05:15:58 +03:00
|
|
|
IPCResult BrowserBridgeParent::RecvLoadURL(const nsCString& aUrl) {
|
2019-04-10 00:38:15 +03:00
|
|
|
Unused << mBrowserParent->SendLoadURL(aUrl, mBrowserParent->GetShowInfo());
|
2019-01-23 20:04:26 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-04-17 03:53:28 +03:00
|
|
|
IPCResult BrowserBridgeParent::RecvResumeLoad(uint64_t aPendingSwitchID) {
|
2019-04-10 00:38:15 +03:00
|
|
|
mBrowserParent->ResumeLoad(aPendingSwitchID);
|
2019-04-17 03:53:28 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-03-05 05:15:58 +03:00
|
|
|
IPCResult BrowserBridgeParent::RecvUpdateDimensions(
|
2019-01-23 20:04:26 +03:00
|
|
|
const DimensionInfo& aDimensions) {
|
2019-04-10 00:38:15 +03:00
|
|
|
Unused << mBrowserParent->SendUpdateDimensions(aDimensions);
|
2019-01-23 20:04:26 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-03-05 05:15:58 +03:00
|
|
|
IPCResult BrowserBridgeParent::RecvRenderLayers(
|
2019-01-23 20:04:26 +03:00
|
|
|
const bool& aEnabled, const bool& aForceRepaint,
|
|
|
|
const layers::LayersObserverEpoch& aEpoch) {
|
2019-04-10 00:38:15 +03:00
|
|
|
Unused << mBrowserParent->SendRenderLayers(aEnabled, aForceRepaint, aEpoch);
|
2019-01-23 20:04:26 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-03-05 05:15:58 +03:00
|
|
|
IPCResult BrowserBridgeParent::RecvNavigateByKey(
|
2019-03-05 22:33:09 +03:00
|
|
|
const bool& aForward, const bool& aForDocumentNavigation) {
|
2019-04-10 00:38:15 +03:00
|
|
|
Unused << mBrowserParent->SendNavigateByKey(aForward, aForDocumentNavigation);
|
2019-03-05 22:33:09 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-03-05 05:15:58 +03:00
|
|
|
IPCResult BrowserBridgeParent::RecvActivate() {
|
2019-04-10 00:38:15 +03:00
|
|
|
mBrowserParent->Activate();
|
2019-03-05 22:33:52 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-03-14 19:00:32 +03:00
|
|
|
IPCResult BrowserBridgeParent::RecvDeactivate() {
|
2019-04-10 00:38:15 +03:00
|
|
|
mBrowserParent->Deactivate();
|
2019-03-14 19:00:32 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-03-05 05:15:58 +03:00
|
|
|
void BrowserBridgeParent::ActorDestroy(ActorDestroyReason aWhy) {
|
2019-01-23 19:38:09 +03:00
|
|
|
mIPCOpen = false;
|
2019-04-17 03:52:53 +03:00
|
|
|
Destroy();
|
2019-01-23 19:38:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|