Bug 1316661 part 2. Eliminate IsCallerChrome callers in HTMLDocument. r=smaug
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 15 Nov 2016 00:18:33 -0500
changeset 350575 9279b5e62d230d2766fbde16dcf8b073a67de9af
parent 350574 40f2ef965fde52a2fd626f8a42c74aa1cd5b254d
child 350576 52620710ec9fea8c3af3aca0d14352bfeb6f626e
push id10621
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 16:02:43 +0000
treeherdermozilla-aurora@dca7b42e6c67 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1316661
milestone53.0a1
Bug 1316661 part 2. Eliminate IsCallerChrome callers in HTMLDocument. r=smaug
dom/html/nsHTMLDocument.cpp
dom/html/nsHTMLDocument.h
dom/interfaces/html/nsIDOMHTMLDocument.idl
dom/webidl/HTMLDocument.webidl
--- a/dom/html/nsHTMLDocument.cpp
+++ b/dom/html/nsHTMLDocument.cpp
@@ -111,16 +111,17 @@
 #include "nsIStringBundle.h"
 #include "nsDOMClassInfo.h"
 #include "nsFocusManager.h"
 #include "nsIFrame.h"
 #include "nsIContent.h"
 #include "nsLayoutStylesheetCache.h"
 #include "mozilla/StyleSheet.h"
 #include "mozilla/StyleSheetInlines.h"
+#include "mozilla/Unused.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 #define NS_MAX_DOCUMENT_WRITE_DEPTH 20
 
 #include "prtime.h"
 
