addon-sdk/source/lib/sdk/deprecated/events/assembler.js

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 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 "use strict";
     7 const { Trait } = require("../light-traits");
     8 const { removeListener, on } = require("../../dom/events");
    10 /**
    11  * Trait may be used for building objects / composing traits that wish to handle
    12  * multiple dom events from multiple event targets in one place. Event targets
    13  * can be added / removed by calling `observe / ignore` methods. Composer should
    14  * provide array of event types it wishes to handle as property
    15  * `supportedEventsTypes` and function for handling all those events as
    16  * `handleEvent` property.
    17  */
    18 exports.DOMEventAssembler = Trait({
    19   /**
    20    * Function that is supposed to handle all the supported events (that are
    21    * present in the `supportedEventsTypes`) from all the observed
    22    * `eventTargets`.
    23    * @param {Event} event
    24    *    Event being dispatched.
    25    */
    26   handleEvent: Trait.required,
    27   /**
    28    * Array of supported event names.
    29    * @type {String[]}
    30    */
    31   supportedEventsTypes: Trait.required,
    32   /**
    33    * Adds `eventTarget` to the list of observed `eventTarget`s. Listeners for
    34    * supported events will be registered on the given `eventTarget`.
    35    * @param {EventTarget} eventTarget
    36    */
    37   observe: function observe(eventTarget) {
    38     this.supportedEventsTypes.forEach(function(eventType) {
    39       on(eventTarget, eventType, this);
    40     }, this);
    41   },
    42   /**
    43    * Removes `eventTarget` from the list of observed `eventTarget`s. Listeners
    44    * for all supported events will be unregistered from the given `eventTarget`.
    45    * @param {EventTarget} eventTarget
    46    */
    47   ignore: function ignore(eventTarget) {
    48     this.supportedEventsTypes.forEach(function(eventType) {
    49       removeListener(eventTarget, eventType, this);
    50     }, this);
    51   }
    52 });

mercurial