Skip to content

Commit

Permalink
Bug 1542664 - Make TabChild use mozilla::PresShell directly rather th…
Browse files Browse the repository at this point in the history
…an via nsIPresShell r=nika

This patch makes `TabChild` use `mozilla::PresShell` directly.

Then, renames `TabChild::GetPresShell()` and `TabChild::GetDocument()` to
`TabChild::GetTopLevelPresShell()` and `TabChild::GetTopLevelDocument()` to
make what they do clearer (e.g., see the change in `PresShell.cpp`).

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

--HG--
extra : moz-landing-system : lando
  • Loading branch information
masayuki-nakano committed Apr 13, 2019
1 parent 3d93741 commit fdbbccd
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 45 deletions.
4 changes: 3 additions & 1 deletion dom/ipc/CoalescedMouseData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "CoalescedMouseData.h"
#include "TabChild.h"

#include "mozilla/PresShell.h"

using namespace mozilla;
using namespace mozilla::dom;

Expand Down Expand Up @@ -92,7 +94,7 @@ void CoalescedMouseMoveFlusher::RemoveObserver() {
}

nsRefreshDriver* CoalescedMouseMoveFlusher::GetRefreshDriver() {
nsCOMPtr<nsIPresShell> presShell = mTabChild->GetPresShell();
PresShell* presShell = mTabChild->GetTopLevelPresShell();
if (!presShell || !presShell->GetPresContext() ||
!presShell->GetPresContext()->RefreshDriver()) {
return nullptr;
Expand Down
3 changes: 2 additions & 1 deletion dom/ipc/ContentChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3054,7 +3054,8 @@ mozilla::ipc::IPCResult ContentChild::RecvPWebBrowserPersistDocumentConstructor(
if (NS_WARN_IF(!aBrowser)) {
return IPC_FAIL_NO_REASON(this);
}
nsCOMPtr<Document> rootDoc = static_cast<TabChild*>(aBrowser)->GetDocument();
nsCOMPtr<Document> rootDoc =
static_cast<TabChild*>(aBrowser)->GetTopLevelDocument();
nsCOMPtr<Document> foundDoc;
if (aOuterWindowID) {
foundDoc = nsContentUtils::GetSubdocumentWithOuterWindowId(rootDoc,
Expand Down
59 changes: 32 additions & 27 deletions dom/ipc/TabChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,17 @@ NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(TabChildBase)
NS_IMPL_CYCLE_COLLECTING_RELEASE(TabChildBase)

already_AddRefed<Document> TabChildBase::GetDocument() const {
already_AddRefed<Document> TabChildBase::GetTopLevelDocument() const {
nsCOMPtr<Document> doc;
WebNavigation()->GetDocument(getter_AddRefs(doc));
return doc.forget();
}

already_AddRefed<nsIPresShell> TabChildBase::GetPresShell() const {
nsCOMPtr<nsIPresShell> result;
if (nsCOMPtr<Document> doc = GetDocument()) {
result = doc->GetPresShell();
PresShell* TabChildBase::GetTopLevelPresShell() const {
if (RefPtr<Document> doc = GetTopLevelDocument()) {
return doc->GetPresShell();
}
return result.forget();
return nullptr;
}

void TabChildBase::DispatchMessageManagerMessage(const nsAString& aMessageName,
Expand Down Expand Up @@ -237,10 +236,10 @@ bool TabChildBase::UpdateFrameHandler(const RepaintRequest& aRequest) {
MOZ_ASSERT(aRequest.GetScrollId() != ScrollableLayerGuid::NULL_SCROLL_ID);

if (aRequest.IsRootContent()) {
if (nsCOMPtr<nsIPresShell> shell = GetPresShell()) {
if (PresShell* presShell = GetTopLevelPresShell()) {
// Guard against stale updates (updates meant for a pres shell which
// has since been torn down and destroyed).
if (aRequest.GetPresShellId() == shell->GetPresShellId()) {
if (aRequest.GetPresShellId() == presShell->GetPresShellId()) {
ProcessUpdateFrame(aRequest);
return true;
}
Expand Down Expand Up @@ -452,7 +451,7 @@ TabChild::Observe(nsISupports* aSubject, const char* aTopic,
if (!strcmp(aTopic, BEFORE_FIRST_PAINT)) {
if (AsyncPanZoomEnabled()) {
nsCOMPtr<Document> subject(do_QueryInterface(aSubject));
nsCOMPtr<Document> doc(GetDocument());
nsCOMPtr<Document> doc(GetTopLevelDocument());

if (subject == doc) {
RefPtr<PresShell> presShell = doc->GetPresShell();
Expand Down Expand Up @@ -1208,7 +1207,7 @@ mozilla::ipc::IPCResult TabChild::RecvSizeModeChanged(
if (!mPuppetWidget->IsVisible()) {
return IPC_OK();
}
nsCOMPtr<Document> document(GetDocument());
nsCOMPtr<Document> document(GetTopLevelDocument());
nsPresContext* presContext = document->GetPresContext();
if (presContext) {
presContext->SizeModeChanged(aSizeMode);
Expand All @@ -1229,8 +1228,8 @@ bool TabChild::UpdateFrame(const RepaintRequest& aRequest) {

mozilla::ipc::IPCResult TabChild::RecvSuppressDisplayport(
const bool& aEnabled) {
if (nsCOMPtr<nsIPresShell> shell = GetPresShell()) {
shell->SuppressDisplayport(aEnabled);
if (RefPtr<PresShell> presShell = GetTopLevelPresShell()) {
presShell->SuppressDisplayport(aEnabled);
}
return IPC_OK();
}
Expand All @@ -1249,7 +1248,7 @@ void TabChild::HandleDoubleTap(const CSSPoint& aPoint,

// Note: there is nothing to do with the modifiers here, as we are not
// synthesizing any sort of mouse event.
RefPtr<Document> document = GetDocument();
RefPtr<Document> document = GetTopLevelDocument();
CSSRect zoomToRect = CalculateRectToZoomTo(document, aPoint);
// The double-tap can be dispatched by any scroll frame (so |aGuid| could be
// the guid of any scroll frame), but the zoom-to-rect operation must be
Expand All @@ -1275,7 +1274,7 @@ mozilla::ipc::IPCResult TabChild::RecvHandleTap(
// to be refcounted. This function can run script, which may trigger a nested
// event loop, which may release this, so we hold a strong reference here.
RefPtr<TabChild> kungFuDeathGrip(this);
nsCOMPtr<nsIPresShell> presShell = GetPresShell();
PresShell* presShell = GetTopLevelPresShell();
if (!presShell) {
return IPC_OK();
}
Expand Down Expand Up @@ -1304,14 +1303,18 @@ mozilla::ipc::IPCResult TabChild::RecvHandleTap(
case GeckoContentController::TapType::eLongTap:
if (mTabChildMessageManager) {
RefPtr<APZEventState> eventState(mAPZEventState);
eventState->ProcessLongTap(presShell, point, scale, aModifiers, aGuid,
// XXX ProcessLongTap() requires nsCOMPtr<nsIPresShell&>.
nsCOMPtr<nsIPresShell> iPresShell = presShell;
eventState->ProcessLongTap(iPresShell, point, scale, aModifiers, aGuid,
aInputBlockId);
}
break;
case GeckoContentController::TapType::eLongTapUp:
if (mTabChildMessageManager) {
RefPtr<APZEventState> eventState(mAPZEventState);
eventState->ProcessLongTapUp(presShell, point, scale, aModifiers);
// XXX ProcessLongTapUp() requires nsCOMPtr<nsIPresShell&>.
nsCOMPtr<nsIPresShell> iPresShell = presShell;
eventState->ProcessLongTapUp(iPresShell, point, scale, aModifiers);
}
break;
}
Expand Down Expand Up @@ -1372,8 +1375,9 @@ mozilla::ipc::IPCResult TabChild::RecvActivate() {
// Ensure that the PresShell exists, otherwise focusing
// is definitely not going to work. GetPresShell should
// create a PresShell if one doesn't exist yet.
nsCOMPtr<nsIPresShell> presShell = GetPresShell();
RefPtr<PresShell> presShell = GetTopLevelPresShell();
MOZ_ASSERT(presShell);
Unused << presShell;

mWebBrowser->FocusActivate();
return IPC_OK();
Expand Down Expand Up @@ -1419,7 +1423,8 @@ mozilla::ipc::IPCResult TabChild::RecvMouseEvent(
// to be refcounted. This function can run script, which may trigger a nested
// event loop, which may release this, so we hold a strong reference here.
RefPtr<TabChild> kungFuDeathGrip(this);
nsCOMPtr<nsIPresShell> presShell(GetPresShell());
// XXX DispatchMouseEvent() requires nsCOMPtr<nsIPresShell>&.
nsCOMPtr<nsIPresShell> presShell = GetTopLevelPresShell();
APZCCallbackHelper::DispatchMouseEvent(
presShell, aType, CSSPoint(aX, aY), aButton, aClickCount, aModifiers,
aIgnoreRootScrollFrame, MouseEvent_Binding::MOZ_SOURCE_UNKNOWN,
Expand Down Expand Up @@ -1584,7 +1589,7 @@ void TabChild::HandleRealMouseButtonEvent(const WidgetMouseEvent& aEvent,
// notifications for them.
UniquePtr<DisplayportSetListener> postLayerization;
if (aInputBlockId && aEvent.mFlags.mHandledByAPZ) {
nsCOMPtr<Document> document(GetDocument());
nsCOMPtr<Document> document(GetTopLevelDocument());
postLayerization = APZCCallbackHelper::SendSetTargetAPZCNotification(
mPuppetWidget, document, aEvent, aGuid, aInputBlockId);
}
Expand Down Expand Up @@ -1676,7 +1681,7 @@ void TabChild::DispatchWheelEvent(const WidgetWheelEvent& aEvent,
const uint64_t& aInputBlockId) {
WidgetWheelEvent localEvent(aEvent);
if (aInputBlockId && aEvent.mFlags.mHandledByAPZ) {
nsCOMPtr<Document> document(GetDocument());
nsCOMPtr<Document> document(GetTopLevelDocument());
UniquePtr<DisplayportSetListener> postLayerization =
APZCCallbackHelper::SendSetTargetAPZCNotification(
mPuppetWidget, document, aEvent, aGuid, aInputBlockId);
Expand Down Expand Up @@ -1744,7 +1749,7 @@ mozilla::ipc::IPCResult TabChild::RecvRealTouchEvent(
mPuppetWidget->GetDefaultScale());

if (localEvent.mMessage == eTouchStart && AsyncPanZoomEnabled()) {
nsCOMPtr<Document> document = GetDocument();
nsCOMPtr<Document> document = GetTopLevelDocument();
if (gfxPrefs::TouchActionEnabled()) {
APZCCallbackHelper::SendSetAllowedTouchBehaviorNotification(
mPuppetWidget, document, localEvent, aInputBlockId,
Expand Down Expand Up @@ -2205,7 +2210,7 @@ mozilla::ipc::IPCResult TabChild::RecvSwappedWithOtherRemoteLoader(

mozilla::ipc::IPCResult TabChild::RecvHandleAccessKey(
const WidgetKeyboardEvent& aEvent, nsTArray<uint32_t>&& aCharCodes) {
nsCOMPtr<Document> document(GetDocument());
nsCOMPtr<Document> document(GetTopLevelDocument());
RefPtr<nsPresContext> pc = document->GetPresContext();
if (pc) {
if (!pc->EventStateManager()->HandleAccessKey(
Expand Down Expand Up @@ -2880,7 +2885,7 @@ nsTArray<RefPtr<TabChild>> TabChild::GetAll() {
return list;
}

TabChild* TabChild::GetFrom(nsIPresShell* aPresShell) {
TabChild* TabChild::GetFrom(PresShell* aPresShell) {
Document* doc = aPresShell->GetDocument();
if (!doc) {
return nullptr;
Expand Down Expand Up @@ -3002,7 +3007,7 @@ void TabChild::ReinitRendering() {
MOZ_ASSERT(lm);
lm->SetLayersObserverEpoch(mLayersObserverEpoch);

nsCOMPtr<Document> doc(GetDocument());
nsCOMPtr<Document> doc(GetTopLevelDocument());
doc->NotifyLayerManagerRecreated();
}

Expand Down Expand Up @@ -3062,7 +3067,7 @@ mozilla::ipc::IPCResult TabChild::RecvUIResolutionChanged(
if (aDpi > 0) {
mPuppetWidget->UpdateBackingScaleCache(aDpi, aRounding, aScale);
}
nsCOMPtr<Document> document(GetDocument());
nsCOMPtr<Document> document(GetTopLevelDocument());
RefPtr<nsPresContext> presContext = document->GetPresContext();
if (presContext) {
presContext->UIResolutionChangedSync();
Expand All @@ -3086,7 +3091,7 @@ mozilla::ipc::IPCResult TabChild::RecvUIResolutionChanged(
mozilla::ipc::IPCResult TabChild::RecvThemeChanged(
nsTArray<LookAndFeelInt>&& aLookAndFeelIntCache) {
LookAndFeel::SetIntCache(aLookAndFeelIntCache);
nsCOMPtr<Document> document(GetDocument());
nsCOMPtr<Document> document(GetTopLevelDocument());
RefPtr<nsPresContext> presContext = document->GetPresContext();
if (presContext) {
presContext->ThemeChanged();
Expand Down Expand Up @@ -3142,7 +3147,7 @@ mozilla::ipc::IPCResult TabChild::RecvGetContentBlockingLog(
bool success = false;
nsAutoCString result;

if (nsCOMPtr<Document> doc = GetDocument()) {
if (nsCOMPtr<Document> doc = GetTopLevelDocument()) {
result = doc->GetContentBlockingLog()->Stringify();
success = true;
}
Expand Down
8 changes: 4 additions & 4 deletions dom/ipc/TabChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "nsIDocShell.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsFrameMessageManager.h"
#include "nsIPresShell.h"
#include "nsWeakReference.h"
#include "nsITabChild.h"
#include "nsITooltipListener.h"
Expand Down Expand Up @@ -61,6 +60,7 @@ class nsPtrHashKey;

namespace mozilla {
class AbstractThread;
class PresShell;

namespace layers {
class APZChild;
Expand Down Expand Up @@ -170,10 +170,10 @@ class TabChildBase : public nsISupports,
virtual ScreenIntSize GetInnerSize() = 0;

// Get the Document for the top-level window in this tab.
already_AddRefed<Document> GetDocument() const;
already_AddRefed<Document> GetTopLevelDocument() const;

// Get the pres-shell of the document for the top-level window in this tab.
already_AddRefed<nsIPresShell> GetPresShell() const;
PresShell* GetTopLevelPresShell() const;

protected:
virtual ~TabChildBase();
Expand Down Expand Up @@ -494,7 +494,7 @@ class TabChild final : public TabChildBase,
return GetFrom(docShell);
}

static TabChild* GetFrom(nsIPresShell* aPresShell);
static TabChild* GetFrom(PresShell* aPresShell);
static TabChild* GetFrom(layers::LayersId aLayersId);

layers::LayersId GetLayersId() { return mLayersId; }
Expand Down
3 changes: 2 additions & 1 deletion dom/security/nsContentSecurityManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ bool nsContentSecurityManager::AllowTopLevelNavigationToDataURI(
nsCOMPtr<nsITabChild> tabChild = do_QueryInterface(context);
nsCOMPtr<Document> doc;
if (tabChild) {
doc = static_cast<mozilla::dom::TabChild*>(tabChild.get())->GetDocument();
doc = static_cast<mozilla::dom::TabChild*>(tabChild.get())
->GetTopLevelDocument();
}
NS_ConvertUTF8toUTF16 specUTF16(NS_UnescapeURL(dataSpec));
const char16_t* params[] = {specUTF16.get()};
Expand Down
5 changes: 1 addition & 4 deletions gfx/layers/apz/util/ContentProcessController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ void ContentProcessController::NotifyMozMouseScrollEvent(

void ContentProcessController::NotifyFlushComplete() {
if (mBrowser) {
RefPtr<PresShell> presShell;
if (nsCOMPtr<dom::Document> doc = mBrowser->GetDocument()) {
presShell = doc->GetPresShell();
}
RefPtr<PresShell> presShell = mBrowser->GetTopLevelPresShell();
APZCCallbackHelper::NotifyFlushComplete(presShell);
}
}
Expand Down
6 changes: 2 additions & 4 deletions layout/base/PresShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5072,9 +5072,7 @@ static bool IsTransparentContainerElement(nsPresContext* aPresContext) {
if (tab) {
// Check if presShell is the top PresShell. Only the top can
// influence the canvas background color.
PresShell* presShell = aPresContext->GetPresShell();
nsCOMPtr<nsIPresShell> topPresShell = tab->GetPresShell();
if (presShell != topPresShell) {
if (aPresContext->GetPresShell() != tab->GetTopLevelPresShell()) {
tab = nullptr;
}
}
Expand Down Expand Up @@ -10755,7 +10753,7 @@ bool nsIPresShell::DetermineFontSizeInflationState() {

// Force-enabling font inflation always trumps the heuristics here.
if (!FontSizeInflationForceEnabled()) {
if (TabChild* tab = TabChild::GetFrom(this)) {
if (TabChild* tab = TabChild::GetFrom(static_cast<PresShell*>(this))) {
// We're in a child process. Cancel inflation if we're not
// async-pan zoomed.
if (!tab->AsyncPanZoomEnabled()) {
Expand Down
3 changes: 1 addition & 2 deletions netwerk/protocol/http/HttpChannelChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2650,8 +2650,7 @@ nsresult HttpChannelChild::ContinueAsyncOpen() {
TimeStamp navigationStartTimeStamp;
if (tabChild) {
MOZ_ASSERT(tabChild->WebNavigation());
RefPtr<Document> document = tabChild->GetDocument();
if (document) {
if (RefPtr<Document> document = tabChild->GetTopLevelDocument()) {
contentWindowId = document->InnerWindowID();
nsDOMNavigationTiming* navigationTiming = document->GetNavigationTiming();
if (navigationTiming) {
Expand Down
3 changes: 2 additions & 1 deletion widget/PuppetWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "mozilla/layers/PLayerTransactionChild.h"
#include "mozilla/layers/WebRenderLayerManager.h"
#include "mozilla/Preferences.h"
#include "mozilla/PresShell.h"
#include "mozilla/TextComposition.h"
#include "mozilla/TextEventDispatcher.h"
#include "mozilla/TextEvents.h"
Expand Down Expand Up @@ -403,7 +404,7 @@ nsEventStatus PuppetWidget::DispatchInputEvent(WidgetInputEvent* aEvent) {
return nsEventStatus_eIgnore;
}

if (nsCOMPtr<nsIPresShell> presShell = mTabChild->GetPresShell()) {
if (PresShell* presShell = mTabChild->GetTopLevelPresShell()) {
// Because the root resolution is conceptually at the parent/child process
// boundary, we need to apply that resolution here because we're sending
// the event from the child to the parent process.
Expand Down

0 comments on commit fdbbccd

Please sign in to comment.