Loading dom/workers/RuntimeService.cpp +14 −5 Original line number Diff line number Diff line Loading @@ -66,6 +66,7 @@ #include "WorkerPrivate.h" #include "WorkerRunnable.h" #include "WorkerThread.h" #include "ThirdPartyUtil.h" #ifdef ENABLE_TESTS #include "BackgroundChildImpl.h" Loading Loading @@ -258,11 +259,13 @@ GetWorkerPref(const nsACString& aPref, // This function creates a key for a SharedWorker composed by "name|scriptSpec". // If the name contains a '|', this will be replaced by '||'. void GenerateSharedWorkerKey(const nsACString& aScriptSpec, const nsACString& aName, GenerateSharedWorkerKey(const nsACString& aScriptSpec, const nsACString& aIsolationKey, const nsACString& aName, bool aPrivateBrowsing, nsCString& aKey) { aKey.Truncate(); aKey.SetCapacity(aScriptSpec.Length() + aName.Length() + 3); aKey.SetCapacity(aScriptSpec.Length() + aName.Length() + aIsolationKey.Length() + 4); aKey.Append(aPrivateBrowsing ? "1|" : "0|"); nsACString::const_iterator start, end; Loading @@ -278,6 +281,9 @@ GenerateSharedWorkerKey(const nsACString& aScriptSpec, const nsACString& aName, aKey.Append('|'); aKey.Append(aScriptSpec); aKey.Append('|'); aKey.Append(aIsolationKey); } void Loading Loading @@ -1512,13 +1518,16 @@ RuntimeService::RegisterWorker(JSContext* aCx, WorkerPrivate* aWorkerPrivate) if (isSharedWorker) { const nsCString& sharedWorkerName = aWorkerPrivate->WorkerName(); const nsCString& isolationKey = aWorkerPrivate->IsolationKey(); nsAutoCString key; GenerateSharedWorkerKey(sharedWorkerScriptSpec, sharedWorkerName, GenerateSharedWorkerKey(sharedWorkerScriptSpec, isolationKey, sharedWorkerName, aWorkerPrivate->IsInPrivateBrowsing(), key); MOZ_ASSERT(!domainInfo->mSharedWorkerInfos.Get(key)); SharedWorkerInfo* sharedWorkerInfo = new SharedWorkerInfo(aWorkerPrivate, sharedWorkerScriptSpec, isolationKey, sharedWorkerName); domainInfo->mSharedWorkerInfos.Put(key, sharedWorkerInfo); } Loading Loading @@ -1591,7 +1600,7 @@ RuntimeService::RemoveSharedWorker(WorkerDomainInfo* aDomainInfo, if (data->mWorkerPrivate == aWorkerPrivate) { #ifdef DEBUG nsAutoCString key; GenerateSharedWorkerKey(data->mScriptSpec, data->mName, GenerateSharedWorkerKey(data->mScriptSpec, data->mIsolationKey, data->mName, aWorkerPrivate->IsInPrivateBrowsing(), key); MOZ_ASSERT(iter.Key() == key); #endif Loading Loading @@ -2339,7 +2348,7 @@ RuntimeService::CreateSharedWorkerFromLoadInfo(JSContext* aCx, NS_ENSURE_SUCCESS(rv, rv); nsAutoCString key; GenerateSharedWorkerKey(scriptSpec, aName, GenerateSharedWorkerKey(scriptSpec, aLoadInfo->mIsolationKey, aName, aLoadInfo->mPrivateBrowsing, key); if (mDomainMap.Get(aLoadInfo->mDomain, &domainInfo) && Loading dom/workers/RuntimeService.h +4 −1 Original line number Diff line number Diff line Loading @@ -30,12 +30,15 @@ class RuntimeService final : public nsIObserver { WorkerPrivate* mWorkerPrivate; nsCString mScriptSpec; nsCString mIsolationKey; nsCString mName; SharedWorkerInfo(WorkerPrivate* aWorkerPrivate, const nsACString& aScriptSpec, const nsACString& aIsolationKey, const nsACString& aName) : mWorkerPrivate(aWorkerPrivate), mScriptSpec(aScriptSpec), mName(aName) : mWorkerPrivate(aWorkerPrivate), mScriptSpec(aScriptSpec), mIsolationKey(aIsolationKey), mName(aName) { } }; Loading dom/workers/WorkerPrivate.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -98,6 +98,7 @@ #include "ServiceWorkerManager.h" #include "ServiceWorkerWindowClient.h" #include "SharedWorker.h" #include "ThirdPartyUtil.h" #include "WorkerDebuggerManager.h" #include "WorkerFeature.h" #include "WorkerRunnable.h" Loading Loading @@ -1798,6 +1799,7 @@ WorkerLoadInfo::StealFrom(WorkerLoadInfo& aOther) mPrincipalInfo = aOther.mPrincipalInfo.forget(); mDomain = aOther.mDomain; mIsolationKey = aOther.mIsolationKey; mServiceWorkerCacheName = aOther.mServiceWorkerCacheName; mWindowID = aOther.mWindowID; mServiceWorkerID = aOther.mServiceWorkerID; Loading Loading @@ -4195,6 +4197,7 @@ WorkerPrivate::GetLoadInfo(JSContext* aCx, nsPIDOMWindow* aWindow, } loadInfo.mDomain = aParent->Domain(); loadInfo.mIsolationKey = aParent->IsolationKey(); loadInfo.mFromWindow = aParent->IsFromWindow(); loadInfo.mWindowID = aParent->WindowID(); loadInfo.mStorageAllowed = aParent->IsStorageAllowed(); Loading Loading @@ -4273,6 +4276,10 @@ WorkerPrivate::GetLoadInfo(JSContext* aCx, nsPIDOMWindow* aWindow, loadInfo.mBaseURI = document->GetDocBaseURI(); loadInfo.mLoadGroup = document->GetDocumentLoadGroup(); nsCString isolationKey; ThirdPartyUtil::GetFirstPartyHost(document, isolationKey); loadInfo.mIsolationKey = isolationKey; // Use the document's NodePrincipal as our principal if we're not being // called from chrome. if (!loadInfo.mPrincipal) { Loading dom/workers/WorkerPrivate.h +6 −0 Original line number Diff line number Diff line Loading @@ -451,6 +451,12 @@ public: return mLoadInfo.mDomain; } const nsCString& IsolationKey() const { return mLoadInfo.mIsolationKey; } bool IsFromWindow() const { Loading dom/workers/Workers.h +1 −0 Original line number Diff line number Diff line Loading @@ -252,6 +252,7 @@ struct WorkerLoadInfo nsAutoPtr<mozilla::ipc::PrincipalInfo> mPrincipalInfo; nsCString mDomain; nsCString mIsolationKey; nsString mServiceWorkerCacheName; Loading Loading
dom/workers/RuntimeService.cpp +14 −5 Original line number Diff line number Diff line Loading @@ -66,6 +66,7 @@ #include "WorkerPrivate.h" #include "WorkerRunnable.h" #include "WorkerThread.h" #include "ThirdPartyUtil.h" #ifdef ENABLE_TESTS #include "BackgroundChildImpl.h" Loading Loading @@ -258,11 +259,13 @@ GetWorkerPref(const nsACString& aPref, // This function creates a key for a SharedWorker composed by "name|scriptSpec". // If the name contains a '|', this will be replaced by '||'. void GenerateSharedWorkerKey(const nsACString& aScriptSpec, const nsACString& aName, GenerateSharedWorkerKey(const nsACString& aScriptSpec, const nsACString& aIsolationKey, const nsACString& aName, bool aPrivateBrowsing, nsCString& aKey) { aKey.Truncate(); aKey.SetCapacity(aScriptSpec.Length() + aName.Length() + 3); aKey.SetCapacity(aScriptSpec.Length() + aName.Length() + aIsolationKey.Length() + 4); aKey.Append(aPrivateBrowsing ? "1|" : "0|"); nsACString::const_iterator start, end; Loading @@ -278,6 +281,9 @@ GenerateSharedWorkerKey(const nsACString& aScriptSpec, const nsACString& aName, aKey.Append('|'); aKey.Append(aScriptSpec); aKey.Append('|'); aKey.Append(aIsolationKey); } void Loading Loading @@ -1512,13 +1518,16 @@ RuntimeService::RegisterWorker(JSContext* aCx, WorkerPrivate* aWorkerPrivate) if (isSharedWorker) { const nsCString& sharedWorkerName = aWorkerPrivate->WorkerName(); const nsCString& isolationKey = aWorkerPrivate->IsolationKey(); nsAutoCString key; GenerateSharedWorkerKey(sharedWorkerScriptSpec, sharedWorkerName, GenerateSharedWorkerKey(sharedWorkerScriptSpec, isolationKey, sharedWorkerName, aWorkerPrivate->IsInPrivateBrowsing(), key); MOZ_ASSERT(!domainInfo->mSharedWorkerInfos.Get(key)); SharedWorkerInfo* sharedWorkerInfo = new SharedWorkerInfo(aWorkerPrivate, sharedWorkerScriptSpec, isolationKey, sharedWorkerName); domainInfo->mSharedWorkerInfos.Put(key, sharedWorkerInfo); } Loading Loading @@ -1591,7 +1600,7 @@ RuntimeService::RemoveSharedWorker(WorkerDomainInfo* aDomainInfo, if (data->mWorkerPrivate == aWorkerPrivate) { #ifdef DEBUG nsAutoCString key; GenerateSharedWorkerKey(data->mScriptSpec, data->mName, GenerateSharedWorkerKey(data->mScriptSpec, data->mIsolationKey, data->mName, aWorkerPrivate->IsInPrivateBrowsing(), key); MOZ_ASSERT(iter.Key() == key); #endif Loading Loading @@ -2339,7 +2348,7 @@ RuntimeService::CreateSharedWorkerFromLoadInfo(JSContext* aCx, NS_ENSURE_SUCCESS(rv, rv); nsAutoCString key; GenerateSharedWorkerKey(scriptSpec, aName, GenerateSharedWorkerKey(scriptSpec, aLoadInfo->mIsolationKey, aName, aLoadInfo->mPrivateBrowsing, key); if (mDomainMap.Get(aLoadInfo->mDomain, &domainInfo) && Loading
dom/workers/RuntimeService.h +4 −1 Original line number Diff line number Diff line Loading @@ -30,12 +30,15 @@ class RuntimeService final : public nsIObserver { WorkerPrivate* mWorkerPrivate; nsCString mScriptSpec; nsCString mIsolationKey; nsCString mName; SharedWorkerInfo(WorkerPrivate* aWorkerPrivate, const nsACString& aScriptSpec, const nsACString& aIsolationKey, const nsACString& aName) : mWorkerPrivate(aWorkerPrivate), mScriptSpec(aScriptSpec), mName(aName) : mWorkerPrivate(aWorkerPrivate), mScriptSpec(aScriptSpec), mIsolationKey(aIsolationKey), mName(aName) { } }; Loading
dom/workers/WorkerPrivate.cpp +7 −0 Original line number Diff line number Diff line Loading @@ -98,6 +98,7 @@ #include "ServiceWorkerManager.h" #include "ServiceWorkerWindowClient.h" #include "SharedWorker.h" #include "ThirdPartyUtil.h" #include "WorkerDebuggerManager.h" #include "WorkerFeature.h" #include "WorkerRunnable.h" Loading Loading @@ -1798,6 +1799,7 @@ WorkerLoadInfo::StealFrom(WorkerLoadInfo& aOther) mPrincipalInfo = aOther.mPrincipalInfo.forget(); mDomain = aOther.mDomain; mIsolationKey = aOther.mIsolationKey; mServiceWorkerCacheName = aOther.mServiceWorkerCacheName; mWindowID = aOther.mWindowID; mServiceWorkerID = aOther.mServiceWorkerID; Loading Loading @@ -4195,6 +4197,7 @@ WorkerPrivate::GetLoadInfo(JSContext* aCx, nsPIDOMWindow* aWindow, } loadInfo.mDomain = aParent->Domain(); loadInfo.mIsolationKey = aParent->IsolationKey(); loadInfo.mFromWindow = aParent->IsFromWindow(); loadInfo.mWindowID = aParent->WindowID(); loadInfo.mStorageAllowed = aParent->IsStorageAllowed(); Loading Loading @@ -4273,6 +4276,10 @@ WorkerPrivate::GetLoadInfo(JSContext* aCx, nsPIDOMWindow* aWindow, loadInfo.mBaseURI = document->GetDocBaseURI(); loadInfo.mLoadGroup = document->GetDocumentLoadGroup(); nsCString isolationKey; ThirdPartyUtil::GetFirstPartyHost(document, isolationKey); loadInfo.mIsolationKey = isolationKey; // Use the document's NodePrincipal as our principal if we're not being // called from chrome. if (!loadInfo.mPrincipal) { Loading
dom/workers/WorkerPrivate.h +6 −0 Original line number Diff line number Diff line Loading @@ -451,6 +451,12 @@ public: return mLoadInfo.mDomain; } const nsCString& IsolationKey() const { return mLoadInfo.mIsolationKey; } bool IsFromWindow() const { Loading
dom/workers/Workers.h +1 −0 Original line number Diff line number Diff line Loading @@ -252,6 +252,7 @@ struct WorkerLoadInfo nsAutoPtr<mozilla::ipc::PrincipalInfo> mPrincipalInfo; nsCString mDomain; nsCString mIsolationKey; nsString mServiceWorkerCacheName; Loading