Bug 1498917 - Make ext-sidebarAction.js consistent with ext-browserAction.js after Bug 1498917. r=mixedpuppy

Differential Revision: https://phabricator.services.mozilla.com/D8676

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Oriol Brufau 2018-10-15 17:05:15 +00:00
Родитель 0e8cef431d
Коммит 6133d88831
1 изменённых файлов: 46 добавлений и 32 удалений

Просмотреть файл

@ -268,50 +268,56 @@ this.sidebarAction = class extends ExtensionAPI {
}
/**
* Gets the target object and its associated values corresponding to
* the `details` parameter of the various get* and set* API methods.
* Gets the target object corresponding to the `details` parameter of the various
* get* and set* API methods.
*
* @param {Object} details
* An object with optional `tabId` or `windowId` properties.
* @throws if both `tabId` and `windowId` are specified, or if they are invalid.
* @returns {Object}
* An object with two properties: `target` and `values`.
* - If a `tabId` was specified, `target` will be the corresponding
* XULElement tab. If a `windowId` was specified, `target` will be
* the corresponding ChromeWindow. Otherwise it will be `null`.
* - `values` will contain the icon, title and panel associated with
* the target.
* @returns {XULElement|ChromeWindow|null}
* If a `tabId` was specified, the corresponding XULElement tab.
* If a `windowId` was specified, the corresponding ChromeWindow.
* Otherwise, `null`.
*/
getContextData({tabId, windowId}) {
getTargetFromDetails({tabId, windowId}) {
if (tabId != null && windowId != null) {
throw new ExtensionError("Only one of tabId and windowId can be specified.");
}
let target, values;
if (tabId != null) {
target = tabTracker.getTab(tabId);
values = this.tabContext.get(target);
return tabTracker.getTab(tabId);
} else if (windowId != null) {
target = windowTracker.getWindow(windowId);
values = this.tabContext.get(target);
} else {
target = null;
values = this.globals;
return windowTracker.getWindow(windowId);
}
return {target, values};
return null;
}
/**
* Gets the data associated with a tab, window, or the global one.
*
* @param {XULElement|ChromeWindow|null} target
* A XULElement tab, a ChromeWindow, or null for the global data.
* @returns {Object}
* The icon, title, panel, etc. associated with the target.
*/
getContextData(target) {
if (target) {
return this.tabContext.get(target);
}
return this.globals;
}
/**
* Set a global, window specific or tab specific property.
*
* @param {Object} details
* An object with optional `tabId` or `windowId` properties.
* @param {XULElement|ChromeWindow|null} target
* A XULElement tab, a ChromeWindow, or null for the global data.
* @param {string} prop
* String property to set ["icon", "title", or "panel"].
* @param {string} value
* Value for property.
*/
setProperty(details, prop, value) {
let {target, values} = this.getContextData(details);
setProperty(target, prop, value) {
let values = this.getContextData(target);
if (value === null) {
delete values[prop];
} else {
@ -324,15 +330,23 @@ this.sidebarAction = class extends ExtensionAPI {
/**
* Retrieve the value of a global, window specific or tab specific property.
*
* @param {Object} details
* An object with optional `tabId` or `windowId` properties.
* @param {XULElement|ChromeWindow|null} target
* A XULElement tab, a ChromeWindow, or null for the global data.
* @param {string} prop
* String property to retrieve ["icon", "title", or "panel"]
* @returns {string} value
* Value of prop.
*/
getProperty(details, prop) {
return this.getContextData(details).values[prop];
getProperty(target, prop) {
return this.getContextData(target)[prop];
}
setPropertyFromDetails(details, prop, value) {
return this.setProperty(this.getTargetFromDetails(details), prop, value);
}
getPropertyFromDetails(details, prop) {
return this.getProperty(this.getTargetFromDetails(details), prop);
}
/**
@ -389,11 +403,11 @@ this.sidebarAction = class extends ExtensionAPI {
return {
sidebarAction: {
async setTitle(details) {
sidebarAction.setProperty(details, "title", details.title);
sidebarAction.setPropertyFromDetails(details, "title", details.title);
},
getTitle(details) {
return sidebarAction.getProperty(details, "title");
return sidebarAction.getPropertyFromDetails(details, "title");
},
async setIcon(details) {
@ -401,7 +415,7 @@ this.sidebarAction = class extends ExtensionAPI {
if (!Object.keys(icon).length) {
icon = null;
}
sidebarAction.setProperty(details, "icon", icon);
sidebarAction.setPropertyFromDetails(details, "icon", icon);
},
async setPanel(details) {
@ -416,11 +430,11 @@ this.sidebarAction = class extends ExtensionAPI {
}
}
sidebarAction.setProperty(details, "panel", url);
sidebarAction.setPropertyFromDetails(details, "panel", url);
},
getPanel(details) {
return sidebarAction.getProperty(details, "panel");
return sidebarAction.getPropertyFromDetails(details, "panel");
},
open() {