CookieServiceParent.h (4119B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #ifndef mozilla_net_CookieServiceParent_h 7 #define mozilla_net_CookieServiceParent_h 8 9 #include "mozilla/net/PCookieServiceParent.h" 10 #include "mozilla/net/CookieKey.h" 11 12 class nsIArray; 13 class nsICookie; 14 namespace mozilla { 15 class OriginAttributes; 16 17 namespace dom { 18 class ContentParent; 19 } // namespace dom 20 } // namespace mozilla 21 22 class nsIEffectiveTLDService; 23 24 namespace mozilla { 25 namespace net { 26 27 class Cookie; 28 class CookieService; 29 30 class CookieServiceParent : public PCookieServiceParent { 31 friend class PCookieServiceParent; 32 33 public: 34 // A RAII class to set and unset the cookie processing flag. 35 class MOZ_STACK_CLASS CookieProcessingGuard final { 36 public: 37 explicit CookieProcessingGuard(CookieServiceParent* aActor = nullptr) { 38 if (aActor) { 39 Initialize(aActor); 40 } 41 } 42 43 void Initialize(CookieServiceParent* aActor) { 44 MOZ_ASSERT(!mActor && aActor); 45 46 mActor = aActor; 47 48 if (mActor) { 49 MOZ_ASSERT(!mActor->mProcessingCookie); 50 mActor->mProcessingCookie = true; 51 } 52 } 53 54 ~CookieProcessingGuard() { 55 if (mActor) { 56 MOZ_ASSERT(mActor->mProcessingCookie); 57 mActor->mProcessingCookie = false; 58 } 59 } 60 61 private: 62 CookieServiceParent* mActor = nullptr; 63 }; 64 65 explicit CookieServiceParent(dom::ContentParent* aContentParent); 66 virtual ~CookieServiceParent() = default; 67 68 void TrackCookieLoad(nsIChannel* aChannel); 69 70 void RemoveBatchDeletedCookies(nsIArray* aCookieList); 71 72 void RemoveAll(); 73 74 void RemoveCookie(const Cookie& aCookie, const nsID* aOperationID); 75 76 void AddCookie(const Cookie& aCookie, const nsID* aOperationID); 77 78 // This will return true if the CookieServiceParent is currently processing 79 // an update from the content process. This is used in ContentParent to make 80 // sure that we are only forwarding those cookie updates to other content 81 // processes, not the one they originated from. 82 bool ProcessingCookie() { return mProcessingCookie; } 83 84 bool ContentProcessHasCookie(const Cookie& cookie); 85 bool ContentProcessHasCookie(const nsACString& aHost, 86 const OriginAttributes& aOriginAttributes); 87 bool InsecureCookieOrSecureOrigin(const Cookie& cookie); 88 void UpdateCookieInContentList(nsIURI* aHostURI, 89 const OriginAttributes& aOriginAttrs); 90 91 mozilla::ipc::IPCResult SetCookies( 92 const nsCString& aBaseDomain, const OriginAttributes& aOriginAttributes, 93 nsIURI* aHost, bool aFromHttp, bool aIsThirdParty, 94 const nsTArray<CookieStruct>& aCookies, 95 dom::BrowsingContext* aBrowsingContext = nullptr); 96 97 protected: 98 virtual void ActorDestroy(ActorDestroyReason aWhy) override; 99 100 mozilla::ipc::IPCResult RecvSetCookies( 101 const nsCString& aBaseDomain, const OriginAttributes& aOriginAttributes, 102 nsIURI* aHost, bool aFromHttp, bool aIsThirdParty, 103 const nsTArray<CookieStruct>& aCookies); 104 105 mozilla::ipc::IPCResult RecvGetCookieList( 106 nsIURI* aHost, const bool& aIsForeign, 107 const bool& aIsThirdPartyTrackingResource, 108 const bool& aIsThirdPartySocialTrackingResource, 109 const bool& aStorageAccessPermissionGranted, 110 const uint32_t& aRejectedReason, const bool& aIsSafeTopLevelNav, 111 const bool& aIsSameSiteForeign, const bool& aHadCrossSiteRedirects, 112 nsTArray<OriginAttributes>&& aAttrsList, 113 GetCookieListResolver&& aResolve); 114 115 static void SerializeCookieListTable( 116 const nsTArray<RefPtr<Cookie>>& aFoundCookieList, 117 nsTArray<CookieStructTable>& aCookiesListTable, nsIURI* aHostURI); 118 119 nsCOMPtr<nsIEffectiveTLDService> mTLDService; 120 RefPtr<CookieService> mCookieService; 121 bool mProcessingCookie; 122 nsTHashMap<CookieKey, bool> mCookieKeysInContent; 123 }; 124 125 } // namespace net 126 } // namespace mozilla 127 128 #endif // mozilla_net_CookieServiceParent_h