diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp index a4e655bf7d3..1e9b90b6001 100644 --- a/dom/workers/RuntimeService.cpp +++ b/dom/workers/RuntimeService.cpp @@ -2280,7 +2280,7 @@ RuntimeService::CreateServiceWorker(const GlobalObject& aGlobal, nsresult RuntimeService::CreateServiceWorkerFromLoadInfo(JSContext* aCx, - WorkerPrivate::LoadInfo* aLoadInfo, + WorkerLoadInfo* aLoadInfo, const nsAString& aScriptURL, const nsACString& aScope, ServiceWorker** aServiceWorker) @@ -2319,7 +2319,7 @@ RuntimeService::CreateSharedWorkerInternal(const GlobalObject& aGlobal, JSContext* cx = aGlobal.Context(); - WorkerPrivate::LoadInfo loadInfo; + WorkerLoadInfo loadInfo; nsresult rv = WorkerPrivate::GetLoadInfo(cx, window, nullptr, aScriptURL, false, WorkerPrivate::OverrideLoadGroup, @@ -2332,7 +2332,7 @@ RuntimeService::CreateSharedWorkerInternal(const GlobalObject& aGlobal, nsresult RuntimeService::CreateSharedWorkerFromLoadInfo(JSContext* aCx, - WorkerPrivate::LoadInfo* aLoadInfo, + WorkerLoadInfo* aLoadInfo, const nsAString& aScriptURL, const nsACString& aName, WorkerType aType, diff --git a/dom/workers/RuntimeService.h b/dom/workers/RuntimeService.h index becc88a4481..48acf2acab8 100644 --- a/dom/workers/RuntimeService.h +++ b/dom/workers/RuntimeService.h @@ -155,7 +155,7 @@ public: nsresult CreateServiceWorkerFromLoadInfo(JSContext* aCx, - WorkerPrivate::LoadInfo* aLoadInfo, + WorkerLoadInfo* aLoadInfo, const nsAString& aScriptURL, const nsACString& aScope, ServiceWorker** aServiceWorker); @@ -308,7 +308,7 @@ private: nsresult CreateSharedWorkerFromLoadInfo(JSContext* aCx, - WorkerPrivate::LoadInfo* aLoadInfo, + WorkerLoadInfo* aLoadInfo, const nsAString& aScriptURL, const nsACString& aName, WorkerType aType, diff --git a/dom/workers/ServiceWorkerManager.cpp b/dom/workers/ServiceWorkerManager.cpp index 5b1a1605f8f..b54ffe3372e 100644 --- a/dom/workers/ServiceWorkerManager.cpp +++ b/dom/workers/ServiceWorkerManager.cpp @@ -2463,7 +2463,7 @@ ServiceWorkerManager::CreateServiceWorker(nsIPrincipal* aPrincipal, AssertIsOnMainThread(); MOZ_ASSERT(aPrincipal); - WorkerPrivate::LoadInfo info; + WorkerLoadInfo info; nsresult rv = NS_NewURI(getter_AddRefs(info.mBaseURI), aScriptSpec, nullptr, nullptr); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index 47306fc5e20..97e326f12c9 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -1933,9 +1933,7 @@ NS_IMPL_ISUPPORTS_INHERITED0(TopLevelWorkerFinishedRunnable, nsRunnable) NS_IMPL_ISUPPORTS(TimerThreadEventTarget, nsIEventTarget) -template -WorkerPrivateParent:: -LoadInfo::LoadInfo() +WorkerLoadInfo::WorkerLoadInfo() : mWindowID(UINT64_MAX) , mFromWindow(false) , mEvalAllowed(false) @@ -1946,15 +1944,114 @@ LoadInfo::LoadInfo() , mIsInCertifiedApp(false) , mIndexedDBAllowed(false) { - MOZ_COUNT_CTOR(WorkerPrivateParent::LoadInfo); + MOZ_COUNT_CTOR(WorkerLoadInfo); +} + +WorkerLoadInfo::~WorkerLoadInfo() +{ + MOZ_COUNT_DTOR(WorkerLoadInfo); +} + +void +WorkerLoadInfo::StealFrom(WorkerLoadInfo& aOther) +{ + MOZ_ASSERT(!mBaseURI); + aOther.mBaseURI.swap(mBaseURI); + + MOZ_ASSERT(!mResolvedScriptURI); + aOther.mResolvedScriptURI.swap(mResolvedScriptURI); + + MOZ_ASSERT(!mPrincipal); + aOther.mPrincipal.swap(mPrincipal); + + MOZ_ASSERT(!mScriptContext); + aOther.mScriptContext.swap(mScriptContext); + + MOZ_ASSERT(!mWindow); + aOther.mWindow.swap(mWindow); + + MOZ_ASSERT(!mCSP); + aOther.mCSP.swap(mCSP); + + MOZ_ASSERT(!mChannel); + aOther.mChannel.swap(mChannel); + + MOZ_ASSERT(!mLoadGroup); + aOther.mLoadGroup.swap(mLoadGroup); + + MOZ_ASSERT(!mInterfaceRequestor); + aOther.mInterfaceRequestor.swap(mInterfaceRequestor); + + MOZ_ASSERT(!mPrincipalInfo); + mPrincipalInfo = aOther.mPrincipalInfo.forget(); + + mDomain = aOther.mDomain; + mWindowID = aOther.mWindowID; + mFromWindow = aOther.mFromWindow; + mEvalAllowed = aOther.mEvalAllowed; + mReportCSPViolations = aOther.mReportCSPViolations; + mXHRParamsAllowed = aOther.mXHRParamsAllowed; + mPrincipalIsSystem = aOther.mPrincipalIsSystem; + mIsInPrivilegedApp = aOther.mIsInPrivilegedApp; + mIsInCertifiedApp = aOther.mIsInCertifiedApp; + mIndexedDBAllowed = aOther.mIndexedDBAllowed; } template -WorkerPrivateParent:: -LoadInfo::~LoadInfo() +class WorkerPrivateParent::EventTarget MOZ_FINAL + : public nsIEventTarget { - MOZ_COUNT_DTOR(WorkerPrivateParent::LoadInfo); -} + // This mutex protects mWorkerPrivate and must be acquired *before* the + // WorkerPrivate's mutex whenever they must both be held. + mozilla::Mutex mMutex; + WorkerPrivate* mWorkerPrivate; + nsIEventTarget* mWeakNestedEventTarget; + nsCOMPtr mNestedEventTarget; + +public: + explicit EventTarget(WorkerPrivate* aWorkerPrivate) + : mMutex("WorkerPrivateParent::EventTarget::mMutex"), + mWorkerPrivate(aWorkerPrivate), mWeakNestedEventTarget(nullptr) + { + MOZ_ASSERT(aWorkerPrivate); + } + + EventTarget(WorkerPrivate* aWorkerPrivate, nsIEventTarget* aNestedEventTarget) + : mMutex("WorkerPrivateParent::EventTarget::mMutex"), + mWorkerPrivate(aWorkerPrivate), mWeakNestedEventTarget(aNestedEventTarget), + mNestedEventTarget(aNestedEventTarget) + { + MOZ_ASSERT(aWorkerPrivate); + MOZ_ASSERT(aNestedEventTarget); + } + + void + Disable() + { + nsCOMPtr nestedEventTarget; + { + MutexAutoLock lock(mMutex); + + MOZ_ASSERT(mWorkerPrivate); + mWorkerPrivate = nullptr; + mNestedEventTarget.swap(nestedEventTarget); + } + } + + nsIEventTarget* + GetWeakNestedEventTarget() const + { + MOZ_ASSERT(mWeakNestedEventTarget); + return mWeakNestedEventTarget; + } + + NS_DECL_THREADSAFE_ISUPPORTS + NS_DECL_NSIEVENTTARGET + +private: + ~EventTarget() + { } +}; template class WorkerPrivateParent::SynchronizeAndResumeRunnable MOZ_FINAL @@ -2012,184 +2109,110 @@ private: } }; -template -class WorkerPrivateParent::InterfaceRequestor MOZ_FINAL - : public nsIInterfaceRequestor +WorkerLoadInfo:: +InterfaceRequestor::InterfaceRequestor(nsIPrincipal* aPrincipal, + nsILoadGroup* aLoadGroup) { - NS_DECL_ISUPPORTS - -public: - InterfaceRequestor(nsIPrincipal* aPrincipal, nsILoadGroup* aLoadGroup) - { - MOZ_ASSERT(NS_IsMainThread()); - MOZ_ASSERT(aPrincipal); - - // Look for an existing LoadContext. This is optional and it's ok if - // we don't find one. - nsCOMPtr baseContext; - if (aLoadGroup) { - nsCOMPtr callbacks; - aLoadGroup->GetNotificationCallbacks(getter_AddRefs(callbacks)); - if (callbacks) { - callbacks->GetInterface(NS_GET_IID(nsILoadContext), - getter_AddRefs(baseContext)); - } - } - - mLoadContext = new LoadContext(aPrincipal, baseContext); - } - - void - MaybeAddTabChild(nsILoadGroup* aLoadGroup) - { - MOZ_ASSERT(NS_IsMainThread()); - - if (!aLoadGroup) { - return; - } + MOZ_ASSERT(NS_IsMainThread()); + MOZ_ASSERT(aPrincipal); + // Look for an existing LoadContext. This is optional and it's ok if + // we don't find one. + nsCOMPtr baseContext; + if (aLoadGroup) { nsCOMPtr callbacks; aLoadGroup->GetNotificationCallbacks(getter_AddRefs(callbacks)); - if (!callbacks) { - return; + if (callbacks) { + callbacks->GetInterface(NS_GET_IID(nsILoadContext), + getter_AddRefs(baseContext)); } - - nsCOMPtr tabChild; - callbacks->GetInterface(NS_GET_IID(nsITabChild), getter_AddRefs(tabChild)); - if (!tabChild) { - return; - } - - // Use weak references to the tab child. Holding a strong reference will - // not prevent an ActorDestroy() from being called on the TabChild. - // Therefore, we should let the TabChild destroy itself as soon as possible. - mTabChildList.AppendElement(do_GetWeakReference(tabChild)); } - NS_IMETHOD - GetInterface(const nsIID& aIID, void** aSink) MOZ_OVERRIDE - { - MOZ_ASSERT(NS_IsMainThread()); - MOZ_ASSERT(mLoadContext); + mLoadContext = new LoadContext(aPrincipal, baseContext); +} - if (aIID.Equals(NS_GET_IID(nsILoadContext))) { - nsCOMPtr ref = mLoadContext; - ref.forget(aSink); - return NS_OK; - } - - // If we still have an active nsITabChild, then return it. Its possible, - // though, that all of the TabChild objects have been destroyed. In that - // case we return NS_NOINTERFACE. - if(aIID.Equals(NS_GET_IID(nsITabChild))) { - nsCOMPtr tabChild = GetAnyLiveTabChild(); - if (!tabChild) { - return NS_NOINTERFACE; - } - tabChild.forget(aSink); - return NS_OK; - } - - return NS_NOINTERFACE; - } - -private: - ~InterfaceRequestor() { } - - already_AddRefed - GetAnyLiveTabChild() - { - MOZ_ASSERT(NS_IsMainThread()); - - // Search our list of known TabChild objects for one that still exists. - while (!mTabChildList.IsEmpty()) { - nsCOMPtr tabChild = - do_QueryReferent(mTabChildList.LastElement()); - - // Does this tab child still exist? If so, return it. We are done. - if (tabChild) { - return tabChild.forget(); - } - - // Otherwise remove the stale weak reference and check the next one - mTabChildList.RemoveElementAt(mTabChildList.Length() - 1); - } - - return nullptr; - } - - nsCOMPtr mLoadContext; - - // Array of weak references to nsITabChild. We do not want to keep TabChild - // actors alive for long after their ActorDestroy() methods are called. - nsTArray mTabChildList; -}; - -template -NS_IMPL_ADDREF(WorkerPrivateParent::InterfaceRequestor) - -template -NS_IMPL_RELEASE(WorkerPrivateParent::InterfaceRequestor) - -template -NS_IMPL_QUERY_INTERFACE(WorkerPrivateParent::InterfaceRequestor, - nsIInterfaceRequestor) - -template -class WorkerPrivateParent::EventTarget MOZ_FINAL - : public nsIEventTarget +void +WorkerLoadInfo:: +InterfaceRequestor::MaybeAddTabChild(nsILoadGroup* aLoadGroup) { - // This mutex protects mWorkerPrivate and must be acquired *before* the - // WorkerPrivate's mutex whenever they must both be held. - mozilla::Mutex mMutex; - WorkerPrivate* mWorkerPrivate; - nsIEventTarget* mWeakNestedEventTarget; - nsCOMPtr mNestedEventTarget; + MOZ_ASSERT(NS_IsMainThread()); -public: - explicit EventTarget(WorkerPrivate* aWorkerPrivate) - : mMutex("WorkerPrivateParent::EventTarget::mMutex"), - mWorkerPrivate(aWorkerPrivate), mWeakNestedEventTarget(nullptr) - { - MOZ_ASSERT(aWorkerPrivate); + if (!aLoadGroup) { + return; } - EventTarget(WorkerPrivate* aWorkerPrivate, nsIEventTarget* aNestedEventTarget) - : mMutex("WorkerPrivateParent::EventTarget::mMutex"), - mWorkerPrivate(aWorkerPrivate), mWeakNestedEventTarget(aNestedEventTarget), - mNestedEventTarget(aNestedEventTarget) - { - MOZ_ASSERT(aWorkerPrivate); - MOZ_ASSERT(aNestedEventTarget); + nsCOMPtr callbacks; + aLoadGroup->GetNotificationCallbacks(getter_AddRefs(callbacks)); + if (!callbacks) { + return; } - void - Disable() - { - nsCOMPtr nestedEventTarget; - { - MutexAutoLock lock(mMutex); + nsCOMPtr tabChild; + callbacks->GetInterface(NS_GET_IID(nsITabChild), getter_AddRefs(tabChild)); + if (!tabChild) { + return; + } - MOZ_ASSERT(mWorkerPrivate); - mWorkerPrivate = nullptr; - mNestedEventTarget.swap(nestedEventTarget); + // Use weak references to the tab child. Holding a strong reference will + // not prevent an ActorDestroy() from being called on the TabChild. + // Therefore, we should let the TabChild destroy itself as soon as possible. + mTabChildList.AppendElement(do_GetWeakReference(tabChild)); +} + +NS_IMETHODIMP +WorkerLoadInfo:: +InterfaceRequestor::GetInterface(const nsIID& aIID, void** aSink) +{ + MOZ_ASSERT(NS_IsMainThread()); + MOZ_ASSERT(mLoadContext); + + if (aIID.Equals(NS_GET_IID(nsILoadContext))) { + nsCOMPtr ref = mLoadContext; + ref.forget(aSink); + return NS_OK; + } + + // If we still have an active nsITabChild, then return it. Its possible, + // though, that all of the TabChild objects have been destroyed. In that + // case we return NS_NOINTERFACE. + if (aIID.Equals(NS_GET_IID(nsITabChild))) { + nsCOMPtr tabChild = GetAnyLiveTabChild(); + if (!tabChild) { + return NS_NOINTERFACE; } + tabChild.forget(aSink); + return NS_OK; } - nsIEventTarget* - GetWeakNestedEventTarget() const - { - MOZ_ASSERT(mWeakNestedEventTarget); - return mWeakNestedEventTarget; + return NS_NOINTERFACE; +} + +already_AddRefed +WorkerLoadInfo:: +InterfaceRequestor::GetAnyLiveTabChild() +{ + MOZ_ASSERT(NS_IsMainThread()); + + // Search our list of known TabChild objects for one that still exists. + while (!mTabChildList.IsEmpty()) { + nsCOMPtr tabChild = + do_QueryReferent(mTabChildList.LastElement()); + + // Does this tab child still exist? If so, return it. We are done. + if (tabChild) { + return tabChild.forget(); + } + + // Otherwise remove the stale weak reference and check the next one + mTabChildList.RemoveElementAt(mTabChildList.Length() - 1); } - NS_DECL_THREADSAFE_ISUPPORTS - NS_DECL_NSIEVENTTARGET + return nullptr; +} -private: - ~EventTarget() - { } -}; +NS_IMPL_ADDREF(WorkerLoadInfo::InterfaceRequestor) +NS_IMPL_RELEASE(WorkerLoadInfo::InterfaceRequestor) +NS_IMPL_QUERY_INTERFACE(WorkerLoadInfo::InterfaceRequestor, nsIInterfaceRequestor) struct WorkerPrivate::TimeoutInfo { @@ -2393,7 +2416,7 @@ WorkerPrivateParent::WorkerPrivateParent( bool aIsChromeWorker, WorkerType aWorkerType, const nsACString& aSharedWorkerName, - LoadInfo& aLoadInfo) + WorkerLoadInfo& aLoadInfo) : mMutex("WorkerPrivateParent Mutex"), mCondVar(mMutex, "WorkerPrivateParent CondVar"), mMemoryReportCondVar(mMutex, "WorkerPrivateParent Memory Report CondVar"), @@ -4106,7 +4129,7 @@ WorkerPrivate::WorkerPrivate(JSContext* aCx, const nsAString& aScriptURL, bool aIsChromeWorker, WorkerType aWorkerType, const nsACString& aSharedWorkerName, - LoadInfo& aLoadInfo) + WorkerLoadInfo& aLoadInfo) : WorkerPrivateParent(aCx, aParent, aScriptURL, aIsChromeWorker, aWorkerType, aSharedWorkerName, aLoadInfo) @@ -4208,7 +4231,7 @@ WorkerPrivate::Constructor(const GlobalObject& aGlobal, const nsAString& aScriptURL, bool aIsChromeWorker, WorkerType aWorkerType, const nsACString& aSharedWorkerName, - LoadInfo* aLoadInfo, ErrorResult& aRv) + WorkerLoadInfo* aLoadInfo, ErrorResult& aRv) { JSContext* cx = aGlobal.Context(); return Constructor(cx, aScriptURL, aIsChromeWorker, aWorkerType, @@ -4221,7 +4244,7 @@ WorkerPrivate::Constructor(JSContext* aCx, const nsAString& aScriptURL, bool aIsChromeWorker, WorkerType aWorkerType, const nsACString& aSharedWorkerName, - LoadInfo* aLoadInfo, ErrorResult& aRv) + WorkerLoadInfo* aLoadInfo, ErrorResult& aRv) { WorkerPrivate* parent = NS_IsMainThread() ? nullptr : @@ -4237,7 +4260,7 @@ WorkerPrivate::Constructor(JSContext* aCx, MOZ_ASSERT_IF(aWorkerType == WorkerTypeDedicated, aSharedWorkerName.IsEmpty()); - Maybe stackLoadInfo; + Maybe stackLoadInfo; if (!aLoadInfo) { stackLoadInfo.emplace(); @@ -4300,7 +4323,7 @@ WorkerPrivate::GetLoadInfo(JSContext* aCx, nsPIDOMWindow* aWindow, WorkerPrivate* aParent, const nsAString& aScriptURL, bool aIsChromeWorker, LoadGroupBehavior aLoadGroupBehavior, - LoadInfo* aLoadInfo) + WorkerLoadInfo* aLoadInfo) { using namespace mozilla::dom::workers::scriptloader; using mozilla::dom::indexedDB::IDBFactory; @@ -4312,7 +4335,7 @@ WorkerPrivate::GetLoadInfo(JSContext* aCx, nsPIDOMWindow* aWindow, AssertIsOnMainThread(); } - LoadInfo loadInfo; + WorkerLoadInfo loadInfo; nsresult rv; if (aParent) { @@ -4556,12 +4579,13 @@ WorkerPrivate::GetLoadInfo(JSContext* aCx, nsPIDOMWindow* aWindow, // static void -WorkerPrivate::OverrideLoadInfoLoadGroup(LoadInfo& aLoadInfo) +WorkerPrivate::OverrideLoadInfoLoadGroup(WorkerLoadInfo& aLoadInfo) { MOZ_ASSERT(!aLoadInfo.mInterfaceRequestor); - aLoadInfo.mInterfaceRequestor = new InterfaceRequestor(aLoadInfo.mPrincipal, - aLoadInfo.mLoadGroup); + aLoadInfo.mInterfaceRequestor = + new WorkerLoadInfo::InterfaceRequestor(aLoadInfo.mPrincipal, + aLoadInfo.mLoadGroup); aLoadInfo.mInterfaceRequestor->MaybeAddTabChild(aLoadInfo.mLoadGroup); nsCOMPtr loadGroup = diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h index 3117d6400bd..63900b9d6d6 100644 --- a/dom/workers/WorkerPrivate.h +++ b/dom/workers/WorkerPrivate.h @@ -133,7 +133,6 @@ class WorkerPrivateParent : public DOMEventTargetHelper class SynchronizeAndResumeRunnable; protected: - class InterfaceRequestor; class EventTarget; friend class EventTarget; @@ -153,84 +152,6 @@ public: nsString mOrigin; }; - struct LoadInfo - { - // All of these should be released in ForgetMainThreadObjects. - nsCOMPtr mBaseURI; - nsCOMPtr mResolvedScriptURI; - nsCOMPtr mPrincipal; - nsCOMPtr mScriptContext; - nsCOMPtr mWindow; - nsCOMPtr mCSP; - nsCOMPtr mChannel; - nsCOMPtr mLoadGroup; - - // Only set if we have a custom overriden load group - nsRefPtr mInterfaceRequestor; - - nsAutoPtr mPrincipalInfo; - nsCString mDomain; - - uint64_t mWindowID; - - bool mFromWindow; - bool mEvalAllowed; - bool mReportCSPViolations; - bool mXHRParamsAllowed; - bool mPrincipalIsSystem; - bool mIsInPrivilegedApp; - bool mIsInCertifiedApp; - bool mIndexedDBAllowed; - - LoadInfo(); - ~LoadInfo(); - - void - StealFrom(LoadInfo& aOther) - { - MOZ_ASSERT(!mBaseURI); - aOther.mBaseURI.swap(mBaseURI); - - MOZ_ASSERT(!mResolvedScriptURI); - aOther.mResolvedScriptURI.swap(mResolvedScriptURI); - - MOZ_ASSERT(!mPrincipal); - aOther.mPrincipal.swap(mPrincipal); - - MOZ_ASSERT(!mScriptContext); - aOther.mScriptContext.swap(mScriptContext); - - MOZ_ASSERT(!mWindow); - aOther.mWindow.swap(mWindow); - - MOZ_ASSERT(!mCSP); - aOther.mCSP.swap(mCSP); - - MOZ_ASSERT(!mChannel); - aOther.mChannel.swap(mChannel); - - MOZ_ASSERT(!mLoadGroup); - aOther.mLoadGroup.swap(mLoadGroup); - - MOZ_ASSERT(!mInterfaceRequestor); - aOther.mInterfaceRequestor.swap(mInterfaceRequestor); - - MOZ_ASSERT(!mPrincipalInfo); - mPrincipalInfo = aOther.mPrincipalInfo.forget(); - - mDomain = aOther.mDomain; - mWindowID = aOther.mWindowID; - mFromWindow = aOther.mFromWindow; - mEvalAllowed = aOther.mEvalAllowed; - mReportCSPViolations = aOther.mReportCSPViolations; - mXHRParamsAllowed = aOther.mXHRParamsAllowed; - mPrincipalIsSystem = aOther.mPrincipalIsSystem; - mIsInPrivilegedApp = aOther.mIsInPrivilegedApp; - mIsInCertifiedApp = aOther.mIsInCertifiedApp; - mIndexedDBAllowed = aOther.mIndexedDBAllowed; - } - }; - protected: typedef mozilla::ErrorResult ErrorResult; @@ -249,7 +170,7 @@ private: LocationInfo mLocationInfo; // The lifetime of these objects within LoadInfo is managed explicitly; // they do not need to be cycle collected. - LoadInfo mLoadInfo; + WorkerLoadInfo mLoadInfo; // Only used for top level workers. nsTArray> mQueuedRunnables; @@ -285,7 +206,7 @@ protected: const nsAString& aScriptURL, bool aIsChromeWorker, WorkerType aWorkerType, const nsACString& aSharedWorkerName, - LoadInfo& aLoadInfo); + WorkerLoadInfo& aLoadInfo); ~WorkerPrivateParent(); @@ -926,12 +847,12 @@ public: Constructor(const GlobalObject& aGlobal, const nsAString& aScriptURL, bool aIsChromeWorker, WorkerType aWorkerType, const nsACString& aSharedWorkerName, - LoadInfo* aLoadInfo, ErrorResult& aRv); + WorkerLoadInfo* aLoadInfo, ErrorResult& aRv); static already_AddRefed Constructor(JSContext* aCx, const nsAString& aScriptURL, bool aIsChromeWorker, WorkerType aWorkerType, const nsACString& aSharedWorkerName, - LoadInfo* aLoadInfo, ErrorResult& aRv); + WorkerLoadInfo* aLoadInfo, ErrorResult& aRv); static bool WorkerAvailable(JSContext* /* unused */, JSObject* /* unused */); @@ -945,10 +866,10 @@ public: static nsresult GetLoadInfo(JSContext* aCx, nsPIDOMWindow* aWindow, WorkerPrivate* aParent, const nsAString& aScriptURL, bool aIsChromeWorker, - LoadGroupBehavior aLoadGroupBehavior, LoadInfo* aLoadInfo); + LoadGroupBehavior aLoadGroupBehavior, WorkerLoadInfo* aLoadInfo); static void - OverrideLoadInfoLoadGroup(LoadInfo& aLoadInfo); + OverrideLoadInfoLoadGroup(WorkerLoadInfo& aLoadInfo); WorkerDebugger* Debugger() const @@ -1255,7 +1176,7 @@ private: WorkerPrivate(JSContext* aCx, WorkerPrivate* aParent, const nsAString& aScriptURL, bool aIsChromeWorker, WorkerType aWorkerType, const nsACString& aSharedWorkerName, - LoadInfo& aLoadInfo); + WorkerLoadInfo& aLoadInfo); void ClearMainEventQueue(WorkerRanOrNot aRanOrNot); diff --git a/dom/workers/Workers.h b/dom/workers/Workers.h index c798f99cc7a..8826162ce33 100644 --- a/dom/workers/Workers.h +++ b/dom/workers/Workers.h @@ -14,6 +14,11 @@ #include "nsCOMPtr.h" #include "nsDebug.h" #include "nsString.h" +#include "nsTArray.h" + +#include "nsILoadContext.h" +#include "nsIWeakReferenceUtils.h" +#include "nsIInterfaceRequestor.h" #define BEGIN_WORKERS_NAMESPACE \ namespace mozilla { namespace dom { namespace workers { @@ -24,9 +29,21 @@ #define WORKERS_SHUTDOWN_TOPIC "web-workers-shutdown" -class nsIGlobalObject; +class nsIContentSecurityPolicy; class nsIScriptContext; +class nsIGlobalObject; class nsPIDOMWindow; +class nsIPrincipal; +class nsILoadGroup; +class nsITabChild; +class nsIChannel; +class nsIURI; + +namespace mozilla { +namespace ipc { +class PrincipalInfo; +} +} BEGIN_WORKERS_NAMESPACE @@ -171,6 +188,64 @@ enum WorkerPreference WORKERPREF_COUNT }; +// Implemented in WorkerPrivate.cpp + +struct WorkerLoadInfo +{ + // All of these should be released in WorkerPrivateParent::ForgetMainThreadObjects. + nsCOMPtr mBaseURI; + nsCOMPtr mResolvedScriptURI; + nsCOMPtr mPrincipal; + nsCOMPtr mScriptContext; + nsCOMPtr mWindow; + nsCOMPtr mCSP; + nsCOMPtr mChannel; + nsCOMPtr mLoadGroup; + + class InterfaceRequestor MOZ_FINAL : public nsIInterfaceRequestor + { + NS_DECL_ISUPPORTS + + public: + InterfaceRequestor(nsIPrincipal* aPrincipal, nsILoadGroup* aLoadGroup); + void MaybeAddTabChild(nsILoadGroup* aLoadGroup); + NS_IMETHOD GetInterface(const nsIID& aIID, void** aSink) MOZ_OVERRIDE; + + private: + ~InterfaceRequestor() { } + + already_AddRefed GetAnyLiveTabChild(); + + nsCOMPtr mLoadContext; + + // Array of weak references to nsITabChild. We do not want to keep TabChild + // actors alive for long after their ActorDestroy() methods are called. + nsTArray mTabChildList; + }; + + // Only set if we have a custom overriden load group + nsRefPtr mInterfaceRequestor; + + nsAutoPtr mPrincipalInfo; + nsCString mDomain; + + uint64_t mWindowID; + + bool mFromWindow; + bool mEvalAllowed; + bool mReportCSPViolations; + bool mXHRParamsAllowed; + bool mPrincipalIsSystem; + bool mIsInPrivilegedApp; + bool mIsInCertifiedApp; + bool mIndexedDBAllowed; + + WorkerLoadInfo(); + ~WorkerLoadInfo(); + + void StealFrom(WorkerLoadInfo& aOther); +}; + // All of these are implemented in RuntimeService.cpp void