From 256fff4fc9b9ed4ecf38d13aa4372bc4c99eaa51 Mon Sep 17 00:00:00 2001 From: Trevor Saunders Date: Tue, 12 Apr 2016 04:09:41 -0400 Subject: [PATCH] bug 1271436 - add nsIDocShell::GetCommandManager() r=smaug --- accessible/generic/DocAccessible.cpp | 16 ++++++++-------- docshell/base/nsDocShell.cpp | 7 +++++++ docshell/base/nsIDocShell.idl | 3 +++ dom/html/nsHTMLDocument.cpp | 2 +- editor/composer/nsComposerCommandsUpdater.cpp | 2 +- editor/composer/nsComposerDocumentCommands.cpp | 2 +- editor/composer/nsEditingSession.cpp | 2 +- 7 files changed, 22 insertions(+), 12 deletions(-) diff --git a/accessible/generic/DocAccessible.cpp b/accessible/generic/DocAccessible.cpp index 131a0b532e87..e69de69e7403 100644 --- a/accessible/generic/DocAccessible.cpp +++ b/accessible/generic/DocAccessible.cpp @@ -537,12 +537,12 @@ DocAccessible::RelativeBounds(nsIFrame** aRelativeFrame) const nsresult DocAccessible::AddEventListeners() { - nsCOMPtr docShellTreeItem(mDocumentNode->GetDocShell()); + nsCOMPtr docShell(mDocumentNode->GetDocShell()); // We want to add a command observer only if the document is content and has // an editor. - if (docShellTreeItem->ItemType() == nsIDocShellTreeItem::typeContent) { - nsCOMPtr commandManager = do_GetInterface(docShellTreeItem); + if (docShell->ItemType() == nsIDocShellTreeItem::typeContent) { + nsCOMPtr commandManager = docShell->GetCommandManager(); if (commandManager) commandManager->AddCommandObserver(this, "obs_documentCreated"); } @@ -567,12 +567,12 @@ DocAccessible::RemoveEventListeners() if (mDocumentNode) { mDocumentNode->RemoveObserver(this); - nsCOMPtr docShellTreeItem(mDocumentNode->GetDocShell()); - NS_ASSERTION(docShellTreeItem, "doc should support nsIDocShellTreeItem."); + nsCOMPtr docShell(mDocumentNode->GetDocShell()); + NS_ASSERTION(docShell, "doc should support nsIDocShellTreeItem."); - if (docShellTreeItem) { - if (docShellTreeItem->ItemType() == nsIDocShellTreeItem::typeContent) { - nsCOMPtr commandManager = do_GetInterface(docShellTreeItem); + if (docShell) { + if (docShell->ItemType() == nsIDocShellTreeItem::typeContent) { + nsCOMPtr commandManager = docShell->GetCommandManager(); if (commandManager) { commandManager->RemoveCommandObserver(this, "obs_documentCreated"); } diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index a04063fac34e..108780231dfd 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -14465,3 +14465,10 @@ nsDocShell::GetTabChild() nsCOMPtr tc = do_GetInterface(owner); return tc.forget(); } + +nsICommandManager* +nsDocShell::GetCommandManager() +{ + NS_ENSURE_SUCCESS(EnsureCommandHandler(), nullptr); + return mCommandManager; +} diff --git a/docshell/base/nsIDocShell.idl b/docshell/base/nsIDocShell.idl index cb47636e2768..50123a0138d7 100644 --- a/docshell/base/nsIDocShell.idl +++ b/docshell/base/nsIDocShell.idl @@ -42,6 +42,7 @@ interface nsIReflowObserver; interface nsIScrollObserver; interface nsITabParent; interface nsITabChild; +interface nsICommandManager; native TabChildRef(already_AddRefed); typedef unsigned long nsLoadFlags; @@ -1105,4 +1106,6 @@ interface nsIDocShell : nsIDocShellTreeItem */ [binaryname(ScriptableTabChild)] readonly attribute nsITabChild tabChild; [noscript,notxpcom,nostdcall] TabChildRef GetTabChild(); + + [noscript,nostdcall,notxpcom] nsICommandManager GetCommandManager(); }; diff --git a/dom/html/nsHTMLDocument.cpp b/dom/html/nsHTMLDocument.cpp index 63acd5f0e7be..15f9b15a26d5 100644 --- a/dom/html/nsHTMLDocument.cpp +++ b/dom/html/nsHTMLDocument.cpp @@ -2963,7 +2963,7 @@ nsHTMLDocument::GetMidasCommandManager(nsICommandManager** aCmdMgr) if (!docshell) return NS_ERROR_FAILURE; - mMidasCommandManager = do_GetInterface(docshell); + mMidasCommandManager = docshell->GetCommandManager(); if (!mMidasCommandManager) return NS_ERROR_FAILURE; diff --git a/editor/composer/nsComposerCommandsUpdater.cpp b/editor/composer/nsComposerCommandsUpdater.cpp index 934db7290c11..c573a701e46a 100644 --- a/editor/composer/nsComposerCommandsUpdater.cpp +++ b/editor/composer/nsComposerCommandsUpdater.cpp @@ -354,7 +354,7 @@ nsComposerCommandsUpdater::GetCommandUpdater() { nsCOMPtr docShell = do_QueryReferent(mDocShell); NS_ENSURE_TRUE(docShell, nullptr); - nsCOMPtr manager = do_GetInterface(docShell); + nsCOMPtr manager = docShell->GetCommandManager(); nsCOMPtr updater = do_QueryInterface(manager); return updater.forget(); } diff --git a/editor/composer/nsComposerDocumentCommands.cpp b/editor/composer/nsComposerDocumentCommands.cpp index 2ee7a8d6a857..7a58b7765c44 100644 --- a/editor/composer/nsComposerDocumentCommands.cpp +++ b/editor/composer/nsComposerDocumentCommands.cpp @@ -400,7 +400,7 @@ nsSetDocumentStateCommand::GetCommandStateParams(const char *aCommandName, * 4. In the appropriate location in editorSession, editor, or commands code, * trigger the notification of this observer by something like: * - * nsCOMPtr commandManager = do_GetInterface(mDocShell); + * nsCOMPtr commandManager = mDocShell->GetCommandManager(); * nsCOMPtr commandUpdater = do_QueryInterface(commandManager); * NS_ENSURE_TRUE(commandUpdater, NS_ERROR_FAILURE); * commandUpdater->CommandStatusChanged(obs_documentCreated); diff --git a/editor/composer/nsEditingSession.cpp b/editor/composer/nsEditingSession.cpp index 42188c84f58b..789413582b70 100644 --- a/editor/composer/nsEditingSession.cpp +++ b/editor/composer/nsEditingSession.cpp @@ -820,7 +820,7 @@ nsEditingSession::OnLocationChange(nsIWebProgress *aWebProgress, nsIDocShell *docShell = piWindow->GetDocShell(); NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); - nsCOMPtr commandManager = do_GetInterface(docShell); + nsCOMPtr commandManager = docShell->GetCommandManager(); nsCOMPtr commandUpdater = do_QueryInterface(commandManager); NS_ENSURE_TRUE(commandUpdater, NS_ERROR_FAILURE);