Bug 1356412: Part 2 - Remove script loader path mangling from DOM code. r=bz
authorKris Maglione <maglione.k@gmail.com>
Fri, 02 Nov 2018 16:15:26 -0700
changeset 501011 00f962601b8b2ce44ce6e26eed1bc82fd0f130a4
parent 501010 9b4bf02afd60b4bec3e7d2cd8b3179e8b63faa3b
child 501012 6d850fafd7d185212f5494a71613a919b11a291b
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1356412
milestone65.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 1356412: Part 2 - Remove script loader path mangling from DOM code. r=bz As in part 1, this no longer serves any purpose. This patch also removes the otherwise unused WrappersEnabled() method, which was similarly only useful before we had compartment-based security isolation. Its functionality is now handled by compartment flags. Differential Revision: https://phabricator.services.mozilla.com/D10796
chrome/nsChromeRegistry.cpp
chrome/nsChromeRegistry.h
chrome/nsIChromeRegistry.idl
dom/base/nsContentUtils.cpp
dom/base/nsContentUtils.h
dom/script/ScriptLoader.cpp
dom/xbl/nsXBLService.cpp
dom/xul/nsXULElement.cpp
--- a/chrome/nsChromeRegistry.cpp
+++ b/chrome/nsChromeRegistry.cpp
@@ -600,38 +600,16 @@ nsChromeRegistry::GetDirectionForLocale(
   if (pref >= 0) {
     return (pref > 0);
   }
   nsAutoCString locale(aLocale);
   SanitizeForBCP47(locale);
   return uloc_isRightToLeft(locale.get());
 }
 
-NS_IMETHODIMP_(bool)
-nsChromeRegistry::WrappersEnabled(nsIURI *aURI)
-{
-  nsCOMPtr<nsIURL> chromeURL (do_QueryInterface(aURI));
-  if (!chromeURL)
-    return false;
-
-  bool isChrome = false;
-  nsresult rv = chromeURL->SchemeIs("chrome", &isChrome);
-  if (NS_FAILED(rv) || !isChrome)
-    return false;
-
-  nsAutoCString package;
-  rv = chromeURL->GetHostPort(package);
-  if (NS_FAILED(rv))
-    return false;
-
-  uint32_t flags;
-  rv = GetFlagsFromPackage(package, &flags);
-  return NS_SUCCEEDED(rv) && (flags & XPCNATIVEWRAPPERS);
-}
-
 already_AddRefed<nsChromeRegistry>
 nsChromeRegistry::GetSingleton()
 {
   if (gChromeRegistry) {
     RefPtr<nsChromeRegistry> registry = gChromeRegistry;
     return registry.forget();
   }
 
--- a/chrome/nsChromeRegistry.h
+++ b/chrome/nsChromeRegistry.h
@@ -44,18 +44,16 @@ public:
                                     bool* _retval) override;
   NS_IMETHOD AllowContentToAccess(nsIURI* url,
                                   bool* _retval) override;
   NS_IMETHOD CanLoadURLRemotely(nsIURI* url,
                                 bool* _retval) override;
   NS_IMETHOD MustLoadURLRemotely(nsIURI* url,
                                  bool* _retval) override;
 
-  // nsIChromeRegistry methods:
-  NS_IMETHOD_(bool) WrappersEnabled(nsIURI *aURI) override;
   NS_IMETHOD ConvertChromeURL(nsIURI* aChromeURI, nsIURI* *aResult) override;
 
   // nsChromeRegistry methods:
   nsChromeRegistry() : mInitialized(false) { }
 
   virtual nsresult Init();
 
   static already_AddRefed<nsIChromeRegistry> GetService();
--- a/chrome/nsIChromeRegistry.idl
+++ b/chrome/nsIChromeRegistry.idl
@@ -33,21 +33,16 @@ interface nsIChromeRegistry : nsISupport
    * @param aChromeURL the URL that is to be converted.
    */
   nsIURI convertChromeURL(in nsIURI aChromeURL);
 
   /**
    * refresh the chrome list at runtime, looking for new packages/etc
    */
   void checkForNewChrome();
