From cddea9ec89497ba1809673fac2580200a609c9cf Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Fri, 8 Jan 2016 15:53:38 -0500 Subject: [PATCH] Bug 1236933 - Return null from FetchEvent.clientId for non-subresource network requests; r=bkelly --- dom/workers/ServiceWorkerManager.cpp | 3 ++- dom/workers/ServiceWorkerPrivate.cpp | 4 ++- .../service-worker/clients-get.https.html | 26 ++++++++++++++++--- .../service-worker/fetch-event.https.html | 10 ++----- .../resources/clients-get-frame.html | 12 +++++++++ .../resources/clients-get-worker.js | 8 ++++++ .../resources/fetch-event-test-worker.js | 2 +- 7 files changed, 50 insertions(+), 15 deletions(-) create mode 100644 testing/web-platform/mozilla/tests/service-workers/service-worker/resources/clients-get-frame.html diff --git a/dom/workers/ServiceWorkerManager.cpp b/dom/workers/ServiceWorkerManager.cpp index 9e8799797460..5aaa9b835602 100644 --- a/dom/workers/ServiceWorkerManager.cpp +++ b/dom/workers/ServiceWorkerManager.cpp @@ -3601,7 +3601,8 @@ ServiceWorkerManager::DispatchFetchEvent(const PrincipalOriginAttributes& aOrigi internalChannel->GetLoadGroup(getter_AddRefs(loadGroup)); - documentId = aDocumentIdForTopLevelNavigation; + // TODO: Use aDocumentIdForTopLevelNavigation for potentialClientId, pending + // the spec change. nsCOMPtr uri; aRv = aChannel->GetSecureUpgradedChannelURI(getter_AddRefs(uri)); diff --git a/dom/workers/ServiceWorkerPrivate.cpp b/dom/workers/ServiceWorkerPrivate.cpp index 813823d9d804..db0a0e8e0640 100644 --- a/dom/workers/ServiceWorkerPrivate.cpp +++ b/dom/workers/ServiceWorkerPrivate.cpp @@ -1243,7 +1243,9 @@ private: init.mRequest.Value() = request; init.mBubbles = false; init.mCancelable = true; - init.mClientId = mClientId; + if (!mClientId.IsEmpty()) { + init.mClientId = mClientId; + } init.mIsReload = mIsReload; RefPtr event = FetchEvent::Constructor(globalObj, NS_LITERAL_STRING("fetch"), init, result); diff --git a/testing/web-platform/mozilla/tests/service-workers/service-worker/clients-get.https.html b/testing/web-platform/mozilla/tests/service-workers/service-worker/clients-get.https.html index 848c2a9e35bf..af38502dd9fc 100644 --- a/testing/web-platform/mozilla/tests/service-workers/service-worker/clients-get.https.html +++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/clients-get.https.html @@ -7,9 +7,10 @@ diff --git a/testing/web-platform/mozilla/tests/service-workers/service-worker/resources/clients-get-worker.js b/testing/web-platform/mozilla/tests/service-workers/service-worker/resources/clients-get-worker.js index 48ad770934a1..9ac2c2264589 100644 --- a/testing/web-platform/mozilla/tests/service-workers/service-worker/resources/clients-get-worker.js +++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/resources/clients-get-worker.js @@ -1,4 +1,12 @@ self.onfetch = function(e) { + if (e.request.url.indexOf("clients-get-frame.html") >= 0) { + if (e.clientId === null) { + e.respondWith(fetch(e.request)); + } else { + e.respondWith(Response.error()); + } + return; + } e.respondWith(new Response(e.clientId)); }; diff --git a/testing/web-platform/mozilla/tests/service-workers/service-worker/resources/fetch-event-test-worker.js b/testing/web-platform/mozilla/tests/service-workers/service-worker/resources/fetch-event-test-worker.js index b56602e0fa2e..1443681f41b4 100644 --- a/testing/web-platform/mozilla/tests/service-workers/service-worker/resources/fetch-event-test-worker.js +++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/resources/fetch-event-test-worker.js @@ -13,7 +13,7 @@ function handleReferrer(event) { function handleClientId(event) { var body; - if (event.clientId !== '') { + if (event.clientId !== null) { body = 'Client ID Found: ' + event.clientId; } else { body = 'Client ID Not Found';