diff --git a/accessible/base/DocManager.cpp b/accessible/base/DocManager.cpp index 08bb581b0920..ca022b86b075 100644 --- a/accessible/base/DocManager.cpp +++ b/accessible/base/DocManager.cpp @@ -499,7 +499,7 @@ DocManager::CreateDocOrRootAccessible(nsIDocument* aDocument) if (IPCAccessibilityActive()) { nsIDocShell* docShell = aDocument->GetDocShell(); if (docShell) { - nsCOMPtr tabChild = do_GetInterface(docShell); + nsCOMPtr tabChild = docShell->GetTabChild(); // XXX We may need to handle the case that we don't have a tab child // differently. It may be that this will cause us to fail to notify diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 225dc4d90d39..6ccc841e6c3a 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -1047,14 +1047,8 @@ nsDocShell::GetInterface(const nsIID& aIID, void** aSink) return treeOwner->QueryInterface(aIID, aSink); } } else if (aIID.Equals(NS_GET_IID(nsITabChild))) { - nsCOMPtr treeOwner; - nsresult rv = GetTreeOwner(getter_AddRefs(treeOwner)); - if (NS_SUCCEEDED(rv) && treeOwner) { - nsCOMPtr ir = do_QueryInterface(treeOwner); - if (ir) { - return ir->GetInterface(aIID, aSink); - } - } + *aSink = GetTabChild().take(); + return *aSink ? NS_OK : NS_ERROR_FAILURE; } else if (aIID.Equals(NS_GET_IID(nsIContentFrameMessageManager))) { nsCOMPtr tabChild = do_GetInterface(static_cast(this)); @@ -14364,3 +14358,18 @@ nsDocShell::GetEditingSession(nsIEditingSession** aEditSession) mEditorData->GetEditingSession(aEditSession); return *aEditSession ? NS_OK : NS_ERROR_FAILURE; } + +NS_IMETHODIMP +nsDocShell::GetScriptableTabChild(nsITabChild** aTabChild) +{ + *aTabChild = GetTabChild().take(); + return *aTabChild ? NS_OK : NS_ERROR_FAILURE; +} + +already_AddRefed +nsDocShell::GetTabChild() +{ + nsCOMPtr owner(mTreeOwner); + nsCOMPtr tc = do_GetInterface(owner); + return tc.forget(); +} diff --git a/docshell/base/nsIDocShell.idl b/docshell/base/nsIDocShell.idl index 09a0d1c312d1..3a6aa7e30698 100644 --- a/docshell/base/nsIDocShell.idl +++ b/docshell/base/nsIDocShell.idl @@ -41,6 +41,8 @@ interface nsIPrivacyTransitionObserver; interface nsIReflowObserver; interface nsIScrollObserver; interface nsITabParent; +interface nsITabChild; +native TabChildRef(already_AddRefed); typedef unsigned long nsLoadFlags; @@ -1097,4 +1099,10 @@ interface nsIDocShell : nsIDocShellTreeItem * The editing session for this docshell. */ readonly attribute nsIEditingSession editingSession; + + /** + * The tab child for this docshell. + */ + [binaryname(ScriptableTabChild)] readonly attribute nsITabChild tabChild; + [noscript,notxpcom,nostdcall] TabChildRef GetTabChild(); }; diff --git a/dom/base/nsCCUncollectableMarker.cpp b/dom/base/nsCCUncollectableMarker.cpp index b8b010402d94..e6453579460a 100644 --- a/dom/base/nsCCUncollectableMarker.cpp +++ b/dom/base/nsCCUncollectableMarker.cpp @@ -303,7 +303,8 @@ MarkWindowList(nsISimpleEnumerator* aWindowList, bool aCleanupJS, MarkDocShell(rootDocShell, aCleanupJS, aPrepareForCC); - nsCOMPtr tabChild = do_GetInterface(rootDocShell); + nsCOMPtr tabChild = + rootDocShell ? rootDocShell->GetTabChild() : nullptr; if (tabChild) { nsCOMPtr mm; tabChild->GetMessageManager(getter_AddRefs(mm)); diff --git a/dom/base/nsFocusManager.cpp b/dom/base/nsFocusManager.cpp index 9e6deeb60f9b..eea9ec531625 100644 --- a/dom/base/nsFocusManager.cpp +++ b/dom/base/nsFocusManager.cpp @@ -869,9 +869,11 @@ nsFocusManager::WindowShown(mozIDOMWindowProxy* aWindow, bool aNeedsFocus) } } - if (nsCOMPtr child = do_GetInterface(window->GetDocShell())) { - bool active = static_cast(child.get())->ParentIsActive(); - ActivateOrDeactivate(window, active); + if (nsIDocShell* docShell = window->GetDocShell()) { + if (nsCOMPtr child = docShell->GetTabChild()) { + bool active = static_cast(child.get())->ParentIsActive(); + ActivateOrDeactivate(window, active); + } } if (mFocusedWindow != window) @@ -1632,7 +1634,7 @@ nsFocusManager::Blur(nsPIDOMWindowOuter* aWindowToClear, if (aAdjustWidgets && objectFrame && !sTestMode) { if (XRE_IsContentProcess()) { // set focus to the top level window via the chrome process. - nsCOMPtr tabChild = do_GetInterface(docShell); + nsCOMPtr tabChild = docShell->GetTabChild(); if (tabChild) { static_cast(tabChild.get())->SendDispatchFocusToTopLevelWindow(); } diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index cde9dee6d262..894bf72f3434 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -9061,9 +9061,12 @@ nsresult nsGlobalWindow::UpdateCommands(const nsAString& anAction, nsISelection* aSel, int16_t aReason) { // If this is a child process, redirect to the parent process. - if (nsCOMPtr child = do_GetInterface(GetDocShell())) { - nsContentUtils::AddScriptRunner(new ChildCommandDispatcher(this, child, anAction)); - return NS_OK; + if (nsIDocShell* docShell = GetDocShell()) { + if (nsCOMPtr child = docShell->GetTabChild()) { + nsContentUtils::AddScriptRunner(new ChildCommandDispatcher(this, child, + anAction)); + return NS_OK; + } } nsPIDOMWindowOuter *rootWindow = nsGlobalWindow::GetPrivateRoot(); @@ -10685,7 +10688,8 @@ nsGlobalWindow::ShowSlowScriptDialog() ProcessHangMonitor::Get()) { ProcessHangMonitor::SlowScriptAction action; RefPtr monitor = ProcessHangMonitor::Get(); - nsCOMPtr child = do_GetInterface(GetDocShell()); + nsIDocShell* docShell = GetDocShell(); + nsCOMPtr child = docShell ? docShell->GetTabChild() : nullptr; action = monitor->NotifySlowScript(child, filename.get(), lineno); diff --git a/dom/events/EventStateManager.cpp b/dom/events/EventStateManager.cpp index 4058ecd89989..bfeda035ffde 100644 --- a/dom/events/EventStateManager.cpp +++ b/dom/events/EventStateManager.cpp @@ -981,7 +981,9 @@ EventStateManager::ExecuteAccessKey(nsTArray& aAccessCharCodes, if (focusChanged && aIsTrustedEvent) { // If this is a child process, inform the parent that we want the focus, but // pass false since we don't want to change the window order. - nsCOMPtr child = do_GetInterface(mPresContext->GetDocShell()); + nsIDocShell* docShell = mPresContext->GetDocShell(); + nsCOMPtr child = + docShell ? docShell->GetTabChild() : nullptr; if (child) { child->SendRequestFocus(false); } diff --git a/dom/ipc/TabChild.h b/dom/ipc/TabChild.h index ecf250b4f9b3..feb2e8f87fbe 100644 --- a/dom/ipc/TabChild.h +++ b/dom/ipc/TabChild.h @@ -512,7 +512,11 @@ public: static inline TabChild* GetFrom(nsIDocShell* aDocShell) { - nsCOMPtr tc = do_GetInterface(aDocShell); + if (!aDocShell) { + return nullptr; + } + + nsCOMPtr tc = aDocShell->GetTabChild(); return static_cast(tc.get()); } diff --git a/embedding/components/printingui/ipc/nsPrintingProxy.cpp b/embedding/components/printingui/ipc/nsPrintingProxy.cpp index ab5f4ff8d0e3..24be3f46f9d6 100644 --- a/embedding/components/printingui/ipc/nsPrintingProxy.cpp +++ b/embedding/components/printingui/ipc/nsPrintingProxy.cpp @@ -73,23 +73,20 @@ nsPrintingProxy::ShowPrintDialog(mozIDOMWindowProxy *parent, NS_ENSURE_ARG(webBrowserPrint); NS_ENSURE_ARG(printSettings); - // Get the root docshell owner of this nsIDOMWindow, which - // should map to a TabChild, which we can then pass up to + // Get the TabChild for this nsIDOMWindow, which we can then pass up to // the parent. nsCOMPtr pwin = nsPIDOMWindowOuter::From(parent); NS_ENSURE_STATE(pwin); nsCOMPtr docShell = pwin->GetDocShell(); NS_ENSURE_STATE(docShell); - nsCOMPtr owner; - nsresult rv = docShell->GetTreeOwner(getter_AddRefs(owner)); - NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr tabchild = do_GetInterface(owner); + nsCOMPtr tabchild = docShell->GetTabChild(); NS_ENSURE_STATE(tabchild); TabChild* pBrowser = static_cast(tabchild.get()); // Next, serialize the nsIWebBrowserPrint and nsIPrintSettings we were given. + nsresult rv = NS_OK; nsCOMPtr po = do_GetService("@mozilla.org/gfx/printsettings-service;1", &rv); NS_ENSURE_SUCCESS(rv, rv); @@ -134,17 +131,13 @@ nsPrintingProxy::ShowProgress(mozIDOMWindowProxy* parent, NS_ENSURE_ARG(printProgressParams); NS_ENSURE_ARG(notifyOnOpen); - // Get the root docshell owner of this nsIDOMWindow, which - // should map to a TabChild, which we can then pass up to + // Get the TabChild for this nsIDOMWindow, which we can then pass up to // the parent. nsCOMPtr pwin = nsPIDOMWindowOuter::From(parent); NS_ENSURE_STATE(pwin); nsCOMPtr docShell = pwin->GetDocShell(); NS_ENSURE_STATE(docShell); - nsCOMPtr owner; - nsresult rv = docShell->GetTreeOwner(getter_AddRefs(owner)); - NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr tabchild = do_GetInterface(owner); + nsCOMPtr tabchild = docShell->GetTabChild(); TabChild* pBrowser = static_cast(tabchild.get()); RefPtr dialogChild = @@ -152,6 +145,7 @@ nsPrintingProxy::ShowProgress(mozIDOMWindowProxy* parent, SendPPrintProgressDialogConstructor(dialogChild); + nsresult rv = NS_OK; mozilla::Unused << SendShowProgress(pBrowser, dialogChild, isForPrinting, notifyOnOpen, &rv); if (NS_FAILED(rv)) { diff --git a/uriloader/prefetch/OfflineCacheUpdateChild.cpp b/uriloader/prefetch/OfflineCacheUpdateChild.cpp index 1cef80b18439..a4e11e617401 100644 --- a/uriloader/prefetch/OfflineCacheUpdateChild.cpp +++ b/uriloader/prefetch/OfflineCacheUpdateChild.cpp @@ -379,18 +379,13 @@ OfflineCacheUpdateChild::Schedule() NS_ASSERTION(mWindow, "Window must be provided to the offline cache update child"); nsCOMPtr window = mWindow.forget(); - nsIDocShell *docshell = window->GetDocShell(); - - nsCOMPtr item = do_QueryInterface(docshell); - if (!item) { + nsCOMPtrdocshell = window->GetDocShell(); + if (!docshell) { NS_WARNING("doc shell tree item is null"); return NS_ERROR_FAILURE; } - nsCOMPtr owner; - item->GetTreeOwner(getter_AddRefs(owner)); - - nsCOMPtr tabchild = do_GetInterface(owner); + nsCOMPtr tabchild = docshell->GetTabChild(); // because owner implements nsITabChild, we can assume that it is // the one and only TabChild. TabChild* child = tabchild ? static_cast(tabchild.get()) : nullptr;