Bug 1316661 part 4. Eliminate IsCallerChrome callers in HTMLMenuElement. r=smaug
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 15 Nov 2016 00:18:33 -0500
changeset 350577 fe7461fb4426bcdfc1167c2a75cccdc2f0523139
parent 350576 52620710ec9fea8c3af3aca0d14352bfeb6f626e
child 350578 4d7cf1d3124cc24ceed1aaa6b9a73131ef891e47
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 4. Eliminate IsCallerChrome callers in HTMLMenuElement. r=smaug
dom/html/HTMLMenuElement.cpp
dom/html/HTMLMenuElement.h
dom/html/moz.build
dom/html/nsIHTMLMenu.idl
mobile/android/chrome/content/browser.js
toolkit/modules/PageMenu.jsm
--- a/dom/html/HTMLMenuElement.cpp
+++ b/dom/html/HTMLMenuElement.cpp
@@ -53,87 +53,69 @@ HTMLMenuElement::HTMLMenuElement(already
 {
 }
 
 HTMLMenuElement::~HTMLMenuElement()
 {
 }
 
 NS_IMPL_ISUPPORTS_INHERITED(HTMLMenuElement, nsGenericHTMLElement,
-                            nsIDOMHTMLMenuElement, nsIHTMLMenu)
+                            nsIDOMHTMLMenuElement)
 
 NS_IMPL_ELEMENT_CLONE(HTMLMenuElement)
 
 NS_IMPL_BOOL_ATTR(HTMLMenuElement, Compact, compact)
 NS_IMPL_ENUM_ATTR_DEFAULT_VALUE(HTMLMenuElement, Type, type,
                                 kMenuDefaultType->tag)
 NS_IMPL_STRING_ATTR(HTMLMenuElement, Label, label)
 
 
