dom/cellbroadcast/src/CellBroadcast.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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.

     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/. */
     6 #include "CellBroadcast.h"
     7 #include "mozilla/dom/MozCellBroadcastBinding.h"
     8 #include "nsIDOMMozCellBroadcastEvent.h"
     9 #include "nsIDOMMozCellBroadcastMessage.h"
    10 #include "nsServiceManagerUtils.h"
    11 #include "GeneratedEvents.h"
    13 #define NS_RILCONTENTHELPER_CONTRACTID "@mozilla.org/ril/content-helper;1"
    15 using namespace mozilla::dom;
    17 /**
    18  * CellBroadcast::Listener Implementation.
    19  */
    21 class CellBroadcast::Listener : public nsICellBroadcastListener
    22 {
    23 private:
    24   CellBroadcast* mCellBroadcast;
    26 public:
    27   NS_DECL_ISUPPORTS
    28   NS_FORWARD_SAFE_NSICELLBROADCASTLISTENER(mCellBroadcast)
    30   Listener(CellBroadcast* aCellBroadcast)
    31     : mCellBroadcast(aCellBroadcast)
    32   {
    33     MOZ_ASSERT(mCellBroadcast);
    34   }
    36   void Disconnect()
    37   {
    38     MOZ_ASSERT(mCellBroadcast);
    39     mCellBroadcast = nullptr;
    40   }
    41 };
    43 NS_IMPL_ISUPPORTS(CellBroadcast::Listener, nsICellBroadcastListener)
    45 /**
    46  * CellBroadcast Implementation.
    47  */
    49 // static
    50 already_AddRefed<CellBroadcast>
    51 CellBroadcast::Create(nsPIDOMWindow* aWindow, ErrorResult& aRv)
    52 {
    53   MOZ_ASSERT(aWindow);
    54   MOZ_ASSERT(aWindow->IsInnerWindow());
    56   nsCOMPtr<nsICellBroadcastProvider> provider =
    57     do_GetService(NS_RILCONTENTHELPER_CONTRACTID);
    58   if (!provider) {
    59     aRv.Throw(NS_ERROR_UNEXPECTED);
    60     return nullptr;
    61   }
    63   nsRefPtr<CellBroadcast> cb = new CellBroadcast(aWindow, provider);
    64   return cb.forget();
    65 }
    67 CellBroadcast::CellBroadcast(nsPIDOMWindow *aWindow,
    68                              nsICellBroadcastProvider *aProvider)
    69   : DOMEventTargetHelper(aWindow)
    70   , mProvider(aProvider)
    71 {
    72   mListener = new Listener(this);
    73   DebugOnly<nsresult> rv = mProvider->RegisterCellBroadcastMsg(mListener);
    74   NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
    75                    "Failed registering Cell Broadcast callback with provider");
    76 }
    78 CellBroadcast::~CellBroadcast()
    79 {
    80   MOZ_ASSERT(mProvider && mListener);
    82   mListener->Disconnect();
    83   mProvider->UnregisterCellBroadcastMsg(mListener);
    84 }
    86 JSObject*
    87 CellBroadcast::WrapObject(JSContext* aCx)
    88 {
    89   return MozCellBroadcastBinding::Wrap(aCx, this);
    90 }
    92 // Forwarded nsICellBroadcastListener methods
    94 NS_IMETHODIMP
    95 CellBroadcast::NotifyMessageReceived(nsIDOMMozCellBroadcastMessage* aMessage)
    96 {
    97   nsCOMPtr<nsIDOMEvent> event;
    98   NS_NewDOMMozCellBroadcastEvent(getter_AddRefs(event), this, nullptr, nullptr);
   100   nsCOMPtr<nsIDOMMozCellBroadcastEvent> ce = do_QueryInterface(event);
   101   nsresult rv = ce->InitMozCellBroadcastEvent(NS_LITERAL_STRING("received"),
   102                                               true, false, aMessage);
   103   NS_ENSURE_SUCCESS(rv, rv);
   105   return DispatchTrustedEvent(ce);
   106 }

mercurial