зеркало из https://github.com/mozilla/gecko-dev.git
Bug 942756 - Unify debugger server startup: fennec code. r=mfinkle
This commit is contained in:
Родитель
39be12a218
Коммит
3bf4dd8105
|
@ -31,9 +31,6 @@ XPCOMUtils.defineLazyModuleGetter(this, "PluralForm",
|
|||
XPCOMUtils.defineLazyModuleGetter(this, "sendMessageToJava",
|
||||
"resource://gre/modules/Messaging.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "DebuggerServer",
|
||||
"resource://gre/modules/devtools/dbg-server.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "UserAgentOverrides",
|
||||
"resource://gre/modules/UserAgentOverrides.jsm");
|
||||
|
||||
|
@ -375,7 +372,6 @@ var BrowserApp = {
|
|||
#else
|
||||
WebappsUI.init();
|
||||
#endif
|
||||
RemoteDebugger.init();
|
||||
Reader.init();
|
||||
UserAgentOverrides.init();
|
||||
DesktopUserAgent.init();
|
||||
|
@ -754,7 +750,6 @@ var BrowserApp = {
|
|||
#ifndef MOZ_ANDROID_SYNTHAPKS
|
||||
WebappsUI.uninit();
|
||||
#endif
|
||||
RemoteDebugger.uninit();
|
||||
Reader.uninit();
|
||||
UserAgentOverrides.uninit();
|
||||
DesktopUserAgent.uninit();
|
||||
|
@ -7321,117 +7316,6 @@ var WebappsUI = {
|
|||
}
|
||||
#endif
|
||||
|
||||
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":
|
||||
if (this._isEnabled())
|
||||
this._restart();
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
uninit: function rd_uninit() {
|
||||
Services.prefs.removeObserver("devtools.debugger.", this);
|
||||
this._stop();
|
||||
},
|
||||
|
||||
_getPort: function _rd_getPort() {
|
||||
return Services.prefs.getIntPref("devtools.debugger.remote-port");
|
||||
},
|
||||
|
||||
_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 true if the connection should be permitted, false otherwise
|
||||
*/
|
||||
_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 true;
|
||||
if (result === 2) {
|
||||
Services.prefs.setBoolPref("devtools.debugger.remote-enabled", false);
|
||||
this._stop();
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
_restart: function rd_restart() {
|
||||
this._stop();
|
||||
this._start();
|
||||
},
|
||||
|
||||
_start: function rd_start() {
|
||||
try {
|
||||
if (!DebuggerServer.initialized) {
|
||||
DebuggerServer.init(this._showConnectionPrompt.bind(this));
|
||||
DebuggerServer.addBrowserActors();
|
||||
DebuggerServer.addActors("chrome://browser/content/dbg-browser-actors.js");
|
||||
}
|
||||
|
||||
let port = this._getPort();
|
||||
DebuggerServer.openListener(port);
|
||||
dump("Remote debugger listening on port " + port);
|
||||
} catch(e) {
|
||||
dump("Remote debugger didn't start: " + e);
|
||||
}
|
||||
},
|
||||
|
||||
_stop: function rd_start() {
|
||||
DebuggerServer.closeListener();
|
||||
dump("Remote debugger stopped");
|
||||
}
|
||||
};
|
||||
|
||||
var Telemetry = {
|
||||
addData: function addData(aHistogramId, aValue) {
|
||||
let histogram = Services.telemetry.getHistogramById(aHistogramId);
|
||||
|
|
|
@ -0,0 +1,145 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* 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/. */
|
||||
|
||||
const { interfaces: Ci, utils: Cu } = Components;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(this,
|
||||
"Alerts",
|
||||
"@mozilla.org/alerts-service;1", "nsIAlertsService");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this,
|
||||
"Prompt",
|
||||
"resource://gre/modules/Prompt.jsm");
|
||||
|
||||
let Strings = {};
|
||||
XPCOMUtils.defineLazyGetter(Strings, "debugger",
|
||||
() => Services.strings.createBundle("chrome://global/locale/devtools/debugger.properties"));
|
||||
XPCOMUtils.defineLazyGetter(Strings, "browser",
|
||||
() => Services.strings.createBundle("chrome://browser/locale/browser.properties"));
|
||||
|
||||
function DebuggerServerController() {
|
||||
}
|
||||
|
||||
DebuggerServerController.prototype = {
|
||||
classID: Components.ID("{f6e8e269-ae4a-4c4a-bf80-fb4164fb072c}"),
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIDebuggerServerController, Ci.nsIObserver]),
|
||||
|
||||
init: function(debuggerServer) {
|
||||
this.debugger = debuggerServer;
|
||||
Services.obs.addObserver(this, "debugger-server-started", false);
|
||||
Services.obs.addObserver(this, "debugger-server-stopped", false);
|
||||
Services.obs.addObserver(this, "xpcom-shutdown", false);
|
||||
},
|
||||
|
||||
uninit: function() {
|
||||
this.debugger = null;
|
||||
Services.obs.removeObserver(this, "debugger-server-started");
|
||||
Services.obs.removeObserver(this, "debugger-server-stopped");
|
||||
Services.obs.removeObserver(this, "xpcom-shutdown");
|
||||
},
|
||||
|
||||
start: function(pathOrPort) {
|
||||
if (!this.debugger.initialized) {
|
||||
this.debugger.init(this.prompt.bind(this));
|
||||
this.debugger.addBrowserActors();
|
||||
this.debugger.addActors("chrome://browser/content/dbg-browser-actors.js");
|
||||
}
|
||||
|
||||
if (!pathOrPort) {
|
||||
// If the "devtools.debugger.unix-domain-socket" pref is set, we use a unix socket.
|
||||
// If not, we use a regular TCP socket.
|
||||
try {
|
||||
pathOrPort = Services.prefs.getCharPref("devtools.debugger.unix-domain-socket");
|
||||
} catch (e) {
|
||||
pathOrPort = Services.prefs.getIntPref("devtools.debugger.remote-port");
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
this.debugger.openListener(pathOrPort);
|
||||
} catch (e) {
|
||||
dump("Unable to start debugger server (" + pathOrPort + "): " + e + "\n");
|
||||
}
|
||||
},
|
||||
|
||||
stop: function() {
|
||||
this.debugger.destroy();
|
||||
},
|
||||
|
||||
prompt: function() {
|
||||
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 true;
|
||||
if (result === 2) {
|
||||
Services.prefs.setBoolPref("devtools.debugger.remote-enabled", false);
|
||||
this.debugger.destroy();
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
// nsIObserver
|
||||
|
||||
observe: function (subject, topic, data) {
|
||||
if (topic == "xpcom-shutdown")
|
||||
this.uninit();
|
||||
if (topic == "debugger-server-started")
|
||||
this._onDebuggerStarted(data);
|
||||
if (topic == "debugger-server-stopped")
|
||||
this._onDebuggerStopped();
|
||||
},
|
||||
|
||||
_onDebuggerStarted: function(portOrPath) {
|
||||
if (!Services.prefs.getBoolPref("devtools.debugger.show-server-notifications"))
|
||||
return;
|
||||
let title = l10n.GetStringFromName("debuggerStartedAlert.title");
|
||||
let port = Number(portOrPath);
|
||||
let detail;
|
||||
if (port) {
|
||||
detail = l10n.formatStringFromName("debuggerStartedAlert.detailPort", [portOrPath], 1);
|
||||
} else {
|
||||
detail = l10n.formatStringFromName("debuggerStartedAlert.detailPath", [portOrPath], 1);
|
||||
}
|
||||
Alerts.showAlertNotification(null, title, detail, false, "", function(){});
|
||||
},
|
||||
|
||||
_onDebuggerStopped: function() {
|
||||
if (!Services.prefs.getBoolPref("devtools.debugger.show-server-notifications"))
|
||||
return;
|
||||
let title = l10n.GetStringFromName("debuggerStopped.title");
|
||||
Alerts.showAlertNotification(null, title, null, false, "", function(){});
|
||||
},
|
||||
};
|
||||
|
||||
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([DebuggerServerController]);
|
|
@ -120,3 +120,7 @@ category update-timer WebappsUpdateTimer @mozilla.org/webapps-update-timer;1,get
|
|||
# ColorPicker.js
|
||||
component {430b987f-bb9f-46a3-99a5-241749220b29} ColorPicker.js
|
||||
contract @mozilla.org/colorpicker;1 {430b987f-bb9f-46a3-99a5-241749220b29}
|
||||
|
||||
# DebuggerServerController.js
|
||||
component {f6e8e269-ae4a-4c4a-bf80-fb4164fb072c} DebuggerServerController.js
|
||||
contract @mozilla.org/devtools/DebuggerServerController;1 {f6e8e269-ae4a-4c4a-bf80-fb4164fb072c}
|
||||
|
|
|
@ -420,6 +420,11 @@
|
|||
@BINPATH@/components/captivedetect.js
|
||||
#endif
|
||||
|
||||
; DevTools
|
||||
@BINPATH@/components/DevToolsComponents.manifest
|
||||
@BINPATH@/components/DevToolsAppStartup.js
|
||||
@BINPATH@/components/DebuggerServerController.js
|
||||
|
||||
#ifdef MOZ_WEBSPEECH
|
||||
@BINPATH@/components/dom_webspeechsynth.xpt
|
||||
#endif
|
||||
|
|
Загрузка…
Ссылка в новой задаче