-NS_IMETHODIMP
+void
 HTMLMenuElement::SendShowEvent()
 {
-  NS_ENSURE_TRUE(nsContentUtils::IsCallerChrome(), NS_ERROR_DOM_SECURITY_ERR);
-
   nsCOMPtr<nsIDocument> document = GetComposedDoc();
   if (!document) {
-    return NS_ERROR_FAILURE;
+    return;
   }
 
   WidgetEvent event(true, eShow);
   event.mFlags.mBubbles = false;
   event.mFlags.mCancelable = false;
 
   nsCOMPtr<nsIPresShell> shell = document->GetShell();
   if (!shell) {
-    return NS_ERROR_FAILURE;
+    return;
   }
  
   RefPtr<nsPresContext> presContext = shell->GetPresContext();
   nsEventStatus status = nsEventStatus_eIgnore;
   EventDispatcher::Dispatch(static_cast<nsIContent*>(this), presContext,
                             &event, nullptr, &status);
-
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-HTMLMenuElement::CreateBuilder(nsIMenuBuilder** _retval)
-{
-  NS_ENSURE_TRUE(nsContentUtils::IsCallerChrome(), NS_ERROR_DOM_SECURITY_ERR);
-
-  nsCOMPtr<nsIMenuBuilder> builder = CreateBuilder();
-  builder.swap(*_retval);
-  return NS_OK;
 }
 
 already_AddRefed<nsIMenuBuilder>
 HTMLMenuElement::CreateBuilder()
 {
   if (mType != MENU_TYPE_CONTEXT) {
     return nullptr;
   }
 
   nsCOMPtr<nsIMenuBuilder> builder = do_CreateInstance(HTMLMENUBUILDER_CONTRACTID);
   NS_WARNING_ASSERTION(builder, "No builder available");
   return builder.forget();
 }
 
-NS_IMETHODIMP
+void
 HTMLMenuElement::Build(nsIMenuBuilder* aBuilder)
 {
-  NS_ENSURE_TRUE(nsContentUtils::IsCallerChrome(), NS_ERROR_DOM_SECURITY_ERR);
-
   if (!aBuilder) {
-    return NS_OK;
+    return;
   }
 
   BuildSubmenu(EmptyString(), this, aBuilder);
-
-  return NS_OK;
 }
 
 
 bool
 HTMLMenuElement::ParseAttribute(int32_t aNamespaceID,
                                 nsIAtom* aAttribute,
                                 const nsAString& aValue,
                                 nsAttrValue& aResult)
--- a/dom/html/HTMLMenuElement.h
+++ b/dom/html/HTMLMenuElement.h
@@ -4,40 +4,37 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_HTMLMenuElement_h
 #define mozilla_dom_HTMLMenuElement_h
 
 #include "mozilla/Attributes.h"
 #include "nsIDOMHTMLMenuElement.h"
-#include "nsIHTMLMenu.h"
 #include "nsGenericHTMLElement.h"
 
+class nsIMenuBuilder;
+
 namespace mozilla {
 namespace dom {
 
 class HTMLMenuElement final : public nsGenericHTMLElement,
-                              public nsIDOMHTMLMenuElement,
-                              public nsIHTMLMenu
+                              public nsIDOMHTMLMenuElement
 {
 public:
   explicit HTMLMenuElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo);
 
   NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLMenuElement, menu)
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
 
   // nsIDOMHTMLMenuElement
   NS_DECL_NSIDOMHTMLMENUELEMENT
 
-  // nsIHTMLMenu
-  NS_DECL_NSIHTMLMENU
-
   virtual bool ParseAttribute(int32_t aNamespaceID,
                                 nsIAtom* aAttribute,
                                 const nsAString& aValue,
                                 nsAttrValue& aResult) override;
 
   virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const override;
 
   uint8_t GetType() const { return mType; }
@@ -60,21 +57,21 @@ public:
   {
     return GetBoolAttr(nsGkAtoms::compact);
   }
   void SetCompact(bool aCompact, ErrorResult& aError)
   {
     SetHTMLBoolAttr(nsGkAtoms::compact, aCompact, aError);
   }
 
-  // The XPCOM SendShowEvent is OK for us
+  void SendShowEvent();
 
   already_AddRefed<nsIMenuBuilder> CreateBuilder();
 
-  // The XPCOM Build is OK for us
+  void Build(nsIMenuBuilder* aBuilder);
 
 protected:
   virtual ~HTMLMenuElement();
 
   virtual JSObject* WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) override;
 
 
 protected:
--- a/dom/html/moz.build
+++ b/dom/html/moz.build
@@ -15,17 +15,16 @@ MOCHITEST_CHROME_MANIFESTS += [
     'test/forms/chrome.ini',
 ]
 
 BROWSER_CHROME_MANIFESTS += ['test/browser.ini']
 
 XPIDL_SOURCES += [
     'nsIDateTimeInputArea.idl',
     'nsIFormSubmitObserver.idl',
-    'nsIHTMLMenu.idl',
     'nsIImageDocument.idl',
     'nsIMenuBuilder.idl',
     'nsIPhonetic.idl',
 ]
 
 XPIDL_MODULE = 'content_html'
 
 EXPORTS += [
deleted file mode 100644
--- a/dom/html/nsIHTMLMenu.idl
+++ /dev/null
@@ -1,42 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "nsISupports.idl"
-
-interface nsIMenuBuilder;
-
-/**
- * A private interface.
- * All methods throw NS_ERROR_DOM_SECURITY_ERR if the caller is not chrome.
- */
-
-[scriptable, uuid(d3d068d8-e223-4228-ba39-4d6df21ba616)]
-interface nsIHTMLMenu : nsISupports
-{
-  /**
-   * Creates and dispatches a trusted event named "show".
-   * The event is not cancelable and does not bubble.
-   * See http://www.whatwg.org/specs/web-apps/current-work/multipage/interactive-elements.html#context-menus
-   */
-  void sendShowEvent();
-
-  /**
-   * Creates a native menu builder. The builder type is dependent on menu type.
-   * Currently, it returns nsXULContextMenuBuilder for context menus.
-   * Toolbar menus are not yet supported (the method returns null).
-   */
-  nsIMenuBuilder createBuilder();
-
-  /*
-   * Builds a menu by iterating over menu children.
-   * See http://www.whatwg.org/specs/web-apps/current-work/multipage/interactive-elements.html#building-menus-and-toolbars
-   * The caller can use a native builder by calling createBuilder() or provide
-   * a custom builder that implements the nsIMenuBuilder interface.
-   * A custom builder can be used for example to build native context menus
-   * that are not defined using <menupopup>.
-   */
-  void build(in nsIMenuBuilder aBuilder);
-
-};
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -2544,17 +2544,16 @@ var NativeWindow = {
      *             corresponding contextmenu will be used.
      */
     _getHTMLContextMenuItemsForElement: function(element) {
       let htmlMenu = element.contextMenu;
       if (!htmlMenu) {
         return [];
       }
 
-      htmlMenu.QueryInterface(Components.interfaces.nsIHTMLMenu);
       htmlMenu.sendShowEvent();
 
       return this._getHTMLContextMenuItemsForMenu(htmlMenu, element);
     },
 
     /* Add a menuitem for an HTML <menu> node
      * Parameters:
      *   menu - The <menu> element to iterate through for menuitems
--- a/toolkit/modules/PageMenu.jsm
+++ b/toolkit/modules/PageMenu.jsm
@@ -37,17 +37,16 @@ PageMenu.prototype = {
   // Given a target node, generate a JSON object for any context menu
   // associated with it, or null if there is no context menu.
   maybeBuild: function(aTarget) {
     let pageMenu = this.getContextMenu(aTarget);
     if (!pageMenu) {
       return null;
     }
 
-    pageMenu.QueryInterface(Components.interfaces.nsIHTMLMenu);
     pageMenu.sendShowEvent();
     // the show event is not cancelable, so no need to check a result here
 
     this._builder = pageMenu.createBuilder();
     if (!this._builder) {
       return null;
     }