Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "mozilla/net/CookieServiceParent.h" |
michael@0 | 7 | #include "mozilla/dom/PContentParent.h" |
michael@0 | 8 | #include "mozilla/net/NeckoParent.h" |
michael@0 | 9 | |
michael@0 | 10 | #include "mozilla/ipc/URIUtils.h" |
michael@0 | 11 | #include "nsCookieService.h" |
michael@0 | 12 | #include "nsNetUtil.h" |
michael@0 | 13 | #include "nsPrintfCString.h" |
michael@0 | 14 | #include "SerializedLoadContext.h" |
michael@0 | 15 | |
michael@0 | 16 | using namespace mozilla::ipc; |
michael@0 | 17 | using mozilla::dom::PContentParent; |
michael@0 | 18 | using mozilla::net::NeckoParent; |
michael@0 | 19 | |
michael@0 | 20 | namespace mozilla { |
michael@0 | 21 | namespace net { |
michael@0 | 22 | |
michael@0 | 23 | MOZ_WARN_UNUSED_RESULT |
michael@0 | 24 | bool |
michael@0 | 25 | CookieServiceParent::GetAppInfoFromParams(const IPC::SerializedLoadContext &aLoadContext, |
michael@0 | 26 | uint32_t& aAppId, |
michael@0 | 27 | bool& aIsInBrowserElement, |
michael@0 | 28 | bool& aIsPrivate) |
michael@0 | 29 | { |
michael@0 | 30 | aAppId = NECKO_NO_APP_ID; |
michael@0 | 31 | aIsInBrowserElement = false; |
michael@0 | 32 | aIsPrivate = false; |
michael@0 | 33 | |
michael@0 | 34 | const char* error = NeckoParent::GetValidatedAppInfo(aLoadContext, |
michael@0 | 35 | Manager()->Manager(), |
michael@0 | 36 | &aAppId, |
michael@0 | 37 | &aIsInBrowserElement); |
michael@0 | 38 | if (error) { |
michael@0 | 39 | NS_WARNING(nsPrintfCString("CookieServiceParent: GetAppInfoFromParams: " |
michael@0 | 40 | "FATAL error: %s: KILLING CHILD PROCESS\n", |
michael@0 | 41 | error).get()); |
michael@0 | 42 | return false; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | if (aLoadContext.IsPrivateBitValid()) { |
michael@0 | 46 | aIsPrivate = aLoadContext.mUsePrivateBrowsing; |
michael@0 | 47 | } |
michael@0 | 48 | return true; |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | CookieServiceParent::CookieServiceParent() |
michael@0 | 52 | { |
michael@0 | 53 | // Instantiate the cookieservice via the service manager, so it sticks around |
michael@0 | 54 | // until shutdown. |
michael@0 | 55 | nsCOMPtr<nsICookieService> cs = do_GetService(NS_COOKIESERVICE_CONTRACTID); |
michael@0 | 56 | |
michael@0 | 57 | // Get the nsCookieService instance directly, so we can call internal methods. |
michael@0 | 58 | mCookieService = |
michael@0 | 59 | already_AddRefed<nsCookieService>(nsCookieService::GetSingleton()); |
michael@0 | 60 | NS_ASSERTION(mCookieService, "couldn't get nsICookieService"); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | CookieServiceParent::~CookieServiceParent() |
michael@0 | 64 | { |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | bool |
michael@0 | 68 | CookieServiceParent::RecvGetCookieString(const URIParams& aHost, |
michael@0 | 69 | const bool& aIsForeign, |
michael@0 | 70 | const bool& aFromHttp, |
michael@0 | 71 | const IPC::SerializedLoadContext& |
michael@0 | 72 | aLoadContext, |
michael@0 | 73 | nsCString* aResult) |
michael@0 | 74 | { |
michael@0 | 75 | if (!mCookieService) |
michael@0 | 76 | return true; |
michael@0 | 77 | |
michael@0 | 78 | // Deserialize URI. Having a host URI is mandatory and should always be |
michael@0 | 79 | // provided by the child; thus we consider failure fatal. |
michael@0 | 80 | nsCOMPtr<nsIURI> hostURI = DeserializeURI(aHost); |
michael@0 | 81 | if (!hostURI) |
michael@0 | 82 | return false; |
michael@0 | 83 | |
michael@0 | 84 | uint32_t appId; |
michael@0 | 85 | bool isInBrowserElement, isPrivate; |
michael@0 | 86 | bool valid = GetAppInfoFromParams(aLoadContext, appId, |
michael@0 | 87 | isInBrowserElement, isPrivate); |
michael@0 | 88 | if (!valid) { |
michael@0 | 89 | return false; |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@4 | 92 | // Method is called nowhere |
michael@4 | 93 | nsAutoCString origDomain; |
michael@0 | 94 | mCookieService->GetCookieStringInternal(hostURI, aIsForeign, aFromHttp, appId, |
michael@4 | 95 | isInBrowserElement, isPrivate, |
michael@4 | 96 | origDomain, *aResult); |
michael@0 | 97 | return true; |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | bool |
michael@0 | 101 | CookieServiceParent::RecvSetCookieString(const URIParams& aHost, |
michael@0 | 102 | const bool& aIsForeign, |
michael@0 | 103 | const nsCString& aCookieString, |
michael@0 | 104 | const nsCString& aServerTime, |
michael@0 | 105 | const bool& aFromHttp, |
michael@0 | 106 | const IPC::SerializedLoadContext& |
michael@0 | 107 | aLoadContext) |
michael@0 | 108 | { |
michael@0 | 109 | if (!mCookieService) |
michael@0 | 110 | return true; |
michael@0 | 111 | |
michael@0 | 112 | // Deserialize URI. Having a host URI is mandatory and should always be |
michael@0 | 113 | // provided by the child; thus we consider failure fatal. |
michael@0 | 114 | nsCOMPtr<nsIURI> hostURI = DeserializeURI(aHost); |
michael@0 | 115 | if (!hostURI) |
michael@0 | 116 | return false; |
michael@0 | 117 | |
michael@0 | 118 | uint32_t appId; |
michael@0 | 119 | bool isInBrowserElement, isPrivate; |
michael@0 | 120 | bool valid = GetAppInfoFromParams(aLoadContext, appId, |
michael@0 | 121 | isInBrowserElement, isPrivate); |
michael@0 | 122 | if (!valid) { |
michael@0 | 123 | return false; |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | nsDependentCString cookieString(aCookieString, 0); |
michael@0 | 127 | //TODO: bug 812475, pass a real channel object |
michael@0 | 128 | mCookieService->SetCookieStringInternal(hostURI, aIsForeign, cookieString, |
michael@0 | 129 | aServerTime, aFromHttp, appId, |
michael@0 | 130 | isInBrowserElement, isPrivate, nullptr); |
michael@0 | 131 | return true; |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | mozilla::ipc::IProtocol* |
michael@0 | 135 | CookieServiceParent::CloneProtocol(Channel* aChannel, |
michael@0 | 136 | mozilla::ipc::ProtocolCloneContext* aCtx) |
michael@0 | 137 | { |
michael@0 | 138 | NeckoParent* manager = aCtx->GetNeckoParent(); |
michael@0 | 139 | nsAutoPtr<PCookieServiceParent> actor(manager->AllocPCookieServiceParent()); |
michael@0 | 140 | if (!actor || !manager->RecvPCookieServiceConstructor(actor)) { |
michael@0 | 141 | return nullptr; |
michael@0 | 142 | } |
michael@0 | 143 | return actor.forget(); |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | } |
michael@0 | 147 | } |
michael@0 | 148 |