1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 WebInspector.ActionRegistry = function()
10 /** @type {!StringMap.<!Runtime.Extension>} */
11 this._actionsById = new StringMap();
12 this._registerActions();
15 WebInspector.ActionRegistry.prototype = {
16 _registerActions: function()
18 self.runtime.extensions(WebInspector.ActionDelegate).forEach(registerExtension, this);
21 * @param {!Runtime.Extension} extension
22 * @this {WebInspector.ActionRegistry}
24 function registerExtension(extension)
26 var actionId = extension.descriptor()["actionId"];
27 console.assert(actionId);
28 console.assert(!this._actionsById.get(actionId));
29 this._actionsById.put(actionId, extension);
34 * @param {!Array.<string>} actionIds
35 * @param {!WebInspector.Context} context
36 * @return {!Array.<string>}
38 applicableActions: function(actionIds, context)
41 actionIds.forEach(function(actionId) {
42 var extension = this._actionsById.get(actionId);
44 extensions.push(extension);
46 return context.applicableExtensions(extensions).values().map(function(extension) {
47 return extension.descriptor()["actionId"];
52 * @param {string} actionId
55 execute: function(actionId)
57 var extension = this._actionsById.get(actionId);
58 console.assert(extension, "No action found for actionId '" + actionId + "'");
59 return extension.instance().handleAction(WebInspector.context);
66 WebInspector.ActionDelegate = function()
70 WebInspector.ActionDelegate.prototype = {
72 * @param {!WebInspector.Context} context
75 handleAction: function(context) {}
78 /** @type {!WebInspector.ActionRegistry} */
79 WebInspector.actionRegistry;