Bug 1324035 part 2. Stop using nsContentUtils::ThreadSafeIsCallerChrome in nsMimeTypeArray. r=qdot
authorBoris Zbarsky <bzbarsky@mit.edu>
Sat, 17 Dec 2016 00:25:52 -0500
changeset 326286 2507af1c9c82452fc5262ffd98f52ff249caee10
parent 326285 108b378e35084591d5733281b8356b2908c68b3d
child 326287 414b97796bb7dbf87673b01264aeb8bd5101a22c
push id31093
push userphilringnalda@gmail.com
push dateSat, 17 Dec 2016 22:01:00 +0000
treeherdermozilla-central@5745bab28ff5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs1324035
milestone53.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 1324035 part 2. Stop using nsContentUtils::ThreadSafeIsCallerChrome in nsMimeTypeArray. r=qdot
dom/base/Navigator.cpp
dom/base/Navigator.h
dom/base/nsMimeTypeArray.cpp
dom/base/nsMimeTypeArray.h
dom/webidl/MimeTypeArray.webidl
dom/webidl/Navigator.webidl
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -708,17 +708,17 @@ Navigator::GetDoNotTrack(nsAString &aRes
   } else {
     aResult.AssignLiteral("unspecified");
   }
 
   return NS_OK;
 }
 
 bool
-Navigator::JavaEnabled(ErrorResult& aRv)
+Navigator::JavaEnabled(CallerType aCallerType, ErrorResult& aRv)
 {
   Telemetry::AutoTimer<Telemetry::CHECK_JAVA_ENABLED> telemetryTimer;
 
   // Return true if we have a handler for the java mime
   nsAdoptingString javaMIME = Preferences::GetString("plugin.java.mime");
   NS_ENSURE_TRUE(!javaMIME.IsEmpty(), false);
 
   if (!mMimeTypes) {
@@ -726,17 +726,17 @@ Navigator::JavaEnabled(ErrorResult& aRv)
       aRv.Throw(NS_ERROR_UNEXPECTED);
       return false;
     }
     mMimeTypes = new nsMimeTypeArray(mWindow);
   }
 
   RefreshMIMEArray();
 
-  nsMimeType *mimeType = mMimeTypes->NamedItem(javaMIME);
+  nsMimeType *mimeType = mMimeTypes->NamedItem(javaMIME, aCallerType);
 
   return mimeType && mimeType->GetEnabledPlugin();
 }
 
 uint64_t
 Navigator::HardwareConcurrency()
 {
   workers::RuntimeService* rts = workers::RuntimeService::GetOrCreateService();
--- a/dom/base/Navigator.h
+++ b/dom/base/Navigator.h
@@ -178,17 +178,17 @@ public:
                 ErrorResult& aRv) const;
   // The XPCOM GetVendor is OK
   // The XPCOM GetVendorSub is OK
   // The XPCOM GetProductSub is OK
   bool CookieEnabled();
   void GetBuildID(nsAString& aBuildID, CallerType aCallerType,
                   ErrorResult& aRv) const;
   PowerManager* GetMozPower(ErrorResult& aRv);
-  bool JavaEnabled(ErrorResult& aRv);
+  bool JavaEnabled(CallerType aCallerType, ErrorResult& aRv);
   uint64_t HardwareConcurrency();
   bool CpuHasSSE2();
   bool TaintEnabled()
   {
     return false;
   }
   void AddIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv);
   void RemoveIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv);
