From 2c058509526ad15fe2b878b5777493e561e1515e Mon Sep 17 00:00:00 2001 From: Trevor Saunders Date: Mon, 14 Mar 2016 14:00:13 -0400 Subject: [PATCH] bug 1257287 - add nsIDocShell::GetEdItingSession() --- accessible/generic/DocAccessible.cpp | 9 ++++++-- accessible/generic/HyperTextAccessible.cpp | 3 ++- docshell/base/nsDocShell.cpp | 26 +++++++++++++--------- docshell/base/nsIDocShell.idl | 6 +++++ dom/html/nsHTMLDocument.cpp | 8 +++---- 5 files changed, 35 insertions(+), 17 deletions(-) diff --git a/accessible/generic/DocAccessible.cpp b/accessible/generic/DocAccessible.cpp index 921295613be9..d11f0b047827 100644 --- a/accessible/generic/DocAccessible.cpp +++ b/accessible/generic/DocAccessible.cpp @@ -335,8 +335,13 @@ DocAccessible::GetEditor() const (!mContent || !mContent->HasFlag(NODE_IS_EDITABLE))) return nullptr; - nsCOMPtr container = mDocumentNode->GetContainer(); - nsCOMPtr editingSession(do_GetInterface(container)); + nsCOMPtr docShell = mDocumentNode->GetDocShell(); + if (!docShell) { + return nullptr; + } + + nsCOMPtr editingSession; + docShell->GetEditingSession(getter_AddRefs(editingSession)); if (!editingSession) return nullptr; // No editing session interface diff --git a/accessible/generic/HyperTextAccessible.cpp b/accessible/generic/HyperTextAccessible.cpp index b34522e75848..91725f0c6376 100644 --- a/accessible/generic/HyperTextAccessible.cpp +++ b/accessible/generic/HyperTextAccessible.cpp @@ -1314,7 +1314,8 @@ HyperTextAccessible::GetEditor() const } nsCOMPtr docShell = nsCoreUtils::GetDocShellFor(mContent); - nsCOMPtr editingSession(do_GetInterface(docShell)); + nsCOMPtr editingSession; + docShell->GetEditingSession(getter_AddRefs(editingSession)); if (!editingSession) return nullptr; // No editing session interface diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index c774cebd2edb..225dc4d90d39 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -1025,16 +1025,11 @@ nsDocShell::GetInterface(const nsIID& aIID, void** aSink) *aSink = mFind; NS_ADDREF((nsISupports*)*aSink); return NS_OK; - } else if (aIID.Equals(NS_GET_IID(nsIEditingSession)) && - NS_SUCCEEDED(EnsureEditorData())) { - nsCOMPtr editingSession; - mEditorData->GetEditingSession(getter_AddRefs(editingSession)); - if (editingSession) { - editingSession.forget(aSink); - return NS_OK; - } - - return NS_NOINTERFACE; + } else if (aIID.Equals(NS_GET_IID(nsIEditingSession))) { + nsCOMPtr es; + GetEditingSession(getter_AddRefs(es)); + es.forget(aSink); + return *aSink ? NS_OK : NS_NOINTERFACE; } else if (aIID.Equals(NS_GET_IID(nsIClipboardDragDropHookList)) && NS_SUCCEEDED(EnsureTransferableHookData())) { *aSink = mTransferableHookData; @@ -14358,3 +14353,14 @@ nsDocShell::IssueWarning(uint32_t aWarning, bool aAsError) } return NS_OK; } + +NS_IMETHODIMP +nsDocShell::GetEditingSession(nsIEditingSession** aEditSession) +{ + if (!NS_SUCCEEDED(EnsureEditorData())) { + return NS_ERROR_FAILURE; + } + + mEditorData->GetEditingSession(aEditSession); + return *aEditSession ? NS_OK : NS_ERROR_FAILURE; +} diff --git a/docshell/base/nsIDocShell.idl b/docshell/base/nsIDocShell.idl index 801a817b17c0..09a0d1c312d1 100644 --- a/docshell/base/nsIDocShell.idl +++ b/docshell/base/nsIDocShell.idl @@ -26,6 +26,7 @@ interface nsIContentViewer; interface nsIDOMEventTarget; interface nsIDocShellLoadInfo; interface nsIEditor; +interface nsIEditingSession; interface nsISimpleEnumerator; interface nsIInputStream; interface nsIRequest; @@ -1091,4 +1092,9 @@ interface nsIDocShell : nsIDocShellTreeItem [implicit_jscontext] void setOriginAttributes(in jsval aAttrs); + + /** + * The editing session for this docshell. + */ + readonly attribute nsIEditingSession editingSession; }; diff --git a/dom/html/nsHTMLDocument.cpp b/dom/html/nsHTMLDocument.cpp index 93ac0ecc10d9..0a97fbb63a11 100644 --- a/dom/html/nsHTMLDocument.cpp +++ b/dom/html/nsHTMLDocument.cpp @@ -2673,8 +2673,8 @@ nsHTMLDocument::TurnEditingOff() if (!docshell) return NS_ERROR_FAILURE; - nsresult rv; - nsCOMPtr editSession = do_GetInterface(docshell, &rv); + nsCOMPtr editSession; + nsresult rv = docshell->GetEditingSession(getter_AddRefs(editSession)); NS_ENSURE_SUCCESS(rv, rv); // turn editing off @@ -2744,8 +2744,8 @@ nsHTMLDocument::EditingStateChanged() if (!docshell) return NS_ERROR_FAILURE; - nsresult rv; - nsCOMPtr editSession = do_GetInterface(docshell, &rv); + nsCOMPtr editSession; + nsresult rv = docshell->GetEditingSession(getter_AddRefs(editSession)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr existingEditor;