Bug 1180996 - Extract remote debugger to separate file. r=margaret

This commit is contained in:
J. Ryan Stinnett 2015-07-02 16:54:47 -05:00
Родитель a82a303f06
Коммит 447b851dab
3 изменённых файлов: 130 добавлений и 123 удалений

Просмотреть файл

@ -0,0 +1,128 @@
// -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
XPCOMUtils.defineLazyModuleGetter(this, "DebuggerServer",
"resource://gre/modules/devtools/dbg-server.jsm");
var RemoteDebugger = {
init() {
Services.prefs.addObserver("devtools.debugger.", this, false);
if (this._isEnabled())
this._start();
},
observe(aSubject, aTopic, aData) {
if (aTopic != "nsPref:changed")
return;
switch (aData) {
case "devtools.debugger.remote-enabled":
if (this._isEnabled())
this._start();
else
this._stop();
break;
case "devtools.debugger.remote-port":
case "devtools.debugger.unix-domain-socket":
if (this._isEnabled())
this._restart();
break;
}
},
_getPort() {
return Services.prefs.getIntPref("devtools.debugger.remote-port");
},
_getPath() {
return Services.prefs.getCharPref("devtools.debugger.unix-domain-socket");
},
_isEnabled() {
return Services.prefs.getBoolPref("devtools.debugger.remote-enabled");
},
/**
* Prompt the user to accept or decline the incoming connection.
* This is passed to DebuggerService.init as a callback.
*
* @return An AuthenticationResult value.
* A promise that will be resolved to the above is also allowed.
*/
_showConnectionPrompt() {
let title = Strings.browser.GetStringFromName("remoteIncomingPromptTitle");
let msg = Strings.browser.GetStringFromName("remoteIncomingPromptMessage");
let disable = Strings.browser.GetStringFromName("remoteIncomingPromptDisable");
let cancel = Strings.browser.GetStringFromName("remoteIncomingPromptCancel");
let agree = Strings.browser.GetStringFromName("remoteIncomingPromptAccept");
// Make prompt. Note: button order is in reverse.
let prompt = new Prompt({
window: null,
hint: "remotedebug",
title: title,
message: msg,
buttons: [ agree, cancel, disable ],
priority: 1
});
// The debugger server expects a synchronous response, so spin on result since Prompt is async.
let result = null;
prompt.show(function(data) {
result = data.button;
});
// Spin this thread while we wait for a result.
let thread = Services.tm.currentThread;
while (result == null)
thread.processNextEvent(true);
if (result === 0)
return DebuggerServer.AuthenticationResult.ALLOW;
if (result === 2) {
return DebuggerServer.AuthenticationResult.DISABLE_ALL;
}
return DebuggerServer.AuthenticationResult.DENY;
},
_restart() {
this._stop();
this._start();
},
_start() {
try {
if (!DebuggerServer.initialized) {
DebuggerServer.init();
DebuggerServer.addBrowserActors();
DebuggerServer.registerModule("resource://gre/modules/dbg-browser-actors.js");
DebuggerServer.allowChromeProcess = true;
}
let pathOrPort = this._getPath();
if (!pathOrPort)
pathOrPort = this._getPort();
let AuthenticatorType = DebuggerServer.Authenticators.get("PROMPT");
let authenticator = new AuthenticatorType.Server();
authenticator.allowConnection = this._showConnectionPrompt.bind(this);
let listener = DebuggerServer.createListener();
listener.portOrPath = pathOrPort;
listener.authenticator = authenticator;
listener.open();
dump("Remote debugger listening at path " + pathOrPort);
} catch(e) {
dump("Remote debugger didn't start: " + e);
}
},
_stop() {
DebuggerServer.closeAllListeners();
dump("Remote debugger stopped");
}
};

Просмотреть файл