--- a/dom/base/nsMimeTypeArray.cpp
+++ b/dom/base/nsMimeTypeArray.cpp
@@ -38,18 +38,18 @@ nsMimeTypeArray::nsMimeTypeArray(nsPIDOM
 {
 }
 
 nsMimeTypeArray::~nsMimeTypeArray()
 {
 }
 
 static bool
-ResistFingerprinting() {
-  return !nsContentUtils::ThreadsafeIsCallerChrome() &&
+ResistFingerprinting(CallerType aCallerType) {
+  return aCallerType != CallerType::System &&
          nsContentUtils::ResistFingerprinting();
 }
 
 JSObject*
 nsMimeTypeArray::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
 {
   return MimeTypeArrayBinding::Wrap(aCx, this, aGivenProto);
 }
@@ -64,35 +64,36 @@ nsMimeTypeArray::Refresh()
 nsPIDOMWindowInner*
 nsMimeTypeArray::GetParentObject() const
 {
   MOZ_ASSERT(mWindow);
   return mWindow;
 }
 
 nsMimeType*
-nsMimeTypeArray::Item(uint32_t aIndex)
+nsMimeTypeArray::Item(uint32_t aIndex, CallerType aCallerType)
 {
   bool unused;
-  return IndexedGetter(aIndex, unused);
+  return IndexedGetter(aIndex, unused, aCallerType);
 }
 
 nsMimeType*
-nsMimeTypeArray::NamedItem(const nsAString& aName)
+nsMimeTypeArray::NamedItem(const nsAString& aName, CallerType aCallerType)
 {
   bool unused;
-  return NamedGetter(aName, unused);
+  return NamedGetter(aName, unused, aCallerType);
 }
 
 nsMimeType*
-nsMimeTypeArray::IndexedGetter(uint32_t aIndex, bool &aFound)
+nsMimeTypeArray::IndexedGetter(uint32_t aIndex, bool &aFound,
+                               CallerType aCallerType)
 {
   aFound = false;
 
-  if (ResistFingerprinting()) {
+  if (ResistFingerprinting(aCallerType)) {
     return nullptr;
   }
 
   EnsurePluginMimeTypes();
 
   if (aIndex >= mMimeTypes.Length()) {
     return nullptr;
   }
@@ -112,21 +113,22 @@ FindMimeType(const nsTArray<RefPtr<nsMim
       return mimeType;
     }
   }
 
   return nullptr;
 }
 
 nsMimeType*
-nsMimeTypeArray::NamedGetter(const nsAString& aName, bool &aFound)
+nsMimeTypeArray::NamedGetter(const nsAString& aName, bool &aFound,
+                             CallerType aCallerType)
 {
   aFound = false;
 
-  if (ResistFingerprinting()) {
+  if (ResistFingerprinting(aCallerType)) {
     return nullptr;
   }
 
   EnsurePluginMimeTypes();
 
   nsString lowerName(aName);
   ToLowerCase(lowerName);
 
@@ -139,19 +141,19 @@ nsMimeTypeArray::NamedGetter(const nsASt
   if (hiddenType) {
     nsPluginArray::NotifyHiddenPluginTouched(hiddenType->GetEnabledPlugin());
   }
 
   return nullptr;
 }
 
 uint32_t
-nsMimeTypeArray::Length()
+nsMimeTypeArray::Length(CallerType aCallerType)
 {
-  if (ResistFingerprinting()) {
+  if (ResistFingerprinting(aCallerType)) {
     return 0;
   }
 
   EnsurePluginMimeTypes();
 
   return mMimeTypes.Length();
 }
 
--- a/dom/base/nsMimeTypeArray.h
+++ b/dom/base/nsMimeTypeArray.h
@@ -6,16 +6,17 @@
 
 #ifndef nsMimeTypeArray_h___
 #define nsMimeTypeArray_h___
 
 #include "nsString.h"
 #include "nsTArray.h"
 #include "nsWrapperCache.h"
 #include "nsPIDOMWindow.h"
+#include "mozilla/dom/BindingDeclarations.h"
 
 class nsMimeType;
 class nsPluginElement;
 
 class nsMimeTypeArray final : public nsISupports,
                               public nsWrapperCache
 {
 public:
@@ -25,21 +26,24 @@ public:
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsMimeTypeArray)
 
   nsPIDOMWindowInner* GetParentObject() const;
   virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 
   void Refresh();
 
   // MimeTypeArray WebIDL methods
-  nsMimeType* Item(uint32_t index);
-  nsMimeType* NamedItem(const nsAString& name);
-  nsMimeType* IndexedGetter(uint32_t index, bool &found);
-  nsMimeType* NamedGetter(const nsAString& name, bool &found);
-  uint32_t Length();
+  nsMimeType* Item(uint32_t index, mozilla::dom::CallerType aCallerType);
+  nsMimeType* NamedItem(const nsAString& name,
+                        mozilla::dom::CallerType aCallerType);
+  nsMimeType* IndexedGetter(uint32_t index, bool &found,
+                            mozilla::dom::CallerType aCallerType);
+  nsMimeType* NamedGetter(const nsAString& name, bool &found,
+                          mozilla::dom::CallerType aCallerType);
+  uint32_t Length(mozilla::dom::CallerType aCallerType);
   void GetSupportedNames(nsTArray<nsString>& retval);
 
 protected:
   virtual ~nsMimeTypeArray();
 
   void EnsurePluginMimeTypes();
   void Clear();
 
--- a/dom/webidl/MimeTypeArray.webidl
+++ b/dom/webidl/MimeTypeArray.webidl
@@ -1,13 +1,16 @@
 /* -*- 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/.
  */
 
 [LegacyUnenumerableNamedProperties]
 interface MimeTypeArray {
+  [NeedsCallerType]
   readonly attribute unsigned long length;
 
+  [NeedsCallerType]
   getter MimeType? item(unsigned long index);
+  [NeedsCallerType]
   getter MimeType? namedItem(DOMString name);
 };
--- a/dom/webidl/Navigator.webidl
+++ b/dom/webidl/Navigator.webidl
@@ -187,17 +187,17 @@ partial interface Navigator {
   // WebKit/Blink/Trident/Presto support this.
   readonly attribute boolean cookieEnabled;
   [Throws, Constant, Cached, NeedsCallerType]
   readonly attribute DOMString buildID;
   [Throws, ChromeOnly, UnsafeInPrerendering]
   readonly attribute MozPowerManager mozPower;
 
   // WebKit/Blink/Trident/Presto support this.
-  [Throws]
+  [Throws, NeedsCallerType]
   boolean javaEnabled();
 
   /**
    * Navigator requests to add an idle observer to the existing window.
    */
   [Throws, ChromeOnly]
   void addIdleObserver(MozIdleObserver aIdleObserver);