1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_dom_workers_WorkerLoadInfo_h 8 #define mozilla_dom_workers_WorkerLoadInfo_h 9 10 #include "mozilla/dom/ChannelInfo.h" 11 #include "mozilla/dom/ServiceWorkerRegistrationDescriptor.h" 12 #include "mozilla/dom/WorkerCommon.h" 13 #include "mozilla/net/ReferrerPolicy.h" 14 #include "nsIInterfaceRequestor.h" 15 #include "nsILoadContext.h" 16 #include "nsIRequest.h" 17 #include "nsISupportsImpl.h" 18 #include "nsIWeakReferenceUtils.h" 19 20 class nsIChannel; 21 class nsIContentSecurityPolicy; 22 class nsILoadGroup; 23 class nsIPrincipal; 24 class nsIRunnable; 25 class nsIScriptContext; 26 class nsITabChild; 27 class nsIURI; 28 class nsPIDOMWindowInner; 29 30 namespace mozilla { 31 32 namespace ipc { 33 class PrincipalInfo; 34 } // namespace ipc 35 36 namespace dom { 37 38 class WorkerPrivate; 39 40 struct WorkerLoadInfo { 41 // All of these should be released in 42 // WorkerPrivateParent::ForgetMainThreadObjects. 43 nsCOMPtr<nsIURI> mBaseURI; 44 nsCOMPtr<nsIURI> mResolvedScriptURI; 45 46 // This is the principal of the global (parent worker or a window) loading 47 // the worker. It can be null if we are executing a ServiceWorker, otherwise, 48 // except for data: URL, it must subsumes the worker principal. 49 // If we load a data: URL, mPrincipal will be a null principal. 50 nsCOMPtr<nsIPrincipal> mLoadingPrincipal; 51 nsCOMPtr<nsIPrincipal> mPrincipal; 52 53 nsCOMPtr<nsIScriptContext> mScriptContext; 54 nsCOMPtr<nsPIDOMWindowInner> mWindow; 55 nsCOMPtr<nsIContentSecurityPolicy> mCSP; 56 nsCOMPtr<nsIChannel> mChannel; 57 nsCOMPtr<nsILoadGroup> mLoadGroup; 58 59 // mLoadFailedAsyncRunnable will execute on main thread if script loading 60 // fails during script loading. If script loading is never started due to 61 // a synchronous error, then the runnable is never executed. The runnable 62 // is guaranteed to be released on the main thread. 63 nsCOMPtr<nsIRunnable> mLoadFailedAsyncRunnable; 64 65 class InterfaceRequestor final : public nsIInterfaceRequestor { 66 NS_DECL_ISUPPORTS 67 68 public: 69 InterfaceRequestor(nsIPrincipal* aPrincipal, nsILoadGroup* aLoadGroup); 70 void MaybeAddTabChild(nsILoadGroup* aLoadGroup); 71 NS_IMETHOD GetInterface(const nsIID& aIID, void** aSink) override; 72 73 private: ~InterfaceRequestorWorkerLoadInfo74 ~InterfaceRequestor() {} 75 76 already_AddRefed<nsITabChild> GetAnyLiveTabChild(); 77 78 nsCOMPtr<nsILoadContext> mLoadContext; 79 nsCOMPtr<nsIInterfaceRequestor> mOuterRequestor; 80 81 // Array of weak references to nsITabChild. We do not want to keep TabChild 82 // actors alive for long after their ActorDestroy() methods are called. 83 nsTArray<nsWeakPtr> mTabChildList; 84 }; 85 86 // Only set if we have a custom overriden load group 87 RefPtr<InterfaceRequestor> mInterfaceRequestor; 88 89 nsAutoPtr<mozilla::ipc::PrincipalInfo> mPrincipalInfo; 90 nsCString mDomain; 91 nsString mOrigin; // Derived from mPrincipal; can be used on worker thread. 92 93 nsString mServiceWorkerCacheName; 94 Maybe<ServiceWorkerDescriptor> mServiceWorkerDescriptor; 95 Maybe<ServiceWorkerRegistrationDescriptor> 96 mServiceWorkerRegistrationDescriptor; 97 98 Maybe<ServiceWorkerDescriptor> mParentController; 99 100 ChannelInfo mChannelInfo; 101 nsLoadFlags mLoadFlags; 102 103 uint64_t mWindowID; 104 105 net::ReferrerPolicy mReferrerPolicy; 106 bool mFromWindow; 107 bool mEvalAllowed; 108 bool mReportCSPViolations; 109 bool mXHRParamsAllowed; 110 bool mPrincipalIsSystem; 111 bool mStorageAllowed; 112 bool mServiceWorkersTestingInWindow; 113 OriginAttributes mOriginAttributes; 114 115 WorkerLoadInfo(); 116 ~WorkerLoadInfo(); 117 118 void StealFrom(WorkerLoadInfo& aOther); 119 120 nsresult SetPrincipalOnMainThread(nsIPrincipal* aPrincipal, 121 nsILoadGroup* aLoadGroup); 122 123 nsresult GetPrincipalAndLoadGroupFromChannel(nsIChannel* aChannel, 124 nsIPrincipal** aPrincipalOut, 125 nsILoadGroup** aLoadGroupOut); 126 127 nsresult SetPrincipalFromChannel(nsIChannel* aChannel); 128 129 bool FinalChannelPrincipalIsValid(nsIChannel* aChannel); 130 131 #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED 132 bool PrincipalIsValid() const; 133 134 bool PrincipalURIMatchesScriptURL(); 135 #endif 136 137 bool ProxyReleaseMainThreadObjects(WorkerPrivate* aWorkerPrivate); 138 139 bool ProxyReleaseMainThreadObjects( 140 WorkerPrivate* aWorkerPrivate, 141 nsCOMPtr<nsILoadGroup>& aLoadGroupToCancel); 142 }; 143 144 } // namespace dom 145 } // namespace mozilla 146 147 #endif // mozilla_dom_workers_WorkerLoadInfo_h 148