Bug 1388001 - part1: Create nsIEditingSession::GetHTMLEditorForWindow() r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Sat, 12 Aug 2017 11:44:16 +0900
changeset 374562 8e0420e233f477499ddd44c7592fcc9597e3b5b6
parent 374561 37ba4f932f57fc60bf27554b5d36df3c721df75f
child 374563 6280fc4d74687b481862f20dfc1def656011003d
push id32332
push userkwierso@gmail.com
push dateTue, 15 Aug 2017 00:28:32 +0000
treeherdermozilla-central@92f3de33d97f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1388001
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1388001 - part1: Create nsIEditingSession::GetHTMLEditorForWindow() r=smaug Some users of HTMLEditor retrieve pointer to editors with nsIEditingSession::GetEditorForWindow() but it returns nsIEditor. So, there should be a method which returns HTMLEditor*. MozReview-Commit-ID: Bzc1LIlTSDF
editor/composer/nsEditingSession.cpp
editor/composer/nsIEditingSession.idl
--- a/editor/composer/nsEditingSession.cpp
+++ b/editor/composer/nsEditingSession.cpp
@@ -591,21 +591,22 @@ nsEditingSession::TearDownEditorOnWindow
   GetEditorForFrame
 
   nsIEditor getEditorForFrame (in nsIDOMWindow aWindow);
 ----------------------------------------------------------------------------*/
 NS_IMETHODIMP
 nsEditingSession::GetEditorForWindow(mozIDOMWindowProxy* aWindow,
                                      nsIEditor **outEditor)
 {
-  NS_ENSURE_STATE(aWindow);
-  nsCOMPtr<nsIDocShell> docShell = nsPIDOMWindowOuter::From(aWindow)->GetDocShell();
-  NS_ENSURE_STATE(docShell);
-
-  return docShell->GetEditor(outEditor);
+  if (NS_WARN_IF(!aWindow)) {
+    return NS_ERROR_INVALID_ARG;
+  }
+  nsCOMPtr<nsIEditor> editor = GetHTMLEditorForWindow(aWindow);
+  editor.forget(outEditor);
+  return NS_OK;
 }
 
 /*---------------------------------------------------------------------------
 
   OnStateChange
 
 ----------------------------------------------------------------------------*/
 NS_IMETHODIMP
@@ -1389,8 +1390,24 @@ nsEditingSession::ReattachToWindow(mozID
     rv = WindowIsEditable(aWindow, &isEditable);
     NS_ENSURE_SUCCESS(rv, rv);
     NS_ASSERTION(isEditable, "Window is not editable after reattaching editor.");
   }
 #endif // DEBUG
 
   return NS_OK;
 }
+
+HTMLEditor*
+nsIEditingSession::GetHTMLEditorForWindow(mozIDOMWindowProxy* aWindow)
+{
+  if (NS_WARN_IF(!aWindow)) {
+    return nullptr;
+  }
+
+  nsCOMPtr<nsIDocShell> docShell =
+    nsPIDOMWindowOuter::From(aWindow)->GetDocShell();
+  if (NS_WARN_IF(!docShell)) {
+    return nullptr;
+  }
+
+  return docShell->GetHTMLEditor();
+}
--- a/editor/composer/nsIEditingSession.idl
+++ b/editor/composer/nsIEditingSession.idl
@@ -4,16 +4,23 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsISupports.idl"
 #include "domstubs.idl"
 
 interface mozIDOMWindowProxy;
 interface nsIEditor;
 
+%{ C++
+class mozIDOMWindowProxy;
+namespace mozilla {
+class HTMLEditor;
+} // namespace mozilla
+%}
+
 [scriptable, builtinclass, uuid(24f963d1-e6fc-43ea-a206-99ac5fcc5265)]
 
 interface nsIEditingSession : nsISupports
 {
   /**
    *  Error codes when we fail to create an editor
    *  is placed in attribute editorStatus
    */
@@ -95,10 +102,20 @@ interface nsIEditingSession : nsISupport
    * to the window.
    */
   void reattachToWindow(in mozIDOMWindowProxy aWindow);
 
   /**
    * Whether this session has disabled JS and plugins.
    */
   readonly attribute boolean jsAndPluginsDisabled;
+
+%{C++
+  /**
+   * This method is implemented with nsIDocShell::GetHTMLEditor().  I.e.,
+   * This method doesn't depend on nsEditingSession.  Therefore, even if
+   * there were some implementation of nsIEditingSession interface, this
+   * would be safe to use.
+   */
+  mozilla::HTMLEditor* GetHTMLEditorForWindow(mozIDOMWindowProxy* aWindow);
+%}
 };