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..8bc9a16f7bc06a06cb2611c906e91f2786789677 100644 |
--- a/Source/devtools/front_end/ui/Toolbar.js |
+++ b/Source/devtools/front_end/ui/Toolbar.js |
@@ -911,3 +911,82 @@ 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 = { |
+ /** |
+ * @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 |
+} |