@@ -2790,27 +2791,31 @@ nsHTMLDocument::EditingStateChanged()
       return NS_OK;
     }
   }
 
   if (makeWindowEditable) {
     // Set the editor to not insert br's on return when in p
     // elements by default.
     // XXX Do we only want to do this for designMode?
-    bool unused;
-    rv = ExecCommand(NS_LITERAL_STRING("insertBrOnReturn"), false,
-                     NS_LITERAL_STRING("false"), &unused);
-
-    if (NS_FAILED(rv)) {
+    // Note that it doesn't matter what CallerType we pass, because the callee
+    // doesn't use it for this command.  Play it safe and pass the more
+    // restricted one.
+    ErrorResult errorResult;
+    Unused << ExecCommand(NS_LITERAL_STRING("insertBrOnReturn"), false,
+                          NS_LITERAL_STRING("false"), CallerType::NonSystem,
+                          errorResult);
+
+    if (errorResult.Failed()) {
       // Editor setup failed. Editing is not on after all.
       // XXX Should we reset the editable flag on nodes?
       editSession->TearDownEditorOnWindow(window);
       mEditingState = eOff;
 
-      return rv;
+      return errorResult.StealNSResult();
     }
   }
 
   if (updateState) {
     nsAutoScriptBlocker scriptBlocker;
     NotifyEditableStateChange(this, this);
   }
 
@@ -3116,32 +3121,21 @@ ConvertToMidasInternalCommand(const nsAS
   nsAutoCString dummyCString;
   nsAutoString dummyString;
   bool dummyBool;
   return ConvertToMidasInternalCommandInner(inCommandID, dummyString,
                                             outCommandID, dummyCString,
                                             dummyBool, dummyBool, true);
 }
 
-/* TODO: don't let this call do anything if the page is not done loading */
-NS_IMETHODIMP
-nsHTMLDocument::ExecCommand(const nsAString& commandID,
-                            bool doShowUI,
-                            const nsAString& value,
-                            bool* _retval)
-{
-  ErrorResult rv;
-  *_retval = ExecCommand(commandID, doShowUI, value, rv);
-  return rv.StealNSResult();
-}
-
 bool
 nsHTMLDocument::ExecCommand(const nsAString& commandID,
                             bool doShowUI,
                             const nsAString& value,
+                            CallerType aCallerType,
                             ErrorResult& rv)
 {
   //  for optional parameters see dom/src/base/nsHistory.cpp: HistoryImpl::Go()
   //  this might add some ugly JS dependencies?
 
   nsAutoCString cmdToDispatch, paramStr;
   bool isBool, boolVal;
   if (!ConvertToMidasInternalCommand(commandID, value,
@@ -3191,17 +3185,17 @@ nsHTMLDocument::ExecCommand(const nsAStr
   }
 
   if (commandID.LowerCaseEqualsLiteral("gethtml")) {
     rv.Throw(NS_ERROR_FAILURE);
     return false;
   }
 
   bool restricted = commandID.LowerCaseEqualsLiteral("paste");
-  if (restricted && !nsContentUtils::IsCallerChrome()) {
+  if (restricted && aCallerType != CallerType::System) {
     return false;
   }
 
   // get command manager and dispatch command to our window if it's acceptable
   nsCOMPtr<nsICommandManager> cmdMgr;
   GetMidasCommandManager(getter_AddRefs(cmdMgr));
   if (!cmdMgr) {
     rv.Throw(NS_ERROR_FAILURE);
@@ -3255,43 +3249,36 @@ nsHTMLDocument::ExecCommand(const nsAStr
       return false;
     }
     rv = cmdMgr->DoCommand(cmdToDispatch.get(), cmdParams, window);
   }
 
   return !rv.Failed();
 }
 
-NS_IMETHODIMP
+bool
 nsHTMLDocument::QueryCommandEnabled(const nsAString& commandID,
-                                    bool* _retval)
-{
-  ErrorResult rv;
-  *_retval = QueryCommandEnabled(commandID, rv);
-  return rv.StealNSResult();
-}
-
-bool
-nsHTMLDocument::QueryCommandEnabled(const nsAString& commandID, ErrorResult& rv)
+                                    CallerType aCallerType,
+                                    ErrorResult& rv)
 {
   nsAutoCString cmdToDispatch;
   if (!ConvertToMidasInternalCommand(commandID, cmdToDispatch)) {
     return false;
   }
 
   // cut & copy are always allowed
   bool isCutCopy = commandID.LowerCaseEqualsLiteral("cut") ||
                    commandID.LowerCaseEqualsLiteral("copy");
   if (isCutCopy) {
     return nsContentUtils::IsCutCopyAllowed();
   }
 
   // Report false for restricted commands
   bool restricted = commandID.LowerCaseEqualsLiteral("paste");
-  if (restricted && !nsContentUtils::IsCallerChrome()) {
+  if (restricted && aCallerType != CallerType::System) {
     return false;
   }
 
   // if editing is not on, bail
   if (!IsEditingOnAfterFlush()) {
     return false;
   }
 
@@ -3449,34 +3436,27 @@ nsHTMLDocument::QueryCommandState(const 
   // If command does not have a state_all value, this call fails and sets
   // retval to false.  This is fine -- we want to return false in that case
   // anyway (bug 738385), so we just succeed and return false regardless.
   bool retval = false;
   cmdParams->GetBooleanValue("state_all", &retval);
   return retval;
 }
 
-NS_IMETHODIMP
-nsHTMLDocument::QueryCommandSupported(const nsAString & commandID,
-                                      bool *_retval)
-{
-  *_retval = QueryCommandSupported(commandID);
-  return NS_OK;
-}
-
 bool
-nsHTMLDocument::QueryCommandSupported(const nsAString& commandID)
+nsHTMLDocument::QueryCommandSupported(const nsAString& commandID,
+                                      CallerType aCallerType)
 {
   // Gecko technically supports all the clipboard commands including
   // cut/copy/paste, but non-privileged content will be unable to call
   // paste, and depending on the pref "dom.allow_cut_copy", cut and copy
   // may also be disallowed to be called from non-privileged content.
   // For that reason, we report the support status of corresponding
   // command accordingly.
-  if (!nsContentUtils::IsCallerChrome()) {
+  if (aCallerType != CallerType::System) {
     if (commandID.LowerCaseEqualsLiteral("paste")) {
       return false;
     }
     if (nsContentUtils::IsCutCopyRestricted()) {
       if (commandID.LowerCaseEqualsLiteral("cut") ||
           commandID.LowerCaseEqualsLiteral("copy")) {
         return false;
       }
--- a/dom/html/nsHTMLDocument.h
+++ b/dom/html/nsHTMLDocument.h
@@ -15,16 +15,17 @@
 #include "nsTArray.h"
 
 #include "PLDHashTable.h"
 #include "nsIHttpChannel.h"
 #include "nsHTMLStyleSheet.h"
 
 #include "nsICommandManager.h"
 #include "mozilla/dom/HTMLSharedElement.h"
+#include "mozilla/dom/BindingDeclarations.h"
 
 class nsIEditor;
 class nsIURI;
 class nsIDocShell;
 class nsICachingChannel;
 class nsIWyciwygChannel;
 class nsILoadGroup;
 
@@ -217,23 +218,27 @@ public:
   }
   void SetDesignMode(const nsAString& aDesignMode,
                      nsIPrincipal& aSubjectPrincipal,
                      mozilla::ErrorResult& rv);
   void SetDesignMode(const nsAString& aDesignMode,
                      const mozilla::Maybe<nsIPrincipal*>& aSubjectPrincipal,
                      mozilla::ErrorResult& rv);
   bool ExecCommand(const nsAString& aCommandID, bool aDoShowUI,
-                   const nsAString& aValue, mozilla::ErrorResult& rv);
+                   const nsAString& aValue,
+                   mozilla::dom::CallerType aCallerType,
+                   mozilla::ErrorResult& rv);
   bool QueryCommandEnabled(const nsAString& aCommandID,
+                           mozilla::dom::CallerType aCallerType,
                            mozilla::ErrorResult& rv);
   bool QueryCommandIndeterm(const nsAString& aCommandID,
                             mozilla::ErrorResult& rv);
   bool QueryCommandState(const nsAString& aCommandID, mozilla::ErrorResult& rv);
-  bool QueryCommandSupported(const nsAString& aCommandID);
+  bool QueryCommandSupported(const nsAString& aCommandID,
+                             mozilla::dom::CallerType aCallerType);
   void QueryCommandValue(const nsAString& aCommandID, nsAString& aValue,
                          mozilla::ErrorResult& rv);
   // The XPCOM Get/SetFgColor work OK for us, since they never throw.
   // The XPCOM Get/SetLinkColor work OK for us, since they never throw.
   // The XPCOM Get/SetVLinkColor work OK for us, since they never throw.
   // The XPCOM Get/SetALinkColor work OK for us, since they never throw.
   // The XPCOM Get/SetBgColor work OK for us, since they never throw.
   nsIHTMLCollection* Anchors();
--- a/dom/interfaces/html/nsIDOMHTMLDocument.idl
+++ b/dom/interfaces/html/nsIDOMHTMLDocument.idl
@@ -47,32 +47,22 @@ interface nsIDOMHTMLDocument : nsIDOMDoc
   [implicit_jscontext]
   void                      writeln([optional, Null(Stringify)] in DOMString text);
 
   /**
    * Midas additions
    */
   attribute DOMString       designMode;
 
-  boolean                   execCommand(in DOMString commandID,
-                                        [optional] in boolean doShowUI,
-                                        [optional] in DOMString value);
-
-  // returns true if the command is enabled (false otherwise)
-  boolean                   queryCommandEnabled(in DOMString commandID);
-  
   // returns true if the command is in a indeterminate state (false otherwise)
   boolean                   queryCommandIndeterm(in DOMString commandID);
 
   // returns true if the command has been executed (false otherwise)
   boolean                   queryCommandState(in DOMString commandID);
 
-  // returns true if the command is supported on the current range
-  boolean                   queryCommandSupported(in DOMString commandID);
-
   // returns the current value of the document or current selection for command
   DOMString                 queryCommandValue(in DOMString commandID);
 
 
   // Obsolete APIs
            attribute DOMString            fgColor;
            attribute DOMString            bgColor;
            attribute DOMString            linkColor;
--- a/dom/webidl/HTMLDocument.webidl
+++ b/dom/webidl/HTMLDocument.webidl
@@ -40,25 +40,26 @@ interface HTMLDocument : Document {
   void close();
   [Throws]
   void write(DOMString... text);
   [Throws]
   void writeln(DOMString... text);
 
   [SetterThrows, NeedsSubjectPrincipal]
            attribute DOMString designMode;
-  [Throws]
+  [Throws, NeedsCallerType]
   boolean execCommand(DOMString commandId, optional boolean showUI = false,
                       optional DOMString value = "");
-  [Throws]
+  [Throws, NeedsCallerType]
   boolean queryCommandEnabled(DOMString commandId);
   [Throws]
   boolean queryCommandIndeterm(DOMString commandId);
   [Throws]
   boolean queryCommandState(DOMString commandId);
+  [NeedsCallerType]
   boolean queryCommandSupported(DOMString commandId);
   [Throws]
   DOMString queryCommandValue(DOMString commandId);
 
   [TreatNullAs=EmptyString] attribute DOMString fgColor;
   [TreatNullAs=EmptyString] attribute DOMString linkColor;
   [TreatNullAs=EmptyString] attribute DOMString vlinkColor;
   [TreatNullAs=EmptyString] attribute DOMString alinkColor;