From 9d614e4dc808eb453e4647baa1474b929db52f57 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Thu, 23 Apr 2015 18:59:52 -0400 Subject: [PATCH] Bug 1156847 - Part 2: Store the security info for a service worker on its WorkerPrivate; r=bent,khuey --- dom/workers/WorkerPrivate.cpp | 12 ++++++++++++ dom/workers/WorkerPrivate.h | 20 ++++++++++++++++++++ dom/workers/Workers.h | 2 ++ 3 files changed, 34 insertions(+) diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index 7a1d94b9d33c..b32dfecb70e2 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -32,6 +32,7 @@ #include "nsIXPConnect.h" #include "nsPerformance.h" #include "nsPIDOMWindow.h" +#include "nsSerializationHelper.h" #include #include "jsfriendapi.h" @@ -4081,6 +4082,17 @@ WorkerPrivateParent::SetPrincipal(nsIPrincipal* aPrincipal, PrincipalToPrincipalInfo(aPrincipal, mLoadInfo.mPrincipalInfo))); } +template +void +WorkerPrivateParent::SetSecurityInfo(nsISerializable* aSerializable) +{ + MOZ_ASSERT(IsServiceWorker()); + AssertIsOnMainThread(); + nsAutoCString securityInfo; + NS_SerializeToString(aSerializable, securityInfo); + SetSecurityInfo(securityInfo); +} + template JSContext* WorkerPrivateParent::ParentJSContext() const diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h index 9f38c2f1fadc..528825f6e68a 100644 --- a/dom/workers/WorkerPrivate.h +++ b/dom/workers/WorkerPrivate.h @@ -37,6 +37,7 @@ class nsIDocument; class nsIEventTarget; class nsIPrincipal; class nsIScriptContext; +class nsISerializable; class nsIThread; class nsIThreadInternal; class nsITimer; @@ -491,6 +492,25 @@ public: return mLoadInfo.mServiceWorkerCacheName; } + const nsCString& + GetSecurityInfo() const + { + MOZ_ASSERT(IsServiceWorker()); + return mLoadInfo.mSecurityInfo; + } + + void + SetSecurityInfo(const nsCString& aSecurityInfo) + { + MOZ_ASSERT(IsServiceWorker()); + AssertIsOnMainThread(); + MOZ_ASSERT(mLoadInfo.mSecurityInfo.IsEmpty()); + mLoadInfo.mSecurityInfo = aSecurityInfo; + } + + void + SetSecurityInfo(nsISerializable* aSerializable); + // This is used to handle importScripts(). When the worker is first loaded // and executed, it happens in a sync loop. At this point it sets // mLoadingWorkerScript to true. importScripts() calls that occur during the diff --git a/dom/workers/Workers.h b/dom/workers/Workers.h index 4d2291350424..5b56565ef3ba 100644 --- a/dom/workers/Workers.h +++ b/dom/workers/Workers.h @@ -243,6 +243,8 @@ struct WorkerLoadInfo nsString mServiceWorkerCacheName; + nsCString mSecurityInfo; + uint64_t mWindowID; bool mFromWindow;