browser/devtools/framework/toolbox-process-window.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 "use strict";
michael@0 5
michael@0 6 const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
michael@0 7
michael@0 8 let { gDevTools } = Cu.import("resource:///modules/devtools/gDevTools.jsm", {});
michael@0 9 let { devtools } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
michael@0 10 let { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
michael@0 11 let { debuggerSocketConnect, DebuggerClient } =
michael@0 12 Cu.import("resource://gre/modules/devtools/dbg-client.jsm", {});
michael@0 13 let { ViewHelpers } =
michael@0 14 Cu.import("resource:///modules/devtools/ViewHelpers.jsm", {});
michael@0 15
michael@0 16 /**
michael@0 17 * Shortcuts for accessing various debugger preferences.
michael@0 18 */
michael@0 19 let Prefs = new ViewHelpers.Prefs("devtools.debugger", {
michael@0 20 chromeDebuggingHost: ["Char", "chrome-debugging-host"],
michael@0 21 chromeDebuggingPort: ["Int", "chrome-debugging-port"]
michael@0 22 });
michael@0 23
michael@0 24 let gToolbox, gClient;
michael@0 25
michael@0 26 function connect() {
michael@0 27 window.removeEventListener("load", connect);
michael@0 28 // Initiate the connection
michael@0 29 let transport = debuggerSocketConnect(
michael@0 30 Prefs.chromeDebuggingHost,
michael@0 31 Prefs.chromeDebuggingPort
michael@0 32 );
michael@0 33 gClient = new DebuggerClient(transport);
michael@0 34 gClient.connect(() => {
michael@0 35 let addonID = getParameterByName("addonID");
michael@0 36
michael@0 37 if (addonID) {
michael@0 38 gClient.listAddons(({addons}) => {
michael@0 39 let addonActor = addons.filter(addon => addon.id === addonID).pop();
michael@0 40 openToolbox({ addonActor: addonActor.actor, title: addonActor.name });
michael@0 41 });
michael@0 42 } else {
michael@0 43 gClient.listTabs(openToolbox);
michael@0 44 }
michael@0 45 });
michael@0 46 }
michael@0 47
michael@0 48 window.addEventListener("load", connect);
michael@0 49
michael@0 50 function openToolbox(form) {
michael@0 51 let options = {
michael@0 52 form: form,
michael@0 53 client: gClient,
michael@0 54 chrome: true
michael@0 55 };
michael@0 56 devtools.TargetFactory.forRemoteTab(options).then(target => {
michael@0 57 let frame = document.getElementById("toolbox-iframe");
michael@0 58 let options = { customIframe: frame };
michael@0 59 gDevTools.showToolbox(target,
michael@0 60 "jsdebugger",
michael@0 61 devtools.Toolbox.HostType.CUSTOM,
michael@0 62 options)
michael@0 63 .then(onNewToolbox);
michael@0 64 });
michael@0 65 }
michael@0 66
michael@0 67 function onNewToolbox(toolbox) {
michael@0 68 gToolbox = toolbox;
michael@0 69 bindToolboxHandlers();
michael@0 70 raise();
michael@0 71 }
michael@0 72
michael@0 73 function bindToolboxHandlers() {
michael@0 74 gToolbox.once("destroyed", quitApp);
michael@0 75 window.addEventListener("unload", onUnload);
michael@0 76 }
michael@0 77
michael@0 78 function onUnload() {
michael@0 79 window.removeEventListener("unload", onUnload);
michael@0 80 window.removeEventListener("message", onMessage);
michael@0 81 gToolbox.destroy();
michael@0 82 }
michael@0 83
michael@0 84 function onMessage(event) {
michael@0 85 try {
michael@0 86 let json = JSON.parse(event.data);
michael@0 87 switch (json.name) {
michael@0 88 case "toolbox-raise":
michael@0 89 raise();
michael@0 90 break;
michael@0 91 case "toolbox-title":
michael@0 92 setTitle(json.data.value);
michael@0 93 break;
michael@0 94 }
michael@0 95 } catch(e) { Cu.reportError(e); }
michael@0 96 }
michael@0 97
michael@0 98 window.addEventListener("message", onMessage);
michael@0 99
michael@0 100 function raise() {
michael@0 101 window.focus();
michael@0 102 }
michael@0 103
michael@0 104 function setTitle(title) {
michael@0 105 document.title = title;
michael@0 106 }
michael@0 107
michael@0 108 function quitApp() {
michael@0 109 let quit = Cc["@mozilla.org/supports-PRBool;1"]
michael@0 110 .createInstance(Ci.nsISupportsPRBool);
michael@0 111 Services.obs.notifyObservers(quit, "quit-application-requested", null);
michael@0 112
michael@0 113 let shouldProceed = !quit.data;
michael@0 114 if (shouldProceed) {
michael@0 115 Services.startup.quit(Ci.nsIAppStartup.eForceQuit);
michael@0 116 }
michael@0 117 }
michael@0 118
michael@0 119 function getParameterByName (name) {
michael@0 120 let name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
michael@0 121 let regex = new RegExp("[\\?&]" + name + "=([^&#]*)");
michael@0 122 let results = regex.exec(window.location.search);
michael@0 123 return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
michael@0 124 }

mercurial