toolkit/devtools/server/actors/eventlooplag.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 /**
     6  * The eventLoopLag actor emits "event-loop-lag" events when the event
     7  * loop gets unresponsive. The event comes with a "time" property (the
     8  * duration of the lag in milliseconds).
     9  */
    11 const {Ci, Cu} = require("chrome");
    12 const Services = require("Services");
    13 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
    14 const protocol = require("devtools/server/protocol");
    15 const {method, Arg, RetVal} = protocol;
    16 const events = require("sdk/event/core");
    18 exports.register = function(handle) {
    19   handle.addGlobalActor(EventLoopLagActor, "eventLoopLagActor");
    20   handle.addTabActor(EventLoopLagActor, "eventLoopLagActor");
    21 };
    23 exports.unregister = function(handle) {
    24   handle.removeGlobalActor(EventLoopLagActor);
    25   handle.removeTabActor(EventLoopLagActor);
    26 };
    28 let EventLoopLagActor = protocol.ActorClass({
    30   typeName: "eventLoopLag",
    32   _observerAdded: false,
    34   events: {
    35     "event-loop-lag" : {
    36       type: "event-loop-lag",
    37       time: Arg(0, "number") // duration of the lag in milliseconds.
    38     }
    39   },
    41   /**
    42    * Start tracking the event loop lags.
    43    */
    44   start: method(function() {
    45     if (!this._observerAdded) {
    46       Services.obs.addObserver(this, 'event-loop-lag', false);
    47       this._observerAdded = true;
    48     }
    49     return Services.appShell.startEventLoopLagTracking();
    50   }, {
    51     request: {},
    52     response: {success: RetVal("number")}
    53   }),
    55   /**
    56    * Stop tracking the event loop lags.
    57    */
    58   stop: method(function() {
    59     if (this._observerAdded) {
    60       Services.obs.removeObserver(this, 'event-loop-lag');
    61       this._observerAdded = false;
    62     }
    63     Services.appShell.stopEventLoopLagTracking();
    64   }, {request: {},response: {}}),
    66   destroy: function() {
    67     this.stop();
    68     protocol.Actor.prototype.destroy.call(this);
    69   },
    71   // nsIObserver
    73   observe: function (subject, topic, data) {
    74     if (topic == "event-loop-lag") {
    75       // Forward event loop lag event
    76       events.emit(this, "event-loop-lag", data);
    77     }
    78   },
    80   QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
    81 });
    83 exports.EventLoopLagFront = protocol.FrontClass(EventLoopLagActor, {
    84   initialize: function(client, form) {
    85     protocol.Front.prototype.initialize.call(this, client);
    86     this.actorID = form.eventLoopLagActor;
    87     client.addActorPool(this);
    88     this.manage(this);
    89   },
    90 });

mercurial