addon-sdk/source/lib/sdk/console/plain-text.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 module.metadata = {
     8   "stability": "unstable"
     9 };
    11 const { Cc, Ci, Cu, Cr } = require("chrome");
    12 const self = require("../self");
    13 const prefs = require("../preferences/service");
    14 const { merge } = require("../util/object");
    15 const { ConsoleAPI } = Cu.import("resource://gre/modules/devtools/Console.jsm", {});
    17 const DEFAULT_LOG_LEVEL = "error";
    18 const ADDON_LOG_LEVEL_PREF = "extensions." + self.id + ".sdk.console.logLevel";
    19 const SDK_LOG_LEVEL_PREF = "extensions.sdk.console.logLevel";
    21 let logLevel = DEFAULT_LOG_LEVEL;
    22 function setLogLevel() {
    23   logLevel = prefs.get(ADDON_LOG_LEVEL_PREF,
    24                            prefs.get(SDK_LOG_LEVEL_PREF,
    25                                      DEFAULT_LOG_LEVEL));
    26 }
    27 setLogLevel();
    29 let logLevelObserver = {
    30   QueryInterface: function(iid) {
    31     if (!iid.equals(Ci.nsIObserver) &&
    32         !iid.equals(Ci.nsISupportsWeakReference) &&
    33         !iid.equals(Ci.nsISupports))
    34       throw Cr.NS_ERROR_NO_INTERFACE;
    35     return this;
    36   },
    37   observe: function(subject, topic, data) {
    38     setLogLevel();
    39   }
    40 };
    41 let branch = Cc["@mozilla.org/preferences-service;1"].
    42              getService(Ci.nsIPrefService).
    43              getBranch(null);
    44 branch.addObserver(ADDON_LOG_LEVEL_PREF, logLevelObserver, true);
    45 branch.addObserver(SDK_LOG_LEVEL_PREF, logLevelObserver, true);
    47 function PlainTextConsole(print, innerID) {
    49   let consoleOptions = {
    50     prefix: self.name + ": ",
    51     maxLogLevel: logLevel,
    52     dump: print,
    53     innerID: innerID
    54   };
    55   let console = new ConsoleAPI(consoleOptions);
    57   // As we freeze the console object, we can't modify this property afterward
    58   Object.defineProperty(console, "maxLogLevel", {
    59     get: function() {
    60       return logLevel;
    61     }
    62   });
    64   // We defined the `__exposedProps__` in our console chrome object.
    65   //
    66   // Meanwhile we're investigating with the platform team if `__exposedProps__`
    67   // are needed, or are just a left-over.
    69   console.__exposedProps__ = Object.keys(ConsoleAPI.prototype).reduce(function(exposed, prop) {
    70     exposed[prop] = "r";
    71     return exposed;
    72   }, {});
    74   Object.freeze(console);
    75   return console;
    76 };
    77 exports.PlainTextConsole = PlainTextConsole;

mercurial