diff --git a/dom/cache/CacheStorage.cpp b/dom/cache/CacheStorage.cpp index 96e10a0de6c..d0a6a2a63e9 100644 --- a/dom/cache/CacheStorage.cpp +++ b/dom/cache/CacheStorage.cpp @@ -119,7 +119,6 @@ IsTrusted(const PrincipalInfo& aPrincipalInfo, bool aTestingPrefEnabled) nsAutoCString scheme(Substring(flatURL, schemePos, schemeLen)); if (scheme.LowerCaseEqualsLiteral("https") || - scheme.LowerCaseEqualsLiteral("app") || scheme.LowerCaseEqualsLiteral("file")) { return true; } diff --git a/dom/cache/TypeUtils.cpp b/dom/cache/TypeUtils.cpp index ad373b26737..4a354c40b60 100644 --- a/dom/cache/TypeUtils.cpp +++ b/dom/cache/TypeUtils.cpp @@ -417,8 +417,7 @@ TypeUtils::ProcessURL(nsACString& aUrl, bool* aSchemeValidOut, if (aSchemeValidOut) { nsAutoCString scheme(Substring(flatURL, schemePos, schemeLen)); *aSchemeValidOut = scheme.LowerCaseEqualsLiteral("http") || - scheme.LowerCaseEqualsLiteral("https") || - scheme.LowerCaseEqualsLiteral("app"); + scheme.LowerCaseEqualsLiteral("https"); } uint32_t queryPos; diff --git a/dom/fetch/ChannelInfo.cpp b/dom/fetch/ChannelInfo.cpp index de31fd6b1bf..5ecc7f7624b 100644 --- a/dom/fetch/ChannelInfo.cpp +++ b/dom/fetch/ChannelInfo.cpp @@ -13,8 +13,6 @@ #include "nsSerializationHelper.h" #include "mozilla/net/HttpBaseChannel.h" #include "mozilla/ipc/ChannelInfo.h" -#include "nsIJARChannel.h" -#include "nsJARChannel.h" #include "nsNetUtil.h" using namespace mozilla; @@ -90,32 +88,20 @@ ChannelInfo::ResurrectInfoOnChannel(nsIChannel* aChannel) MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(mInited); - // These pointers may be null at this point. They must be checked before - // being dereferenced. - nsCOMPtr httpChannel = - do_QueryInterface(aChannel); - nsCOMPtr jarChannel = - do_QueryInterface(aChannel); - if (!mSecurityInfo.IsEmpty()) { nsCOMPtr infoObj; nsresult rv = NS_DeserializeObject(mSecurityInfo, getter_AddRefs(infoObj)); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } - if (httpChannel) { - net::HttpBaseChannel* httpBaseChannel = - static_cast(httpChannel.get()); - rv = httpBaseChannel->OverrideSecurityInfo(infoObj); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } - } else { - if (NS_WARN_IF(!jarChannel)) { - return NS_ERROR_FAILURE; - } - static_cast(jarChannel.get())-> - OverrideSecurityInfo(infoObj); + nsCOMPtr httpChannel = + do_QueryInterface(aChannel); + MOZ_ASSERT(httpChannel); + net::HttpBaseChannel* httpBaseChannel = + static_cast(httpChannel.get()); + rv = httpBaseChannel->OverrideSecurityInfo(infoObj); + if (NS_WARN_IF(NS_FAILED(rv))) { + return rv; } } diff --git a/dom/fetch/FetchDriver.cpp b/dom/fetch/FetchDriver.cpp index a9b340f8e4d..c05823ed248 100644 --- a/dom/fetch/FetchDriver.cpp +++ b/dom/fetch/FetchDriver.cpp @@ -14,7 +14,6 @@ #include "nsIHttpChannel.h" #include "nsIHttpChannelInternal.h" #include "nsIHttpHeaderVisitor.h" -#include "nsIJARChannel.h" #include "nsIScriptSecurityManager.h" #include "nsIThreadRetargetableRequest.h" #include "nsIUploadChannel2.h" @@ -463,7 +462,6 @@ FetchDriver::OnStartRequest(nsIRequest* aRequest, RefPtr response; nsCOMPtr channel = do_QueryInterface(aRequest); nsCOMPtr httpChannel = do_QueryInterface(aRequest); - nsCOMPtr jarChannel = do_QueryInterface(aRequest); // On a successful redirect we perform the following substeps of HTTP Fetch, // step 5, "redirect status", step 11. @@ -508,18 +506,6 @@ FetchDriver::OnStartRequest(nsIRequest* aRequest, if (NS_WARN_IF(NS_FAILED(rv))) { NS_WARNING("Failed to visit all headers."); } - } else if (jarChannel) { - // We simulate the http protocol for jar/app requests - uint32_t responseStatus = 200; - nsAutoCString statusText; - response = new InternalResponse(responseStatus, NS_LITERAL_CSTRING("OK")); - ErrorResult result; - nsAutoCString contentType; - jarChannel->GetContentType(contentType); - response->Headers()->Append(NS_LITERAL_CSTRING("content-type"), - contentType, - result); - MOZ_ASSERT(!result.Failed()); } else { response = new InternalResponse(200, NS_LITERAL_CSTRING("OK")); diff --git a/dom/fetch/InternalRequest.cpp b/dom/fetch/InternalRequest.cpp index 01fe39f8bf0..e65d29232dd 100644 --- a/dom/fetch/InternalRequest.cpp +++ b/dom/fetch/InternalRequest.cpp @@ -306,14 +306,6 @@ InternalRequest::MapChannelToRequestMode(nsIChannel* aChannel) // TODO: remove following code once securityMode is fully implemented (bug 1189945) - // We only support app:// protocol interception in non-release builds. -#ifndef RELEASE_BUILD - nsCOMPtr jarChannel = do_QueryInterface(aChannel); - if (jarChannel) { - return RequestMode::No_cors; - } -#endif - nsCOMPtr httpChannel = do_QueryInterface(aChannel); uint32_t corsMode; diff --git a/dom/fetch/moz.build b/dom/fetch/moz.build index 9b3e60ddcc5..b0d140ca2be 100644 --- a/dom/fetch/moz.build +++ b/dom/fetch/moz.build @@ -36,8 +36,6 @@ IPDL_SOURCES += [ LOCAL_INCLUDES += [ '../workers', - # For nsJARChannel.h - '/modules/libjar', # For HttpBaseChannel.h dependencies '/netwerk/base', # For nsDataHandler.h diff --git a/dom/workers/ServiceWorkerManager.cpp b/dom/workers/ServiceWorkerManager.cpp index 38e439bd4e8..280cae1d138 100644 --- a/dom/workers/ServiceWorkerManager.cpp +++ b/dom/workers/ServiceWorkerManager.cpp @@ -14,7 +14,6 @@ #include "nsIHttpChannel.h" #include "nsIHttpChannelInternal.h" #include "nsIHttpHeaderVisitor.h" -#include "nsIJARChannel.h" #include "nsINetworkInterceptController.h" #include "nsIMutableArray.h" #include "nsIScriptError.h" @@ -1766,15 +1765,7 @@ ServiceWorkerManager::Register(nsIDOMWindow* aWindow, aScriptURI->SchemeIs("http", &isHttp); aScriptURI->SchemeIs("https", &isHttps); if (NS_WARN_IF(!isHttp && !isHttps)) { -#ifdef RELEASE_BUILD return NS_ERROR_DOM_SECURITY_ERR; -#else - bool isApp = false; - aScriptURI->SchemeIs("app", &isApp); - if (NS_WARN_IF(!isApp)) { - return NS_ERROR_DOM_SECURITY_ERR; - } -#endif } nsCString cleanedScope; diff --git a/dom/workers/ServiceWorkerPrivate.cpp b/dom/workers/ServiceWorkerPrivate.cpp index 4c5fc3966d6..c5e501ba959 100644 --- a/dom/workers/ServiceWorkerPrivate.cpp +++ b/dom/workers/ServiceWorkerPrivate.cpp @@ -998,7 +998,6 @@ class FetchEventRunnable : public ExtendableFunctionalEventWorkerRunnable nsCString mMethod; nsString mClientId; bool mIsReload; - DebugOnly mIsHttpChannel; RequestMode mRequestMode; RequestRedirect mRequestRedirect; RequestCredentials mRequestCredentials; @@ -1021,7 +1020,6 @@ public: , mScriptSpec(aScriptSpec) , mClientId(aDocumentId) , mIsReload(aIsReload) - , mIsHttpChannel(false) , mRequestMode(RequestMode::No_cors) , mRequestRedirect(RequestRedirect::Follow) // By default we set it to same-origin since normal HTTP fetches always @@ -1070,61 +1068,46 @@ public: nsCOMPtr referrerURI; rv = NS_GetReferrerFromChannel(channel, getter_AddRefs(referrerURI)); - // We can't bail on failure since certain non-http channels like JAR - // channels are intercepted but don't have referrers. - if (NS_SUCCEEDED(rv) && referrerURI) { + NS_ENSURE_SUCCESS(rv, rv); + if (referrerURI) { rv = referrerURI->GetSpec(mReferrer); NS_ENSURE_SUCCESS(rv, rv); } nsCOMPtr httpChannel = do_QueryInterface(channel); - if (httpChannel) { - mIsHttpChannel = true; + MOZ_ASSERT(httpChannel, "How come we don't have an HTTP channel?"); - rv = httpChannel->GetRequestMethod(mMethod); + rv = httpChannel->GetRequestMethod(mMethod); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr internalChannel = do_QueryInterface(httpChannel); + NS_ENSURE_TRUE(internalChannel, NS_ERROR_NOT_AVAILABLE); + + mRequestMode = InternalRequest::MapChannelToRequestMode(channel); + + // This is safe due to static_asserts at top of file. + uint32_t redirectMode; + internalChannel->GetRedirectMode(&redirectMode); + mRequestRedirect = static_cast(redirectMode); + + mRequestCredentials = InternalRequest::MapChannelToRequestCredentials(channel); + + rv = httpChannel->VisitNonDefaultRequestHeaders(this); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr uploadChannel = do_QueryInterface(httpChannel); + if (uploadChannel) { + MOZ_ASSERT(!mUploadStream); + bool bodyHasHeaders = false; + rv = uploadChannel->GetUploadStreamHasHeaders(&bodyHasHeaders); NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr internalChannel = do_QueryInterface(httpChannel); - NS_ENSURE_TRUE(internalChannel, NS_ERROR_NOT_AVAILABLE); - - mRequestMode = InternalRequest::MapChannelToRequestMode(channel); - - // This is safe due to static_asserts at top of file. - uint32_t redirectMode; - internalChannel->GetRedirectMode(&redirectMode); - mRequestRedirect = static_cast(redirectMode); - - mRequestCredentials = InternalRequest::MapChannelToRequestCredentials(channel); - - rv = httpChannel->VisitNonDefaultRequestHeaders(this); + nsCOMPtr uploadStream; + rv = uploadChannel->CloneUploadStream(getter_AddRefs(uploadStream)); NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr uploadChannel = do_QueryInterface(httpChannel); - if (uploadChannel) { - MOZ_ASSERT(!mUploadStream); - bool bodyHasHeaders = false; - rv = uploadChannel->GetUploadStreamHasHeaders(&bodyHasHeaders); - NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr uploadStream; - rv = uploadChannel->CloneUploadStream(getter_AddRefs(uploadStream)); - NS_ENSURE_SUCCESS(rv, rv); - if (bodyHasHeaders) { - HandleBodyWithHeaders(uploadStream); - } else { - mUploadStream = uploadStream; - } - } - } else { - nsCOMPtr jarChannel = do_QueryInterface(channel); - // If it is not an HTTP channel it must be a JAR one. - NS_ENSURE_TRUE(jarChannel, NS_ERROR_NOT_AVAILABLE); - - mMethod = "GET"; - - mRequestMode = InternalRequest::MapChannelToRequestMode(channel); - - if (loadFlags & nsIRequest::LOAD_ANONYMOUS) { - mRequestCredentials = RequestCredentials::Omit; + if (bodyHasHeaders) { + HandleBodyWithHeaders(uploadStream); + } else { + mUploadStream = uploadStream; } } @@ -1213,9 +1196,7 @@ private: } RefPtr request = new Request(global, internalReq); - // TODO: remove conditional on http here once app protocol support is - // removed from service worker interception - MOZ_ASSERT_IF(mIsHttpChannel && internalReq->IsNavigationRequest(), + MOZ_ASSERT_IF(internalReq->IsNavigationRequest(), request->Redirect() == RequestRedirect::Manual); RootedDictionary init(aCx); diff --git a/dom/workers/ServiceWorkerScriptCache.cpp b/dom/workers/ServiceWorkerScriptCache.cpp index 48da522b0c9..81f41efd3e0 100644 --- a/dom/workers/ServiceWorkerScriptCache.cpp +++ b/dom/workers/ServiceWorkerScriptCache.cpp @@ -724,83 +724,54 @@ CompareNetwork::OnStreamComplete(nsIStreamLoader* aLoader, nsISupports* aContext } nsCOMPtr httpChannel = do_QueryInterface(request); - if (httpChannel) { - bool requestSucceeded; - rv = httpChannel->GetRequestSucceeded(&requestSucceeded); - if (NS_WARN_IF(NS_FAILED(rv))) { - mManager->NetworkFinished(rv); - return NS_OK; - } + MOZ_ASSERT(httpChannel, "How come we don't have an HTTP channel?"); - if (NS_WARN_IF(!requestSucceeded)) { - mManager->NetworkFinished(NS_ERROR_FAILURE); - return NS_OK; - } - - nsAutoCString maxScope; - // Note: we explicitly don't check for the return value here, because the - // absence of the header is not an error condition. - Unused << httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Service-Worker-Allowed"), - maxScope); - - mManager->SetMaxScope(maxScope); - - bool isFromCache = false; - nsCOMPtr cacheChannel(do_QueryInterface(httpChannel)); - if (cacheChannel) { - cacheChannel->IsFromCache(&isFromCache); - } - - // [9.2 Update]4.13, If response's cache state is not "local", - // set registration's last update check time to the current time - if (!isFromCache) { - RefPtr registration = - mManager->GetRegistration(); - registration->RefreshLastUpdateCheckTime(); - } - - nsAutoCString mimeType; - rv = httpChannel->GetContentType(mimeType); - if (NS_WARN_IF(NS_FAILED(rv))) { - mManager->NetworkFinished(NS_ERROR_DOM_SECURITY_ERR); - return rv; - } - - if (!mimeType.LowerCaseEqualsLiteral("text/javascript") && - !mimeType.LowerCaseEqualsLiteral("application/x-javascript") && - !mimeType.LowerCaseEqualsLiteral("application/javascript")) { - mManager->NetworkFinished(NS_ERROR_DOM_SECURITY_ERR); - return rv; - } + bool requestSucceeded; + rv = httpChannel->GetRequestSucceeded(&requestSucceeded); + if (NS_WARN_IF(NS_FAILED(rv))) { + mManager->NetworkFinished(rv); + return NS_OK; } - else { - // The only supported request schemes are http, https, and app. - // Above, we check to ensure that the request is http or https - // based on the channel qi. Here we test the scheme to ensure - // that it is app. Otherwise, bail. - nsCOMPtr channel = do_QueryInterface(request); - if (NS_WARN_IF(!channel)) { - mManager->NetworkFinished(NS_ERROR_FAILURE); - return NS_OK; - } - nsCOMPtr uri; - rv = channel->GetURI(getter_AddRefs(uri)); - if (NS_WARN_IF(NS_FAILED(rv))) { - mManager->NetworkFinished(rv); - return NS_OK; - } - nsAutoCString scheme; - rv = uri->GetScheme(scheme); - if (NS_WARN_IF(NS_FAILED(rv))) { - mManager->NetworkFinished(rv); - return NS_OK; - } + if (NS_WARN_IF(!requestSucceeded)) { + mManager->NetworkFinished(NS_ERROR_FAILURE); + return NS_OK; + } - if (NS_WARN_IF(!scheme.LowerCaseEqualsLiteral("app"))) { - mManager->NetworkFinished(NS_ERROR_FAILURE); - return NS_OK; - } + nsAutoCString maxScope; + // Note: we explicitly don't check for the return value here, because the + // absence of the header is not an error condition. + Unused << httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Service-Worker-Allowed"), + maxScope); + + mManager->SetMaxScope(maxScope); + + bool isFromCache = false; + nsCOMPtr cacheChannel(do_QueryInterface(httpChannel)); + if (cacheChannel) { + cacheChannel->IsFromCache(&isFromCache); + } + + // [9.2 Update]4.13, If response's cache state is not "local", + // set registration's last update check time to the current time + if (!isFromCache) { + RefPtr registration = + mManager->GetRegistration(); + registration->RefreshLastUpdateCheckTime(); + } + + nsAutoCString mimeType; + rv = httpChannel->GetContentType(mimeType); + if (NS_WARN_IF(NS_FAILED(rv))) { + mManager->NetworkFinished(NS_ERROR_DOM_SECURITY_ERR); + return rv; + } + + if (!mimeType.LowerCaseEqualsLiteral("text/javascript") && + !mimeType.LowerCaseEqualsLiteral("application/x-javascript") && + !mimeType.LowerCaseEqualsLiteral("application/javascript")) { + mManager->NetworkFinished(NS_ERROR_DOM_SECURITY_ERR); + return rv; } char16_t* buffer = nullptr; diff --git a/dom/workers/test/serviceworkers/app-protocol/README.txt b/dom/workers/test/serviceworkers/app-protocol/README.txt deleted file mode 100644 index 541e2bda232..00000000000 --- a/dom/workers/test/serviceworkers/app-protocol/README.txt +++ /dev/null @@ -1,3 +0,0 @@ -application.list contains a list of files that are in application.zip. - -To update application.zip when changing one of those files, run makezip.sh. diff --git a/dom/workers/test/serviceworkers/app-protocol/application.list b/dom/workers/test/serviceworkers/app-protocol/application.list deleted file mode 100644 index 8404b315478..00000000000 --- a/dom/workers/test/serviceworkers/app-protocol/application.list +++ /dev/null @@ -1,8 +0,0 @@ -controlled.html -foo.txt -index.html -manifest.webapp -sw.js -test.js -test_doc_load_interception.js -unregister.html diff --git a/dom/workers/test/serviceworkers/app-protocol/application.zip b/dom/workers/test/serviceworkers/app-protocol/application.zip deleted file mode 100644 index 5274ade945f..00000000000 Binary files a/dom/workers/test/serviceworkers/app-protocol/application.zip and /dev/null differ diff --git a/dom/workers/test/serviceworkers/app-protocol/controlled.html b/dom/workers/test/serviceworkers/app-protocol/controlled.html deleted file mode 100644 index ce8ce987e0a..00000000000 --- a/dom/workers/test/serviceworkers/app-protocol/controlled.html +++ /dev/null @@ -1,36 +0,0 @@ - - - - Test app for bug 1161684 - - - - - - - diff --git a/dom/workers/test/serviceworkers/app-protocol/foo.txt b/dom/workers/test/serviceworkers/app-protocol/foo.txt deleted file mode 100644 index 8d1556472f3..00000000000 --- a/dom/workers/test/serviceworkers/app-protocol/foo.txt +++ /dev/null @@ -1 +0,0 @@ -networkresponse \ No newline at end of file diff --git a/dom/workers/test/serviceworkers/app-protocol/index.html b/dom/workers/test/serviceworkers/app-protocol/index.html deleted file mode 100644 index 7dcc8cac529..00000000000 --- a/dom/workers/test/serviceworkers/app-protocol/index.html +++ /dev/null @@ -1,31 +0,0 @@ - - - - Test app for bug 1161684 - - - - - - diff --git a/dom/workers/test/serviceworkers/app-protocol/makezip.sh b/dom/workers/test/serviceworkers/app-protocol/makezip.sh deleted file mode 100755 index 317c9089199..00000000000 --- a/dom/workers/test/serviceworkers/app-protocol/makezip.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -rm application.zip -zip application.zip `cat application.list` diff --git a/dom/workers/test/serviceworkers/app-protocol/manifest.webapp b/dom/workers/test/serviceworkers/app-protocol/manifest.webapp deleted file mode 100644 index e47d156f44a..00000000000 --- a/dom/workers/test/serviceworkers/app-protocol/manifest.webapp +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "App", - "launch_path": "/index.html", - "description": "Test app for bug 1161684" -} diff --git a/dom/workers/test/serviceworkers/app-protocol/realindex.html b/dom/workers/test/serviceworkers/app-protocol/realindex.html deleted file mode 100644 index a0a381f5b34..00000000000 --- a/dom/workers/test/serviceworkers/app-protocol/realindex.html +++ /dev/null @@ -1,2 +0,0 @@ - -real index diff --git a/dom/workers/test/serviceworkers/app-protocol/realindex.html^headers^ b/dom/workers/test/serviceworkers/app-protocol/realindex.html^headers^ deleted file mode 100644 index cb762eff806..00000000000 --- a/dom/workers/test/serviceworkers/app-protocol/realindex.html^headers^ +++ /dev/null @@ -1 +0,0 @@ -Access-Control-Allow-Origin: * diff --git a/dom/workers/test/serviceworkers/app-protocol/redirect-https.sjs b/dom/workers/test/serviceworkers/app-protocol/redirect-https.sjs deleted file mode 100644 index 7806ee0a057..00000000000 --- a/dom/workers/test/serviceworkers/app-protocol/redirect-https.sjs +++ /dev/null @@ -1,5 +0,0 @@ -function handleRequest(request, response) { - response.setStatusLine(null, 308, "Permanent Redirect"); - response.setHeader("Access-Control-Allow-Origin", "*", false); - response.setHeader("Location", "https://example.org/tests/dom/workers/test/serviceworkers/app-protocol/realindex.html", false); -} diff --git a/dom/workers/test/serviceworkers/app-protocol/redirect.sjs b/dom/workers/test/serviceworkers/app-protocol/redirect.sjs deleted file mode 100644 index a63b0c2f925..00000000000 --- a/dom/workers/test/serviceworkers/app-protocol/redirect.sjs +++ /dev/null @@ -1,5 +0,0 @@ -function handleRequest(request, response) { - response.setStatusLine(null, 308, "Permanent Redirect"); - response.setHeader("Access-Control-Allow-Origin", "*", false); - response.setHeader("Location", "http://example.org/tests/dom/workers/test/serviceworkers/app-protocol/realindex.html", false); -} diff --git a/dom/workers/test/serviceworkers/app-protocol/sw.js b/dom/workers/test/serviceworkers/app-protocol/sw.js deleted file mode 100644 index 7b9c42cb063..00000000000 --- a/dom/workers/test/serviceworkers/app-protocol/sw.js +++ /dev/null @@ -1,69 +0,0 @@ -const kHTTPRedirect = "http://example.com/tests/dom/workers/test/serviceworkers/app-protocol/redirect.sjs"; -const kHTTPSRedirect = "https://example.com/tests/dom/workers/test/serviceworkers/app-protocol/redirect-https.sjs"; - -self.addEventListener('install', (event) => { - event.waitUntil( - self.caches.open("origin-app-cache") - .then(c => { - return Promise.all( - [ - c.add(kHTTPRedirect), - c.add(kHTTPSRedirect), - ] - ); - }) - ); -}); - -self.addEventListener('fetch', (event) => { - if (event.request.url.indexOf('foo.txt') >= 0) { - var url = new URL(event.request.url); - var shouldFetch = url.searchParams.get('fetch'); - if (shouldFetch) { - event.respondWith(fetch(event.request)); - return; - } - event.respondWith(new Response('swresponse', { - headers: {'Content-Type': 'text/plain'} - })); - } - - if (event.request.url.indexOf('test_doc_load_interception.js') >= 0 ) { - var scriptContent = 'alert("OK: Script modified by service worker")'; - event.respondWith(new Response(scriptContent, { - headers: {'Content-Type': 'application/javascript'} - })); - } - - if (event.request.url.indexOf('test_custom_content_type') >= 0) { - event.respondWith(new Response('customContentType', { - headers: {'Content-Type': 'text/html'} - })); - } - - if (event.request.url.indexOf('redirected.html') >= 0) { - event.respondWith(fetch(kHTTPRedirect)); - } - - if (event.request.url.indexOf('redirected-https.html') >= 0) { - event.respondWith(fetch(kHTTPSRedirect)); - } - - if (event.request.url.indexOf('redirected-cached.html') >= 0) { - event.respondWith( - self.caches.open("origin-app-cache") - .then(c => { - return c.match(kHTTPRedirect); - }) - ); - } - - if (event.request.url.indexOf('redirected-https-cached.html') >= 0) { - event.respondWith( - self.caches.open("origin-app-cache") - .then(c => { - return c.match(kHTTPSRedirect); - }) - ); - } -}); diff --git a/dom/workers/test/serviceworkers/app-protocol/test.js b/dom/workers/test/serviceworkers/app-protocol/test.js deleted file mode 100644 index 5e90d6e5bec..00000000000 --- a/dom/workers/test/serviceworkers/app-protocol/test.js +++ /dev/null @@ -1,72 +0,0 @@ -function ok(aCondition, aMessage) { - if (aCondition) { - alert('OK: ' + aMessage); - } else { - alert('KO: ' + aMessage); - } -} - -function ready() { - alert('READY'); -} - -function done() { - alert('DONE'); -} - -function testFetchAppResource(aUrl, - aExpectedResponse, - aExpectedContentType) { - return fetch(aUrl).then(res => { - ok(true, 'fetch should resolve for ' + aUrl); - if (res.type == 'error') { - ok(false, 'fetch failed'); - } - ok(res.status == 200, 'status should be 200'); - ok(res.statusText == 'OK', 'statusText should be OK'); - if (aExpectedContentType) { - var headers = res.headers.getAll('Content-Type'); - ok(headers.length, "Headers length"); - var contentType = res.headers.get('Content-Type'); - ok(contentType == aExpectedContentType, ('content type ' + - contentType + ' should match with ' + aExpectedContentType)); - } - return res.text().then(body => { - ok(body == aExpectedResponse, 'body ' + body + - ' should match with ' + aExpectedResponse); - }); - }); -} - -function testRedirectedResponse() { - return testRedirectedResponseWorker("redirected", "IFRAMELOADED"); -} - -function testRedirectedHttpsResponse() { - return testRedirectedResponseWorker("redirected-https", "HTTPSIFRAMELOADED"); -} - -function testCachedRedirectedResponse() { - return testRedirectedResponseWorker("redirected-cached", "IFRAMELOADED"); -} - -function testCachedRedirectedHttpsResponse() { - return testRedirectedResponseWorker("redirected-https-cached", "HTTPSIFRAMELOADED"); -} - -function testRedirectedResponseWorker(aFrameId, aAlert) { - // Because of the CSP policies applied to privileged apps, we cannot run - // inline script inside realindex.html, and loading a script from the app:// - // URI is also not an option, so we let the parent iframe which has access - // to the SpecialPowers API use those privileges to access the document. - var iframe = document.createElement("iframe"); - document.body.appendChild(iframe); - iframe.src = aFrameId + ".html"; - iframe.id = aFrameId; - return new Promise(resolve => { - iframe.addEventListener("load", event => { - alert(aAlert); - resolve(); - }, false); - }); -} diff --git a/dom/workers/test/serviceworkers/app-protocol/test_doc_load_interception.js b/dom/workers/test/serviceworkers/app-protocol/test_doc_load_interception.js deleted file mode 100644 index df429042691..00000000000 --- a/dom/workers/test/serviceworkers/app-protocol/test_doc_load_interception.js +++ /dev/null @@ -1 +0,0 @@ -alert('KO: Should not load this file, but the sw modified version instead'); diff --git a/dom/workers/test/serviceworkers/app-protocol/unregister.html b/dom/workers/test/serviceworkers/app-protocol/unregister.html deleted file mode 100644 index 3d5022d104c..00000000000 --- a/dom/workers/test/serviceworkers/app-protocol/unregister.html +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - diff --git a/dom/workers/test/serviceworkers/app-protocol/update.webapp b/dom/workers/test/serviceworkers/app-protocol/update.webapp deleted file mode 100644 index e4649d81c85..00000000000 --- a/dom/workers/test/serviceworkers/app-protocol/update.webapp +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "App", - "launch_path": "/index.html", - "description": "Test app for bug 1161684", - "package_path": "application.zip" -} diff --git a/dom/workers/test/serviceworkers/app-protocol/update.webapp^headers^ b/dom/workers/test/serviceworkers/app-protocol/update.webapp^headers^ deleted file mode 100644 index 90818c6398e..00000000000 --- a/dom/workers/test/serviceworkers/app-protocol/update.webapp^headers^ +++ /dev/null @@ -1 +0,0 @@ -Content-Type: application/manifest+json diff --git a/dom/workers/test/serviceworkers/app/index.html b/dom/workers/test/serviceworkers/app/index.html deleted file mode 100644 index a12702484f0..00000000000 --- a/dom/workers/test/serviceworkers/app/index.html +++ /dev/null @@ -1,41 +0,0 @@ - - - - Test app for bug 1169249 - - - - - diff --git a/dom/workers/test/serviceworkers/app/manifest.webapp b/dom/workers/test/serviceworkers/app/manifest.webapp deleted file mode 100644 index e8ead7c6055..00000000000 --- a/dom/workers/test/serviceworkers/app/manifest.webapp +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "App", - "launch_path": "/index.html", - "description": "Test app for bug 1169249" -} diff --git a/dom/workers/test/serviceworkers/app/manifest.webapp^headers^ b/dom/workers/test/serviceworkers/app/manifest.webapp^headers^ deleted file mode 100644 index 90818c6398e..00000000000 --- a/dom/workers/test/serviceworkers/app/manifest.webapp^headers^ +++ /dev/null @@ -1 +0,0 @@ -Content-Type: application/manifest+json diff --git a/dom/workers/test/serviceworkers/app/sw.js b/dom/workers/test/serviceworkers/app/sw.js deleted file mode 100644 index 9d071d6df7b..00000000000 --- a/dom/workers/test/serviceworkers/app/sw.js +++ /dev/null @@ -1 +0,0 @@ -// Useless service worker. diff --git a/dom/workers/test/serviceworkers/app2/client.html b/dom/workers/test/serviceworkers/app2/client.html deleted file mode 100644 index 3a48672b9ae..00000000000 --- a/dom/workers/test/serviceworkers/app2/client.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - Test app for bug 1178233 - - - - - diff --git a/dom/workers/test/serviceworkers/app2/index.html b/dom/workers/test/serviceworkers/app2/index.html deleted file mode 100644 index 09e7fb3b53b..00000000000 --- a/dom/workers/test/serviceworkers/app2/index.html +++ /dev/null @@ -1,81 +0,0 @@ - - - - Test app for bug 1178233 - - - - - diff --git a/dom/workers/test/serviceworkers/app2/manifest.webapp b/dom/workers/test/serviceworkers/app2/manifest.webapp deleted file mode 100644 index a002467bde9..00000000000 --- a/dom/workers/test/serviceworkers/app2/manifest.webapp +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "App", - "launch_path": "/index.html", - "description": "Test app for bug 1178233" -} diff --git a/dom/workers/test/serviceworkers/app2/manifest.webapp^headers^ b/dom/workers/test/serviceworkers/app2/manifest.webapp^headers^ deleted file mode 100644 index 90818c6398e..00000000000 --- a/dom/workers/test/serviceworkers/app2/manifest.webapp^headers^ +++ /dev/null @@ -1 +0,0 @@ -Content-Type: application/manifest+json diff --git a/dom/workers/test/serviceworkers/app2/sw.sjs b/dom/workers/test/serviceworkers/app2/sw.sjs deleted file mode 100644 index f60400cbf22..00000000000 --- a/dom/workers/test/serviceworkers/app2/sw.sjs +++ /dev/null @@ -1,22 +0,0 @@ -function handleRequest(request, response) { - var stateName = request.scheme + 'counter'; - if (!getState(stateName)) { - setState(stateName, '1'); - } else { - // Make sure that we pass a string value to setState! - setState(stateName, "" + (parseInt(getState(stateName)) + 1)); - } - response.setHeader("Content-Type", "application/javascript", false); - response.write(getScript(stateName)); -} - -function getScript(stateName) { - return "oninstall = function(evt) {" + - "evt.waitUntil(self.skipWaiting());" + - "}; " + - "onfetch = function(evt) {" + - "if (evt.request.url.indexOf('get-sw-version') > -1) {" + - "evt.respondWith(new Response('" + getState(stateName) + "'));" + - "}" + - "};"; -} diff --git a/dom/workers/test/serviceworkers/app2/version.html b/dom/workers/test/serviceworkers/app2/version.html deleted file mode 100644 index 9d4537648d5..00000000000 --- a/dom/workers/test/serviceworkers/app2/version.html +++ /dev/null @@ -1,19 +0,0 @@ - - - - Test app for bug 1178233 - - - - - diff --git a/dom/workers/test/serviceworkers/app2/wait_for_update.html b/dom/workers/test/serviceworkers/app2/wait_for_update.html deleted file mode 100644 index fb4410f4fcd..00000000000 --- a/dom/workers/test/serviceworkers/app2/wait_for_update.html +++ /dev/null @@ -1,25 +0,0 @@ - - - - Test app for bug 1178233 - - - - - diff --git a/dom/workers/test/serviceworkers/app3/index.html b/dom/workers/test/serviceworkers/app3/index.html deleted file mode 100644 index 8e363e9f364..00000000000 --- a/dom/workers/test/serviceworkers/app3/index.html +++ /dev/null @@ -1,51 +0,0 @@ - - - - Test app for bug 1169249 - - - - - diff --git a/dom/workers/test/serviceworkers/app3/manifest.webapp b/dom/workers/test/serviceworkers/app3/manifest.webapp deleted file mode 100644 index e8ead7c6055..00000000000 --- a/dom/workers/test/serviceworkers/app3/manifest.webapp +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "App", - "launch_path": "/index.html", - "description": "Test app for bug 1169249" -} diff --git a/dom/workers/test/serviceworkers/app3/manifest.webapp^headers^ b/dom/workers/test/serviceworkers/app3/manifest.webapp^headers^ deleted file mode 100644 index 90818c6398e..00000000000 --- a/dom/workers/test/serviceworkers/app3/manifest.webapp^headers^ +++ /dev/null @@ -1 +0,0 @@ -Content-Type: application/manifest+json diff --git a/dom/workers/test/serviceworkers/chrome.ini b/dom/workers/test/serviceworkers/chrome.ini index 75261eea937..a5b493bfb0f 100644 --- a/dom/workers/test/serviceworkers/chrome.ini +++ b/dom/workers/test/serviceworkers/chrome.ini @@ -1,9 +1,6 @@ [DEFAULT] skip-if = buildapp == 'b2g' || os == 'android' support-files = - app/* - app2/* - app3/* chrome_helpers.js empty.js serviceworker.html @@ -13,10 +10,6 @@ support-files = worker.js worker2.js -[test_aboutserviceworkers.html] -skip-if = true #bug 1193319 -[test_clear_origin_data.html] -[test_app_installation.html] [test_privateBrowsing.html] [test_serviceworkerinfo.xul] [test_serviceworkermanager.xul] diff --git a/dom/workers/test/serviceworkers/mochitest.ini b/dom/workers/test/serviceworkers/mochitest.ini index 4df68d7eb39..c5fb718db59 100644 --- a/dom/workers/test/serviceworkers/mochitest.ini +++ b/dom/workers/test/serviceworkers/mochitest.ini @@ -161,7 +161,6 @@ support-files = claim_worker_2.js claim_clients/client.html claim_fetch_worker.js - app-protocol/* force_refresh_worker.js sw_clients/refresher.html sw_clients/refresher_compressed.html @@ -199,8 +198,6 @@ support-files = redirect.sjs open_window/client.html -[test_app_protocol.html] -skip-if = release_build || (e10s && debug && os == 'win') [test_bug1151916.html] skip-if = e10s && debug && os == 'win' [test_claim.html] diff --git a/dom/workers/test/serviceworkers/test_aboutserviceworkers.html b/dom/workers/test/serviceworkers/test_aboutserviceworkers.html deleted file mode 100644 index 2d0a01f45c5..00000000000 --- a/dom/workers/test/serviceworkers/test_aboutserviceworkers.html +++ /dev/null @@ -1,164 +0,0 @@ - - - - - - Test for Bug 1178233 - - - - - -Mozilla Bug 1178233 -

- -
-
-
- - diff --git a/dom/workers/test/serviceworkers/test_app_installation.html b/dom/workers/test/serviceworkers/test_app_installation.html deleted file mode 100644 index 17f99add04b..00000000000 --- a/dom/workers/test/serviceworkers/test_app_installation.html +++ /dev/null @@ -1,168 +0,0 @@ - - - - - Test for Bug {1169249} - - - - - - -Mozilla Bug {1169249} -

- -
-
-
-
- - diff --git a/dom/workers/test/serviceworkers/test_app_protocol.html b/dom/workers/test/serviceworkers/test_app_protocol.html deleted file mode 100644 index 59a28fc586a..00000000000 --- a/dom/workers/test/serviceworkers/test_app_protocol.html +++ /dev/null @@ -1,193 +0,0 @@ - - - - - Bug 1161684 - Allow JAR channels to be intercepted by service workers - - - - -

- -

-
-
- - diff --git a/dom/workers/test/serviceworkers/test_clear_origin_data.html b/dom/workers/test/serviceworkers/test_clear_origin_data.html deleted file mode 100644 index c0bf5b66f29..00000000000 --- a/dom/workers/test/serviceworkers/test_clear_origin_data.html +++ /dev/null @@ -1,152 +0,0 @@ - - - - - Test for Bug {1233644} - - - - - - -Mozilla Bug {1233644} -

- -
-
-
-
- - diff --git a/modules/libjar/InterceptedJARChannel.cpp b/modules/libjar/InterceptedJARChannel.cpp deleted file mode 100644 index 1609afb739d..00000000000 --- a/modules/libjar/InterceptedJARChannel.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set expandtab ts=2 sw=2 sts=2 cin: */ -/* 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/. */ - -#include "InterceptedJARChannel.h" -#include "nsIPipe.h" -#include "mozilla/dom/ChannelInfo.h" - -using namespace mozilla::net; - -NS_IMPL_ISUPPORTS(InterceptedJARChannel, nsIInterceptedChannel) - -InterceptedJARChannel::InterceptedJARChannel(nsJARChannel* aChannel, - nsINetworkInterceptController* aController) -: mController(aController) -, mChannel(aChannel) -{ -} - -NS_IMETHODIMP -InterceptedJARChannel::GetResponseBody(nsIOutputStream** aStream) -{ - NS_IF_ADDREF(*aStream = mResponseBody); - return NS_OK; -} - -NS_IMETHODIMP -InterceptedJARChannel::GetInternalContentPolicyType(nsContentPolicyType* aPolicyType) -{ - NS_ENSURE_ARG(aPolicyType); - nsCOMPtr loadInfo; - nsresult rv = mChannel->GetLoadInfo(getter_AddRefs(loadInfo)); - NS_ENSURE_SUCCESS(rv, rv); - - *aPolicyType = loadInfo->InternalContentPolicyType(); - return NS_OK; -} - -NS_IMETHODIMP -InterceptedJARChannel::GetChannel(nsIChannel** aChannel) -{ - NS_IF_ADDREF(*aChannel = mChannel); - return NS_OK; -} - -NS_IMETHODIMP -InterceptedJARChannel::GetSecureUpgradedChannelURI(nsIURI** aURI) -{ - return mChannel->GetURI(aURI); -} - -NS_IMETHODIMP -InterceptedJARChannel::ResetInterception() -{ - if (!mChannel) { - return NS_ERROR_NOT_AVAILABLE; - } - - mResponseBody = nullptr; - mSynthesizedInput = nullptr; - - mChannel->ResetInterception(); - mReleaseHandle = nullptr; - mChannel = nullptr; - return NS_OK; -} - -NS_IMETHODIMP -InterceptedJARChannel::SynthesizeStatus(uint16_t aStatus, - const nsACString& aReason) -{ - return NS_OK; -} - -NS_IMETHODIMP -InterceptedJARChannel::SynthesizeHeader(const nsACString& aName, - const nsACString& aValue) -{ - if (aName.LowerCaseEqualsLiteral("content-type")) { - mContentType = aValue; - } - return NS_OK; -} - -NS_IMETHODIMP -InterceptedJARChannel::FinishSynthesizedResponse(const nsACString& aFinalURLSpec) -{ - if (NS_WARN_IF(!mChannel)) { - return NS_ERROR_NOT_AVAILABLE; - } - - if (!aFinalURLSpec.IsEmpty()) { - // We don't support rewriting responses for JAR channels where the principal - // needs to be modified. - return NS_ERROR_NOT_IMPLEMENTED; - } - - mChannel->OverrideWithSynthesizedResponse(mSynthesizedInput, mContentType); - - mResponseBody = nullptr; - mReleaseHandle = nullptr; - mChannel = nullptr; - return NS_OK; -} - -NS_IMETHODIMP -InterceptedJARChannel::Cancel(nsresult aStatus) -{ - MOZ_ASSERT(NS_FAILED(aStatus)); - - if (!mChannel) { - return NS_ERROR_FAILURE; - } - - nsresult rv = mChannel->Cancel(aStatus); - NS_ENSURE_SUCCESS(rv, rv); - mResponseBody = nullptr; - mReleaseHandle = nullptr; - mChannel = nullptr; - return NS_OK; -} - -NS_IMETHODIMP -InterceptedJARChannel::SetChannelInfo(mozilla::dom::ChannelInfo* aChannelInfo) -{ - if (!mChannel) { - return NS_ERROR_FAILURE; - } - - return aChannelInfo->ResurrectInfoOnChannel(mChannel); -} - -NS_IMETHODIMP -InterceptedJARChannel::GetConsoleReportCollector(nsIConsoleReportCollector**) -{ - return NS_ERROR_NOT_AVAILABLE; -} - -NS_IMETHODIMP -InterceptedJARChannel::SetReleaseHandle(nsISupports* aHandle) -{ - MOZ_ASSERT(NS_IsMainThread()); - MOZ_ASSERT(!mReleaseHandle); - MOZ_ASSERT(aHandle); - mReleaseHandle = aHandle; - return NS_OK; -} - -void -InterceptedJARChannel::NotifyController() -{ - nsresult rv = NS_NewPipe(getter_AddRefs(mSynthesizedInput), - getter_AddRefs(mResponseBody), - 0, UINT32_MAX, true, true); - NS_ENSURE_SUCCESS_VOID(rv); - - rv = mController->ChannelIntercepted(this); - if (NS_WARN_IF(NS_FAILED(rv))) { - rv = ResetInterception(); - NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), - "Failed to resume intercepted network request"); - } - mController = nullptr; -} diff --git a/modules/libjar/InterceptedJARChannel.h b/modules/libjar/InterceptedJARChannel.h deleted file mode 100644 index 63fc79ba93f..00000000000 --- a/modules/libjar/InterceptedJARChannel.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim:set expandtab ts=2 sw=2 sts=2 cin: */ -/* 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/. */ - -#ifndef InterceptedJARChannel_h -#define InterceptedJARChannel_h - -#include "nsJAR.h" -#include "nsJARChannel.h" -#include "nsIInputStream.h" -#include "nsIInputStreamPump.h" -#include "nsINetworkInterceptController.h" -#include "nsIOutputStream.h" -#include "mozilla/RefPtr.h" - -#include "mozilla/Maybe.h" - -class nsIStreamListener; -class nsJARChannel; - -namespace mozilla { -namespace net { - -// An object representing a channel that has been intercepted. This avoids -// complicating the actual channel implementation with the details of -// synthesizing responses. -class InterceptedJARChannel : public nsIInterceptedChannel -{ - // The interception controller to notify about the successful channel - // interception. - nsCOMPtr mController; - - // The actual channel being intercepted. - RefPtr mChannel; - - // Reader-side of the synthesized response body. - nsCOMPtr mSynthesizedInput; - - // The stream to write the body of the synthesized response. - nsCOMPtr mResponseBody; - - nsCOMPtr mReleaseHandle; - - // The content type of the synthesized response. - nsCString mContentType; - - virtual ~InterceptedJARChannel() {}; -public: - InterceptedJARChannel(nsJARChannel* aChannel, - nsINetworkInterceptController* aController); - - NS_DECL_ISUPPORTS - NS_DECL_NSIINTERCEPTEDCHANNEL - - void NotifyController(); -}; - -} // namespace net -} // namespace mozilla - -#endif // InterceptedJARChannel_h diff --git a/modules/libjar/moz.build b/modules/libjar/moz.build index c4f86a48491..1647afe66d5 100644 --- a/modules/libjar/moz.build +++ b/modules/libjar/moz.build @@ -23,14 +23,12 @@ XPIDL_SOURCES += [ XPIDL_MODULE = 'jar' EXPORTS += [ - 'InterceptedJARChannel.h', 'nsJARURI.h', 'nsZipArchive.h', 'zipstruct.h', ] UNIFIED_SOURCES += [ - 'InterceptedJARChannel.cpp', 'nsJARProtocolHandler.cpp', 'nsJARURI.cpp', ] diff --git a/modules/libjar/nsJARChannel.cpp b/modules/libjar/nsJARChannel.cpp index 4d548703f49..f49be0f6449 100644 --- a/modules/libjar/nsJARChannel.cpp +++ b/modules/libjar/nsJARChannel.cpp @@ -25,8 +25,6 @@ #include "mozilla/net/RemoteOpenFileChild.h" #include "nsITabChild.h" #include "private/pprio.h" -#include "nsINetworkInterceptController.h" -#include "InterceptedJARChannel.h" #include "nsInputStreamPump.h" using namespace mozilla; @@ -203,7 +201,6 @@ nsJARChannel::nsJARChannel() , mIsPending(false) , mIsUnsafe(true) , mOpeningRemote(false) - , mSynthesizedStreamLength(0) , mBlockRemoteFiles(false) { if (!gJarProtocolLog) @@ -521,8 +518,6 @@ nsJARChannel::GetStatus(nsresult *status) { if (mPump && NS_SUCCEEDED(mStatus)) mPump->GetStatus(status); - else if (mSynthesizedResponsePump && NS_SUCCEEDED(mStatus)) - mSynthesizedResponsePump->GetStatus(status); else *status = mStatus; return NS_OK; @@ -534,8 +529,6 @@ nsJARChannel::Cancel(nsresult status) mStatus = status; if (mPump) return mPump->Cancel(status); - if (mSynthesizedResponsePump) - return mSynthesizedResponsePump->Cancel(status); NS_ASSERTION(!mIsPending, "need to implement cancel when downloading"); return NS_OK; @@ -546,8 +539,6 @@ nsJARChannel::Suspend() { if (mPump) return mPump->Suspend(); - if (mSynthesizedResponsePump) - return mSynthesizedResponsePump->Suspend(); NS_ASSERTION(!mIsPending, "need to implement suspend when downloading"); return NS_OK; @@ -558,8 +549,6 @@ nsJARChannel::Resume() { if (mPump) return mPump->Resume(); - if (mSynthesizedResponsePump) - return mSynthesizedResponsePump->Resume(); NS_ASSERTION(!mIsPending, "need to implement resume when downloading"); return NS_OK; @@ -863,78 +852,6 @@ nsJARChannel::Open2(nsIInputStream** aStream) return Open(aStream); } -bool -nsJARChannel::BypassServiceWorker() const -{ - return mLoadFlags & LOAD_BYPASS_SERVICE_WORKER; -} - -bool -nsJARChannel::ShouldIntercept() -{ - LOG(("nsJARChannel::ShouldIntercept [this=%x]\n", this)); - // We only intercept app:// requests - if (!mAppURI) { - return false; - } - - nsCOMPtr controller; - NS_QueryNotificationCallbacks(mCallbacks, mLoadGroup, - NS_GET_IID(nsINetworkInterceptController), - getter_AddRefs(controller)); - bool shouldIntercept = false; - if (controller && !BypassServiceWorker() && mLoadInfo) { - nsresult rv = controller->ShouldPrepareForIntercept(mAppURI, - nsContentUtils::IsNonSubresourceRequest(this), - &shouldIntercept); - NS_ENSURE_SUCCESS(rv, false); - } - - return shouldIntercept; -} - -void nsJARChannel::ResetInterception() -{ - LOG(("nsJARChannel::ResetInterception [this=%x]\n", this)); - - // Continue with the original request. - nsresult rv = ContinueAsyncOpen(); - NS_ENSURE_SUCCESS_VOID(rv); -} - -void -nsJARChannel::OverrideWithSynthesizedResponse(nsIInputStream* aSynthesizedInput, - const nsACString& aContentType) -{ - // In our current implementation, the FetchEvent handler will copy the - // response stream completely into the pipe backing the input stream so we - // can treat the available as the length of the stream. - uint64_t available; - nsresult rv = aSynthesizedInput->Available(&available); - if (NS_WARN_IF(NS_FAILED(rv))) { - mSynthesizedStreamLength = -1; - } else { - mSynthesizedStreamLength = int64_t(available); - } - - rv = nsInputStreamPump::Create(getter_AddRefs(mSynthesizedResponsePump), - aSynthesizedInput, - int64_t(-1), int64_t(-1), 0, 0, true); - if (NS_WARN_IF(NS_FAILED(rv))) { - aSynthesizedInput->Close(); - return; - } - - SetContentType(aContentType); - - mIsUnsafe = false; - - FinishAsyncOpen(); - - rv = mSynthesizedResponsePump->AsyncRead(this, nullptr); - NS_ENSURE_SUCCESS_VOID(rv); -} - NS_IMETHODIMP nsJARChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx) { @@ -961,48 +878,6 @@ nsJARChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx) mListenerContext = ctx; mIsPending = true; -// Bug 1171651 - Disable the interception of app:// URIs in service workers -// on release builds -#ifndef RELEASE_BUILD - // Check if this channel should intercept the network request and prepare - // for a possible synthesized response instead. - if (ShouldIntercept()) { - nsCOMPtr controller; - NS_QueryNotificationCallbacks(mCallbacks, mLoadGroup, - NS_GET_IID(nsINetworkInterceptController), - getter_AddRefs(controller)); - - RefPtr intercepted = - new InterceptedJARChannel(this, controller); - intercepted->NotifyController(); - - // We get the JAREntry so we can infer the content type later in case - // that it isn't provided along with the synthesized response. - nsresult rv = mJarURI->GetJAREntry(mJarEntry); - if (NS_FAILED(rv)) { - return rv; - } - - return NS_OK; - } -#endif - - return ContinueAsyncOpen(); -} - -NS_IMETHODIMP -nsJARChannel::AsyncOpen2(nsIStreamListener *aListener) -{ - nsCOMPtr listener = aListener; - nsresult rv = nsContentSecurityManager::doContentSecurityCheck(this, listener); - NS_ENSURE_SUCCESS(rv, rv); - return AsyncOpen(listener, nullptr); -} - -nsresult -nsJARChannel::ContinueAsyncOpen() -{ - LOG(("nsJARChannel::ContinueAsyncOpen [this=%x]\n", this)); nsresult rv = LookupFile(true); if (NS_FAILED(rv)) { mIsPending = false; @@ -1057,19 +932,21 @@ nsJARChannel::ContinueAsyncOpen() return rv; } - - FinishAsyncOpen(); - - return NS_OK; -} - -void -nsJARChannel::FinishAsyncOpen() -{ if (mLoadGroup) mLoadGroup->AddRequest(this, nullptr); mOpened = true; + + return NS_OK; +} + +NS_IMETHODIMP +nsJARChannel::AsyncOpen2(nsIStreamListener *aListener) +{ + nsCOMPtr listener = aListener; + nsresult rv = nsContentSecurityManager::doContentSecurityCheck(this, listener); + NS_ENSURE_SUCCESS(rv, rv); + return AsyncOpen(listener, nullptr); } //----------------------------------------------------------------------------- diff --git a/modules/libjar/nsJARChannel.h b/modules/libjar/nsJARChannel.h index 8c5d6f6ab67..f78d34c7b5d 100644 --- a/modules/libjar/nsJARChannel.h +++ b/modules/libjar/nsJARChannel.h @@ -10,7 +10,6 @@ #include "nsIJARChannel.h" #include "nsIJARURI.h" #include "nsIInputStreamPump.h" -#include "InterceptedJARChannel.h" #include "nsIInterfaceRequestor.h" #include "nsIProgressEventSink.h" #include "nsIStreamListener.h" @@ -30,12 +29,6 @@ class nsJARInputThunk; class nsInputStreamPump; -namespace mozilla { -namespace net { - class InterceptedJARChannel; -} // namespace net -} // namespace mozilla - //----------------------------------------------------------------------------- class nsJARChannel final : public nsIJARChannel @@ -80,23 +73,6 @@ private: mozilla::net::MemoryDownloader::Data aData) override; - bool BypassServiceWorker() const; - - // Returns true if this channel should intercept the network request and - // prepare for a possible synthesized response instead. - bool ShouldIntercept(); - - nsresult ContinueAsyncOpen(); - void FinishAsyncOpen(); - - // Discard the prior interception and continue with the original network - // request. - void ResetInterception(); - // Override this channel's pending response with a synthesized one. The - // content will be asynchronously read from the pump. - void OverrideWithSynthesizedResponse(nsIInputStream* aSynthesizedInput, - const nsACString& aContentType); - nsCString mSpec; bool mOpened; @@ -135,12 +111,8 @@ private: nsCString mJarEntry; nsCString mInnerJarEntry; - RefPtr mSynthesizedResponsePump; - int64_t mSynthesizedStreamLength; - // True if this channel should not download any remote files. bool mBlockRemoteFiles; - friend class mozilla::net::InterceptedJARChannel; }; #endif // nsJARChannel_h__ diff --git a/netwerk/protocol/app/AppProtocolHandler.cpp b/netwerk/protocol/app/AppProtocolHandler.cpp index 0c7b40cb634..a7291a8a580 100644 --- a/netwerk/protocol/app/AppProtocolHandler.cpp +++ b/netwerk/protocol/app/AppProtocolHandler.cpp @@ -15,6 +15,7 @@ #include "nsXULAppAPI.h" #include "nsPrincipal.h" #include "nsContentSecurityManager.h" +#include "nsContentUtils.h" #include "mozilla/dom/ScriptSettings.h" #include "mozilla/Preferences.h"