gecko-dev/dom/ipc/RemoteFrameChild.cpp
Ryan Hunt f83e394596 Bug 1500257 part 5 - Implement messages for loading and displaying remote subframes on PRemoteFrame. r=qdot
This commit hooks up the pieces of the PRemoteFrame protocol that
will proxy initialization, sizing, and display messages. The messages
chosen are just enough to start the frame and get an initial rendering.

Differential Revision: https://phabricator.services.mozilla.com/D17445

--HG--
extra : source : b68b732411e2e1e6851799262246bff70e6649da
extra : intermediate-source : c19bc81c4f43a5adba92184b2572c09c6c5a0680
2019-01-23 11:04:26 -06:00

88 lines
3.1 KiB
C++

/* -*- 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/RemoteFrameChild.h"
using namespace mozilla::ipc;
namespace mozilla {
namespace dom {
RemoteFrameChild::RemoteFrameChild(nsFrameLoader* aFrameLoader)
: mLayersId{0}, mIPCOpen(true), mFrameLoader(aFrameLoader) {}
RemoteFrameChild::~RemoteFrameChild() {}
already_AddRefed<RemoteFrameChild> RemoteFrameChild::Create(
nsFrameLoader* aFrameLoader, const TabContext& aContext,
const nsString& aRemoteType) {
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);
RefPtr<RemoteFrameChild> remoteFrame = new RemoteFrameChild(aFrameLoader);
// Reference is freed in TabChild::DeallocPRemoteFrameChild.
tabChild->SendPRemoteFrameConstructor(
do_AddRef(remoteFrame).take(),
PromiseFlatString(aContext.PresentationURL()), aRemoteType);
remoteFrame->mIPCOpen = true;
return remoteFrame.forget();
}
void RemoteFrameChild::UpdateDimensions(const nsIntRect& aRect,
const mozilla::ScreenIntSize& aSize) {
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);
}
IPCResult RemoteFrameChild::RecvSetLayersId(
const mozilla::layers::LayersId& aLayersId) {
MOZ_ASSERT(!mLayersId.IsValid() && aLayersId.IsValid());
mLayersId = aLayersId;
return IPC_OK();
}
void RemoteFrameChild::ActorDestroy(ActorDestroyReason aWhy) {
mIPCOpen = false;
}
} // namespace dom
} // namespace mozilla