@ -44,9 +44,6 @@ XPCOMUtils.defineLazyModuleGetter(this, "Downloads",
XPCOMUtils.defineLazyModuleGetter(this, "Messaging", XPCOMUtils.defineLazyModuleGetter(this, "Messaging",
"resource://gre/modules/Messaging.jsm"); "resource://gre/modules/Messaging.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "DebuggerServer",
"resource://gre/modules/devtools/dbg-server.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "UserAgentOverrides", XPCOMUtils.defineLazyModuleGetter(this, "UserAgentOverrides",
"resource://gre/modules/UserAgentOverrides.jsm"); "resource://gre/modules/UserAgentOverrides.jsm");
@ -130,6 +127,7 @@ let lazilyLoadedBrowserScripts = [
["Linkifier", "chrome://browser/content/Linkify.js"], ["Linkifier", "chrome://browser/content/Linkify.js"],
["ZoomHelper", "chrome://browser/content/ZoomHelper.js"], ["ZoomHelper", "chrome://browser/content/ZoomHelper.js"],
["CastingApps", "chrome://browser/content/CastingApps.js"], ["CastingApps", "chrome://browser/content/CastingApps.js"],
["RemoteDebugger", "chrome://browser/content/RemoteDebugger.js"],
]; ];
if (AppConstants.NIGHTLY_BUILD) { if (AppConstants.NIGHTLY_BUILD) {
lazilyLoadedBrowserScripts.push( lazilyLoadedBrowserScripts.push(
@ -7544,126 +7542,6 @@ var ActivityObserver = {
} }
}; };
var RemoteDebugger = {
init: function rd_init() {
Services.prefs.addObserver("devtools.debugger.", this, false);
if (this._isEnabled())
this._start();
},
observe: function rd_observe(aSubject, aTopic, aData) {
if (aTopic != "nsPref:changed")
return;
switch (aData) {
case "devtools.debugger.remote-enabled":
if (this._isEnabled())
this._start();
else
this._stop();
break;
case "devtools.debugger.remote-port":
case "devtools.debugger.unix-domain-socket":
if (this._isEnabled())
this._restart();
break;
}
},
_getPort: function _rd_getPort() {
return Services.prefs.getIntPref("devtools.debugger.remote-port");
},
_getPath: function _rd_getPath() {
return Services.prefs.getCharPref("devtools.debugger.unix-domain-socket");
},
_isEnabled: function rd_isEnabled() {
return Services.prefs.getBoolPref("devtools.debugger.remote-enabled");
},
/**
* Prompt the user to accept or decline the incoming connection.
* This is passed to DebuggerService.init as a callback.
*
* @return An AuthenticationResult value.
* A promise that will be resolved to the above is also allowed.
*/
_showConnectionPrompt: function rd_showConnectionPrompt() {
let title = Strings.browser.GetStringFromName("remoteIncomingPromptTitle");
let msg = Strings.browser.GetStringFromName("remoteIncomingPromptMessage");
let disable = Strings.browser.GetStringFromName("remoteIncomingPromptDisable");
let cancel = Strings.browser.GetStringFromName("remoteIncomingPromptCancel");
let agree = Strings.browser.GetStringFromName("remoteIncomingPromptAccept");
// Make prompt. Note: button order is in reverse.
let prompt = new Prompt({
window: null,
hint: "remotedebug",
title: title,
message: msg,
buttons: [ agree, cancel, disable ],
priority: 1
});
// The debugger server expects a synchronous response, so spin on result since Prompt is async.
let result = null;
prompt.show(function(data) {
result = data.button;
});
// Spin this thread while we wait for a result.
let thread = Services.tm.currentThread;
while (result == null)
thread.processNextEvent(true);
if (result === 0)
return DebuggerServer.AuthenticationResult.ALLOW;
if (result === 2) {
return DebuggerServer.AuthenticationResult.DISABLE_ALL;
}
return DebuggerServer.AuthenticationResult.DENY;
},
_restart: function rd_restart() {
this._stop();
this._start();
},
_start: function rd_start() {
try {
if (!DebuggerServer.initialized) {
DebuggerServer.init();
DebuggerServer.addBrowserActors();
DebuggerServer.registerModule("resource://gre/modules/dbg-browser-actors.js");
DebuggerServer.allowChromeProcess = true;
}
let pathOrPort = this._getPath();
if (!pathOrPort)
pathOrPort = this._getPort();
let AuthenticatorType = DebuggerServer.Authenticators.get("PROMPT");
let authenticator = new AuthenticatorType.Server();
authenticator.allowConnection = this._showConnectionPrompt.bind(this);
let listener = DebuggerServer.createListener();
listener.portOrPath = pathOrPort;
listener.authenticator = authenticator;
listener.open();
dump("Remote debugger listening at path " + pathOrPort);
} catch(e) {
dump("Remote debugger didn't start: " + e);
}
},
_stop: function rd_start() {
DebuggerServer.closeAllListeners();
dump("Remote debugger stopped");
}
};
var Telemetry = { var Telemetry = {
addData: function addData(aHistogramId, aValue) { addData: function addData(aHistogramId, aValue) {
let histogram = Services.telemetry.getHistogramById(aHistogramId); let histogram = Services.telemetry.getHistogramById(aHistogramId);

Просмотреть файл

@ -50,6 +50,7 @@ chrome.jar:
content/Linkify.js (content/Linkify.js) content/Linkify.js (content/Linkify.js)
content/ZoomHelper.js (content/ZoomHelper.js) content/ZoomHelper.js (content/ZoomHelper.js)
content/CastingApps.js (content/CastingApps.js) content/CastingApps.js (content/CastingApps.js)
content/RemoteDebugger.js (content/RemoteDebugger.js)
#ifdef MOZ_SERVICES_HEALTHREPORT #ifdef MOZ_SERVICES_HEALTHREPORT
content/aboutHealthReport.xhtml (content/aboutHealthReport.xhtml) content/aboutHealthReport.xhtml (content/aboutHealthReport.xhtml)
content/aboutHealthReport.js (content/aboutHealthReport.js) content/aboutHealthReport.js (content/aboutHealthReport.js)