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.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 /**
michael@0 6 * The eventLoopLag actor emits "event-loop-lag" events when the event
michael@0 7 * loop gets unresponsive. The event comes with a "time" property (the
michael@0 8 * duration of the lag in milliseconds).
michael@0 9 */
michael@0 10
michael@0 11 const {Ci, Cu} = require("chrome");
michael@0 12 const Services = require("Services");
michael@0 13 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
michael@0 14 const protocol = require("devtools/server/protocol");
michael@0 15 const {method, Arg, RetVal} = protocol;
michael@0 16 const events = require("sdk/event/core");
michael@0 17
michael@0 18 exports.register = function(handle) {
michael@0 19 handle.addGlobalActor(EventLoopLagActor, "eventLoopLagActor");
michael@0 20 handle.addTabActor(EventLoopLagActor, "eventLoopLagActor");
michael@0 21 };
michael@0 22
michael@0 23 exports.unregister = function(handle) {
michael@0 24 handle.removeGlobalActor(EventLoopLagActor);
michael@0 25 handle.removeTabActor(EventLoopLagActor);
michael@0 26 };
michael@0 27
michael@0 28 let EventLoopLagActor = protocol.ActorClass({
michael@0 29
michael@0 30 typeName: "eventLoopLag",
michael@0 31
michael@0 32 _observerAdded: false,
michael@0 33
michael@0 34 events: {
michael@0 35 "event-loop-lag" : {
michael@0 36 type: "event-loop-lag",
michael@0 37 time: Arg(0, "number") // duration of the lag in milliseconds.
michael@0 38 }
michael@0 39 },
michael@0 40
michael@0 41 /**
michael@0 42 * Start tracking the event loop lags.
michael@0 43 */
michael@0 44 start: method(function() {
michael@0 45 if (!this._observerAdded) {
michael@0 46 Services.obs.addObserver(this, 'event-loop-lag', false);
michael@0 47 this._observerAdded = true;
michael@0 48 }
michael@0 49 return Services.appShell.startEventLoopLagTracking();
michael@0 50 }, {
michael@0 51 request: {},
michael@0 52 response: {success: RetVal("number")}
michael@0 53 }),
michael@0 54
michael@0 55 /**
michael@0 56 * Stop tracking the event loop lags.
michael@0 57 */
michael@0 58 stop: method(function() {
michael@0 59 if (this._observerAdded) {
michael@0 60 Services.obs.removeObserver(this, 'event-loop-lag');
michael@0 61 this._observerAdded = false;
michael@0 62 }
michael@0 63 Services.appShell.stopEventLoopLagTracking();
michael@0 64 }, {request: {},response: {}}),
michael@0 65
michael@0 66 destroy: function() {
michael@0 67 this.stop();
michael@0 68 protocol.Actor.prototype.destroy.call(this);
michael@0 69 },
michael@0 70
michael@0 71 // nsIObserver
michael@0 72
michael@0 73 observe: function (subject, topic, data) {
michael@0 74 if (topic == "event-loop-lag") {
michael@0 75 // Forward event loop lag event
michael@0 76 events.emit(this, "event-loop-lag", data);
michael@0 77 }
michael@0 78 },
michael@0 79
michael@0 80 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
michael@0 81 });
michael@0 82
michael@0 83 exports.EventLoopLagFront = protocol.FrontClass(EventLoopLagActor, {
michael@0 84 initialize: function(client, form) {
michael@0 85 protocol.Front.prototype.initialize.call(this, client);
michael@0 86 this.actorID = form.eventLoopLagActor;
michael@0 87 client.addActorPool(this);
michael@0 88 this.manage(this);
michael@0 89 },
michael@0 90 });

mercurial