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/BrowserBridgeChild.h"
|
2019-03-14 21:50:47 +03:00
|
|
|
#include "mozilla/dom/BrowsingContext.h"
|
2019-03-14 19:20:51 +03:00
|
|
|
#include "nsFocusManager.h"
|
2019-03-05 05:15:58 +03:00
|
|
|
#include "nsFrameLoader.h"
|
2019-03-05 22:33:09 +03:00
|
|
|
#include "nsFrameLoaderOwner.h"
|
2019-03-05 05:15:58 +03:00
|
|
|
#include "nsQueryObject.h"
|
2019-03-05 22:33:09 +03:00
|
|
|
|
2019-01-23 19:38:09 +03:00
|
|
|
using namespace mozilla::ipc;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2019-03-14 21:50:47 +03:00
|
|
|
BrowserBridgeChild::BrowserBridgeChild(nsFrameLoader* aFrameLoader,
|
|
|
|
BrowsingContext* aBrowsingContext)
|
|
|
|
: mLayersId{0},
|
|
|
|
mIPCOpen(true),
|
|
|
|
mFrameLoader(aFrameLoader),
|
|
|
|
mBrowsingContext(aBrowsingContext) {}
|
2019-01-23 19:38:09 +03:00
|
|
|
|
2019-03-05 05:15:58 +03:00
|
|
|
BrowserBridgeChild::~BrowserBridgeChild() {}
|
2019-01-23 19:38:09 +03:00
|
|
|
|
2019-03-05 05:15:58 +03:00
|
|
|
already_AddRefed<BrowserBridgeChild> BrowserBridgeChild::Create(
|
2019-01-23 19:38:09 +03:00
|
|
|
nsFrameLoader* aFrameLoader, const TabContext& aContext,
|
2019-03-14 21:50:47 +03:00
|
|
|
const nsString& aRemoteType, BrowsingContext* aBrowsingContext) {
|
2019-01-23 19:38:09 +03:00
|
|
|
MOZ_ASSERT(XRE_IsContentProcess());
|
|
|
|
|
|
|
|
// Determine our embedder's TabChild actor.
|
|
|
|
RefPtr<Element> owner = aFrameLoader->GetOwnerContent();
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(owner);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShell> docShell = do_GetInterface(owner->GetOwnerGlobal());
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(docShell);
|
|
|
|
|
|
|
|
RefPtr<TabChild> tabChild = TabChild::GetFrom(docShell);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(tabChild);
|
|
|
|
|
2019-03-05 05:15:58 +03:00
|
|
|
RefPtr<BrowserBridgeChild> browserBridge =
|
2019-03-14 21:50:47 +03:00
|
|
|
new BrowserBridgeChild(aFrameLoader, aBrowsingContext);
|
2019-03-05 05:15:58 +03:00
|
|
|
// Reference is freed in TabChild::DeallocPBrowserBridgeChild.
|
|
|
|
tabChild->SendPBrowserBridgeConstructor(
|
|
|
|
do_AddRef(browserBridge).take(),
|
2019-03-14 21:50:47 +03:00
|
|
|
PromiseFlatString(aContext.PresentationURL()), aRemoteType,
|
|
|
|
aBrowsingContext);
|
2019-03-05 05:15:58 +03:00
|
|
|
browserBridge->mIPCOpen = true;
|
2019-01-23 19:38:09 +03:00
|
|
|
|
2019-03-05 05:15:58 +03:00
|
|
|
return browserBridge.forget();
|
2019-01-23 19:38:09 +03:00
|
|
|
}
|
|
|
|
|
2019-03-05 05:15:58 +03:00
|
|
|
void BrowserBridgeChild::UpdateDimensions(const nsIntRect& aRect,
|
|
|
|
const mozilla::ScreenIntSize& aSize) {
|
2019-01-23 20:04:26 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mIPCOpen);
|
|
|
|
|
|
|
|
RefPtr<Element> owner = mFrameLoader->GetOwnerContent();
|
|
|
|
nsCOMPtr<nsIWidget> widget = nsContentUtils::WidgetForContent(owner);
|
|
|
|
if (!widget) {
|
|
|
|
widget = nsContentUtils::WidgetForDocument(owner->OwnerDoc());
|
|
|
|
}
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(widget);
|
|
|
|
|
|
|
|
CSSToLayoutDeviceScale widgetScale = widget->GetDefaultScale();
|
|
|
|
|
|
|
|
LayoutDeviceIntRect devicePixelRect = ViewAs<LayoutDevicePixel>(
|
|
|
|
aRect, PixelCastJustification::LayoutDeviceIsScreenForTabDims);
|
|
|
|
LayoutDeviceIntSize devicePixelSize = ViewAs<LayoutDevicePixel>(
|
|
|
|
aSize, PixelCastJustification::LayoutDeviceIsScreenForTabDims);
|
|
|
|
|
|
|
|
// XXX What are clientOffset and chromeOffset used for? Are they meaningful
|
|
|
|
// for nested iframes with transforms?
|
|
|
|
LayoutDeviceIntPoint clientOffset;
|
|
|
|
LayoutDeviceIntPoint chromeOffset;
|
|
|
|
|
|
|
|
CSSRect unscaledRect = devicePixelRect / widgetScale;
|
|
|
|
CSSSize unscaledSize = devicePixelSize / widgetScale;
|
|
|
|
hal::ScreenOrientation orientation = hal::eScreenOrientation_Default;
|
|
|
|
DimensionInfo di(unscaledRect, unscaledSize, orientation, clientOffset,
|
|
|
|
chromeOffset);
|
|
|
|
|
|
|
|
Unused << SendUpdateDimensions(di);
|
|
|
|
}
|
|
|
|
|
2019-03-05 05:15:58 +03:00
|
|
|
void BrowserBridgeChild::NavigateByKey(bool aForward,
|
|
|
|
bool aForDocumentNavigation) {
|
2019-03-05 22:33:09 +03:00
|
|
|
Unused << SendNavigateByKey(aForward, aForDocumentNavigation);
|
|
|
|
}
|
|
|
|
|
2019-03-05 05:15:58 +03:00
|
|
|
void BrowserBridgeChild::Activate() { Unused << SendActivate(); }
|
2019-03-05 22:33:52 +03:00
|
|
|
|
2019-03-14 19:00:32 +03:00
|
|
|
void BrowserBridgeChild::Deactivate() { Unused << SendDeactivate(); }
|
|
|
|
|
2019-03-05 22:33:09 +03:00
|
|
|
/*static*/
|
2019-03-05 05:15:58 +03:00
|
|
|
BrowserBridgeChild* BrowserBridgeChild::GetFrom(nsFrameLoader* aFrameLoader) {
|
2019-03-05 22:33:09 +03:00
|
|
|
if (!aFrameLoader) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2019-03-05 05:15:58 +03:00
|
|
|
return aFrameLoader->GetBrowserBridgeChild();
|
2019-03-05 22:33:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/
|
2019-03-05 05:15:58 +03:00
|
|
|
BrowserBridgeChild* BrowserBridgeChild::GetFrom(nsIContent* aContent) {
|
2019-03-05 22:33:09 +03:00
|
|
|
RefPtr<nsFrameLoaderOwner> loaderOwner = do_QueryObject(aContent);
|
|
|
|
if (!loaderOwner) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
RefPtr<nsFrameLoader> frameLoader = loaderOwner->GetFrameLoader();
|
|
|
|
return GetFrom(frameLoader);
|
|
|
|
}
|
|
|
|
|
2019-03-05 05:15:58 +03:00
|
|
|
IPCResult BrowserBridgeChild::RecvSetLayersId(
|
2019-01-23 20:04:26 +03:00
|
|
|
const mozilla::layers::LayersId& aLayersId) {
|
|
|
|
MOZ_ASSERT(!mLayersId.IsValid() && aLayersId.IsValid());
|
|
|
|
mLayersId = aLayersId;
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-03-14 19:20:51 +03:00
|
|
|
mozilla::ipc::IPCResult BrowserBridgeChild::RecvRequestFocus(
|
|
|
|
const bool& aCanRaise) {
|
|
|
|
// Adapted from TabParent
|
|
|
|
nsCOMPtr<nsIFocusManager> fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (!fm) {
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<Element> owner = mFrameLoader->GetOwnerContent();
|
|
|
|
|
|
|
|
if (!owner || !owner->OwnerDoc()) {
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t flags = nsIFocusManager::FLAG_NOSCROLL;
|
|
|
|
if (aCanRaise) {
|
|
|
|
flags |= nsIFocusManager::FLAG_RAISE;
|
|
|
|
}
|
|
|
|
|
|
|
|
fm->SetFocus(owner, flags);
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-03-14 19:25:33 +03:00
|
|
|
mozilla::ipc::IPCResult BrowserBridgeChild::RecvMoveFocus(
|
|
|
|
const bool& aForward, const bool& aForDocumentNavigation) {
|
|
|
|
// Adapted from TabParent
|
|
|
|
nsCOMPtr<nsIFocusManager> fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (!fm) {
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<Element> owner = mFrameLoader->GetOwnerContent();
|
|
|
|
|
|
|
|
if (!owner || !owner->OwnerDoc()) {
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<Element> dummy;
|
|
|
|
|
|
|
|
uint32_t type =
|
|
|
|
aForward
|
|
|
|
? (aForDocumentNavigation
|
|
|
|
? static_cast<uint32_t>(nsIFocusManager::MOVEFOCUS_FORWARDDOC)
|
|
|
|
: static_cast<uint32_t>(nsIFocusManager::MOVEFOCUS_FORWARD))
|
|
|
|
: (aForDocumentNavigation
|
|
|
|
? static_cast<uint32_t>(nsIFocusManager::MOVEFOCUS_BACKWARDDOC)
|
|
|
|
: static_cast<uint32_t>(nsIFocusManager::MOVEFOCUS_BACKWARD));
|
|
|
|
fm->MoveFocus(nullptr, owner, type, nsIFocusManager::FLAG_BYKEY,
|
|
|
|
getter_AddRefs(dummy));
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2019-03-05 05:15:58 +03:00
|
|
|
void BrowserBridgeChild::ActorDestroy(ActorDestroyReason aWhy) {
|
2019-01-23 19:38:09 +03:00
|
|
|
mIPCOpen = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|