Bug 1533250 - Remove *JSAndPlugins* methods from nsIEditingSession. r=masayuki
authorMakoto Kato <m_kato@ga2.so-net.ne.jp>
Sun, 10 Feb 2019 19:41:43 +0900
changeset 520783 f7a8e21490276df21e5427e57e08797c2dcec26d
parent 520782 1cf46b8b22dfd4bc2c0f12df0f9a7d240f3b5990
child 520784 1b4fd78107e2bcf7fe0f44038176ca745b07cd88
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki
bugs1533250
milestone67.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 1533250 - Remove *JSAndPlugins* methods from nsIEditingSession. r=masayuki Firefox, comm-central and bluegriffon don't use `*JSAndPlugin*` methods of `nsIEditingSession` from script. Let's remove or move to `nsEditingSession`. Differential Revision: https://phabricator.services.mozilla.com/D22465
editor/composer/nsEditingSession.cpp
editor/composer/nsEditingSession.h
editor/composer/nsIEditingSession.idl
--- a/editor/composer/nsEditingSession.cpp
+++ b/editor/composer/nsEditingSession.cpp
@@ -121,17 +121,17 @@ nsEditingSession::MakeWindowEditable(moz
   NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
 
   mDocShell = do_GetWeakReference(docShell);
   mInteractive = aInteractive;
   mMakeWholeDocumentEditable = aMakeWholeDocumentEditable;
 
   nsresult rv;
   if (!mInteractive) {
-    rv = DisableJSAndPlugins(aWindow);
+    rv = DisableJSAndPlugins(*docShell);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // Always remove existing editor
   TearDownEditorOnWindow(aWindow);
 
   // Tells embedder that startup is in progress
   mEditorStatus = eEditorCreationInProgress;
@@ -173,68 +173,58 @@ nsEditingSession::MakeWindowEditable(moz
     //  it IS ok to destroy current editor
     if (NS_FAILED(rv)) {
       TearDownEditorOnWindow(aWindow);
     }
   }
   return rv;
 }
 
-NS_IMETHODIMP
-nsEditingSession::DisableJSAndPlugins(mozIDOMWindowProxy* aWindow) {
-  NS_ENSURE_TRUE(aWindow, NS_ERROR_FAILURE);
-  nsIDocShell* docShell = nsPIDOMWindowOuter::From(aWindow)->GetDocShell();
-  NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
-
+nsresult nsEditingSession::DisableJSAndPlugins(nsIDocShell& aDocShell) {
   bool tmp;
-  nsresult rv = docShell->GetAllowJavascript(&tmp);
+  nsresult rv = aDocShell.GetAllowJavascript(&tmp);
   NS_ENSURE_SUCCESS(rv, rv);
 
   mScriptsEnabled = tmp;
 
-  rv = docShell->SetAllowJavascript(false);
+  rv = aDocShell.SetAllowJavascript(false);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Disable plugins in this document:
-  mPluginsEnabled = docShell->PluginsAllowedInCurrentDoc();
+  mPluginsEnabled = aDocShell.PluginsAllowedInCurrentDoc();
 
-  rv = docShell->SetAllowPlugins(false);
+  rv = aDocShell.SetAllowPlugins(false);
   NS_ENSURE_SUCCESS(rv, rv);
 
   mDisabledJSAndPlugins = true;
 
   return NS_OK;
 }
 
-NS_IMETHODIMP
-nsEditingSession::RestoreJSAndPlugins(mozIDOMWindowProxy* aWindow) {
+nsresult nsEditingSession::RestoreJSAndPlugins(nsPIDOMWindowOuter* aWindow) {
   if (!mDisabledJSAndPlugins) {
     return NS_OK;
   }
 
   mDisabledJSAndPlugins = false;
 
-  NS_ENSURE_TRUE(aWindow, NS_ERROR_FAILURE);
-  nsIDocShell* docShell = nsPIDOMWindowOuter::From(aWindow)->GetDocShell();
+  if (NS_WARN_IF(!aWindow)) {
+    // DetachFromWindow may call this method with nullptr.
+    return NS_ERROR_FAILURE;
+  }
+  nsIDocShell* docShell = aWindow->GetDocShell();
   NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
 
   nsresult rv = docShell->SetAllowJavascript(mScriptsEnabled);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Disable plugins in this document:
   return docShell->SetAllowPlugins(mPluginsEnabled);
 }
 
-NS_IMETHODIMP
-nsEditingSession::GetJsAndPluginsDisabled(bool* aResult) {
-  NS_ENSURE_ARG_POINTER(aResult);
-  *aResult = mDisabledJSAndPlugins;
-  return NS_OK;
-}
-
 /*---------------------------------------------------------------------------
 
   WindowIsEditable
 
   boolean windowIsEditable (in nsIDOMWindow aWindow);
 ----------------------------------------------------------------------------*/
 NS_IMETHODIMP
 nsEditingSession::WindowIsEditable(mozIDOMWindowProxy* aWindow,
@@ -536,17 +526,17 @@ nsEditingSession::TearDownEditorOnWindow
   // Null out the editor on the docShell to trigger PreDestroy which
   // needs to happen before document state listeners are removed below.
   docShell->SetEditor(nullptr);
 
   RemoveListenersAndControllers(window, htmlEditor);
 
   if (stopEditing) {
     // Make things the way they were before we started editing.
-    RestoreJSAndPlugins(aWindow);
+    RestoreJSAndPlugins(window);
     RestoreAnimationMode(window);
 
     if (mMakeWholeDocumentEditable) {
       doc->SetEditableFlag(false);
       nsCOMPtr<nsIHTMLDocument> htmlDocument = do_QueryInterface(doc);
       if (htmlDocument) {
         htmlDocument->SetEditingState(nsIHTMLDocument::eOff);
       }
@@ -1234,17 +1224,17 @@ nsresult nsEditingSession::DetachFromWin
   }
 
   auto* window = nsPIDOMWindowOuter::From(aWindow);
 
   // Remove controllers, webprogress listener, and otherwise
   // make things the way they were before we started editing.
   RemoveEditorControllers(window);
   RemoveWebProgressListener(window);
-  RestoreJSAndPlugins(aWindow);
+  RestoreJSAndPlugins(window);
   RestoreAnimationMode(window);
 
   // Kill our weak reference to our original window, in case
   // it changes on restore, or otherwise dies.
   mDocShell = nullptr;
 
   return NS_OK;
 }
@@ -1262,17 +1252,17 @@ nsresult nsEditingSession::ReattachToWin
 
   auto* window = nsPIDOMWindowOuter::From(aWindow);
   nsIDocShell* docShell = window->GetDocShell();
   NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
   mDocShell = do_GetWeakReference(docShell);
 
   // Disable plugins.
   if (!mInteractive) {
-    rv = DisableJSAndPlugins(aWindow);
+    rv = DisableJSAndPlugins(*docShell);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // Tells embedder that startup is in progress.
   mEditorStatus = eEditorCreationInProgress;
 
   // Adds back web progress listener.
   rv = PrepareForEditing(window);
--- a/editor/composer/nsEditingSession.h
+++ b/editor/composer/nsEditingSession.h
@@ -81,16 +81,27 @@ class nsEditingSession final : public ns
   bool IsProgressForTargetDocument(nsIWebProgress* aWebProgress);
 
   void RemoveEditorControllers(nsPIDOMWindowOuter* aWindow);
   void RemoveWebProgressListener(nsPIDOMWindowOuter* aWindow);
   void RestoreAnimationMode(nsPIDOMWindowOuter* aWindow);
   void RemoveListenersAndControllers(nsPIDOMWindowOuter* aWindow,
                                      mozilla::HTMLEditor* aHTMLEditor);
 
+  /**
+   * Disable scripts and plugins in aDocShell.
+   */
+  nsresult DisableJSAndPlugins(nsIDocShell& aDocShell);
+
+  /**
+   * Restore JS and plugins (enable/disable them) according to the state they
+   * were before the last call to disableJSAndPlugins.
+   */
+  nsresult RestoreJSAndPlugins(nsPIDOMWindowOuter* aWindow);
+
  protected:
   bool mDoneSetup;  // have we prepared for editing yet?
 
   // Used to prevent double creation of editor because nsIWebProgressListener
   //  receives a STATE_STOP notification before the STATE_START
   //  for our document, so we wait for the STATE_START, then STATE_STOP
   //  before creating an editor
   bool mCanCreateEditor;
--- a/editor/composer/nsIEditingSession.idl
+++ b/editor/composer/nsIEditingSession.idl
@@ -76,43 +76,27 @@ interface nsIEditingSession : nsISupport
    *   Destroy editor and related support objects
    */
   void tearDownEditorOnWindow(in mozIDOMWindowProxy window);
 
   void setEditorOnControllers(in mozIDOMWindowProxy aWindow,
                               in nsIEditor aEditor);
 
   /**
-   * Disable scripts and plugins in aWindow.
-   */
-  void disableJSAndPlugins(in mozIDOMWindowProxy aWindow);
-
-  /**
-   * Restore JS and plugins (enable/disable them) according to the state they
-   * were before the last call to disableJSAndPlugins.
-   */
-  void restoreJSAndPlugins(in mozIDOMWindowProxy aWindow);
-
-  /**
    * Removes all the editor's controllers/listeners etc and makes the window
    * uneditable.
    */
   void detachFromWindow(in mozIDOMWindowProxy aWindow);
 
   /**
    * Undos detachFromWindow(), reattaches this editing session/editor
    * 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);