michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: const { Cc, Ci, Cu } = require("chrome"); michael@0: const TargetFactory = require("resource://gre/modules/devtools/Loader.jsm").devtools.TargetFactory; michael@0: michael@0: const Telemetry = require("devtools/shared/telemetry"); michael@0: const telemetry = new Telemetry(); michael@0: michael@0: const EventEmitter = require("devtools/toolkit/event-emitter"); michael@0: const eventEmitter = new EventEmitter(); michael@0: michael@0: const gcli = require("gcli/index"); michael@0: michael@0: function onPaintFlashingChanged(context) { michael@0: let tab = context.environment.chromeWindow.gBrowser.selectedTab; michael@0: eventEmitter.emit("changed", tab); michael@0: function fireChange() { michael@0: eventEmitter.emit("changed", tab); michael@0: } michael@0: let target = TargetFactory.forTab(tab); michael@0: target.off("navigate", fireChange); michael@0: target.once("navigate", fireChange); michael@0: michael@0: let window = context.environment.window; michael@0: let wUtils = window.QueryInterface(Ci.nsIInterfaceRequestor) michael@0: .getInterface(Ci.nsIDOMWindowUtils); michael@0: if (wUtils.paintFlashing) { michael@0: telemetry.toolOpened("paintflashing"); michael@0: } else { michael@0: telemetry.toolClosed("paintflashing"); michael@0: } michael@0: } michael@0: michael@0: exports.items = [ michael@0: { michael@0: name: "paintflashing", michael@0: description: gcli.lookup("paintflashingDesc") michael@0: }, michael@0: { michael@0: name: "paintflashing on", michael@0: description: gcli.lookup("paintflashingOnDesc"), michael@0: manual: gcli.lookup("paintflashingManual"), michael@0: params: [{ michael@0: group: "options", michael@0: params: [ michael@0: { michael@0: type: "boolean", michael@0: name: "chrome", michael@0: get hidden() gcli.hiddenByChromePref(), michael@0: description: gcli.lookup("paintflashingChromeDesc"), michael@0: } michael@0: ] michael@0: }], michael@0: exec: function(args, context) { michael@0: let window = args.chrome ? michael@0: context.environment.chromeWindow : michael@0: context.environment.window; michael@0: michael@0: window.QueryInterface(Ci.nsIInterfaceRequestor) michael@0: .getInterface(Ci.nsIDOMWindowUtils) michael@0: .paintFlashing = true; michael@0: onPaintFlashingChanged(context); michael@0: } michael@0: }, michael@0: { michael@0: name: "paintflashing off", michael@0: description: gcli.lookup("paintflashingOffDesc"), michael@0: manual: gcli.lookup("paintflashingManual"), michael@0: params: [{ michael@0: group: "options", michael@0: params: [ michael@0: { michael@0: type: "boolean", michael@0: name: "chrome", michael@0: get hidden() gcli.hiddenByChromePref(), michael@0: description: gcli.lookup("paintflashingChromeDesc"), michael@0: } michael@0: ] michael@0: }], michael@0: exec: function(args, context) { michael@0: let window = args.chrome ? michael@0: context.environment.chromeWindow : michael@0: context.environment.window; michael@0: michael@0: window.QueryInterface(Ci.nsIInterfaceRequestor) michael@0: .getInterface(Ci.nsIDOMWindowUtils) michael@0: .paintFlashing = false; michael@0: onPaintFlashingChanged(context); michael@0: } michael@0: }, michael@0: { michael@0: name: "paintflashing toggle", michael@0: hidden: true, michael@0: buttonId: "command-button-paintflashing", michael@0: buttonClass: "command-button command-button-invertable", michael@0: state: { michael@0: isChecked: function(aTarget) { michael@0: if (aTarget.isLocalTab) { michael@0: let window = aTarget.tab.linkedBrowser.contentWindow; michael@0: let wUtils = window.QueryInterface(Ci.nsIInterfaceRequestor). michael@0: getInterface(Ci.nsIDOMWindowUtils); michael@0: return wUtils.paintFlashing; michael@0: } else { michael@0: throw new Error("Unsupported target"); michael@0: } michael@0: }, michael@0: onChange: function(aTarget, aChangeHandler) { michael@0: eventEmitter.on("changed", aChangeHandler); michael@0: }, michael@0: offChange: function(aTarget, aChangeHandler) { michael@0: eventEmitter.off("changed", aChangeHandler); michael@0: }, michael@0: }, michael@0: tooltipText: gcli.lookup("paintflashingTooltip"), michael@0: description: gcli.lookup("paintflashingToggleDesc"), michael@0: manual: gcli.lookup("paintflashingManual"), michael@0: exec: function(args, context) { michael@0: let window = context.environment.window; michael@0: let wUtils = window.QueryInterface(Ci.nsIInterfaceRequestor). michael@0: getInterface(Ci.nsIDOMWindowUtils); michael@0: wUtils.paintFlashing = !wUtils.paintFlashing; michael@0: onPaintFlashingChanged(context); michael@0: } michael@0: } michael@0: ];