Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 911098 - Implement addon dubugger UI #3

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions modules/libpref/src/init/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,9 @@ pref("devtools.debugger.enable-content-actors", true);
// Block tools from seeing / interacting with certified apps
pref("devtools.debugger.forbid-certified-apps", true);

// Disable add-on debugging
pref("devtools.debugger.addon-enabled", false);

// DevTools default color unit
pref("devtools.defaultColorUnit", "hex");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
<!ENTITY cmd.installAddon.accesskey "I">
<!ENTITY cmd.uninstallAddon.label "Remove">
<!ENTITY cmd.uninstallAddon.accesskey "R">
<!ENTITY cmd.debugAddon.label "Debug">
<!ENTITY cmd.showPreferencesWin.label "Options">
<!ENTITY cmd.showPreferencesWin.tooltip "Change this add-on's options">
<!ENTITY cmd.showPreferencesUnix.label "Preferences">
Expand Down
16 changes: 16 additions & 0 deletions toolkit/mozapps/extensions/XPIProvider.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -6594,6 +6594,22 @@ function AddonWrapper(aAddon) {
return ops;
});

this.__defineGetter__("isBootstrapped", function AddonWrapper_isBootstrapped() {
return this.operationsRequiringRestart === AddonManager.OP_NEEDS_RESTART_NONE;
});

this.__defineGetter__("isJetpack", function AddonWrapper_isJetpack() {
// Assume that if there's a `harness-options.json` file in restartless add-on
// it's a jetpack.
return this.isBootstrapped && this.hasResource("harness-options.json");
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mossop I believe @erikvold is going to expose isJetpack for native jetpacks anyway, so is there point in delaying it ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like Blair to review any API addition here.

On Thu, Jan 23, 2014 at 3:01 PM, Irakli Gozalishvili <
notifications@github.com> wrote:

In toolkit/mozapps/extensions/XPIProvider.jsm:

@@ -6594,6 +6594,22 @@ function AddonWrapper(aAddon) {
return ops;
});

  • this.defineGetter("isBootstrapped", function AddonWrapper_isBootstrapped() {
  • return this.operationsRequiringRestart === AddonManager.OP_NEEDS_RESTART_NONE;
  • });
  • this.defineGetter("isJetpack", function AddonWrapper_isJetpack() {
  • // Assume that if there's a harness-options.json file in restartless add-on
  • // it's a jetpack.
  • return this.isBootstrapped && this.hasResource("harness-options.json");
  • });

@Mossop https://github.com/Mossop I believe @erikvoldhttps://github.com/erikvoldis going to expose
isJetpack for native jetpacks anyway, so is there point in delaying it ?


Reply to this email directly or view it on GitHubhttps://github.com//pull/3/files#r9134079
.



this.__defineGetter__("isDebuggable", function AddonWrapper_isDebuggable() {
// At the moment only jetpacks are debuggable.
return this.isActive && this.isJetpack;
});

this.__defineGetter__("permissions", function AddonWrapper_permisionsGetter() {
let permissions = 0;

Expand Down
25 changes: 25 additions & 0 deletions toolkit/mozapps/extensions/content/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Cu.import("resource://gre/modules/PluralForm.jsm");
Cu.import("resource://gre/modules/DownloadUtils.jsm");
Cu.import("resource://gre/modules/AddonManager.jsm");
Cu.import("resource://gre/modules/AddonRepository.jsm");
XPCOMUtils.defineLazyGetter(this, "BrowserDebuggerProcess", function() {
return Cu.import("resource:///modules/devtools/DebuggerProcess.jsm", {}).
BrowserDebuggerProcess;
});


const PREF_DISCOVERURL = "extensions.webservice.discoverURL";
Expand All @@ -26,6 +30,7 @@ const PREF_GETADDONS_CACHE_ENABLED = "extensions.getAddons.cache.enabled";
const PREF_GETADDONS_CACHE_ID_ENABLED = "extensions.%ID%.getAddons.cache.enabled";
const PREF_UI_TYPE_HIDDEN = "extensions.ui.%TYPE%.hidden";
const PREF_UI_LASTCATEGORY = "extensions.ui.lastCategory";
const PREF_ADDON_DEBUGGING_ENABLED = "devtools.debugger.addon-enabled";

const LOADING_MSG_DELAY = 100;

Expand Down Expand Up @@ -107,6 +112,14 @@ function initialize(event) {
}

gViewController.loadInitialView(view);

Services.prefs.addObserver(PREF_ADDON_DEBUGGING_ENABLED, {
observe: function() {
gViewController.updateState();
gViewController.updateCommands();
gViewController.notifyViewChanged();
}
}, false);
}

function notifyInitialized() {
Expand Down Expand Up @@ -902,6 +915,18 @@ var gViewController = {
}
},

cmd_debugItem: {
doCommand: function cmd_debugItem_doCommand(aAddon) {
BrowserDebuggerProcess.init({ addonID: aAddon.id });
},

isEnabled: function cmd_debugItem_isEnabled(aAddon) {
let debuggerEnabled = Services.prefs.
getBoolPref("devtools.debugger.addon-enabled");
return aAddon && aAddon.isDebuggable && debuggerEnabled;
}
},

cmd_showItemPreferences: {
isEnabled: function cmd_showItemPreferences_isEnabled(aAddon) {
if (!aAddon || !aAddon.isActive || !aAddon.optionsURL)
Expand Down
18 changes: 18 additions & 0 deletions toolkit/mozapps/extensions/content/extensions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,11 @@
tooltiptext="&cmd.showPreferencesUnix.tooltip;"
#endif
oncommand="document.getBindingParent(this).showPreferences();"/>
<!-- label="&cmd.debugAddon.label;" -->
<xul:button anonid="debug-btn" class="addon-control debug"
label="&cmd.debugAddon.label;"
oncommand="document.getBindingParent(this).debug();"/>

<xul:button anonid="enable-btn" class="addon-control enable"
label="&cmd.enableAddon.label;"
oncommand="document.getBindingParent(this).userDisabled = false;"/>
Expand Down Expand Up @@ -1003,6 +1008,10 @@
document.getAnonymousElementByAttribute(this, "anonid",
"enable-btn");
</field>
<field name="_debugBtn">
document.getAnonymousElementByAttribute(this, "anonid",
"debug-btn");
</field>
<field name="_disableBtn">
document.getAnonymousElementByAttribute(this, "anonid",
"disable-btn");
Expand Down Expand Up @@ -1332,6 +1341,9 @@
var showProgress = this.mAddon.purchaseURL || (this.mAddon.install &&
this.mAddon.install.state != AddonManager.STATE_INSTALLED);
this._showStatus(showProgress ? "progress" : "none");

this._debugBtn.disabled = !this.mAddon.isDebuggable ||
!Services.prefs.getBoolPref('devtools.debugger.addon-enabled');
]]></body>
</method>

Expand Down Expand Up @@ -1492,6 +1504,12 @@
]]></body>
</method>

