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-05-24 22:23:18 +03:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
# include "mozilla/a11y/DocAccessibleParent.h"
|
|
|
|
#endif
|
2019-03-05 05:15:58 +03:00
|
|
|
#include "mozilla/dom/BrowserBridgeParent.h"
|
2019-05-07 19:07:47 +03:00
|
|
|
#include "mozilla/dom/BrowserParent.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-05-06 11:12:21 +03:00
|
|
|
#include "mozilla/layers/InputAPZContext.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-05-24 22:23:18 +03:00
|
|
|
BrowserBridgeParent::BrowserBridgeParent()
|
2019-05-30 17:49:40 +03:00
|
|
|
:
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
mEmbedderAccessibleID(0),
|
|
|
|
#endif
|
|
|
|
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.
|
2019-05-15 18:34:03 +03:00
|
|
|
RefPtr<BrowserParent> browserParent(new BrowserParent(
|
|
|
|
constructorSender, tabId, tabContext, aBrowsingContext, aChromeFlags));
|
|
|
|
browserParent->SetBrowserBridgeParent(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-05-07 19:07:47 +03:00
|
|
|
CanonicalBrowsingContext* BrowserBridgeParent::GetBrowsingContext() {
|
|
|
|
return mBrowserParent->GetBrowsingContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
BrowserParent* BrowserBridgeParent::Manager() {
|
|
|
|
MOZ_ASSERT(mIPCOpen);
|
|
|
|
return static_cast<BrowserParent*>(PBrowserBridgeParent::Manager());
|
|
|
|
}
|
|
|
|
|
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-05-15 23:26:25 +03:00
|
|
|
IPCResult BrowserBridgeParent::RecvUpdateEffects(const EffectsInfo& aEffects) {
|
|
|
|
Unused << mBrowserParent->SendUpdateEffects(aEffects);
|
|
|
|
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-05-06 11:12:21 +03:00
|
|
|
IPCResult BrowserBridgeParent::RecvDispatchSynthesizedMouseEvent(
|
|
|
|
const WidgetMouseEvent& aEvent) {
|
|
|
|
if (aEvent.mMessage != eMouseMove ||
|
|
|
|
aEvent.mReason != WidgetMouseEvent::eSynthesized) {
|
|
|
|
return IPC_FAIL(this, "Unexpected event type");
|
|
|
|
}
|
|
|
|
|
|
|
|
WidgetMouseEvent event = aEvent;
|
|
|
|
// Convert mRefPoint from the dispatching child process coordinate space
|
|
|
|
// to the parent coordinate space. The SendRealMouseEvent call will convert
|
|
|
|
// it into the dispatchee child process coordinate space
|
|
|
|
event.mRefPoint = Manager()->TransformChildToParent(event.mRefPoint);
|
|
|
|
// We need to set up an InputAPZContext on the stack because
|
|
|
|
// BrowserParent::SendRealMouseEvent requires one. But the only thing in
|
|
|
|
// that context that is actually used in this scenario is the layers id,
|
|
|
|
// and we already have that on the mouse event.
|
|
|
|
layers::InputAPZContext context(
|
|
|
|
layers::ScrollableLayerGuid(event.mLayersId, 0,
|
|
|
|
layers::ScrollableLayerGuid::NULL_SCROLL_ID),
|
|
|
|
0, nsEventStatus_eIgnore);
|
|
|
|
mBrowserParent->SendRealMouseEvent(event);
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-04-04 01:40:28 +03:00
|
|
|
IPCResult BrowserBridgeParent::RecvSkipBrowsingContextDetach() {
|
|
|
|
mBrowserParent->SkipBrowsingContextDetach();
|
|
|
|
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-05-27 18:09:53 +03:00
|
|
|
IPCResult BrowserBridgeParent::RecvDeactivate() {
|
|
|
|
mBrowserParent->Deactivate();
|
2019-03-14 19:00:32 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-05-13 04:49:07 +03:00
|
|
|
IPCResult BrowserBridgeParent::RecvSetIsUnderHiddenEmbedderElement(
|
|
|
|
const bool& aIsUnderHiddenEmbedderElement) {
|
|
|
|
Unused << mBrowserParent->SendSetIsUnderHiddenEmbedderElement(
|
|
|
|
aIsUnderHiddenEmbedderElement);
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-05-24 22:23:18 +03:00
|
|
|
IPCResult BrowserBridgeParent::RecvSetEmbedderAccessible(
|
|
|
|
PDocAccessibleParent* aDoc, uint64_t aID) {
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
mEmbedderAccessibleDoc = static_cast<a11y::DocAccessibleParent*>(aDoc);
|
|
|
|
mEmbedderAccessibleID = aID;
|
|
|
|
#endif
|
|
|
|
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
|