dom/events/EventTarget.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     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 "mozilla/EventListenerManager.h"
     7 #include "mozilla/dom/EventTarget.h"
     8 #include "nsThreadUtils.h"
    10 namespace mozilla {
    11 namespace dom {
    13 void
    14 EventTarget::RemoveEventListener(const nsAString& aType,
    15                                  EventListener* aListener,
    16                                  bool aUseCapture,
    17                                  ErrorResult& aRv)
    18 {
    19   EventListenerManager* elm = GetExistingListenerManager();
    20   if (elm) {
    21     elm->RemoveEventListener(aType, aListener, aUseCapture);
    22   }
    23 }
    25 EventHandlerNonNull*
    26 EventTarget::GetEventHandler(nsIAtom* aType, const nsAString& aTypeString)
    27 {
    28   EventListenerManager* elm = GetExistingListenerManager();
    29   return elm ? elm->GetEventHandler(aType, aTypeString) : nullptr;
    30 }
    32 void
    33 EventTarget::SetEventHandler(const nsAString& aType,
    34                              EventHandlerNonNull* aHandler,
    35                              ErrorResult& aRv)
    36 {
    37   if (!StringBeginsWith(aType, NS_LITERAL_STRING("on"))) {
    38     aRv.Throw(NS_ERROR_INVALID_ARG);
    39     return;
    40   }
    41   if (NS_IsMainThread()) {
    42     nsCOMPtr<nsIAtom> type = do_GetAtom(aType);
    43     SetEventHandler(type, EmptyString(), aHandler);
    44     return;
    45   }
    46   SetEventHandler(nullptr,
    47                   Substring(aType, 2), // Remove "on"
    48                   aHandler);
    49 }
    51 void
    52 EventTarget::SetEventHandler(nsIAtom* aType, const nsAString& aTypeString,
    53                              EventHandlerNonNull* aHandler)
    54 {
    55   GetOrCreateListenerManager()->SetEventHandler(aType, aTypeString, aHandler);
    56 }
    58 } // namespace dom
    59 } // namespace mozilla

mercurial