[Pkg-mozext-commits] [firebug] 08/16: Fix compatibility with Firefox
David Prévot
taffit at moszumanska.debian.org
Sun Feb 7 19:14:47 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository firebug.
commit 568d87dccfbdb310cf39b8cd29348d20253919ee
Author: Jan Odvarko <odvarko at gmail.com>
Date: Tue Jan 26 08:32:31 2016 +0100
Fix compatibility with Firefox
---
extension/bootstrap.js | 5 +-
extension/content/firebug/console/commandEditor.js | 79 +++++-------
.../firebug/console/commands/commandLineInclude.js | 22 +---
.../firebug/debugger/actors/breakpointActor.js | 5 +-
.../firebug/debugger/actors/elementActor.js | 5 +-
.../content/firebug/debugger/actors/objectActor.js | 6 +-
.../content/firebug/debugger/actors/threadActor.js | 6 +-
extension/content/firebug/debugger/commands.js | 5 +-
extension/content/firebug/lib/devtools.js | 134 ++++++++++++++++++---
.../content/firebug/remoting/debuggerClient.js | 22 ++--
extension/content/firebug/server/server.js | 7 +-
11 files changed, 189 insertions(+), 107 deletions(-)
diff --git a/extension/bootstrap.js b/extension/bootstrap.js
index 17784cb..6ee6a33 100644
--- a/extension/bootstrap.js
+++ b/extension/bootstrap.js
@@ -74,8 +74,9 @@ function startup(params, reason)
Services.obs.addObserver(windowWatcher, "chrome-document-global-created", false);
// GCLI commands
- Cu.import("resource://firebug/gcli.js");
- FirebugGCLICommands.startup();
+ // Not supported anymore
+ //Cu.import("resource://firebug/gcli.js");
+ //FirebugGCLICommands.startup();
}
function shutdown(params, reason)
diff --git a/extension/content/firebug/console/commandEditor.js b/extension/content/firebug/console/commandEditor.js
index 8ab0e18..95c3bb0 100644
--- a/extension/content/firebug/console/commandEditor.js
+++ b/extension/content/firebug/console/commandEditor.js
@@ -11,13 +11,14 @@ define([
"firebug/lib/options",
"firebug/lib/promise",
"firebug/lib/string",
+ "firebug/lib/devtools",
"firebug/chrome/module",
"firebug/chrome/menu",
"firebug/console/autoCompleter",
"firebug/console/commandLine",
"firebug/editor/sourceEditor",
],
-function(Firebug, FBTrace, Obj, Events, Dom, Locale, Css, Options, Promise, Str, Module, Menu,
+function(Firebug, FBTrace, Obj, Events, Dom, Locale, Css, Options, Promise, Str, DevTools, Module, Menu,
AutoCompleter, CommandLine, SourceEditor) {
"use strict";
@@ -352,49 +353,32 @@ var CommandEditor = Obj.extend(Module,
return;
var worker = getPrettyPrintWorker();
+ if (!worker) {
+ return;
+ }
+
var id = "firebug-" + Obj.getUniqueId();
var deferred = Promise.defer();
- var onReply = ({data}) =>
- {
- if (data.id !== id)
- return;
-
- worker.removeEventListener("message", onReply, false);
-
- if (data.error)
- {
- TraceError.sysout("commandEditor.prettyPrint; ERROR " + data.error, data);
-
- // Remove stack trace info from the error message (separated by a newline,
- // see pretty-print-worker.js)
- var message = Str.safeToString(data.error);
- var index = message.indexOf("\n");
- message = message.substr(0, index);
-
- // Log only an error message into the Console panel.
- Firebug.Console.logFormatted([message], context, "error", true);
-
- deferred.reject(data.error);
- }
- else
- {
- this.setText(data.code);
-
- deferred.resolve(data.code);
- }
- };
-
- worker.addEventListener("message", onReply, false);
-
- worker.postMessage({
- id: id,
- url: "(command-editor)",
- indent: Options.get("replaceTabs"),
- source: this.getText()
+ return worker.performTask("pretty-print", {
+ url: "(command-editor)",
+ indent: Options.get("replaceTabs"),
+ source: this.getText()
+ }).then(data => {
+ this.setText(data.code);
+ }).then(null, error => {
+ TraceError.sysout("commandEditor.prettyPrint; ERROR " + error, error);
+
+ // Remove stack trace info from the error message (separated by a newline,
+ // see pretty-print-worker.js)
+ var message = Str.safeToString(error);
+ var index = message.indexOf("\n");
+ if (index != -1)
+ message = message.substr(0, index);
+
+ // Log only an error message into the Console panel.
+ Firebug.Console.logFormatted([message], context, "error", true);
});
-
- return deferred.promise;
}
});
@@ -522,14 +506,15 @@ function getPrettyPrintWorker()
{
if (!prettyPrintWorker)
{
- prettyPrintWorker = new ChromeWorker(
- "resource://gre/modules/devtools/server/actors/pretty-print-worker.js");
+ if (!DevTools.DevToolsWorker)
+ return null;
- prettyPrintWorker.addEventListener("error", ({message, fileName, lineNo}) =>
- {
- TraceError.sysout("commandEditor.getPrettyPrintWorker; ERROR " + message +
- " " + fileName + ":" + lineNo);
- }, false);
+ prettyPrintWorker = new DevTools.DevToolsWorker(
+ DevTools.prettyPrintWorkerUrl, {
+ name: "pretty-print",
+ verbose: DevTools.DevToolsUtils.dumpn.wantLogging
+ }
+ );
}
return prettyPrintWorker;
diff --git a/extension/content/firebug/console/commands/commandLineInclude.js b/extension/content/firebug/console/commands/commandLineInclude.js
index fe54fb1..3f3683e 100644
--- a/extension/content/firebug/console/commands/commandLineInclude.js
+++ b/extension/content/firebug/console/commands/commandLineInclude.js
@@ -15,13 +15,14 @@ define([
"firebug/lib/system",
"firebug/lib/xpcom",
"firebug/lib/object",
+ "firebug/lib/devtools",
"firebug/chrome/tableRep",
"firebug/console/console",
"firebug/editor/editor",
"firebug/editor/inlineEditor",
],
function(Module, Rep, FirebugReps, Domplate, Locale, Dom, Win, Css, Str, Options, Menu, System,
- Xpcom, Obj, TableRep, Console, Editor, InlineEditor) {
+ Xpcom, Obj, DevTools, TableRep, Console, Editor, InlineEditor) {
// ********************************************************************************************* //
// Constants
@@ -37,22 +38,7 @@ var Trace = FBTrace.to("DBG_COMMANDLINE");
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
-var ScratchpadManager;
-
-try
-{
- // Module paths have changed, see also: https://bugzilla.mozilla.org/show_bug.cgi?id=912121
- var scope = System.importModule([
- "resource:///modules/devtools/client/scratchpad/scratchpad-manager.jsm",
- "resource:///modules/devtools/scratchpad-manager.jsm"
- ]);
- ScratchpadManager = scope.ScratchpadManager;
-}
-catch(ex)
-{
- // Scratchpad does not exists (when using Seamonkey ...)
-}
-
+var ScratchpadManager = DevTools.ScratchpadManager;
var storageScope = {}, StorageService;
Cu.import("resource://firebug/storageService.js", storageScope);
StorageService = storageScope.StorageService;
@@ -307,7 +293,7 @@ var CommandLineIncludeRep = domplate(TableRep,
}
];
- if (ScratchpadManager)
+ if (typeof ScratchpadManager.openScratchpad == "function")
{
items.push({
label: "commandline.label.OpenInScratchpad",
diff --git a/extension/content/firebug/debugger/actors/breakpointActor.js b/extension/content/firebug/debugger/actors/breakpointActor.js
index 07af36d..fb85084 100644
--- a/extension/content/firebug/debugger/actors/breakpointActor.js
+++ b/extension/content/firebug/debugger/actors/breakpointActor.js
@@ -3,10 +3,11 @@
define([
"firebug/lib/object",
"firebug/lib/trace",
+ "firebug/lib/devtools",
"firebug/debugger/debuggerLib",
"firebug/debugger/breakpoints/breakpointStore",
],
-function(Obj, FBTrace, DebuggerLib, BreakpointStore) {
+function(Obj, FBTrace, DevTools, DebuggerLib, BreakpointStore) {
"use strict";
@@ -21,7 +22,7 @@ function(Obj, FBTrace, DebuggerLib, BreakpointStore) {
var Cu = Components.utils;
-Cu["import"]("resource://gre/modules/devtools/dbg-server.jsm");
+var DebuggerServer = DevTools.DebuggerServer;
// xxxHonza: Firefox 32 changes the location of BreakpointActor object,
// but implements support for server side breakpoint condition evaluation
diff --git a/extension/content/firebug/debugger/actors/elementActor.js b/extension/content/firebug/debugger/actors/elementActor.js
index 4a97780..6e929f8 100644
--- a/extension/content/firebug/debugger/actors/elementActor.js
+++ b/extension/content/firebug/debugger/actors/elementActor.js
@@ -3,8 +3,9 @@
define([
"firebug/lib/object",
"firebug/lib/trace",
+ "firebug/lib/devtools",
],
-function(Obj, FBTrace) {
+function(Obj, FBTrace, DevTools) {
// ********************************************************************************************* //
// Constants
@@ -13,7 +14,7 @@ var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;
-Cu["import"]("resource://gre/modules/devtools/dbg-server.jsm");
+var DebuggerServer = DevTools.DebuggerServer;
// ********************************************************************************************* //
// Implementation
diff --git a/extension/content/firebug/debugger/actors/objectActor.js b/extension/content/firebug/debugger/actors/objectActor.js
index 13639cd..b2f5970 100644
--- a/extension/content/firebug/debugger/actors/objectActor.js
+++ b/extension/content/firebug/debugger/actors/objectActor.js
@@ -4,8 +4,9 @@ define([
"firebug/lib/object",
"firebug/lib/trace",
"firebug/lib/options",
+ "firebug/lib/devtools",
],
-function(Obj, FBTrace, Options) {
+function(Obj, FBTrace, Options, DevTools) {
// ********************************************************************************************* //
// Constants
@@ -14,8 +15,7 @@ var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;
-Cu["import"]("resource://gre/modules/devtools/dbg-server.jsm");
-
+var DebuggerServer = DevTools.DebuggerServer;
var ObjectActor = DebuggerServer.ObjectActor;
var propMax = Options.get("ObjectShortIteratorMax");
diff --git a/extension/content/firebug/debugger/actors/threadActor.js b/extension/content/firebug/debugger/actors/threadActor.js
index d2593e0..8d42389 100644
--- a/extension/content/firebug/debugger/actors/threadActor.js
+++ b/extension/content/firebug/debugger/actors/threadActor.js
@@ -4,9 +4,10 @@ define([
"firebug/lib/object",
"firebug/lib/trace",
"firebug/lib/options",
+ "firebug/lib/devtools",
"firebug/debugger/actors/elementActor",
],
-function(Obj, FBTrace, Options, ElementActor) {
+function(Obj, FBTrace, Options, DevTools, ElementActor) {
// ********************************************************************************************* //
// Constants
@@ -15,8 +16,7 @@ var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;
-Cu["import"]("resource://gre/modules/devtools/dbg-server.jsm");
-
+var DebuggerServer = DevTools.DebuggerServer;
var ThreadActor = DebuggerServer.ThreadActor;
// ********************************************************************************************* //
diff --git a/extension/content/firebug/debugger/commands.js b/extension/content/firebug/debugger/commands.js
index d0b1358..00258ba 100644
--- a/extension/content/firebug/debugger/commands.js
+++ b/extension/content/firebug/debugger/commands.js
@@ -7,12 +7,13 @@ define([
"firebug/lib/trace",
"firebug/lib/object",
"firebug/lib/options",
+ "firebug/lib/devtools",
"firebug/chrome/module",
"firebug/debugger/rdp",
"firebug/debugger/debuggerLib",
"firebug/debugger/breakpoints/breakpointStore"
],
-function(Firebug, FBTrace, Obj, Options, Module, RDP, DebuggerLib, BreakpointStore) {
+function(Firebug, FBTrace, Obj, Options, DevTools, Module, RDP, DebuggerLib, BreakpointStore) {
"use strict";
@@ -23,7 +24,7 @@ var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;
-Cu["import"]("resource://gre/modules/devtools/dbg-server.jsm");
+var DebuggerServer = DevTools.DebuggerServer;
var Trace = FBTrace.to("DBG_DEBUGGER_COMMANDS");
var TraceError = FBTrace.toError();
diff --git a/extension/content/firebug/lib/devtools.js b/extension/content/firebug/lib/devtools.js
index d4aab0f..3c0b5aa 100644
--- a/extension/content/firebug/lib/devtools.js
+++ b/extension/content/firebug/lib/devtools.js
@@ -8,24 +8,34 @@ function() {
"use strict";
var Cu = Components.utils;
+var Cc = Components.classes;
+var Ci = Components.interfaces;
+
+var appInfo = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo);
+var versionComparator = Cc["@mozilla.org/xpcom/version-comparator;1"].getService(Ci.nsIVersionComparator);
var exports = {};
-// Support for new devtools modules path.
-// See also:
-// * https://wiki.mozilla.org/DevTools/Hacking
-// * https://github.com/jryans/devtools-migrate/blob/master/README.md
-// * https://developer.mozilla.org/en-US/docs/Tools/Contributing
-// * https://bugzilla.mozilla.org/show_bug.cgi?id=912121
-try {
- exports.devtools = Cu.import("resource://gre/modules/devtools/shared/Loader.jsm", {}).devtools;
- exports.DevToolsUtils = exports.devtools["require"]("devtools/shared/DevToolsUtils");
-} catch(e) {
- exports.devtools = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools;
- exports.DevToolsUtils = exports.devtools["require"]("devtools/toolkit/DevToolsUtils");
+/**
+ * Allows importing a JS module (Firefox platform) and specify alternative locations
+ * to keep backward compatibility in case when the module location changes.
+ * It helps Firebug to support multiple Firefox versions.
+ *
+ * @param {Array} locations List of URLs to try when importing the module.
+ * @returns Scope of the imported module or an empty scope if module wasn't successfully loaded.
+ */
+function safeImport(...args) {
+ for (var i=0; i<args.length; i++) {
+ try {
+ return Cu["import"](args[i], {});
+ }
+ catch (err) {
+ }
+ }
+ return {};
}
-exports.require = exports.devtools["require"];
+exports.safeImport = safeImport;
/**
* Allows requiring a devtools module and specify alternative locations
@@ -36,7 +46,7 @@ exports.require = exports.devtools["require"];
* @param {Array} locations List of URLs to try when importing the module.
* @returns Scope of the imported module or an empty scope if module wasn't successfully loaded.
*/
-exports.safeRequire = function(devtools, ...args) {
+function safeRequire(devtools, ...args) {
for (var i=0; i<args.length; i++) {
try {
return devtools["require"](args[i]);
@@ -45,7 +55,101 @@ exports.safeRequire = function(devtools, ...args) {
}
}
return {};
-};
+}
+
+exports.safeRequire = safeRequire;
+
+/**
+ * Allows importing or requiring a devtools module and specify alternative
+ * locations to keep backward compatibility when the module location changes.
+ */
+function safeGet(devtools, ...args) {
+ for (var i=0; i<args.length; i++) {
+ var url = args[i];
+ if (url.startsWith("resource://")) {
+ try {
+ return Cu["import"](url, {});
+ }
+ catch (err) {
+ }
+ } else if (url.startsWith("devtools/")) {
+ try {
+ return devtools["require"](url);
+ }
+ catch (err) {
+ }
+ }
+ }
+ return {};
+}
+
+exports.safeGet = safeGet;
+
+// Support for new devtools modules path.
+// See also:
+// * https://wiki.mozilla.org/DevTools/Hacking
+// * https://github.com/jryans/devtools-migrate/blob/master/README.md
+// * https://developer.mozilla.org/en-US/docs/Tools/Contributing
+// * https://bugzilla.mozilla.org/show_bug.cgi?id=912121
+// * https://bugzilla.mozilla.org/show_bug.cgi?id=1203159
+
+const devtools = exports.devtools = safeImport(
+ "resource://devtools/shared/Loader.jsm",
+ "resource://gre/modules/devtools/shared/Loader.jsm",
+ "resource://gre/modules/devtools/Loader.jsm"
+).devtools;
+
+exports.DevToolsUtils = safeRequire(devtools,
+ "devtools/shared/DevToolsUtils",
+ "devtools/toolkit/DevToolsUtils"
+);
+
+exports.makeInfallible = exports.DevToolsUtils.makeInfallible;
+
+exports.gDevTools = safeImport(
+ "resource:///devtools/client/framework/gDevTools.jsm",
+ "resource:///modules/devtools/client/framework/gDevTools.jsm",
+ "resource:///modules/devtools/gDevTools.jsm"
+).gDevTools;
+
+exports.EventEmitter = safeRequire(devtools,
+ "devtools/shared/event-emitter",
+ "devtools/toolkit/event-emitter"
+);
+
+exports.ToolSidebar = safeRequire(devtools,
+ "devtools/client/framework/sidebar",
+ "devtools/framework/sidebar"
+).ToolSidebar;
+
+exports.DebuggerServer = safeGet(devtools,
+ "devtools/server/main",
+ "resource://gre/modules/devtools/dbg-server.jsm"
+).DebuggerServer;
+
+exports.DebuggerClient = safeGet(devtools,
+ "devtools/shared/client/main",
+ "resource://gre/modules/devtools/dbg-client.jsm"
+).DebuggerClient;
+
+exports.DevToolsWorker = safeGet(devtools,
+ "devtools/shared/worker/worker",
+ "devtools/toolkit/shared/worker"
+).DevToolsWorker;
+
+exports.ScratchpadManager = safeImport(
+ "resource://devtools/client/scratchpad/scratchpad-manager.jsm",
+ "resource:///modules/devtools/client/scratchpad/scratchpad-manager.jsm",
+ "resource:///modules/devtools/scratchpad-manager.jsm"
+).ScratchpadManager;
+
+exports.require = exports.devtools["require"];
+
+// Pretty print worker
+var fx43OrEarlier = (versionComparator.compare(appInfo.version, "44a1") < 0);
+exports.prettyPrintWorkerUrl = fx43OrEarlier ?
+ "resource://gre/modules/devtools/server/actors/pretty-print-worker.js" :
+ "resource://devtools/server/actors/pretty-print-worker.js";
return exports;
diff --git a/extension/content/firebug/remoting/debuggerClient.js b/extension/content/firebug/remoting/debuggerClient.js
index 3f54fdb..9a8209c 100644
--- a/extension/content/firebug/remoting/debuggerClient.js
+++ b/extension/content/firebug/remoting/debuggerClient.js
@@ -6,12 +6,13 @@ define([
"firebug/lib/object",
"firebug/lib/options",
"firebug/lib/events",
+ "firebug/lib/devtools",
"firebug/chrome/tabWatcher",
"firebug/chrome/firefox",
"firebug/chrome/window",
"firebug/remoting/tabClient",
],
-function(Firebug, FBTrace, Obj, Options, Events, TabWatcher, Firefox, Win, TabClient) {
+function(Firebug, FBTrace, Obj, Options, Events, DevTools, TabWatcher, Firefox, Win, TabClient) {
"use strict";
@@ -24,11 +25,12 @@ var Trace = FBTrace.to("DBG_DEBUGGERCLIENT");
var TraceConn = FBTrace.to("DBG_CONNECTION");
var TraceError = FBTrace.toError();
-var dbgClientScope = {};
-var dbgServerScope = {};
-
-Cu["import"]("resource://gre/modules/devtools/dbg-client.jsm", dbgClientScope);
-Cu["import"]("resource://gre/modules/devtools/dbg-server.jsm", dbgServerScope);
+var dbgClientScope = {
+ DebuggerClient: DevTools.DebuggerClient
+};
+var dbgServerScope = {
+ DebuggerServer: DevTools.DebuggerServer
+};
// ********************************************************************************************* //
// Module Implementation
@@ -109,10 +111,10 @@ var DebuggerClient = Obj.extend(Firebug.Module,
{
// The debugger server might be already initialized either by Firebug
// in another browser window or by built-in devtools.
- if (!DebuggerServer.initialized)
+ if (!dbgServerScope.DebuggerServer.initialized)
{
- DebuggerServer.init(function () { return true; });
- DebuggerServer.addBrowserActors();
+ dbgServerScope.DebuggerServer.init(function () { return true; });
+ dbgServerScope.DebuggerServer.addBrowserActors();
}
}
catch (e)
@@ -123,7 +125,7 @@ var DebuggerClient = Obj.extend(Firebug.Module,
this.transport = (this.isRemoteDebugger) ?
debuggerSocketConnect(Options.get("remoteHost"), Options.get("remotePort")) :
- DebuggerServer.connectPipe();
+ dbgServerScope.DebuggerServer.connectPipe();
// Load Firebug actors. If Firebug is running server side these actors
// should also be loaded.
diff --git a/extension/content/firebug/server/server.js b/extension/content/firebug/server/server.js
index 5e8504a..736e3ad 100644
--- a/extension/content/firebug/server/server.js
+++ b/extension/content/firebug/server/server.js
@@ -2,8 +2,9 @@
define([
"firebug/lib/trace",
+ "firebug/lib/devtools",
],
-function(FBTrace) {
+function(FBTrace, DevTools) {
// xxxHonza: FBTrace isn't available when loading from within bootstrap.js
// The default FBTrace implementation should buffer all logs that are fired
@@ -16,6 +17,8 @@ var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;
+var DebuggerServer = DevTools.DebuggerServer;
+
// ********************************************************************************************* //
// Module
@@ -28,8 +31,6 @@ var Server =
{
try
{
- Cu.import("resource:///modules/devtools/dbg-server.jsm");
-
DebuggerServer.init(function() { return true; });
// Add built-in actors (like e.g. debugger actors)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/firebug.git
More information about the Pkg-mozext-commits
mailing list