Bug 1438945 - Allow passing an existing URL into the Worker script loader. r=asuth
authorBlake Kaplan <mrbkap@gmail.com>
Mon, 19 Nov 2018 15:18:34 -0800
changeset 503580 fab208773c488ca77ce4778ad40598c5bc51c1b2
parent 503579 7733e4286f9c615bde46ad140329ab73dd613e1e
child 503581 d71fcd5f9cb5f47d7ffa42d6a59f4523e1811d3a
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)
reviewersasuth
bugs1438945
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 1438945 - Allow passing an existing URL into the Worker script loader. r=asuth In the next patch I get rid of the duplicated arguments. Differential Revision: https://phabricator.services.mozilla.com/D11826
dom/workers/ScriptLoader.cpp
dom/workers/ScriptLoader.h
dom/workers/WorkerPrivate.cpp
dom/workers/remoteworkers/RemoteWorkerChild.cpp
--- a/dom/workers/ScriptLoader.cpp
+++ b/dom/workers/ScriptLoader.cpp
@@ -116,31 +116,36 @@ nsresult
 ChannelFromScriptURL(nsIPrincipal* principal,
                      nsIURI* baseURI,
                      nsIDocument* parentDoc,
                      WorkerPrivate* aWorkerPrivate,
                      nsILoadGroup* loadGroup,
                      nsIIOService* ios,
                      nsIScriptSecurityManager* secMan,
                      const nsAString& aScriptURL,
+                     nsIURI* aResolvedScriptURL,
                      const Maybe<ClientInfo>& aClientInfo,
                      const Maybe<ServiceWorkerDescriptor>& aController,
                      bool aIsMainScript,
                      WorkerScriptType aWorkerScriptType,
                      nsContentPolicyType aMainScriptContentPolicyType,
                      nsLoadFlags aLoadFlags,
                      bool aDefaultURIEncoding,
                      nsIChannel** aChannel)
 {
   AssertIsOnMainThread();
+  MOZ_ASSERT(!aResolvedScriptURL || aScriptURL.IsEmpty());
 
   nsresult rv;
   nsCOMPtr<nsIURI> uri;
 
-  if (aDefaultURIEncoding) {
+  if (aResolvedScriptURL) {
+    uri = aResolvedScriptURL;
+    rv = NS_OK;
+  } else if (aDefaultURIEncoding) {
     rv = NS_NewURI(getter_AddRefs(uri), aScriptURL, nullptr, baseURI);
   } else {
     rv = nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(uri),
                                                    aScriptURL, parentDoc,
                                                    baseURI);
   }
 
   if (NS_FAILED(rv)) {
@@ -1051,17 +1056,17 @@ private:
     }
 
     if (!channel) {
       // Only top level workers' main script use the document charset for the
       // script uri encoding. Otherwise, default encoding (UTF-8) is applied.
       bool useDefaultEncoding = !(!parentWorker && IsMainWorkerScript());
       rv = ChannelFromScriptURL(principal, baseURI, parentDoc, mWorkerPrivate,
                                 loadGroup, ios,
-                                secMan, loadInfo.mURL,
+                                secMan, loadInfo.mURL, nullptr,
                                 mClientInfo, mController,
                                 IsMainWorkerScript(),
                                 mWorkerScriptType,
                                 mWorkerPrivate->ContentPolicyType(), loadFlags,
                                 useDefaultEncoding,
                                 getter_AddRefs(channel));
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
@@ -1976,16 +1981,17 @@ public:
     clientInfo.emplace(mClientInfo);
 
     nsCOMPtr<nsIChannel> channel;
     mResult = workerinternals::
       ChannelFromScriptURLMainThread(mLoadInfo.mLoadingPrincipal,
                                      baseURI, parentDoc,
                                      mLoadInfo.mLoadGroup,
                                      mScriptURL,
+                                     nullptr,
                                      clientInfo,
                                      // Nested workers are always dedicated.
                                      nsIContentPolicy::TYPE_INTERNAL_WORKER,
                                      // Nested workers use default uri encoding.
                                      true,
                                      getter_AddRefs(channel));
     NS_ENSURE_SUCCESS(mResult, true);
 
@@ -2322,30 +2328,33 @@ LoadAllScripts(WorkerPrivate* aWorkerPri
 namespace workerinternals {
 
 nsresult
 ChannelFromScriptURLMainThread(nsIPrincipal* aPrincipal,
                                nsIURI* aBaseURI,
                                nsIDocument* aParentDoc,
                                nsILoadGroup* aLoadGroup,
                                const nsAString& aScriptURL,
+                               nsIURI* aResolvedScriptURL,
                                const Maybe<ClientInfo>& aClientInfo,
                                nsContentPolicyType aMainScriptContentPolicyType,
                                bool aDefaultURIEncoding,
                                nsIChannel** aChannel)
 {
   AssertIsOnMainThread();
+  MOZ_ASSERT(!aResolvedScriptURL || aScriptURL.IsEmpty());
 
   nsCOMPtr<nsIIOService> ios(do_GetIOService());
 
   nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
   NS_ASSERTION(secMan, "This should never be null!");
 
   return ChannelFromScriptURL(aPrincipal, aBaseURI, aParentDoc, nullptr,
-                              aLoadGroup, ios, secMan, aScriptURL, aClientInfo,
+                              aLoadGroup, ios, secMan, aScriptURL,
+                              aResolvedScriptURL, aClientInfo,
                               Maybe<ServiceWorkerDescriptor>(),
                               true, WorkerScript, aMainScriptContentPolicyType,
                               nsIRequest::LOAD_NORMAL, aDefaultURIEncoding,
                               aChannel);
 }
 
 nsresult
 ChannelFromScriptURLWorkerThread(JSContext* aCx,
--- a/dom/workers/ScriptLoader.h
+++ b/dom/workers/ScriptLoader.h
@@ -34,16 +34,17 @@ enum WorkerScriptType {
 namespace workerinternals {
 
 nsresult
 ChannelFromScriptURLMainThread(nsIPrincipal* aPrincipal,
                                nsIURI* aBaseURI,
                                nsIDocument* aParentDoc,
                                nsILoadGroup* aLoadGroup,
                                const nsAString& aScriptURL,
+                               nsIURI* aResolvedScriptURL,
                                const Maybe<ClientInfo>& aClientInfo,
                                nsContentPolicyType aContentPolicyType,
                                bool aDefaultURIEncoding,
                                nsIChannel** aChannel);
 
 nsresult
 ChannelFromScriptURLWorkerThread(JSContext* aCx,
                                  WorkerPrivate* aParent,
--- a/dom/workers/WorkerPrivate.cpp
+++ b/dom/workers/WorkerPrivate.cpp
@@ -2735,17 +2735,17 @@ WorkerPrivate::GetLoadInfo(JSContext* aC
                                             loadInfo.mLoadingPrincipal));
 
     // Top level workers' main script use the document charset for the script
     // uri encoding.
     bool useDefaultEncoding = false;
     rv = ChannelFromScriptURLMainThread(loadInfo.mLoadingPrincipal,
                                         loadInfo.mBaseURI,
                                         document, loadInfo.mLoadGroup,
-                                        aScriptURL,
+                                        aScriptURL, nullptr,
                                         clientInfo,
                                         ContentPolicyType(aWorkerType),
                                         useDefaultEncoding,
                                         getter_AddRefs(loadInfo.mChannel));
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = NS_GetFinalChannelURI(loadInfo.mChannel,
                                getter_AddRefs(loadInfo.mResolvedScriptURI));
--- a/dom/workers/remoteworkers/RemoteWorkerChild.cpp
+++ b/dom/workers/remoteworkers/RemoteWorkerChild.cpp
@@ -327,17 +327,18 @@ RemoteWorkerChild::ExecWorkerOnMainThrea
   }
 
   // Top level workers' main script use the document charset for the script
   // uri encoding.
   rv = ChannelFromScriptURLMainThread(info.mLoadingPrincipal,
                                       info.mBaseURI,
                                       nullptr /* parent document */,
                                       info.mLoadGroup,
-                                      aData.originalScriptURL(),
+                                      EmptyString(),
+                                      info.mResolvedScriptURI,
                                       clientInfo,
                                       aData.isSharedWorker()
                                         ? nsIContentPolicy::TYPE_INTERNAL_SHARED_WORKER
                                         : nsIContentPolicy::TYPE_INTERNAL_SERVICE_WORKER,
                                       false /* default encoding */,
                                       getter_AddRefs(info.mChannel));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;