mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-26 20:30:41 +00:00
Bug 1487078 - Copy addon helper to aboutdebugging-new;r=daisuke
Depends on D4548 Differential Revision: https://phabricator.services.mozilla.com/D4646 --HG-- rename : devtools/client/aboutdebugging/modules/addon.js => devtools/client/aboutdebugging-new/src/modules/extensions-helper.js extra : moz-landing-system : lando
This commit is contained in:
parent
82f188b48e
commit
eee68972ac
@ -13,7 +13,7 @@ const {
|
||||
debugLocalAddon,
|
||||
openTemporaryExtension,
|
||||
uninstallAddon,
|
||||
} = require("devtools/client/aboutdebugging/modules/addon");
|
||||
} = require("devtools/client/aboutdebugging-new/src/modules/extensions-helper");
|
||||
|
||||
const {
|
||||
CONNECT_RUNTIME_FAILURE,
|
||||
|
@ -12,7 +12,7 @@ const {
|
||||
const {
|
||||
getExtensionUuid,
|
||||
parseFileUri
|
||||
} = require("devtools/client/aboutdebugging/modules/addon");
|
||||
} = require("devtools/client/aboutdebugging-new/src/modules/extensions-helper");
|
||||
|
||||
/**
|
||||
* This middleware converts extensions object that get from DebuggerClient.listAddons()
|
||||
|
@ -0,0 +1,137 @@
|
||||
/* 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";
|
||||
|
||||
const { Cc, Ci } = require("chrome");
|
||||
loader.lazyImporter(this, "BrowserToolboxProcess",
|
||||
"resource://devtools/client/framework/ToolboxProcess.jsm");
|
||||
loader.lazyImporter(this, "AddonManager", "resource://gre/modules/AddonManager.jsm");
|
||||
|
||||
const {TargetFactory} = require("devtools/client/framework/target");
|
||||
const {Toolbox} = require("devtools/client/framework/toolbox");
|
||||
|
||||
const {gDevTools} = require("devtools/client/framework/devtools");
|
||||
|
||||
let browserToolboxProcess = null;
|
||||
let remoteAddonToolbox = null;
|
||||
function closeToolbox() {
|
||||
if (browserToolboxProcess) {
|
||||
browserToolboxProcess.close();
|
||||
}
|
||||
|
||||
if (remoteAddonToolbox) {
|
||||
remoteAddonToolbox.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start debugging an addon in the current instance of Firefox.
|
||||
*
|
||||
* @param {String} addonID
|
||||
* String id of the addon to debug.
|
||||
*/
|
||||
exports.debugLocalAddon = async function(addonID) {
|
||||
// Close previous addon debugging toolbox.
|
||||
closeToolbox();
|
||||
|
||||
browserToolboxProcess = BrowserToolboxProcess.init({
|
||||
addonID,
|
||||
onClose: () => {
|
||||
browserToolboxProcess = null;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Start debugging an addon in a remote instance of Firefox.
|
||||
*
|
||||
* @param {Object} addonForm
|
||||
* Necessary to create an addon debugging target.
|
||||
* @param {DebuggerClient} client
|
||||
* Required for remote debugging.
|
||||
*/
|
||||
exports.debugRemoteAddon = async function(addonForm, client) {
|
||||
// Close previous addon debugging toolbox.
|
||||
closeToolbox();
|
||||
|
||||
const options = {
|
||||
form: addonForm,
|
||||
chrome: true,
|
||||
client,
|
||||
isBrowsingContext: addonForm.isWebExtension
|
||||
};
|
||||
|
||||
const target = await TargetFactory.forRemoteTab(options);
|
||||
|
||||
const hostType = Toolbox.HostType.WINDOW;
|
||||
remoteAddonToolbox = await gDevTools.showToolbox(target, null, hostType);
|
||||
remoteAddonToolbox.once("destroy", () => {
|
||||
remoteAddonToolbox = null;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Uninstall the addon with the provided id.
|
||||
* Resolves when the addon shutdown has completed.
|
||||
*/
|
||||
exports.uninstallAddon = async function(addonID) {
|
||||
const addon = await AddonManager.getAddonByID(addonID);
|
||||
return addon && addon.uninstall();
|
||||
};
|
||||
|
||||
exports.parseFileUri = function(url) {
|
||||
// Strip a leading slash from Windows drive letter URIs.
|
||||
// file:///home/foo ~> /home/foo
|
||||
// file:///C:/foo ~> C:/foo
|
||||
const windowsRegex = /^file:\/\/\/([a-zA-Z]:\/.*)/;
|
||||
if (windowsRegex.test(url)) {
|
||||
return windowsRegex.exec(url)[1];
|
||||
}
|
||||
return url.slice("file://".length);
|
||||
};
|
||||
|
||||
exports.getExtensionUuid = function(extension) {
|
||||
const { manifestURL } = extension;
|
||||
// Strip off the protocol and rest, leaving us with just the UUID.
|
||||
return manifestURL ? /moz-extension:\/\/([^/]*)/.exec(manifestURL)[1] : null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Open a file picker to allow the user to locate a temporary extension. A temporary
|
||||
* extension can either be:
|
||||
* - a folder
|
||||
* - a .xpi file
|
||||
* - a .zip file
|
||||
*
|
||||
* @param {Window} win
|
||||
* The window object where the filepicker should be opened.
|
||||
* Note: We cannot use the global window object here because it is undefined if
|
||||
* this module is loaded from a file outside of devtools/client/aboutdebugging/.
|
||||
* See browser-loader.js `uri.startsWith(baseURI)` for more details.
|
||||
* @param {String} message
|
||||
* The help message that should be displayed to the user in the filepicker.
|
||||
* @return {Promise} returns a promise that resolves a File object corresponding to the
|
||||
* file selected by the user.
|
||||
*/
|
||||
exports.openTemporaryExtension = function(win, message) {
|
||||
return new Promise(resolve => {
|
||||
const fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
|
||||
fp.init(win, message, Ci.nsIFilePicker.modeOpen);
|
||||
fp.open(res => {
|
||||
if (res == Ci.nsIFilePicker.returnCancel || !fp.file) {
|
||||
return;
|
||||
}
|
||||
let file = fp.file;
|
||||
// AddonManager.installTemporaryAddon accepts either
|
||||
// addon directory or final xpi file.
|
||||
if (!file.isDirectory() &&
|
||||
!file.leafName.endsWith(".xpi") && !file.leafName.endsWith(".zip")) {
|
||||
file = file.parent;
|
||||
}
|
||||
|
||||
resolve(file);
|
||||
});
|
||||
});
|
||||
};
|
@ -3,5 +3,6 @@
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
DevToolsModules(
|
||||
'extensions-helper.js',
|
||||
'network-locations.js',
|
||||
)
|
||||
|
@ -4,83 +4,22 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
const { Cc, Ci } = require("chrome");
|
||||
loader.lazyImporter(this, "BrowserToolboxProcess",
|
||||
"resource://devtools/client/framework/ToolboxProcess.jsm");
|
||||
loader.lazyImporter(this, "AddonManager", "resource://gre/modules/AddonManager.jsm");
|
||||
loader.lazyImporter(this, "AddonManagerPrivate", "resource://gre/modules/AddonManager.jsm");
|
||||
|
||||
var {TargetFactory} = require("devtools/client/framework/target");
|
||||
var {Toolbox} = require("devtools/client/framework/toolbox");
|
||||
|
||||
var {gDevTools} = require("devtools/client/framework/devtools");
|
||||
|
||||
let browserToolboxProcess = null;
|
||||
let remoteAddonToolbox = null;
|
||||
function closeToolbox() {
|
||||
if (browserToolboxProcess) {
|
||||
browserToolboxProcess.close();
|
||||
}
|
||||
|
||||
if (remoteAddonToolbox) {
|
||||
remoteAddonToolbox.destroy();
|
||||
}
|
||||
}
|
||||
const {
|
||||
debugLocalAddon,
|
||||
debugRemoteAddon,
|
||||
getExtensionUuid,
|
||||
openTemporaryExtension,
|
||||
parseFileUri,
|
||||
uninstallAddon,
|
||||
} = require("devtools/client/aboutdebugging-new/src/modules/extensions-helper");
|
||||
|
||||
/**
|
||||
* Start debugging an addon in the current instance of Firefox.
|
||||
*
|
||||
* @param {String} addonID
|
||||
* String id of the addon to debug.
|
||||
* Most of the implementation for this module has been moved to
|
||||
* devtools/client/aboutdebugging-new/src/modules/extensions-helper.js
|
||||
* The only methods implemented here are the ones used in the old aboutdebugging only.
|
||||
*/
|
||||
exports.debugLocalAddon = async function(addonID) {
|
||||
// Close previous addon debugging toolbox.
|
||||
closeToolbox();
|
||||
|
||||
browserToolboxProcess = BrowserToolboxProcess.init({
|
||||
addonID,
|
||||
onClose: () => {
|
||||
browserToolboxProcess = null;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Start debugging an addon in a remote instance of Firefox.
|
||||
*
|
||||
* @param {Object} addonForm
|
||||
* Necessary to create an addon debugging target.
|
||||
* @param {DebuggerClient} client
|
||||
* Required for remote debugging.
|
||||
*/
|
||||
exports.debugRemoteAddon = async function(addonForm, client) {
|
||||
// Close previous addon debugging toolbox.
|
||||
closeToolbox();
|
||||
|
||||
const options = {
|
||||
form: addonForm,
|
||||
chrome: true,
|
||||
client,
|
||||
isBrowsingContext: addonForm.isWebExtension
|
||||
};
|
||||
|
||||
const target = await TargetFactory.forRemoteTab(options);
|
||||
|
||||
const hostType = Toolbox.HostType.WINDOW;
|
||||
remoteAddonToolbox = await gDevTools.showToolbox(target, null, hostType);
|
||||
remoteAddonToolbox.once("destroy", () => {
|
||||
remoteAddonToolbox = null;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Uninstall the addon with the provided id.
|
||||
* Resolves when the addon shutdown has completed.
|
||||
*/
|
||||
exports.uninstallAddon = async function(addonID) {
|
||||
const addon = await AddonManager.getAddonByID(addonID);
|
||||
return addon && addon.uninstall();
|
||||
};
|
||||
|
||||
exports.isTemporaryID = function(addonID) {
|
||||
return AddonManagerPrivate.isTemporaryInstallID(addonID);
|
||||
@ -99,57 +38,14 @@ exports.isLegacyTemporaryExtension = function(addonForm) {
|
||||
!addonForm.isAPIExtension;
|
||||
};
|
||||
|
||||
exports.parseFileUri = function(url) {
|
||||
// Strip a leading slash from Windows drive letter URIs.
|
||||
// file:///home/foo ~> /home/foo
|
||||
// file:///C:/foo ~> C:/foo
|
||||
const windowsRegex = /^file:\/\/\/([a-zA-Z]:\/.*)/;
|
||||
if (windowsRegex.test(url)) {
|
||||
return windowsRegex.exec(url)[1];
|
||||
}
|
||||
return url.slice("file://".length);
|
||||
};
|
||||
|
||||
exports.getExtensionUuid = function(extension) {
|
||||
const { manifestURL } = extension;
|
||||
// Strip off the protocol and rest, leaving us with just the UUID.
|
||||
return manifestURL ? /moz-extension:\/\/([^/]*)/.exec(manifestURL)[1] : null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Open a file picker to allow the user to locate a temporary extension. A temporary
|
||||
* extension can either be:
|
||||
* - a folder
|
||||
* - a .xpi file
|
||||
* - a .zip file
|
||||
*
|
||||
* @param {Window} win
|
||||
* The window object where the filepicker should be opened.
|
||||
* Note: We cannot use the global window object here because it is undefined if
|
||||
* this module is loaded from a file outside of devtools/client/aboutdebugging/.
|
||||
* See browser-loader.js `uri.startsWith(baseURI)` for more details.
|
||||
* @param {String} message
|
||||
* The help message that should be displayed to the user in the filepicker.
|
||||
* @return {Promise} returns a promise that resolves a File object corresponding to the
|
||||
* file selected by the user.
|
||||
* See JSDoc in devtools/client/aboutdebugging-new/src/modules/extensions-helper for all
|
||||
* the methods exposed below.
|
||||
*/
|
||||
exports.openTemporaryExtension = function(win, message) {
|
||||
return new Promise(resolve => {
|
||||
const fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
|
||||
fp.init(win, message, Ci.nsIFilePicker.modeOpen);
|
||||
fp.open(res => {
|
||||
if (res == Ci.nsIFilePicker.returnCancel || !fp.file) {
|
||||
return;
|
||||
}
|
||||
let file = fp.file;
|
||||
// AddonManager.installTemporaryAddon accepts either
|
||||
// addon directory or final xpi file.
|
||||
if (!file.isDirectory() &&
|
||||
!file.leafName.endsWith(".xpi") && !file.leafName.endsWith(".zip")) {
|
||||
file = file.parent;
|
||||
}
|
||||
|
||||
resolve(file);
|
||||
});
|
||||
});
|
||||
};
|
||||
exports.debugLocalAddon = debugLocalAddon;
|
||||
exports.debugRemoteAddon = debugRemoteAddon;
|
||||
exports.getExtensionUuid = getExtensionUuid;
|
||||
exports.openTemporaryExtension = openTemporaryExtension;
|
||||
exports.parseFileUri = parseFileUri;
|
||||
exports.uninstallAddon = uninstallAddon;
|
||||
|
@ -3,7 +3,7 @@
|
||||
"use strict";
|
||||
|
||||
const { parseFileUri } =
|
||||
require("devtools/client/aboutdebugging/modules/addon");
|
||||
require("devtools/client/aboutdebugging-new/src/modules/extensions-helper");
|
||||
|
||||
add_task(async function testParseFileUri() {
|
||||
equal(
|
||||
|
Loading…
x
Reference in New Issue
Block a user