mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 867485: Move the devtools loader into toolkit/ r=jwalker
This commit is contained in:
parent
41da137708
commit
4410b7de65
@ -437,7 +437,7 @@ nsContextMenu.prototype = {
|
||||
},
|
||||
|
||||
inspectNode: function CM_inspectNode() {
|
||||
let {devtools} = Cu.import("resource:///modules/devtools/gDevTools.jsm", {});
|
||||
let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
|
||||
let gBrowser = this.browser.ownerDocument.defaultView.gBrowser;
|
||||
let tt = devtools.TargetFactory.forTab(gBrowser.selectedTab);
|
||||
return gDevTools.showToolbox(tt, "inspector").then(function(toolbox) {
|
||||
|
@ -20,7 +20,7 @@ Cu.import("resource:///modules/devtools/shared/event-emitter.js");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "gDevTools",
|
||||
"resource:///modules/devtools/gDevTools.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "devtools",
|
||||
"resource:///modules/devtools/gDevTools.jsm");
|
||||
"resource://gre/modules/devtools/Loader.jsm");
|
||||
|
||||
/* CmdAddon ---------------------------------------------------------------- */
|
||||
|
||||
|
@ -24,7 +24,7 @@ let require = (Cu.import("resource://gre/modules/devtools/Require.jsm", {})).req
|
||||
Components.utils.import("resource:///modules/devtools/gcli.jsm", {});
|
||||
|
||||
let console = (Cu.import("resource://gre/modules/devtools/Console.jsm", {})).console;
|
||||
let devtools = (Cu.import("resource:///modules/devtools/gDevTools.jsm", {})).devtools;
|
||||
let devtools = (Cu.import("resource://gre/modules/devtools/Loader.jsm", {})).devtools;
|
||||
let TargetFactory = devtools.TargetFactory;
|
||||
|
||||
let Promise = (Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js", {})).Promise;
|
||||
|
@ -12,6 +12,7 @@ Cu.import("resource://gre/modules/devtools/dbg-server.jsm", tempScope);
|
||||
Cu.import("resource://gre/modules/devtools/dbg-client.jsm", tempScope);
|
||||
Cu.import("resource:///modules/source-editor.jsm", tempScope);
|
||||
Cu.import("resource:///modules/devtools/gDevTools.jsm", tempScope);
|
||||
Cu.import("resource://gre/modules/devtools/Loader.jsm", tempScope);
|
||||
let Services = tempScope.Services;
|
||||
let SourceEditor = tempScope.SourceEditor;
|
||||
let DebuggerServer = tempScope.DebuggerServer;
|
||||
|
@ -2,7 +2,8 @@
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
let tempScope = {};
|
||||
let {devtools, gDevTools} = Cu.import("resource:///modules/devtools/gDevTools.jsm", {});
|
||||
let {gDevTools} = Cu.import("resource:///modules/devtools/gDevTools.jsm", {});
|
||||
let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
|
||||
let TargetFactory = devtools.TargetFactory;
|
||||
|
||||
let DOMUtils = Cc["@mozilla.org/inspector/dom-utils;1"].getService(Ci.inIDOMUtils);
|
||||
|
@ -10,7 +10,8 @@ const Cu = Components.utils;
|
||||
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/devtools/dbg-client.jsm");
|
||||
let {devtools, gDevTools} = Cu.import("resource:///modules/devtools/gDevTools.jsm", {});
|
||||
let {gDevTools} = Cu.import("resource:///modules/devtools/gDevTools.jsm", {});
|
||||
let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
|
||||
|
||||
let gClient;
|
||||
let gConnectionTimeout;
|
||||
|
@ -4,192 +4,15 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
this.EXPORTED_SYMBOLS = [ "gDevTools", "DevTools", "gDevToolsBrowser", "devtools" ];
|
||||
this.EXPORTED_SYMBOLS = [ "gDevTools", "DevTools", "gDevToolsBrowser" ];
|
||||
|
||||
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource:///modules/devtools/shared/event-emitter.js");
|
||||
Cu.import("resource://gre/modules/FileUtils.jsm");
|
||||
Cu.import("resource://gre/modules/NetUtil.jsm");
|
||||
Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "OS", "resource://gre/modules/osfile.jsm");
|
||||
|
||||
let loader = Cu.import("resource://gre/modules/commonjs/toolkit/loader.js", {}).Loader;
|
||||
|
||||
// Used when the tools should be loaded from the Firefox package itself (the default)
|
||||
|
||||
var BuiltinProvider = {
|
||||
load: function(done) {
|
||||
this.loader = new loader.Loader({
|
||||
paths: {
|
||||
"": "resource://gre/modules/commonjs/",
|
||||
"main" : "resource:///modules/devtools/main",
|
||||
"devtools": "resource:///modules/devtools",
|
||||
"devtools/toolkit": "resource://gre/modules/devtools"
|
||||
},
|
||||
globals: {},
|
||||
});
|
||||
this.main = loader.main(this.loader, "main");
|
||||
|
||||
return Promise.resolve(undefined);
|
||||
},
|
||||
|
||||
unload: function(reason) {
|
||||
loader.unload(this.loader, reason);
|
||||
delete this.loader;
|
||||
},
|
||||
};
|
||||
|
||||
var SrcdirProvider = {
|
||||
load: function(done) {
|
||||
let srcdir = Services.prefs.getComplexValue("devtools.loader.srcdir",
|
||||
Ci.nsISupportsString);
|
||||
srcdir = OS.Path.normalize(srcdir.data.trim());
|
||||
let devtoolsDir = OS.Path.join(srcdir, "browser/devtools");
|
||||
let toolkitDir = OS.Path.join(srcdir, "toolkit/devtools");
|
||||
|
||||
this.loader = new loader.Loader({
|
||||
paths: {
|
||||
"": "resource://gre/modules/commonjs/",
|
||||
"devtools/toolkit": "file://" + toolkitDir,
|
||||
"devtools": "file://" + devtoolsDir,
|
||||
"main": "file://" + devtoolsDir + "/main.js"
|
||||
},
|
||||
globals: {}
|
||||
});
|
||||
|
||||
this.main = loader.main(this.loader, "main");
|
||||
|
||||
return this._writeManifest(devtoolsDir).then((data) => {
|
||||
this._writeManifest(toolkitDir);
|
||||
}).then(null, Cu.reportError);
|
||||
},
|
||||
|
||||
unload: function(reason) {
|
||||
loader.unload(this.loader, reason);
|
||||
delete this.loader;
|
||||
},
|
||||
|
||||
_readFile: function(filename) {
|
||||
let deferred = Promise.defer();
|
||||
let file = new FileUtils.File(filename);
|
||||
NetUtil.asyncFetch(file, (inputStream, status) => {
|
||||
if (!Components.isSuccessCode(status)) {
|
||||
deferred.reject(new Error("Couldn't load manifest: " + filename + "\n"));
|
||||
return;
|
||||
}
|
||||
var data = NetUtil.readInputStreamToString(inputStream, inputStream.available());
|
||||
deferred.resolve(data);
|
||||
});
|
||||
return deferred.promise;
|
||||
},
|
||||
|
||||
_writeFile: function(filename, data) {
|
||||
let deferred = Promise.defer();
|
||||
let file = new FileUtils.File(filename);
|
||||
|
||||
var ostream = FileUtils.openSafeFileOutputStream(file)
|
||||
|
||||
var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].
|
||||
createInstance(Ci.nsIScriptableUnicodeConverter);
|
||||
converter.charset = "UTF-8";
|
||||
var istream = converter.convertToInputStream(data);
|
||||
NetUtil.asyncCopy(istream, ostream, (status) => {
|
||||
if (!Components.isSuccessCode(status)) {
|
||||
deferred.reject(new Error("Couldn't write manifest: " + filename + "\n"));
|
||||
return;
|
||||
}
|
||||
|
||||
deferred.resolve(null);
|
||||
});
|
||||
return deferred.promise;
|
||||
},
|
||||
|
||||
_writeManifest: function(dir) {
|
||||
return this._readFile(dir + "/jar.mn").then((data) => {
|
||||
// The file data is contained within inputStream.
|
||||
// You can read it into a string with
|
||||
let entries = [];
|
||||
let lines = data.split(/\n/);
|
||||
let preprocessed = /^\s*\*/;
|
||||
let contentEntry = new RegExp("^\\s+content/(\\w+)/(\\S+)\\s+\\((\\S+)\\)");
|
||||
for (let line of lines) {
|
||||
if (preprocessed.test(line)) {
|
||||
dump("Unable to override preprocessed file: " + line + "\n");
|
||||
continue;
|
||||
}
|
||||
let match = contentEntry.exec(line);
|
||||
if (match) {
|
||||
let entry = "override chrome://" + match[1] + "/content/" + match[2] + "\tfile://" + dir + "/" + match[3];
|
||||
entries.push(entry);
|
||||
}
|
||||
}
|
||||
return this._writeFile(dir + "/chrome.manifest", entries.join("\n"));
|
||||
}).then(() => {
|
||||
Components.manager.addBootstrappedManifestLocation(new FileUtils.File(dir));
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
this.devtools = {
|
||||
_provider: null,
|
||||
|
||||
get main() this._provider.main,
|
||||
|
||||
// This is a gross gross hack. In one place (computed-view.js) we use
|
||||
// Iterator, but the addon-sdk loader takes Iterator off the global.
|
||||
// Give computed-view.js a way to get back to the Iterator until we have
|
||||
// a chance to fix that crap.
|
||||
_Iterator: Iterator,
|
||||
|
||||
setProvider: function(provider) {
|
||||
if (provider === this._provider) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._provider) {
|
||||
delete this.require;
|
||||
this._provider.unload("newprovider");
|
||||
gDevTools._teardown();
|
||||
}
|
||||
this._provider = provider;
|
||||
this._provider.load();
|
||||
this.require = loader.Require(this._provider.loader, { id: "devtools" })
|
||||
|
||||
let exports = this._provider.main;
|
||||
// Let clients find exports on this object.
|
||||
Object.getOwnPropertyNames(exports).forEach(key => {
|
||||
XPCOMUtils.defineLazyGetter(this, key, () => exports[key]);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Choose a default tools provider based on the preferences.
|
||||
*/
|
||||
_chooseProvider: function() {
|
||||
if (Services.prefs.prefHasUserValue("devtools.loader.srcdir")) {
|
||||
this.setProvider(SrcdirProvider);
|
||||
} else {
|
||||
this.setProvider(BuiltinProvider);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Reload the current provider.
|
||||
*/
|
||||
reload: function() {
|
||||
var events = devtools.require("sdk/system/events");
|
||||
events.emit("startupcache-invalidate", {});
|
||||
|
||||
this._provider.unload("reload");
|
||||
delete this._provider;
|
||||
gDevTools._teardown();
|
||||
this._chooseProvider();
|
||||
},
|
||||
};
|
||||
Cu.import("resource://gre/modules/devtools/Loader.jsm");
|
||||
|
||||
const FORBIDDEN_IDS = new Set(["toolbox", ""]);
|
||||
|
||||
@ -868,5 +691,5 @@ gDevTools.on("toolbox-destroyed", gDevToolsBrowser._updateMenuCheckbox);
|
||||
|
||||
Services.obs.addObserver(gDevToolsBrowser.destroy, "quit-application", false);
|
||||
|
||||
// Now load the tools.
|
||||
devtools._chooseProvider();
|
||||
// Load the browser devtools main module as the loader's main module.
|
||||
devtools.main("devtools/main");
|
||||
|
@ -6,6 +6,9 @@ let temp = {}
|
||||
Cu.import("resource:///modules/devtools/gDevTools.jsm", temp);
|
||||
let DevTools = temp.DevTools;
|
||||
|
||||
Cu.import("resource://gre/modules/devtools/Loader.jsm", temp);
|
||||
let devtools = temp.devtools;
|
||||
|
||||
let Toolbox = devtools.Toolbox;
|
||||
|
||||
let toolbox, target;
|
||||
|
@ -10,7 +10,7 @@ let console = tempScope.console;
|
||||
Components.utils.import("resource://gre/modules/commonjs/sdk/core/promise.js", tempScope);
|
||||
let Promise = tempScope.Promise;
|
||||
|
||||
let {devtools} = Components.utils.import("resource:///modules/devtools/gDevTools.jsm", {});
|
||||
let {devtools} = Components.utils.import("resource://gre/modules/devtools/Loader.jsm", {});
|
||||
let TargetFactory = devtools.TargetFactory;
|
||||
|
||||
/**
|
||||
|
@ -11,7 +11,7 @@ Cu.import('resource://gre/modules/XPCOMUtils.jsm');
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "gDevTools",
|
||||
"resource:///modules/devtools/gDevTools.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "devtools",
|
||||
"resource:///modules/devtools/gDevTools.jsm");
|
||||
"resource://gre/modules/devtools/Loader.jsm");
|
||||
|
||||
/**
|
||||
* 'inspect' command
|
||||
|
@ -9,7 +9,7 @@ let tempScope = {};
|
||||
Cu.import("resource:///modules/devtools/LayoutHelpers.jsm", tempScope);
|
||||
let LayoutHelpers = tempScope.LayoutHelpers;
|
||||
|
||||
let {devtools} = Cu.import("resource:///modules/devtools/gDevTools.jsm", tempScope);
|
||||
let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", tempScope);
|
||||
let TargetFactory = devtools.TargetFactory;
|
||||
|
||||
Components.utils.import("resource://gre/modules/devtools/Console.jsm", tempScope);
|
||||
|
@ -24,7 +24,7 @@ let require = (Cu.import("resource://gre/modules/devtools/Require.jsm", {})).req
|
||||
Components.utils.import("resource:///modules/devtools/gcli.jsm", {});
|
||||
|
||||
let console = (Cu.import("resource://gre/modules/devtools/Console.jsm", {})).console;
|
||||
let {devtools} = Cu.import("resource:///modules/devtools/gDevTools.jsm", {});
|
||||
let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
|
||||
let TargetFactory = devtools.TargetFactory;
|
||||
|
||||
let Promise = (Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js", {})).Promise;
|
||||
|
@ -1,7 +1,7 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
let {devtools} = Cu.import("resource:///modules/devtools/gDevTools.jsm", {});
|
||||
let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
|
||||
let TargetFactory = devtools.TargetFactory;
|
||||
|
||||
function test() {
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
const Cu = Components.utils;
|
||||
|
||||
let {devtools} = Cu.import("resource:///modules/devtools/gDevTools.jsm", {});
|
||||
let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
|
||||
let TargetFactory = devtools.TargetFactory;
|
||||
|
||||
// Clear preferences that may be set during the course of tests.
|
||||
|
@ -6,7 +6,8 @@ const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
|
||||
|
||||
let { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
|
||||
let { Promise } = Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js", {});
|
||||
let { gDevTools, devtools } = Cu.import("resource:///modules/devtools/gDevTools.jsm", {});
|
||||
let { gDevTools } = Cu.import("resource:///modules/devtools/gDevTools.jsm", {});
|
||||
let { devtools } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
|
||||
let TargetFactory = devtools.TargetFactory;
|
||||
let Toolbox = devtools.Toolbox;
|
||||
|
||||
|
@ -7,6 +7,8 @@ const REMOTE_ENABLED = "devtools.debugger.remote-enabled";
|
||||
|
||||
Cu.import("resource:///modules/devtools/gDevTools.jsm", temp);
|
||||
let gDevTools = temp.gDevTools;
|
||||
|
||||
Cu.import("resource://gre/modules/devtools/Loader.jsm", temp);
|
||||
let TargetFactory = temp.devtools.TargetFactory;
|
||||
|
||||
Cu.import("resource://gre/modules/devtools/dbg-server.jsm", temp);
|
||||
|
@ -31,7 +31,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "PluralForm",
|
||||
"resource://gre/modules/PluralForm.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "devtools",
|
||||
"resource:///modules/devtools/gDevTools.jsm");
|
||||
"resource://gre/modules/devtools/Loader.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "require",
|
||||
"resource://gre/modules/devtools/Require.jsm");
|
||||
|
@ -2,7 +2,7 @@
|
||||
* 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/. */
|
||||
|
||||
let {devtools} = Cu.import("resource:///modules/devtools/gDevTools.jsm", {});
|
||||
let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
|
||||
let TargetFactory = devtools.TargetFactory;
|
||||
|
||||
/**
|
||||
|
@ -7,7 +7,7 @@ const TEST_BASE_HTTPS = "https://example.com/browser/browser/devtools/styleedito
|
||||
const TEST_HOST = 'mochi.test:8888';
|
||||
|
||||
let tempScope = {};
|
||||
Cu.import("resource:///modules/devtools/gDevTools.jsm", tempScope);
|
||||
Cu.import("resource://gre/modules/devtools/Loader.jsm", tempScope);
|
||||
let TargetFactory = tempScope.devtools.TargetFactory;
|
||||
Components.utils.import("resource://gre/modules/devtools/Console.jsm", tempScope);
|
||||
let console = tempScope.console;
|
||||
|
@ -24,7 +24,7 @@ let require = (Cu.import("resource://gre/modules/devtools/Require.jsm", {})).req
|
||||
Components.utils.import("resource:///modules/devtools/gcli.jsm", {});
|
||||
|
||||
let console = (Cu.import("resource://gre/modules/devtools/Console.jsm", {})).console;
|
||||
let devtools = (Cu.import("resource:///modules/devtools/gDevTools.jsm", {})).devtools;
|
||||
let devtools = (Cu.import("resource://gre/modules/devtools/Loader.jsm", {})).devtools;
|
||||
let TargetFactory = devtools.TargetFactory;
|
||||
|
||||
let Promise = (Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js", {})).Promise;
|
||||
|
@ -14,8 +14,6 @@ Cu.import("resource://gre/modules/PluralForm.jsm");
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource:///modules/devtools/Templater.jsm");
|
||||
|
||||
Cu.import("resource:///modules/devtools/gDevTools.jsm");
|
||||
|
||||
const FILTER_CHANGED_TIMEOUT = 300;
|
||||
|
||||
const HTML_NS = "http://www.w3.org/1999/xhtml";
|
||||
@ -43,7 +41,7 @@ const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
||||
function UpdateProcess(aWin, aGenerator, aOptions)
|
||||
{
|
||||
this.win = aWin;
|
||||
this.iter = devtools._Iterator(aGenerator);
|
||||
this.iter = _Iterator(aGenerator);
|
||||
this.onItem = aOptions.onItem || function() {};
|
||||
this.onBatch = aOptions.onBatch || function () {};
|
||||
this.onDone = aOptions.onDone || function() {};
|
||||
|
@ -35,7 +35,7 @@
|
||||
|
||||
<script type="application/javascript;version=1.8">
|
||||
window.setPanel = function(panel, iframe) {
|
||||
let {devtools} = Components.utils.import("resource:///modules/devtools/gDevTools.jsm", {});
|
||||
let {devtools} = Components.utils.import("resource://gre/modules/devtools/Loader.jsm", {});
|
||||
let inspector = devtools.require("devtools/styleinspector/style-inspector");
|
||||
this.computedview = new inspector.ComputedViewTool(panel, window, iframe);
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
<script type="application/javascript;version=1.8">
|
||||
window.setPanel = function(panel, iframe) {
|
||||
let {devtools} = Components.utils.import("resource:///modules/devtools/gDevTools.jsm", {});
|
||||
let {devtools} = Components.utils.import("resource://gre/modules/devtools/Loader.jsm", {});
|
||||
let inspector = devtools.require("devtools/styleinspector/style-inspector");
|
||||
this.ruleview = new inspector.RuleViewTool(panel, window, iframe);
|
||||
}
|
||||
|
@ -7,7 +7,10 @@ let tempScope = {};
|
||||
Cu.import("resource:///modules/devtools/gDevTools.jsm", tempScope);
|
||||
let ConsoleUtils = tempScope.ConsoleUtils;
|
||||
let gDevTools = tempScope.gDevTools;
|
||||
|
||||
Cu.import("resource://gre/modules/devtools/Loader.jsm", tempScope);
|
||||
let devtools = tempScope.devtools;
|
||||
|
||||
let TargetFactory = devtools.TargetFactory;
|
||||
let {CssHtmlTree} = devtools.require("devtools/styleinspector/computed-view");
|
||||
let {CssRuleView, _ElementStyle} = devtools.require("devtools/styleinspector/rule-view");
|
||||
|
@ -7,7 +7,7 @@ this.EXPORTED_SYMBOLS = [ ];
|
||||
|
||||
Components.utils.import('resource://gre/modules/XPCOMUtils.jsm');
|
||||
Components.utils.import("resource:///modules/devtools/gcli.jsm");
|
||||
Components.utils.import("resource:///modules/devtools/gDevTools.jsm");
|
||||
Components.utils.import("resource://gre/modules/devtools/Loader.jsm");
|
||||
|
||||
// Fetch TiltManager using the current loader, but don't save a
|
||||
// reference to it, because it might change with a tool reload.
|
||||
|
@ -17,7 +17,7 @@ function test() {
|
||||
waitForExplicitFinish();
|
||||
|
||||
createTab(function() {
|
||||
let { devtools } = Cu.import("resource:///modules/devtools/gDevTools.jsm", {});
|
||||
let { devtools } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
|
||||
let target = devtools.TargetFactory.forTab(gBrowser.selectedTab);
|
||||
|
||||
gDevTools.showToolbox(target, "inspector").then(function(toolbox) {
|
||||
|
@ -2,7 +2,7 @@
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
"use strict";
|
||||
|
||||
let {devtools} = Components.utils.import("resource:///modules/devtools/gDevTools.jsm", {});
|
||||
let {devtools} = Components.utils.import("resource://gre/modules/devtools/Loader.jsm", {});
|
||||
let TiltManager = devtools.require("devtools/tilt/tilt").TiltManager;
|
||||
let TiltGL = devtools.require("devtools/tilt/tilt-gl");
|
||||
let {EPSILON, TiltMath, vec3, mat3, mat4, quat4} = devtools.require("devtools/tilt/tilt-math");
|
||||
|
@ -17,7 +17,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "gDevTools",
|
||||
"resource:///modules/devtools/gDevTools.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "devtools",
|
||||
"resource:///modules/devtools/gDevTools.jsm");
|
||||
"resource://gre/modules/devtools/Loader.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "Services",
|
||||
"resource://gre/modules/Services.jsm");
|
||||
|
@ -10,6 +10,7 @@ Cu.import("resource://gre/modules/devtools/WebConsoleUtils.jsm", tempScope);
|
||||
let WebConsoleUtils = tempScope.WebConsoleUtils;
|
||||
Cu.import("resource:///modules/devtools/gDevTools.jsm", tempScope);
|
||||
let gDevTools = tempScope.gDevTools;
|
||||
Cu.import("resource://gre/module/devtools/Loader.jsm", tempScope);
|
||||
let TargetFactory = tempScope.devtools.TargetFactory;
|
||||
Components.utils.import("resource://gre/modules/devtools/Console.jsm", tempScope);
|
||||
let console = tempScope.console;
|
||||
|
@ -41,7 +41,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "EventEmitter",
|
||||
"resource:///modules/devtools/shared/event-emitter.js");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "devtools",
|
||||
"resource:///modules/devtools/gDevTools.jsm");
|
||||
"resource://gre/modules/devtools/Loader.jsm");
|
||||
|
||||
const STRINGS_URI = "chrome://browser/locale/devtools/webconsole.properties";
|
||||
let l10n = new WebConsoleUtils.l10n(STRINGS_URI);
|
||||
|
238
toolkit/devtools/Loader.jsm
Normal file
238
toolkit/devtools/Loader.jsm
Normal file
@ -0,0 +1,238 @@
|
||||
/* 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";
|
||||
|
||||
/**
|
||||
* Manages the addon-sdk loader instance used to load the developer tools.
|
||||
*/
|
||||
|
||||
let Cu = Components.utils;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "NetUtil", "resource://gre/modules/NetUtil.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "FileUtils", "resource://gre/modules/NetUtil.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "OS", "resource://gre/modules/osfile.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "console", "resource://gre/modules/devtools/Console.jsm");
|
||||
|
||||
let loader = Cu.import("resource://gre/modules/commonjs/toolkit/loader.js", {}).Loader;
|
||||
let Promise = Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js", {}).Promise;
|
||||
|
||||
this.EXPORTED_SYMBOLS = ["devtools"];
|
||||
|
||||
/**
|
||||
* Providers are different strategies for loading the devtools.
|
||||
*/
|
||||
|
||||
let loaderGlobals = {
|
||||
console: console,
|
||||
_Iterator: Iterator
|
||||
}
|
||||
|
||||
// Used when the tools should be loaded from the Firefox package itself (the default)
|
||||
var BuiltinProvider = {
|
||||
load: function(done) {
|
||||
this.loader = new loader.Loader({
|
||||
paths: {
|
||||
"": "resource://gre/modules/commonjs/",
|
||||
"main": "resource:///modules/devtools/main.js",
|
||||
"devtools": "resource:///modules/devtools",
|
||||
"devtools/server": "resource://gre/modules/devtools/server"
|
||||
},
|
||||
globals: loaderGlobals
|
||||
});
|
||||
|
||||
return Promise.resolve(undefined);
|
||||
},
|
||||
|
||||
unload: function(reason) {
|
||||
loader.unload(this.loader, reason);
|
||||
delete this.loader;
|
||||
},
|
||||
};
|
||||
|
||||
// Used when the tools should be loaded from a mozilla-central checkout. In addition
|
||||
// to different paths, it needs to write chrome.manifest files to override chrome urls
|
||||
// from the builtin tools.
|
||||
var SrcdirProvider = {
|
||||
load: function(done) {
|
||||
let srcdir = Services.prefs.getComplexValue("devtools.loader.srcdir",
|
||||
Ci.nsISupportsString);
|
||||
srcdir = OS.Path.normalize(srcdir.data.trim());
|
||||
let devtoolsDir = OS.Path.join(srcdir, "browser/devtools");
|
||||
let toolkitDir = OS.Path.join(srcdir, "toolkit/devtools");
|
||||
let serverDir = OS.path.join(toolkitDir, "server")
|
||||
|
||||
this.loader = new loader.Loader({
|
||||
paths: {
|
||||
"": "resource://gre/modules/commonjs/",
|
||||
"devtools/server": "file://" + serverDir,
|
||||
"devtools": "file://" + devtoolsDir,
|
||||
"main": "file://" + devtoolsDir + "/main.js"
|
||||
},
|
||||
globals: loaderGlobals
|
||||
});
|
||||
|
||||
return this._writeManifest(devtoolsDir).then((data) => {
|
||||
this._writeManifest(toolkitDir);
|
||||
}).then(null, Cu.reportError);
|
||||
},
|
||||
|
||||
unload: function(reason) {
|
||||
loader.unload(this.loader, reason);
|
||||
delete this.loader;
|
||||
},
|
||||
|
||||
_readFile: function(filename) {
|
||||
let deferred = Promise.defer();
|
||||
let file = new FileUtils.File(filename);
|
||||
NetUtil.asyncFetch(file, (inputStream, status) => {
|
||||
if (!Components.isSuccessCode(status)) {
|
||||
deferred.reject(new Error("Couldn't load manifest: " + filename + "\n"));
|
||||
return;
|
||||
}
|
||||
var data = NetUtil.readInputStreamToString(inputStream, inputStream.available());
|
||||
deferred.resolve(data);
|
||||
});
|
||||
return deferred.promise;
|
||||
},
|
||||
|
||||
_writeFile: function(filename, data) {
|
||||
let deferred = Promise.defer();
|
||||
let file = new FileUtils.File(filename);
|
||||
|
||||
var ostream = FileUtils.openSafeFileOutputStream(file)
|
||||
|
||||
var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].
|
||||
createInstance(Ci.nsIScriptableUnicodeConverter);
|
||||
converter.charset = "UTF-8";
|
||||
var istream = converter.convertToInputStream(data);
|
||||
NetUtil.asyncCopy(istream, ostream, (status) => {
|
||||
if (!Components.isSuccessCode(status)) {
|
||||
deferred.reject(new Error("Couldn't write manifest: " + filename + "\n"));
|
||||
return;
|
||||
}
|
||||
|
||||
deferred.resolve(null);
|
||||
});
|
||||
return deferred.promise;
|
||||
},
|
||||
|
||||
_writeManifest: function(dir) {
|
||||
return this._readFile(dir + "/jar.mn").then((data) => {
|
||||
// The file data is contained within inputStream.
|
||||
// You can read it into a string with
|
||||
let entries = [];
|
||||
let lines = data.split(/\n/);
|
||||
let preprocessed = /^\s*\*/;
|
||||
let contentEntry = new RegExp("^\\s+content/(\\w+)/(\\S+)\\s+\\((\\S+)\\)");
|
||||
for (let line of lines) {
|
||||
if (preprocessed.test(line)) {
|
||||
dump("Unable to override preprocessed file: " + line + "\n");
|
||||
continue;
|
||||
}
|
||||
let match = contentEntry.exec(line);
|
||||
if (match) {
|
||||
let entry = "override chrome://" + match[1] + "/content/" + match[2] + "\tfile://" + dir + "/" + match[3];
|
||||
entries.push(entry);
|
||||
}
|
||||
}
|
||||
return this._writeFile(dir + "/chrome.manifest", entries.join("\n"));
|
||||
}).then(() => {
|
||||
Components.manager.addBootstrappedManifestLocation(new FileUtils.File(dir));
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The main devtools API.
|
||||
* In addition to a few loader-related details, this object will also include all
|
||||
* exports from the main module.
|
||||
*/
|
||||
this.devtools = {
|
||||
_provider: null,
|
||||
|
||||
/**
|
||||
* Add a URI to the loader.
|
||||
* @param string id
|
||||
* The module id that can be used within the loader to refer to this module.
|
||||
* @param string uri
|
||||
* The URI to load as a module.
|
||||
* @returns The module's exports.
|
||||
*/
|
||||
loadURI: function(id, uri) {
|
||||
let module = loader.Module(id, uri);
|
||||
return loader.load(this._provider.loader, module).exports;
|
||||
},
|
||||
|
||||
/**
|
||||
* Let the loader know the ID of the main module to load.
|
||||
*
|
||||
* The loader doesn't need a main module, but it's nice to have. This
|
||||
* will be called by the browser devtools to load the devtools/main module.
|
||||
*
|
||||
* When only using the server, there's no main module, and this method
|
||||
* can be ignored.
|
||||
*/
|
||||
main: function(id) {
|
||||
this._mainid = id;
|
||||
this._main = loader.main(this._provider.loader, id);
|
||||
|
||||
// Mirror the main module's exports on this object.
|
||||
Object.getOwnPropertyNames(this._main).forEach(key => {
|
||||
XPCOMUtils.defineLazyGetter(this, key, () => this._main[key]);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Override the provider used to load the tools.
|
||||
*/
|
||||
setProvider: function(provider) {
|
||||
if (provider === this._provider) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._provider) {
|
||||
delete this.require;
|
||||
this._provider.unload("newprovider");
|
||||
gDevTools._teardown();
|
||||
}
|
||||
this._provider = provider;
|
||||
this._provider.load();
|
||||
this.require = loader.Require(this._provider.loader, { id: "devtools" });
|
||||
|
||||
if (this._mainid) {
|
||||
this.main(mainid);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Choose a default tools provider based on the preferences.
|
||||
*/
|
||||
_chooseProvider: function() {
|
||||
if (Services.prefs.prefHasUserValue("devtools.loader.srcdir")) {
|
||||
this.setProvider(SrcdirProvider);
|
||||
} else {
|
||||
this.setProvider(BuiltinProvider);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Reload the current provider.
|
||||
*/
|
||||
reload: function() {
|
||||
var events = devtools.require("sdk/system/events");
|
||||
events.emit("startupcache-invalidate", {});
|
||||
|
||||
this._provider.unload("reload");
|
||||
delete this._provider;
|
||||
gDevTools._teardown();
|
||||
this._chooseProvider();
|
||||
},
|
||||
};
|
||||
|
||||
// Now load the tools.
|
||||
devtools._chooseProvider();
|
@ -33,7 +33,7 @@ XPCOMUtils.defineLazyServiceGetter(this, "gActivityDistributor",
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "gDevTools",
|
||||
"resource:///modules/devtools/gDevTools.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "devtools",
|
||||
"resource:///modules/devtools/gDevTools.jsm");
|
||||
"resource://gre/modules/devtools/Loader.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "VariablesView",
|
||||
"resource:///modules/devtools/VariablesView.jsm");
|
||||
|
Loading…
Reference in New Issue
Block a user