-
-  /**
-   * returns whether XPCNativeWrappers are enabled for aURI.
-   */
-  [notxpcom] boolean wrappersEnabled(in nsIURI aURI);
 };
 
 [scriptable, uuid(93251ddf-5e85-4172-ac2a-31780562974f)]
 interface nsIXULChromeRegistry : nsIChromeRegistry
 {
   // If the optional asBCP47 parameter is true, the locale code will be
   // converted to a BCP47 language tag; in particular, this means that
   // "ja-JP-mac" will be returned as "ja-JP-x-lvariant-mac", which can be
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -4182,72 +4182,16 @@ nsContentUtils::IsUtf8OnlyPlainTextType(
 {
   // NOTE: This must be a subset of the list in IsPlainTextType().
   return aContentType.EqualsLiteral(TEXT_CACHE_MANIFEST) ||
          aContentType.EqualsLiteral(APPLICATION_JSON) ||
          aContentType.EqualsLiteral(TEXT_JSON) ||
          aContentType.EqualsLiteral(TEXT_VTT);
 }
 
-bool
-nsContentUtils::GetWrapperSafeScriptFilename(nsIDocument* aDocument,
-                                             nsIURI* aURI,
-                                             nsACString& aScriptURI,
-                                             nsresult* aRv)
-{
-  MOZ_ASSERT(aRv);
-  bool scriptFileNameModified = false;
-  *aRv = NS_OK;
-
-  *aRv = aURI->GetSpec(aScriptURI);
-  NS_ENSURE_SUCCESS(*aRv, false);
-
-  if (IsChromeDoc(aDocument)) {
-    nsCOMPtr<nsIChromeRegistry> chromeReg =
-      mozilla::services::GetChromeRegistryService();
-
-    if (!chromeReg) {
-      // If we're running w/o a chrome registry we won't modify any
-      // script file names.
-
-      return scriptFileNameModified;
-    }
-
-    bool docWrappersEnabled =
-      chromeReg->WrappersEnabled(aDocument->GetDocumentURI());
-
-    bool uriWrappersEnabled = chromeReg->WrappersEnabled(aURI);
-
-    nsIURI *docURI = aDocument->GetDocumentURI();
-
-    if (docURI && docWrappersEnabled && !uriWrappersEnabled) {
-      // aURI is a script from a URL that doesn't get wrapper
-      // automation. aDocument is a chrome document that does get
-      // wrapper automation. Prepend the chrome document's URI
-      // followed by the string " -> " to the URI of the script we're
-      // loading here so that script in that URI gets the same wrapper
-      // automation that the chrome document expects.
-      nsAutoCString spec;
-      *aRv = docURI->GetSpec(spec);
-      if (NS_WARN_IF(NS_FAILED(*aRv))) {
-        return false;
-      }
-
-      spec.AppendLiteral(" -> ");
-      spec.Append(aScriptURI);
-
-      aScriptURI = spec;
-
-      scriptFileNameModified = true;
-    }
-  }
-
-  return scriptFileNameModified;
-}
-
 // static
 bool
 nsContentUtils::IsInChromeDocshell(nsIDocument *aDocument)
 {
   if (!aDocument) {
     return false;
   }
 
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -1258,30 +1258,16 @@ public:
   static bool IsPlainTextType(const nsACString& aContentType);
 
   /**
    * Returns true iff the type is rendered as plain text and doesn't support
    * non-UTF-8 encodings.
    */
   static bool IsUtf8OnlyPlainTextType(const nsACString& aContentType);
 
-  /**
-   * Get the script file name to use when compiling the script
-   * referenced by aURI. In cases where there's no need for any extra
-   * security wrapper automation the script file name that's returned
-   * will be the spec in aURI, else it will be the spec in aDocument's
-   * URI followed by aURI's spec, separated by " -> ". Returns true
-   * if the script file name was modified, false if it's aURI's
-   * spec.
-   */
-  static bool GetWrapperSafeScriptFilename(nsIDocument *aDocument,
-                                             nsIURI *aURI,
-                                             nsACString& aScriptURI,
-                                             nsresult* aRv);
-
 
   /**
    * Returns true if aDocument belongs to a chrome docshell for
    * display purposes.  Returns false for null documents or documents
    * which do not belong to a docshell.
    */
   static bool IsInChromeDocshell(nsIDocument *aDocument);
 
--- a/dom/script/ScriptLoader.cpp
+++ b/dom/script/ScriptLoader.cpp
@@ -2128,19 +2128,17 @@ ScriptLoader::GetScriptGlobalObject()
 nsresult
 ScriptLoader::FillCompileOptionsForRequest(const AutoJSAPI&jsapi,
                                            ScriptLoadRequest* aRequest,
                                            JS::Handle<JSObject*> aScopeChain,
                                            JS::CompileOptions* aOptions)
 {
   // It's very important to use aRequest->mURI, not the final URI of the channel
   // aRequest ended up getting script data from, as the script filename.
-  nsresult rv;
-  nsContentUtils::GetWrapperSafeScriptFilename(mDocument, aRequest->mURI,
-                                               aRequest->mURL, &rv);
+  nsresult rv = aRequest->mURI->GetSpec(aRequest->mURL);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   if (mDocument) {
     mDocument->NoteScriptTrackingStatus(aRequest->mURL, aRequest->IsTracking());
   }
 
--- a/dom/xbl/nsXBLService.cpp
+++ b/dom/xbl/nsXBLService.cpp
@@ -550,29 +550,21 @@ nsXBLService::LoadBindings(Element* aEle
   if (binding && !binding->MarkedForDeath() &&
       binding->PrototypeBinding()->CompareBindingURI(aURL)) {
     return NS_OK;
   }
 
   nsCOMPtr<nsIDocument> document = aElement->OwnerDoc();
 
   nsAutoCString urlspec;
-  nsresult rv;
-  bool ok = nsContentUtils::GetWrapperSafeScriptFilename(document, aURL,
-                                                         urlspec, &rv);
+  nsresult rv = aURL->GetSpec(urlspec);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
-  if (ok) {
-    // Block an attempt to load a binding that has special wrapper
-    // automation needs.
-    return NS_OK;
-  }
-
   if (binding) {
     FlushStyleBindings(aElement);
     binding = nullptr;
   }
 
   bool ready;
   RefPtr<nsXBLBinding> newBinding;
   if (NS_FAILED(rv = GetBinding(aElement, aURL, false, aOriginPrincipal,
--- a/dom/xul/nsXULElement.cpp
+++ b/dom/xul/nsXULElement.cpp
@@ -2285,19 +2285,18 @@ nsXULPrototypeScript::Compile(JS::Source
 {
     // We'll compile the script in the compilation scope.
     AutoJSAPI jsapi;
     if (!jsapi.Init(xpc::CompilationScope())) {
         return NS_ERROR_UNEXPECTED;
     }
     JSContext* cx = jsapi.cx();
 
-    nsresult rv;
     nsAutoCString urlspec;
-    nsContentUtils::GetWrapperSafeScriptFilename(aDocument, aURI, urlspec, &rv);
+    nsresult rv = aURI->GetSpec(urlspec);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
 
     // Ok, compile it to create a prototype script object!
     JS::CompileOptions options(cx);
     options.setIntroductionType("scriptElement")
            .setFileAndLine(urlspec.get(), aLineNo);