dom/base/MessageChannel.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 "MessageChannel.h"
     7 #include "mozilla/Preferences.h"
     8 #include "mozilla/dom/MessageChannelBinding.h"
     9 #include "mozilla/dom/MessagePort.h"
    10 #include "nsContentUtils.h"
    11 #include "nsPIDOMWindow.h"
    13 namespace mozilla {
    14 namespace dom {
    16 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_3(MessageChannel, mWindow, mPort1, mPort2)
    17 NS_IMPL_CYCLE_COLLECTING_ADDREF(MessageChannel)
    18 NS_IMPL_CYCLE_COLLECTING_RELEASE(MessageChannel)
    20 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MessageChannel)
    21   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
    22   NS_INTERFACE_MAP_ENTRY(nsISupports)
    23 NS_INTERFACE_MAP_END
    25 namespace {
    26   bool gPrefInitialized = false;
    27   bool gPrefEnabled = false;
    29 }
    32 /* static */ bool
    33 MessageChannel::PrefEnabled()
    34 {
    35   if (!gPrefInitialized) {
    36     Preferences::AddBoolVarCache(&gPrefEnabled, "dom.messageChannel.enabled");
    37     gPrefInitialized = true;
    38   }
    40   return gPrefEnabled;
    41 }
    43 MessageChannel::MessageChannel(nsPIDOMWindow* aWindow)
    44   : mWindow(aWindow)
    45 {
    46   MOZ_COUNT_CTOR(MessageChannel);
    47   SetIsDOMBinding();
    49   mPort1 = new MessagePort(mWindow);
    50   mPort2 = new MessagePort(mWindow);
    52   mPort1->Entangle(mPort2);
    53   mPort2->Entangle(mPort1);
    54 }
    56 MessageChannel::~MessageChannel()
    57 {
    58   MOZ_COUNT_DTOR(MessageChannel);
    59 }
    61 JSObject*
    62 MessageChannel::WrapObject(JSContext* aCx)
    63 {
    64   return MessageChannelBinding::Wrap(aCx, this);
    65 }
    67 /* static */ already_AddRefed<MessageChannel>
    68 MessageChannel::Constructor(const GlobalObject& aGlobal, ErrorResult& aRv)
    69 {
    70   nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.GetAsSupports());
    71   if (!window) {
    72     aRv.Throw(NS_ERROR_UNEXPECTED);
    73     return nullptr;
    74   }
    76   nsRefPtr<MessageChannel> channel = new MessageChannel(window);
    77   return channel.forget();
    78 }
    80 } // namespace dom
    81 } // namespace mozilla

mercurial