Chromium Code Reviews| Index: Source/devtools/front_end/ui/Toolbar.js |
| diff --git a/Source/devtools/front_end/ui/Toolbar.js b/Source/devtools/front_end/ui/Toolbar.js |
| index 3720720fb16a54a16cca5ac7bd0707cf58c40c5c..f029408cea6d5f541f293b38a155f44cc2c7b976 100644 |
| --- a/Source/devtools/front_end/ui/Toolbar.js |
| +++ b/Source/devtools/front_end/ui/Toolbar.js |
| @@ -911,3 +911,83 @@ WebInspector.ToolbarStatesSettingButton.prototype = { |
| __proto__: WebInspector.ToolbarButton.prototype |
| } |
| + |
| +/** |
| + * @constructor |
| + * @extends {WebInspector.Toolbar} |
| + * @param {string} location |
| + * @param {!Element=} parentElement |
| + */ |
| +WebInspector.ExtensibleToolbar = function(location, parentElement) |
| +{ |
| + WebInspector.Toolbar.call(this, parentElement); |
| + this._loadItems(location); |
| +} |
| + |
| +WebInspector.ExtensibleToolbar.prototype = { |
| + |
|
dgozman
2015/04/23 14:09:36
nit: extra blank line
sergeyv
2015/04/23 17:42:12
Done.
|
| + /** |
| + * @param {string} location |
| + */ |
| + _loadItems: function(location) |
| + { |
| + var extensions = self.runtime.extensions(WebInspector.ToolbarItem.Provider); |
| + var promises = []; |
| + for (var i = 0; i < extensions.length; ++i) { |
| + if (extensions[i].descriptor()["location"] === location) |
| + promises.push(resolveItem(extensions[i])); |
| + } |
| + Promise.all(promises).then(appendItemsInOrder.bind(this)); |
| + |
| + /** |
| + * @param {!Runtime.Extension} extension |
| + * @return {!Promise.<?WebInspector.ToolbarItem>} |
| + */ |
| + function resolveItem(extension) |
| + { |
| + var descriptor = extension.descriptor(); |
| + if (!descriptor.className) |
| + return Promise.resolve(new WebInspector.ToolbarButton(WebInspector.UIString(descriptor["title"]), descriptor["elementClass"])).then(attachHandler); |
| + return extension.instancePromise().then(fetchItemFromProvider).then(attachHandler); |
| + |
| + /** |
| + * @param {!Object} provider |
| + */ |
| + function fetchItemFromProvider(provider) |
| + { |
| + return /** @type {!WebInspector.ToolbarItem.Provider} */ (provider).item(); |
| + } |
| + |
| + /** |
| + * @param {?WebInspector.ToolbarItem} item |
| + * @return {?WebInspector.ToolbarItem} item |
| + */ |
| + function attachHandler(item) |
| + { |
| + if (extension.descriptor()["actionId"] && item) |
| + item.addEventListener("click", handler); |
| + return item; |
| + } |
| + |
| + function handler() |
| + { |
| + WebInspector.actionRegistry.execute(extension.descriptor()["actionId"]); |
| + } |
| + } |
| + |
| + /** |
| + * @param {!Array.<?WebInspector.ToolbarItem>} items |
| + * @this {WebInspector.ExtensibleToolbar} |
| + */ |
| + function appendItemsInOrder(items) |
| + { |
| + for (var i = 0; i < items.length; ++i) { |
| + var item = items[i]; |
| + if (item) |
| + this.appendToolbarItem(item); |
| + } |
| + } |
| + }, |
| + |
| + __proto__: WebInspector.Toolbar.prototype |
| +} |