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-03-28 21:54:28 +03:00
|
|
|
BrowserBridgeParent::~BrowserBridgeParent() {
|
|
|
|
if (mTabParent) {
|
|
|
|
mTabParent->mBrowserBridgeParent = nullptr;
|
|
|
|
}
|
|
|
|
}
|
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.mAppId = nsIScriptSecurityManager::NO_APP_ID;
|
|
|
|
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());
|
|
|
|
|
|
|
|
// Construct the TabParent object for our subframe.
|
2019-03-14 21:50:45 +03:00
|
|
|
RefPtr<TabParent> tabParent(new TabParent(constructorSender, tabId,
|
2019-03-14 21:50:47 +03:00
|
|
|
tabContext, aBrowsingContext,
|
2019-04-09 00:22:58 +03:00
|
|
|
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 =
|
|
|
|
constructorSender->OpenPBrowserEndpoint(do_AddRef(tabParent).take());
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set our TabParent object to the newly created browser.
|
2019-04-17 03:51:38 +03:00
|
|
|
mTabParent = tabParent.forget();
|
2019-01-23 19:40:08 +03:00
|
|
|
mTabParent->SetOwnerElement(Manager()->GetOwnerElement());
|
|
|
|
mTabParent->InitRendering();
|
|
|
|
|
2019-01-23 20:04:26 +03:00
|
|
|
RenderFrame* rf = mTabParent->GetRenderFrame();
|
|
|
|
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-03-05 05:15:58 +03:00
|
|
|
IPCResult BrowserBridgeParent::RecvShow(const ScreenIntSize& aSize,
|
|
|
|
const bool& aParentIsActive,
|
|
|
|
const nsSizeMode& aSizeMode) {
|
2019-01-23 20:04:26 +03:00
|
|
|
RenderFrame* rf = mTabParent->GetRenderFrame();
|
|
|
|
if (!rf->AttachLayerManager()) {
|
|
|
|
MOZ_CRASH();
|
|
|
|
}
|
|
|
|
|
|
|
|
Unused << mTabParent->SendShow(aSize, mTabParent->GetShowInfo(),
|
|
|
|
aParentIsActive, aSizeMode);
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-03-05 05:15:58 +03:00
|
|
|
IPCResult BrowserBridgeParent::RecvLoadURL(const nsCString& aUrl) {
|
2019-01-23 20:04:26 +03:00
|
|
|
Unused << mTabParent->SendLoadURL(aUrl, mTabParent->GetShowInfo());
|
|
|
|
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) {
|
|
|
|
Unused << mTabParent->SendUpdateDimensions(aDimensions);
|
|
|
|
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) {
|
|
|
|
Unused << mTabParent->SendRenderLayers(aEnabled, aForceRepaint, aEpoch);
|
|
|
|
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) {
|
|
|
|
Unused << mTabParent->SendNavigateByKey(aForward, aForDocumentNavigation);
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-03-05 05:15:58 +03:00
|
|
|
IPCResult BrowserBridgeParent::RecvActivate() {
|
2019-03-05 22:33:52 +03:00
|
|
|
mTabParent->Activate();
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-03-14 19:00:32 +03:00
|
|
|
IPCResult BrowserBridgeParent::RecvDeactivate() {
|
|
|
|
mTabParent->Deactivate();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|