Bug 1437760 P1 Propagate the FetchEvent.request.url fragment to the synthesized Response.url. r=asuth
authorBen Kelly <ben@wanderview.com>
Wed, 21 Feb 2018 07:28:32 -0800
changeset 404648 c6b9c2cb220d504dd68263f8d7291d4cdaa0f54c
parent 404647 6de1bb4f3df3c039c109cbbcbf0e95e24e6ee218
child 404649 bb3c9990840a0fae2afc840b5952d7874785b112
push id100056
push userbkelly@mozilla.com
push dateWed, 21 Feb 2018 15:28:42 +0000
treeherdermozilla-inbound@bb3c9990840a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1437760
milestone60.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 1437760 P1 Propagate the FetchEvent.request.url fragment to the synthesized Response.url. r=asuth
dom/serviceworkers/ServiceWorkerEvents.cpp
--- a/dom/serviceworkers/ServiceWorkerEvents.cpp
+++ b/dom/serviceworkers/ServiceWorkerEvents.cpp
@@ -413,41 +413,44 @@ class RespondWithHandler final : public 
   nsMainThreadPtrHandle<ServiceWorkerRegistrationInfo> mRegistration;
   const RequestMode mRequestMode;
   const RequestRedirect mRequestRedirectMode;
 #ifdef DEBUG
   const bool mIsClientRequest;
 #endif
   const nsCString mScriptSpec;
   const nsString mRequestURL;
+  const nsCString mRequestFragment;
   const nsCString mRespondWithScriptSpec;
   const uint32_t mRespondWithLineNumber;
   const uint32_t mRespondWithColumnNumber;
   bool mRequestWasHandled;
 public:
   NS_DECL_ISUPPORTS
 
   RespondWithHandler(nsMainThreadPtrHandle<nsIInterceptedChannel>& aChannel,
                      nsMainThreadPtrHandle<ServiceWorkerRegistrationInfo>& aRegistration,
                      RequestMode aRequestMode, bool aIsClientRequest,
                      RequestRedirect aRedirectMode,
                      const nsACString& aScriptSpec,
                      const nsAString& aRequestURL,
+                     const nsACString& aRequestFragment,
                      const nsACString& aRespondWithScriptSpec,
                      uint32_t aRespondWithLineNumber,
                      uint32_t aRespondWithColumnNumber)
     : mInterceptedChannel(aChannel)
     , mRegistration(aRegistration)
     , mRequestMode(aRequestMode)
     , mRequestRedirectMode(aRedirectMode)
 #ifdef DEBUG
     , mIsClientRequest(aIsClientRequest)
 #endif
     , mScriptSpec(aScriptSpec)
     , mRequestURL(aRequestURL)
+    , mRequestFragment(aRequestFragment)
     , mRespondWithScriptSpec(aRespondWithScriptSpec)
     , mRespondWithLineNumber(aRespondWithLineNumber)
     , mRespondWithColumnNumber(aRespondWithColumnNumber)
     , mRequestWasHandled(false)
   {
   }
 
   void ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override;
@@ -711,16 +714,28 @@ RespondWithHandler::ResolvedCallback(JSC
   }
 
   // Propagate the URL to the content if the request mode is not "navigate".
   // Note that, we only reflect the final URL if the response.redirected is
   // false. We propagate all the URLs if the response.redirected is true.
   nsCString responseURL;
   if (mRequestMode != RequestMode::Navigate) {
     responseURL = ir->GetUnfilteredURL();
+
+    // Similar to how we apply the request fragment to redirects automatically
+    // we also want to apply it automatically when propagating the response
+    // URL from a service worker interception.  Currently response.url strips
+    // the fragment, so this will never conflict with an existing fragment
+    // on the response.  In the future we will have to check for a response
+    // fragment and avoid overriding in that case.
+    if (!mRequestFragment.IsEmpty()) {
+      MOZ_ASSERT(!responseURL.Contains('#'));
+      responseURL.Append(NS_LITERAL_CSTRING("#"));
+      responseURL.Append(mRequestFragment);
+    }
   }
 
   UniquePtr<RespondWithClosure> closure(new RespondWithClosure(mInterceptedChannel,
                                                                mRegistration,
                                                                mRequestURL,
                                                                mRespondWithScriptSpec,
                                                                mRespondWithLineNumber,
                                                                mRespondWithColumnNumber));
@@ -811,17 +826,17 @@ FetchEvent::RespondWith(JSContext* aCx, 
   ir->GetURL(requestURL);
 
   StopImmediatePropagation();
   mWaitToRespond = true;
   RefPtr<RespondWithHandler> handler =
     new RespondWithHandler(mChannel, mRegistration, mRequest->Mode(),
                            ir->IsClientRequest(), mRequest->Redirect(),
                            mScriptSpec, NS_ConvertUTF8toUTF16(requestURL),
-                           spec, line, column);
+                           ir->GetFragment(), spec, line, column);
   aArg.AppendNativeHandler(handler);
 
   if (!WaitOnPromise(aArg)) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
   }
 }
 
 void