[TychoAM] Make the Add-ons Manager conditionally devtools free

This commit is contained in:
NTD 2018-05-01 16:14:17 -04:00 • committed by Roy Tam
commit c9446a4319
4 changed files with 27 additions and 0 deletions

View file

@ -18,10 +18,12 @@ Cu.import("resource://gre/modules/addons/AddonRepository.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PluralForm", XPCOMUtils.defineLazyModuleGetter(this, "PluralForm",
"resource://gre/modules/PluralForm.jsm"); "resource://gre/modules/PluralForm.jsm");
#ifdef MOZ_DEVTOOLS
XPCOMUtils.defineLazyGetter(this, "BrowserToolboxProcess", function () { XPCOMUtils.defineLazyGetter(this, "BrowserToolboxProcess", function () {
return Cu.import("resource://devtools/client/framework/ToolboxProcess.jsm", {}). return Cu.import("resource://devtools/client/framework/ToolboxProcess.jsm", {}).
BrowserToolboxProcess; BrowserToolboxProcess;
}); });
#endif
const PREF_DISCOVERURL = "extensions.webservice.discoverURL"; const PREF_DISCOVERURL = "extensions.webservice.discoverURL";
const PREF_DISCOVER_ENABLED = "extensions.getAddons.showPane"; const PREF_DISCOVER_ENABLED = "extensions.getAddons.showPane";
@ -1002,6 +1004,7 @@ var gViewController = {
} }
}, },
#ifdef MOZ_DEVTOOLS
cmd_debugItem: { cmd_debugItem: {
doCommand: function cmd_debugItem_doCommand(aAddon) { doCommand: function cmd_debugItem_doCommand(aAddon) {
BrowserToolboxProcess.init({ addonID: aAddon.id }); BrowserToolboxProcess.init({ addonID: aAddon.id });
@ -1015,6 +1018,7 @@ var gViewController = {
return aAddon && aAddon.isDebuggable && debuggerEnabled && remoteEnabled; return aAddon && aAddon.isDebuggable && debuggerEnabled && remoteEnabled;
} }
}, },
#endif
cmd_showItemPreferences: { cmd_showItemPreferences: {
isEnabled: function cmd_showItemPreferences_isEnabled(aAddon) { isEnabled: function cmd_showItemPreferences_isEnabled(aAddon) {

View file

@ -1628,11 +1628,13 @@
]]></body> ]]></body>
</method> </method>
#ifdef MOZ_DEVTOOLS
<method name="debug"> <method name="debug">
<body><![CDATA[ <body><![CDATA[
gViewController.doCommand("cmd_debugItem", this.mAddon); gViewController.doCommand("cmd_debugItem", this.mAddon);
]]></body> ]]></body>
</method> </method>
#endif
<method name="showPreferences"> <method name="showPreferences">
<body><![CDATA[ <body><![CDATA[

View file

@ -53,8 +53,10 @@
<menuitem id="menuitem_uninstallItem" command="cmd_uninstallItem" <menuitem id="menuitem_uninstallItem" command="cmd_uninstallItem"
label="&cmd.uninstallAddon.label;" label="&cmd.uninstallAddon.label;"
accesskey="&cmd.uninstallAddon.accesskey;"/> accesskey="&cmd.uninstallAddon.accesskey;"/>
#ifdef MOZ_DEVTOOLS
<menuitem id="menuitem_debugItem" command="cmd_debugItem" <menuitem id="menuitem_debugItem" command="cmd_debugItem"
label="&cmd.debugAddon.label;"/> label="&cmd.debugAddon.label;"/>
#endif
<menuseparator id="addonitem-menuseparator" /> <menuseparator id="addonitem-menuseparator" />
<menuitem id="menuitem_preferences" command="cmd_showItemPreferences" <menuitem id="menuitem_preferences" command="cmd_showItemPreferences"
#ifdef XP_WIN #ifdef XP_WIN
@ -101,7 +103,9 @@
<command id="cmd_findItemUpdates"/> <command id="cmd_findItemUpdates"/>
<command id="cmd_showItemPreferences"/> <command id="cmd_showItemPreferences"/>
<command id="cmd_showItemAbout"/> <command id="cmd_showItemAbout"/>
#ifdef MOZ_DEVTOOLS
<command id="cmd_debugItem"/> <command id="cmd_debugItem"/>
#endif
<command id="cmd_enableItem"/> <command id="cmd_enableItem"/>
<command id="cmd_disableItem"/> <command id="cmd_disableItem"/>
<command id="cmd_installItem"/> <command id="cmd_installItem"/>
@ -631,9 +635,11 @@
#endif #endif
command="cmd_showItemPreferences"/> command="cmd_showItemPreferences"/>
<spacer flex="1"/> <spacer flex="1"/>
#ifdef MOZ_DEVTOOLS
<button id="detail-debug-btn" class="addon-control debug" <button id="detail-debug-btn" class="addon-control debug"
label="Debug" label="Debug"
command="cmd_debugItem" /> command="cmd_debugItem" />
#endif
<button id="detail-enable-btn" class="addon-control enable" <button id="detail-enable-btn" class="addon-control enable"
label="&cmd.enableAddon.label;" label="&cmd.enableAddon.label;"
accesskey="&cmd.enableAddon.accesskey;" accesskey="&cmd.enableAddon.accesskey;"

View file

@ -36,8 +36,10 @@ XPCOMUtils.defineLazyModuleGetter(this, "Task",
"resource://gre/modules/Task.jsm"); "resource://gre/modules/Task.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "OS", XPCOMUtils.defineLazyModuleGetter(this, "OS",
"resource://gre/modules/osfile.jsm"); "resource://gre/modules/osfile.jsm");
#ifdef MOZ_DEVTOOLS
XPCOMUtils.defineLazyModuleGetter(this, "BrowserToolboxProcess", XPCOMUtils.defineLazyModuleGetter(this, "BrowserToolboxProcess",
"resource://devtools/client/framework/ToolboxProcess.jsm"); "resource://devtools/client/framework/ToolboxProcess.jsm");
#endif
XPCOMUtils.defineLazyModuleGetter(this, "ConsoleAPI", XPCOMUtils.defineLazyModuleGetter(this, "ConsoleAPI",
"resource://gre/modules/Console.jsm"); "resource://gre/modules/Console.jsm");
@ -138,7 +140,9 @@ const FIREFOX_APPCOMPATVERSION = "56.9"
// The value for this is in Makefile.in // The value for this is in Makefile.in
#expand const DB_SCHEMA = __MOZ_EXTENSIONS_DB_SCHEMA__; #expand const DB_SCHEMA = __MOZ_EXTENSIONS_DB_SCHEMA__;
#ifdef MOZ_DEVTOOLS
const NOTIFICATION_TOOLBOXPROCESS_LOADED = "ToolboxProcessLoaded"; const NOTIFICATION_TOOLBOXPROCESS_LOADED = "ToolboxProcessLoaded";
#endif
// Properties that exist in the install manifest // Properties that exist in the install manifest
const PROP_METADATA = ["id", "version", "type", "internalName", "updateURL", const PROP_METADATA = ["id", "version", "type", "internalName", "updateURL",
@ -1846,8 +1850,10 @@ this.XPIProvider = {
_enabledExperiments: null, _enabledExperiments: null,
// A Map from an add-on install to its ID // A Map from an add-on install to its ID
_addonFileMap: new Map(), _addonFileMap: new Map(),
#ifdef MOZ_DEVTOOLS
// Flag to know if ToolboxProcess.jsm has already been loaded by someone or not // Flag to know if ToolboxProcess.jsm has already been loaded by someone or not
_toolboxProcessLoaded: false, _toolboxProcessLoaded: false,
#endif
// Have we started shutting down bootstrap add-ons? // Have we started shutting down bootstrap add-ons?
_closing: false, _closing: false,
@ -2083,6 +2089,8 @@ this.XPIProvider = {
Services.prefs.addObserver(PREF_EM_MIN_COMPAT_APP_VERSION, this, false); Services.prefs.addObserver(PREF_EM_MIN_COMPAT_APP_VERSION, this, false);
Services.prefs.addObserver(PREF_EM_MIN_COMPAT_PLATFORM_VERSION, this, false); Services.prefs.addObserver(PREF_EM_MIN_COMPAT_PLATFORM_VERSION, this, false);
Services.obs.addObserver(this, NOTIFICATION_FLUSH_PERMISSIONS, false); Services.obs.addObserver(this, NOTIFICATION_FLUSH_PERMISSIONS, false);
#ifdef MOZ_DEVTOOLS
if (Cu.isModuleLoaded("resource://devtools/client/framework/ToolboxProcess.jsm")) { if (Cu.isModuleLoaded("resource://devtools/client/framework/ToolboxProcess.jsm")) {
// If BrowserToolboxProcess is already loaded, set the boolean to true // If BrowserToolboxProcess is already loaded, set the boolean to true
// and do whatever is needed // and do whatever is needed
@ -2094,6 +2102,7 @@ this.XPIProvider = {
// Else, wait for it to load // Else, wait for it to load
Services.obs.addObserver(this, NOTIFICATION_TOOLBOXPROCESS_LOADED, false); Services.obs.addObserver(this, NOTIFICATION_TOOLBOXPROCESS_LOADED, false);
} }
#endif
let flushCaches = this.checkForChanges(aAppChanged, aOldAppVersion, let flushCaches = this.checkForChanges(aAppChanged, aOldAppVersion,
aOldPlatformVersion); aOldPlatformVersion);
@ -4088,12 +4097,14 @@ this.XPIProvider = {
} }
return; return;
} }
#ifdef MOZ_DEVTOOLS
else if (aTopic == NOTIFICATION_TOOLBOXPROCESS_LOADED) { else if (aTopic == NOTIFICATION_TOOLBOXPROCESS_LOADED) {
Services.obs.removeObserver(this, NOTIFICATION_TOOLBOXPROCESS_LOADED, false); Services.obs.removeObserver(this, NOTIFICATION_TOOLBOXPROCESS_LOADED, false);
this._toolboxProcessLoaded = true; this._toolboxProcessLoaded = true;
BrowserToolboxProcess.on("connectionchange", BrowserToolboxProcess.on("connectionchange",
this.onDebugConnectionChange.bind(this)); this.onDebugConnectionChange.bind(this));
} }
#endif
if (aTopic == "nsPref:changed") { if (aTopic == "nsPref:changed") {
switch (aData) { switch (aData) {
@ -4358,12 +4369,14 @@ this.XPIProvider = {
logger.warn("Error loading bootstrap.js for " + aId, e); logger.warn("Error loading bootstrap.js for " + aId, e);
} }
#ifdef MOZ_DEVTOOLS
// Only access BrowserToolboxProcess if ToolboxProcess.jsm has been // Only access BrowserToolboxProcess if ToolboxProcess.jsm has been
// initialized as otherwise, when it will be initialized, all addons' // initialized as otherwise, when it will be initialized, all addons'
// globals will be added anyways // globals will be added anyways
if (this._toolboxProcessLoaded) { if (this._toolboxProcessLoaded) {
BrowserToolboxProcess.setAddonOptions(aId, { global: this.bootstrapScopes[aId] }); BrowserToolboxProcess.setAddonOptions(aId, { global: this.bootstrapScopes[aId] });
} }
#endif
}, },
/** /**
@ -4383,11 +4396,13 @@ this.XPIProvider = {
this.persistBootstrappedAddons(); this.persistBootstrappedAddons();
this.addAddonsToCrashReporter(); this.addAddonsToCrashReporter();
#ifdef MOZ_DEVTOOLS
// Only access BrowserToolboxProcess if ToolboxProcess.jsm has been // Only access BrowserToolboxProcess if ToolboxProcess.jsm has been
// initialized as otherwise, there won't be any addon globals added to it // initialized as otherwise, there won't be any addon globals added to it
if (this._toolboxProcessLoaded) { if (this._toolboxProcessLoaded) {
BrowserToolboxProcess.setAddonOptions(aId, { global: null }); BrowserToolboxProcess.setAddonOptions(aId, { global: null });
} }
#endif
}, },
/** /**