addon-sdk/source/lib/sdk/preferences/event-target.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/. */
     4 'use strict';
     6 module.metadata = {
     7   "stability": "unstable"
     8 };
    10 const { Cc, Ci } = require('chrome');
    11 const { Class } = require('../core/heritage');
    12 const { EventTarget } = require('../event/target');
    13 const { Branch } = require('./service');
    14 const { emit, off } = require('../event/core');
    15 const { when: unload } = require('../system/unload');
    17 const prefTargetNS = require('../core/namespace').ns();
    19 const PrefsTarget = Class({
    20   extends: EventTarget,
    21   initialize: function(options) {
    22     options = options || {};
    23     EventTarget.prototype.initialize.call(this, options);
    25     let branchName = options.branchName || '';
    26     let branch = Cc["@mozilla.org/preferences-service;1"].
    27         getService(Ci.nsIPrefService).
    28         getBranch(branchName).
    29         QueryInterface(Ci.nsIPrefBranch2);
    30     prefTargetNS(this).branch = branch;
    32     // provides easy access to preference values
    33     this.prefs = Branch(branchName);
    35     // start listening to preference changes
    36     let observer = prefTargetNS(this).observer = onChange.bind(this);
    37     branch.addObserver('', observer, false);
    39     // Make sure to destroy this on unload
    40     unload(destroy.bind(this));
    41   }
    42 });
    43 exports.PrefsTarget = PrefsTarget;
    45 /* HELPERS */
    47 function onChange(subject, topic, name) {
    48   if (topic === 'nsPref:changed') {
    49     emit(this, name, name);
    50     emit(this, '', name);
    51   }
    52 }
    54 function destroy() {
    55   off(this);
    57   // stop listening to preference changes
    58   let branch = prefTargetNS(this).branch;
    59   branch.removeObserver('', prefTargetNS(this).observer, false);
    60   prefTargetNS(this).observer = null;
    61 }

mercurial