mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-02 15:15:23 +00:00
7814d5af7a
MozReview-Commit-ID: Lh2iwPgmlhU --HG-- extra : transplant_source : %D4zhF%D7F%CA%07UIC%E8yB%E05%7B%EB%F6t
130 lines
3.4 KiB
JavaScript
130 lines
3.4 KiB
JavaScript
/* 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 { AddonManager } = require("resource://gre/modules/AddonManager.jsm");
|
|
const { createFactory, createClass, DOM: dom } =
|
|
require("devtools/client/shared/vendor/react");
|
|
const Services = require("Services");
|
|
|
|
const AddonsControls = createFactory(require("./addons-controls"));
|
|
const AddonTarget = createFactory(require("./addon-target"));
|
|
const TabHeader = createFactory(require("./tab-header"));
|
|
const TargetList = createFactory(require("./target-list"));
|
|
|
|
const Strings = Services.strings.createBundle(
|
|
"chrome://devtools/locale/aboutdebugging.properties");
|
|
|
|
const ExtensionIcon = "chrome://mozapps/skin/extensions/extensionGeneric.svg";
|
|
const CHROME_ENABLED_PREF = "devtools.chrome.enabled";
|
|
const REMOTE_ENABLED_PREF = "devtools.debugger.remote-enabled";
|
|
|
|
module.exports = createClass({
|
|
displayName: "AddonsTab",
|
|
|
|
getInitialState() {
|
|
return {
|
|
extensions: [],
|
|
debugDisabled: false,
|
|
};
|
|
},
|
|
|
|
componentDidMount() {
|
|
AddonManager.addAddonListener(this);
|
|
|
|
Services.prefs.addObserver(CHROME_ENABLED_PREF,
|
|
this.updateDebugStatus, false);
|
|
Services.prefs.addObserver(REMOTE_ENABLED_PREF,
|
|
this.updateDebugStatus, false);
|
|
|
|
this.updateDebugStatus();
|
|
this.updateAddonsList();
|
|
},
|
|
|
|
componentWillUnmount() {
|
|
AddonManager.removeAddonListener(this);
|
|
Services.prefs.removeObserver(CHROME_ENABLED_PREF,
|
|
this.updateDebugStatus);
|
|
Services.prefs.removeObserver(REMOTE_ENABLED_PREF,
|
|
this.updateDebugStatus);
|
|
},
|
|
|
|
updateDebugStatus() {
|
|
let debugDisabled =
|
|
!Services.prefs.getBoolPref(CHROME_ENABLED_PREF) ||
|
|
!Services.prefs.getBoolPref(REMOTE_ENABLED_PREF);
|
|
|
|
this.setState({ debugDisabled });
|
|
},
|
|
|
|
updateAddonsList() {
|
|
this.props.client.listAddons()
|
|
.then(({addons}) => {
|
|
let extensions = addons.filter(addon => addon.debuggable).map(addon => {
|
|
return {
|
|
name: addon.name,
|
|
icon: addon.iconURL || ExtensionIcon,
|
|
addonID: addon.id,
|
|
addonActor: addon.actor
|
|
};
|
|
});
|
|
|
|
this.setState({ extensions });
|
|
}, error => {
|
|
throw new Error("Client error while listing addons: " + error);
|
|
});
|
|
},
|
|
|
|
/**
|
|
* Mandatory callback as AddonManager listener.
|
|
*/
|
|
onInstalled() {
|
|
this.updateAddonsList();
|
|
},
|
|
|
|
/**
|
|
* Mandatory callback as AddonManager listener.
|
|
*/
|
|
onUninstalled() {
|
|
this.updateAddonsList();
|
|
},
|
|
|
|
/**
|
|
* Mandatory callback as AddonManager listener.
|
|
*/
|
|
onEnabled() {
|
|
this.updateAddonsList();
|
|
},
|
|
|
|
/**
|
|
* Mandatory callback as AddonManager listener.
|
|
*/
|
|
onDisabled() {
|
|
this.updateAddonsList();
|
|
},
|
|
|
|
render() {
|
|
let { client } = this.props;
|
|
let { debugDisabled, extensions: targets } = this.state;
|
|
let name = Strings.GetStringFromName("extensions");
|
|
let targetClass = AddonTarget;
|
|
|
|
return dom.div({
|
|
id: "tab-addons",
|
|
className: "tab",
|
|
role: "tabpanel",
|
|
"aria-labelledby": "tab-addons-header-name"
|
|
},
|
|
TabHeader({
|
|
id: "tab-addons-header-name",
|
|
name: Strings.GetStringFromName("addons")
|
|
}),
|
|
AddonsControls({ debugDisabled }),
|
|
dom.div({ id: "addons" },
|
|
TargetList({ name, targets, client, debugDisabled, targetClass })
|
|
));
|
|
}
|
|
});
|