Bug 1168208 - Refactor the existing logic for syncing the security info between Response and channel objects into a new helper class; r=nsm,jdm,bkelly

This commit is contained in:
Ehsan Akhgari
2015-05-25 14:21:05 -04:00
parent 070caf25e5
commit f770eb78bf
22 changed files with 327 additions and 140 deletions

View File

@@ -14,7 +14,6 @@
#include "nsIIOService.h"
#include "nsIProtocolHandler.h"
#include "nsIScriptSecurityManager.h"
#include "nsISerializable.h"
#include "nsIStreamLoader.h"
#include "nsIStreamListenerTee.h"
#include "nsIThreadRetargetableRequest.h"
@@ -422,7 +421,7 @@ private:
bool mFailed;
nsCOMPtr<nsIInputStreamPump> mPump;
nsCOMPtr<nsIURI> mBaseURI;
nsCString mSecurityInfo;
ChannelInfo mChannelInfo;
};
NS_IMPL_ISUPPORTS(CacheScriptLoader, nsIStreamLoaderObserver)
@@ -589,19 +588,9 @@ private:
new InternalResponse(200, NS_LITERAL_CSTRING("OK"));
ir->SetBody(mReader);
// Set the security info of the channel on the response so that it's
// Set the channel 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()!");
}
}
ir->InitChannelInfo(channel);
nsRefPtr<Response> response = new Response(mCacheCreator->Global(), ir);
@@ -965,18 +954,9 @@ private:
// Take care of the base URI first.
mWorkerPrivate->SetBaseURI(finalURI);
// Store the security info if needed.
// Store the channel 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()!");
}
}
mWorkerPrivate->InitChannelInfo(channel);
}
// Now to figure out which principal to give this worker.
@@ -1047,7 +1027,8 @@ private:
void
DataReceivedFromCache(uint32_t aIndex, const uint8_t* aString,
uint32_t aStringLen, const nsCString& aSecurityInfo)
uint32_t aStringLen,
const ChannelInfo& aChannelInfo)
{
AssertIsOnMainThread();
MOZ_ASSERT(aIndex < mLoadInfos.Length());
@@ -1075,7 +1056,7 @@ private:
MOZ_ASSERT(principal);
nsILoadGroup* loadGroup = mWorkerPrivate->GetLoadGroup();
MOZ_ASSERT(loadGroup);
mWorkerPrivate->SetSecurityInfo(aSecurityInfo);
mWorkerPrivate->InitChannelInfo(aChannelInfo);
// Needed to initialize the principal info. This is fine because
// the cache principal cannot change, unlike the channel principal.
mWorkerPrivate->SetPrincipal(principal, loadGroup);
@@ -1429,11 +1410,11 @@ CacheScriptLoader::ResolvedCallback(JSContext* aCx,
nsCOMPtr<nsIInputStream> inputStream;
response->GetBody(getter_AddRefs(inputStream));
mSecurityInfo = response->GetSecurityInfo();
mChannelInfo = response->GetChannelInfo();
if (!inputStream) {
mLoadInfo.mCacheStatus = ScriptLoadInfo::Cached;
mRunnable->DataReceivedFromCache(mIndex, (uint8_t*)"", 0, mSecurityInfo);
mRunnable->DataReceivedFromCache(mIndex, (uint8_t*)"", 0, mChannelInfo);
return;
}
@@ -1489,7 +1470,7 @@ CacheScriptLoader::OnStreamComplete(nsIStreamLoader* aLoader, nsISupports* aCont
mLoadInfo.mCacheStatus = ScriptLoadInfo::Cached;
mRunnable->DataReceivedFromCache(mIndex, aString, aStringLen, mSecurityInfo);
mRunnable->DataReceivedFromCache(mIndex, aString, aStringLen, mChannelInfo);
return NS_OK;
}