Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
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 "CellBroadcast.h" |
michael@0 | 7 | #include "mozilla/dom/MozCellBroadcastBinding.h" |
michael@0 | 8 | #include "nsIDOMMozCellBroadcastEvent.h" |
michael@0 | 9 | #include "nsIDOMMozCellBroadcastMessage.h" |
michael@0 | 10 | #include "nsServiceManagerUtils.h" |
michael@0 | 11 | #include "GeneratedEvents.h" |
michael@0 | 12 | |
michael@0 | 13 | #define NS_RILCONTENTHELPER_CONTRACTID "@mozilla.org/ril/content-helper;1" |
michael@0 | 14 | |
michael@0 | 15 | using namespace mozilla::dom; |
michael@0 | 16 | |
michael@0 | 17 | /** |
michael@0 | 18 | * CellBroadcast::Listener Implementation. |
michael@0 | 19 | */ |
michael@0 | 20 | |
michael@0 | 21 | class CellBroadcast::Listener : public nsICellBroadcastListener |
michael@0 | 22 | { |
michael@0 | 23 | private: |
michael@0 | 24 | CellBroadcast* mCellBroadcast; |
michael@0 | 25 | |
michael@0 | 26 | public: |
michael@0 | 27 | NS_DECL_ISUPPORTS |
michael@0 | 28 | NS_FORWARD_SAFE_NSICELLBROADCASTLISTENER(mCellBroadcast) |
michael@0 | 29 | |
michael@0 | 30 | Listener(CellBroadcast* aCellBroadcast) |
michael@0 | 31 | : mCellBroadcast(aCellBroadcast) |
michael@0 | 32 | { |
michael@0 | 33 | MOZ_ASSERT(mCellBroadcast); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | void Disconnect() |
michael@0 | 37 | { |
michael@0 | 38 | MOZ_ASSERT(mCellBroadcast); |
michael@0 | 39 | mCellBroadcast = nullptr; |
michael@0 | 40 | } |
michael@0 | 41 | }; |
michael@0 | 42 | |
michael@0 | 43 | NS_IMPL_ISUPPORTS(CellBroadcast::Listener, nsICellBroadcastListener) |
michael@0 | 44 | |
michael@0 | 45 | /** |
michael@0 | 46 | * CellBroadcast Implementation. |
michael@0 | 47 | */ |
michael@0 | 48 | |
michael@0 | 49 | // static |
michael@0 | 50 | already_AddRefed<CellBroadcast> |
michael@0 | 51 | CellBroadcast::Create(nsPIDOMWindow* aWindow, ErrorResult& aRv) |
michael@0 | 52 | { |
michael@0 | 53 | MOZ_ASSERT(aWindow); |
michael@0 | 54 | MOZ_ASSERT(aWindow->IsInnerWindow()); |
michael@0 | 55 | |
michael@0 | 56 | nsCOMPtr<nsICellBroadcastProvider> provider = |
michael@0 | 57 | do_GetService(NS_RILCONTENTHELPER_CONTRACTID); |
michael@0 | 58 | if (!provider) { |
michael@0 | 59 | aRv.Throw(NS_ERROR_UNEXPECTED); |
michael@0 | 60 | return nullptr; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | nsRefPtr<CellBroadcast> cb = new CellBroadcast(aWindow, provider); |
michael@0 | 64 | return cb.forget(); |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | CellBroadcast::CellBroadcast(nsPIDOMWindow *aWindow, |
michael@0 | 68 | nsICellBroadcastProvider *aProvider) |
michael@0 | 69 | : DOMEventTargetHelper(aWindow) |
michael@0 | 70 | , mProvider(aProvider) |
michael@0 | 71 | { |
michael@0 | 72 | mListener = new Listener(this); |
michael@0 | 73 | DebugOnly<nsresult> rv = mProvider->RegisterCellBroadcastMsg(mListener); |
michael@0 | 74 | NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), |
michael@0 | 75 | "Failed registering Cell Broadcast callback with provider"); |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | CellBroadcast::~CellBroadcast() |
michael@0 | 79 | { |
michael@0 | 80 | MOZ_ASSERT(mProvider && mListener); |
michael@0 | 81 | |
michael@0 | 82 | mListener->Disconnect(); |
michael@0 | 83 | mProvider->UnregisterCellBroadcastMsg(mListener); |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | JSObject* |
michael@0 | 87 | CellBroadcast::WrapObject(JSContext* aCx) |
michael@0 | 88 | { |
michael@0 | 89 | return MozCellBroadcastBinding::Wrap(aCx, this); |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | // Forwarded nsICellBroadcastListener methods |
michael@0 | 93 | |
michael@0 | 94 | NS_IMETHODIMP |
michael@0 | 95 | CellBroadcast::NotifyMessageReceived(nsIDOMMozCellBroadcastMessage* aMessage) |
michael@0 | 96 | { |
michael@0 | 97 | nsCOMPtr<nsIDOMEvent> event; |
michael@0 | 98 | NS_NewDOMMozCellBroadcastEvent(getter_AddRefs(event), this, nullptr, nullptr); |
michael@0 | 99 | |
michael@0 | 100 | nsCOMPtr<nsIDOMMozCellBroadcastEvent> ce = do_QueryInterface(event); |
michael@0 | 101 | nsresult rv = ce->InitMozCellBroadcastEvent(NS_LITERAL_STRING("received"), |
michael@0 | 102 | true, false, aMessage); |
michael@0 | 103 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 104 | |
michael@0 | 105 | return DispatchTrustedEvent(ce); |
michael@0 | 106 | } |