Bug 1154494 - patch 2 - Hold a ref to the sandbox. r=baku

This commit is contained in:
Nikhil Marathe 2015-05-04 13:02:12 -04:00
parent ba01e3a362
commit b9f39271ea

View File

@ -23,7 +23,8 @@ namespace serviceWorkerScriptCache {
namespace {
already_AddRefed<CacheStorage>
CreateCacheStorage(nsIPrincipal* aPrincipal, ErrorResult& aRv)
CreateCacheStorage(nsIPrincipal* aPrincipal, ErrorResult& aRv,
nsIXPConnectJSObjectHolder** aHolder = nullptr)
{
AssertIsOnMainThread();
MOZ_ASSERT(aPrincipal);
@ -46,6 +47,10 @@ CreateCacheStorage(nsIPrincipal* aPrincipal, ErrorResult& aRv)
return nullptr;
}
if (aHolder) {
sandbox.forget(aHolder);
}
return CacheStorage::CreateOnMainThread(cache::CHROME_ONLY_NAMESPACE,
sandboxGlobalObject,
aPrincipal, aRv);
@ -281,7 +286,7 @@ public:
// Always create a CacheStorage since we want to write the network entry to
// the cache even if there isn't an existing one.
ErrorResult result;
mCacheStorage = CreateCacheStorage(aPrincipal, result);
mCacheStorage = CreateCacheStorage(aPrincipal, result, getter_AddRefs(mSandbox));
if (NS_WARN_IF(result.Failed())) {
MOZ_ASSERT(!result.IsErrorWithMessage());
return result.StealNSResult();
@ -540,6 +545,7 @@ private:
}
nsRefPtr<CompareCallback> mCallback;
nsCOMPtr<nsIXPConnectJSObjectHolder> mSandbox;
nsRefPtr<CacheStorage> mCacheStorage;
nsRefPtr<CompareNetwork> mCN;