mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:30:27 +00:00
import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1156847 - Part 3: When loading a service worker from the network, remember the security info of the channel on the WorkerPrivate; r=nsm (d2f579b83) - Bug 1156847 - Part 4: When storing a service worker script to the cache, store its security info in the cache as well; r=khuey (8440bb596) - Bug 1156847 - Part 5: When loading a service worker from the cache, set its security info on the WorkerPrivate; r=nsm (656aa49a1) - Bug 1156847 - Part 6: When calling FetchEvent.respondWith(), fall back to the security info of the service worker if the Response object that we are responding with doesn't have its own security info; r=nsm (bab71f147) - Bug 1156847 - Part 7: Add unit tests for responding to a FetchEvent with a synthesized Response both in the case where the service worker is loaded from the network and from the cache; r=nsm (8e56133c8) - Bug 1156847 followup: annotate workers helper-class "ScriptLoaderRunnable" OnStartRequest/OnStopRequest as override. rs=ehsan (88def1fa6) - Bug 1153929 - Add assertions and null checks to fix windows crash in nsHttpTransaction r=mcmanus (2547bda07) - Bug 1153929 - Add diagnostic asserts to check vtable is still present for mPipeOut r=mcmanus (b141045b9) - Bug 1130101 - Part 1: Store the value of the Service-Worker-Allowed header in the CompareManager object; r=nsm (7cecb4099) - Bug 1130101 - Part 2: Honor the Service-Worker-Allowed header when prefix matching the service worker scope; r=nsm (ed55a1670) - Bug 1130101 - Part 3: Add unit tests for the handling of the Service-Worker-Allowed header; r=nsm (fdb91f97b) - Bug 1130684 - Implement Service Worker clients.claim. r=nsm,ehsan (fdbf75e48) - Bug 1159407 - JavaScript error at aboutServiceWorkers.js when updating the service worker via about:serviceworkers page. r=baku (49d511930) - Bug 1162088 - patch 1 - ServiceWorkerManager should use OriginAttributes from the principal as scopeKey, r=nsm, r=bholley (162db819e) - Bug 1162088 - patch 2 - ServiceWorkerManager should use OriginAttributes from the principal as scopeKey, r=nsm (non-jsm part only) (983045b41) - Bug 1171486 - Avoid recursively obtaining the service worker manager service; r=nsm (7d9253661) - Bug 1131352 - Part 1: Fix codegen issue. r=smaug (488aa914f) - Bug 1157108 - onpush EventHandler support. r=ehsan (9905bbebf) - Bug 1132673 - Removing the scope line from ServiceWorkerGlobalScope and changing the signature and body of getScope. r=nsm,baku (ccfb8111b) - Bug 1140239 - Remove the commented out global properties of ServiceWorkerGlobalScope; r=baku (4730659f4) - Bug 1158728 - ServiceWorkerClient: use innerWindow id for referencing clients. r=nsm (22c3aecc9) - Bug 1130684 - Test fetch events are intercepted after a client is claimed. r=nsm (c5de59e99) - Bug 1161684 - Allow JAR channels to be intercepted by service workers. Tests. r=jdm (9f9227bf9) - Bug 1157619 P2 Test that service worker is not intercepted on force refresh. r=ehsan (5d3a804c1) - Bug 1170550 - Don't crash when registering a service worker which has a strict mode error; r=baku (12783152a) - Bug 1131352 - Part 2: Add ServiceWorkerGlobalScope skipWaiting(). r=nsm, r=baku (f5a3f06b5) - Bug 1131352 - Part 3: ServiceWorkerManager::SetSkipWaitingFlag() updated CLOSED TREE (88657b944)
This commit is contained in:
+103
-38
@@ -14,6 +14,7 @@
|
||||
#include "nsIIOService.h"
|
||||
#include "nsIProtocolHandler.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
#include "nsISerializable.h"
|
||||
#include "nsIStreamLoader.h"
|
||||
#include "nsIStreamListenerTee.h"
|
||||
#include "nsIThreadRetargetableRequest.h"
|
||||
@@ -421,6 +422,7 @@ private:
|
||||
bool mFailed;
|
||||
nsCOMPtr<nsIInputStreamPump> mPump;
|
||||
nsCOMPtr<nsIURI> mBaseURI;
|
||||
nsCString mSecurityInfo;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(CacheScriptLoader, nsIStreamLoaderObserver)
|
||||
@@ -458,7 +460,8 @@ private:
|
||||
|
||||
class ScriptLoaderRunnable final : public WorkerFeature,
|
||||
public nsIRunnable,
|
||||
public nsIStreamLoaderObserver
|
||||
public nsIStreamLoaderObserver,
|
||||
public nsIRequestObserver
|
||||
{
|
||||
friend class ScriptExecutorRunnable;
|
||||
friend class CachePromiseHandler;
|
||||
@@ -468,6 +471,7 @@ class ScriptLoaderRunnable final : public WorkerFeature,
|
||||
nsCOMPtr<nsIEventTarget> mSyncLoopTarget;
|
||||
nsTArray<ScriptLoadInfo> mLoadInfos;
|
||||
nsRefPtr<CacheCreator> mCacheCreator;
|
||||
nsCOMPtr<nsIInputStream> mReader;
|
||||
bool mIsMainScript;
|
||||
WorkerScriptType mWorkerScriptType;
|
||||
bool mCanceled;
|
||||
@@ -561,6 +565,79 @@ private:
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD
|
||||
OnStartRequest(nsIRequest* aRequest, nsISupports* aContext) override
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
|
||||
nsCOMPtr<nsISupportsPRUint32> indexSupports(do_QueryInterface(aContext));
|
||||
MOZ_ASSERT(indexSupports, "This should never fail!");
|
||||
|
||||
uint32_t index = UINT32_MAX;
|
||||
if (NS_FAILED(indexSupports->GetData(&index)) ||
|
||||
index >= mLoadInfos.Length()) {
|
||||
MOZ_CRASH("Bad index!");
|
||||
}
|
||||
|
||||
ScriptLoadInfo& loadInfo = mLoadInfos[index];
|
||||
|
||||
nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
|
||||
MOZ_ASSERT(channel == loadInfo.mChannel);
|
||||
|
||||
// We synthesize the result code, but its never exposed to content.
|
||||
nsRefPtr<InternalResponse> ir =
|
||||
new InternalResponse(200, NS_LITERAL_CSTRING("OK"));
|
||||
ir->SetBody(mReader);
|
||||
|
||||
// Set the security info of the channel on the response so that it's
|
||||
// saved in the cache.
|
||||
nsCOMPtr<nsISupports> infoObj;
|
||||
channel->GetSecurityInfo(getter_AddRefs(infoObj));
|
||||
if (infoObj) {
|
||||
nsCOMPtr<nsISerializable> serializable = do_QueryInterface(infoObj);
|
||||
if (serializable) {
|
||||
ir->SetSecurityInfo(serializable);
|
||||
MOZ_ASSERT(!ir->GetSecurityInfo().IsEmpty());
|
||||
} else {
|
||||
NS_WARNING("A non-serializable object was obtained from nsIChannel::GetSecurityInfo()!");
|
||||
}
|
||||
}
|
||||
|
||||
nsRefPtr<Response> response = new Response(mCacheCreator->Global(), ir);
|
||||
|
||||
RequestOrUSVString request;
|
||||
|
||||
MOZ_ASSERT(!loadInfo.mFullURL.IsEmpty());
|
||||
request.SetAsUSVString().Rebind(loadInfo.mFullURL.Data(),
|
||||
loadInfo.mFullURL.Length());
|
||||
|
||||
ErrorResult error;
|
||||
nsRefPtr<Promise> cachePromise =
|
||||
mCacheCreator->Cache_()->Put(request, *response, error);
|
||||
if (NS_WARN_IF(error.Failed())) {
|
||||
nsresult rv = error.StealNSResult();
|
||||
channel->Cancel(rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsRefPtr<CachePromiseHandler> promiseHandler =
|
||||
new CachePromiseHandler(this, loadInfo, index);
|
||||
cachePromise->AppendNativeHandler(promiseHandler);
|
||||
|
||||
loadInfo.mCachePromise.swap(cachePromise);
|
||||
loadInfo.mCacheStatus = ScriptLoadInfo::WritingToCache;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD
|
||||
OnStopRequest(nsIRequest* aRequest, nsISupports* aContext,
|
||||
nsresult aStatusCode) override
|
||||
{
|
||||
// Nothing to do here!
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
virtual bool
|
||||
Notify(JSContext* aCx, Status aStatus) override
|
||||
{
|
||||
@@ -774,59 +851,29 @@ private:
|
||||
return rv;
|
||||
}
|
||||
} else {
|
||||
nsCOMPtr<nsIInputStream> reader;
|
||||
nsCOMPtr<nsIOutputStream> writer;
|
||||
|
||||
// In case we return early.
|
||||
loadInfo.mCacheStatus = ScriptLoadInfo::Cancel;
|
||||
|
||||
rv = NS_NewPipe(getter_AddRefs(reader), getter_AddRefs(writer), 0,
|
||||
rv = NS_NewPipe(getter_AddRefs(mReader), getter_AddRefs(writer), 0,
|
||||
UINT32_MAX, // unlimited size to avoid writer WOULD_BLOCK case
|
||||
true, false); // non-blocking reader, blocking writer
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
// We synthesize the result code, but its never exposed to content.
|
||||
nsRefPtr<InternalResponse> ir =
|
||||
new InternalResponse(200, NS_LITERAL_CSTRING("OK"));
|
||||
ir->SetBody(reader);
|
||||
|
||||
nsCOMPtr<nsIStreamListenerTee> tee =
|
||||
do_CreateInstance(NS_STREAMLISTENERTEE_CONTRACTID);
|
||||
rv = tee->Init(loader, writer, nullptr);
|
||||
rv = tee->Init(loader, writer, this);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = channel->AsyncOpen(tee, indexSupports);
|
||||
nsresult rv = channel->AsyncOpen(tee, indexSupports);
|
||||
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsRefPtr<Response> response = new Response(mCacheCreator->Global(), ir);
|
||||
|
||||
RequestOrUSVString request;
|
||||
|
||||
MOZ_ASSERT(!loadInfo.mFullURL.IsEmpty());
|
||||
request.SetAsUSVString().Rebind(loadInfo.mFullURL.Data(),
|
||||
loadInfo.mFullURL.Length());
|
||||
|
||||
ErrorResult error;
|
||||
nsRefPtr<Promise> cachePromise =
|
||||
mCacheCreator->Cache_()->Put(request, *response, error);
|
||||
if (NS_WARN_IF(error.Failed())) {
|
||||
nsresult rv = error.StealNSResult();
|
||||
channel->Cancel(rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsRefPtr<CachePromiseHandler> promiseHandler =
|
||||
new CachePromiseHandler(this, loadInfo, aIndex);
|
||||
cachePromise->AppendNativeHandler(promiseHandler);
|
||||
|
||||
loadInfo.mCachePromise.swap(cachePromise);
|
||||
loadInfo.mCacheStatus = ScriptLoadInfo::WritingToCache;
|
||||
}
|
||||
|
||||
loadInfo.mChannel.swap(channel);
|
||||
@@ -936,6 +983,20 @@ private:
|
||||
// Take care of the base URI first.
|
||||
mWorkerPrivate->SetBaseURI(finalURI);
|
||||
|
||||
// Store the security info if needed.
|
||||
if (mWorkerPrivate->IsServiceWorker()) {
|
||||
nsCOMPtr<nsISupports> infoObj;
|
||||
channel->GetSecurityInfo(getter_AddRefs(infoObj));
|
||||
if (infoObj) {
|
||||
nsCOMPtr<nsISerializable> serializable = do_QueryInterface(infoObj);
|
||||
if (serializable) {
|
||||
mWorkerPrivate->SetSecurityInfo(serializable);
|
||||
} else {
|
||||
NS_WARNING("A non-serializable object was obtained from nsIChannel::GetSecurityInfo()!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now to figure out which principal to give this worker.
|
||||
WorkerPrivate* parent = mWorkerPrivate->GetParent();
|
||||
|
||||
@@ -1004,7 +1065,7 @@ private:
|
||||
|
||||
void
|
||||
DataReceivedFromCache(uint32_t aIndex, const uint8_t* aString,
|
||||
uint32_t aStringLen)
|
||||
uint32_t aStringLen, const nsCString& aSecurityInfo)
|
||||
{
|
||||
AssertIsOnMainThread();
|
||||
MOZ_ASSERT(aIndex < mLoadInfos.Length());
|
||||
@@ -1032,6 +1093,7 @@ private:
|
||||
MOZ_ASSERT(principal);
|
||||
nsILoadGroup* loadGroup = mWorkerPrivate->GetLoadGroup();
|
||||
MOZ_ASSERT(loadGroup);
|
||||
mWorkerPrivate->SetSecurityInfo(aSecurityInfo);
|
||||
// Needed to initialize the principal info. This is fine because
|
||||
// the cache principal cannot change, unlike the channel principal.
|
||||
mWorkerPrivate->SetPrincipal(principal, loadGroup);
|
||||
@@ -1115,7 +1177,9 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(ScriptLoaderRunnable, nsIRunnable, nsIStreamLoaderObserver)
|
||||
NS_IMPL_ISUPPORTS(ScriptLoaderRunnable, nsIRunnable,
|
||||
nsIStreamLoaderObserver,
|
||||
nsIRequestObserver)
|
||||
|
||||
void
|
||||
CachePromiseHandler::ResolvedCallback(JSContext* aCx,
|
||||
@@ -1383,10 +1447,11 @@ CacheScriptLoader::ResolvedCallback(JSContext* aCx,
|
||||
|
||||
nsCOMPtr<nsIInputStream> inputStream;
|
||||
response->GetBody(getter_AddRefs(inputStream));
|
||||
mSecurityInfo = response->GetSecurityInfo();
|
||||
|
||||
if (!inputStream) {
|
||||
mLoadInfo.mCacheStatus = ScriptLoadInfo::Cached;
|
||||
mRunnable->DataReceivedFromCache(mIndex, (uint8_t*)"", 0);
|
||||
mRunnable->DataReceivedFromCache(mIndex, (uint8_t*)"", 0, mSecurityInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1442,7 +1507,7 @@ CacheScriptLoader::OnStreamComplete(nsIStreamLoader* aLoader, nsISupports* aCont
|
||||
|
||||
mLoadInfo.mCacheStatus = ScriptLoadInfo::Cached;
|
||||
|
||||
mRunnable->DataReceivedFromCache(mIndex, aString, aStringLen);
|
||||
mRunnable->DataReceivedFromCache(mIndex, aString, aStringLen, mSecurityInfo);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user