<method name="debug">
<body><![CDATA[
gViewController.doCommand("cmd_debugItem", this.mAddon);
]]></body>
</method>

<method name="showPreferences">
<body><![CDATA[
gViewController.doCommand("cmd_showItemPreferences", this.mAddon);
Expand Down
6 changes: 6 additions & 0 deletions toolkit/mozapps/extensions/content/extensions.xul
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
<menuitem id="menuitem_uninstallItem" command="cmd_uninstallItem"
label="&cmd.uninstallAddon.label;"
accesskey="&cmd.uninstallAddon.accesskey;"/>
<menuitem id="menuitem_debugItem" command="cmd_debugItem"
label="&cmd.debugAddon.label;"/>
<menuseparator id="addonitem-menuseparator" />
<menuitem id="menuitem_preferences" command="cmd_showItemPreferences"
#ifdef XP_WIN
Expand Down Expand Up @@ -102,6 +104,7 @@
<command id="cmd_findItemUpdates"/>
<command id="cmd_showItemPreferences"/>
<command id="cmd_showItemAbout"/>
<command id="cmd_debugItem"/>
<command id="cmd_enableItem"/>
<command id="cmd_disableItem"/>
<command id="cmd_installItem"/>
Expand Down Expand Up @@ -604,6 +607,9 @@
#endif
command="cmd_showItemPreferences"/>
<spacer flex="1"/>
<button id="detail-debug-btn" class="addon-control debug"
label="Debug"
command="cmd_debugItem" />
<button id="detail-enable-btn" class="addon-control enable"
label="&cmd.enableAddon.label;"
accesskey="&cmd.enableAddon.accesskey;"
Expand Down
17 changes: 17 additions & 0 deletions toolkit/mozapps/extensions/test/addons/test_jetpack/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Components.utils.import("resource://gre/modules/Services.jsm");

function install(data, reason) {
Services.prefs.setIntPref("jetpacktest.installed_version", 1);
}

function startup(data, reason) {
Services.prefs.setIntPref("jetpacktest.active_version", 1);
}

function shutdown(data, reason) {
Services.prefs.setIntPref("jetpacktest.active_version", 0);
}

function uninstall(data, reason) {
Services.prefs.setIntPref("jetpacktest.installed_version", 0);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
28 changes: 28 additions & 0 deletions toolkit/mozapps/extensions/test/addons/test_jetpack/install.rdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0"?>

<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla.org/2004/em-rdf#">

<Description about="urn:mozilla:install-manifest">
<em:id>jetpack@tests.mozilla.org</em:id>
<em:version>1.0</em:version>
<em:bootstrap>true</em:bootstrap>

<!-- Front End MetaData -->
<em:name>Test jetpack</em:name>
<em:description>Test Description</em:description>

<em:iconURL>chrome://foo/skin/icon.png</em:iconURL>
<em:aboutURL>chrome://foo/content/about.xul</em:aboutURL>
<em:optionsURL>chrome://foo/content/options.xul</em:optionsURL>

<em:targetApplication>
<Description>
<em:id>xpcshell@tests.mozilla.org</em:id>
<em:minVersion>1</em:minVersion>
<em:maxVersion>1</em:maxVersion>
</Description>
</em:targetApplication>

</Description>
</RDF>
1 change: 1 addition & 0 deletions toolkit/mozapps/extensions/test/browser/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ MOCHITEST_BROWSER_MAIN_FILES = \
browser_bug679604.js \
browser_bug714593.js \
browser_bug590347.js \
browser_debug_button.js \
browser_details.js \
browser_discovery.js \
browser_dragdrop.js \
Expand Down
50 changes: 50 additions & 0 deletions toolkit/mozapps/extensions/test/browser/browser_debug_button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/

/**
* Tests debug button for addons in list view
*/

const getDebugButton = node =>
node.ownerDocument.getAnonymousElementByAttribute(node,
"anonid",
"debug-btn");

function test() {
requestLongerTimeout(2);

waitForExplicitFinish();


var gProvider = new MockProvider();
gProvider.createAddons([{
id: "non-debuggable@tests.mozilla.org",
name: "No debug",
description: "foo"
},
{
id: "debuggable@tests.mozilla.org",
name: "Debuggable",
description: "bar",
isDebuggable: true
}]);

// Enable add-on debugger
Services.prefs.setBoolPref("devtools.debugger.addon-enabled", true);

open_manager("addons://list/extension", function(aManager) {
const {document} = aManager;
const addonList = document.getElementById("addon-list");
const nondebug = addonList.querySelector("[name='No debug']");
const debuggable = addonList.querySelector("[name='Debuggable']");

is(getDebugButton(nondebug).disabled, true,
"button is disabled for legacy addons");

is(getDebugButton(debuggable).disabled, false,
"button is enabled for debuggable addons");

close_manager(aManager, finish);
});
}
1 change: 1 addition & 0 deletions toolkit/mozapps/extensions/test/browser/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,7 @@ function MockAddon(aId, aName, aType, aOperationsRequiringRestart) {
this.type = aType || "extension";
this.version = "";
this.isCompatible = true;
this.isDebuggable = false;
this.providesUpdatesSecurely = true;
this.blocklistState = 0;
this._appDisabled = false;
Expand Down
35 changes: 35 additions & 0 deletions toolkit/mozapps/extensions/test/xpcshell/test_isDebuggable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* 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/.
*/

var ADDONS = [
"test_bootstrap2_1", // restartless addon
"test_bootstrap1_4", // old-school addon
"test_jetpack" // sdk addon
];

var IDS = [
"bootstrap1@tests.mozilla.org",
"bootstrap2@tests.mozilla.org",
"jetpacktest@tests.mozilla.org"
];

function run_test() {
do_test_pending();
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2", "2");

startupManager();
AddonManager.checkCompatibility = false;

installAllFiles([do_get_addon(a) for each (a in ADDONS)], function() {
restartManager();

AddonManager.getAddonsByIDs(IDS, function([a1, a2, a3]) {
do_check_eq(a1.isDebuggable, false);
do_check_eq(a2.isDebuggable, false);
do_check_eq(a3.isDebuggable, true);
do_test_finished();
});
}, true);
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ skip-if = os == "android"
# Bug 676992: test consistently hangs on Android
skip-if = os == "android"
run-sequentially = Uses hardcoded ports in xpi files.
[test_isDebuggable.js]
[test_locale.js]
[test_locked.js]
[test_locked2.js]
Expand Down