Bug 1318630 - Part 1: Fix missing control pref checks for custom element feature; r=wchen a=jcristau
authorEdgar Chen <echen@mozilla.com>
Thu, 08 Dec 2016 09:22:46 -1000
changeset 366130 6a7b2a984a1a5834b8476a75cc97960ff015b719
parent 366129 a7e613c48e2ab4a4c6a495dc759acf0bbda20d44
child 366131 f724a0c2c3d7072da6dbf438b6c76b5729364916
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-beta@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswchen, jcristau
bugs1318630
milestone52.0a2
Bug 1318630 - Part 1: Fix missing control pref checks for custom element feature; r=wchen a=jcristau MozReview-Commit-ID: F9EJMk0kVEA
dom/base/CustomElementRegistry.cpp
dom/base/CustomElementRegistry.h
dom/base/nsDocument.cpp
--- a/dom/base/CustomElementRegistry.cpp
+++ b/dom/base/CustomElementRegistry.cpp
@@ -159,37 +159,31 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(CustomE
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CustomElementRegistry)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
 
 /* static */ bool
 CustomElementRegistry::IsCustomElementEnabled(JSContext* aCx, JSObject* aObject)
 {
-  JS::Rooted<JSObject*> obj(aCx, aObject);
-  if (Preferences::GetBool("dom.webcomponents.customelements.enabled") ||
-      Preferences::GetBool("dom.webcomponents.enabled")) {
-    return true;
-  }
-
-  return false;
+  return Preferences::GetBool("dom.webcomponents.customelements.enabled") ||
+         Preferences::GetBool("dom.webcomponents.enabled");
 }
 
 /* static */ already_AddRefed<CustomElementRegistry>
 CustomElementRegistry::Create(nsPIDOMWindowInner* aWindow)
 {
   MOZ_ASSERT(aWindow);
   MOZ_ASSERT(aWindow->IsInnerWindow());
 
   if (!aWindow->GetDocShell()) {
     return nullptr;
   }
 
-  if (!Preferences::GetBool("dom.webcomponents.customelements.enabled") &&
-      !Preferences::GetBool("dom.webcomponents.enabled")) {
+  if (!IsCustomElementEnabled()) {
     return nullptr;
   }
 
   RefPtr<CustomElementRegistry> customElementRegistry =
     new CustomElementRegistry(aWindow);
   return customElementRegistry.forget();
 }
 
--- a/dom/base/CustomElementRegistry.h
+++ b/dom/base/CustomElementRegistry.h
@@ -135,17 +135,18 @@ class CustomElementRegistry final : publ
   // Allow nsDocument to access mCustomDefinitions and mCandidatesMap.
   friend class ::nsDocument;
 
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(CustomElementRegistry)
 
 public:
-  static bool IsCustomElementEnabled(JSContext* aCx, JSObject* aObject);
+  static bool IsCustomElementEnabled(JSContext* aCx = nullptr,
+                                     JSObject* aObject = nullptr);
   static already_AddRefed<CustomElementRegistry> Create(nsPIDOMWindowInner* aWindow);
   static void ProcessTopElementQueue();
 
   static void XPCOMShutdown();
 
   /**
    * Looking up a custom element definition.
    * https://html.spec.whatwg.org/#look-up-a-custom-element-definition
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -12788,17 +12788,17 @@ const nsString*
 nsDocument::CheckCustomElementName(const ElementCreationOptions& aOptions,
                                    const nsAString& aLocalName,
                                    uint32_t aNamespaceID,
                                    ErrorResult& rv)
 {
   // only check aOptions if 'is' is passed and the webcomponents preference
   // is enabled
   if (!aOptions.mIs.WasPassed() ||
-      !Preferences::GetBool("dom.webcomponents.enabled")) {
+      !CustomElementRegistry::IsCustomElementEnabled()) {
       return nullptr;
   }
 
   const nsString* is = &aOptions.mIs.Value();
 
   // Throw NotFoundError if 'is' is not-null and definition is null
   if (!nsContentUtils::LookupCustomElementDefinition(this, aLocalName,
                                                      aNamespaceID, is)) {