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 {!Map.<string, !Runtime.Extension>} */
11 this._actionsById
= new Map();
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
.set(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
).valuesArray().map(function(extension
) {
47 return extension
.descriptor()["actionId"];
52 * @param {string} actionId
53 * @return {!Promise.<undefined>}
55 execute: function(actionId
)
57 var extension
= this._actionsById
.get(actionId
);
58 console
.assert(extension
, "No action found for actionId '" + actionId
+ "'");
59 return extension
.instancePromise().then(handleAction
);
62 * @param {!Object} actionDelegate
64 function handleAction(actionDelegate
)
66 /** @type {!WebInspector.ActionDelegate} */(actionDelegate
).handleAction(WebInspector
.context
, actionId
);
71 * @param {string} actionId
74 actionTitle: function(actionId
)
76 var extension
= this._actionsById
.get(actionId
);
77 console
.assert(extension
, "No action found for actionId '" + actionId
+ "'");
78 return extension
.descriptor()["title"] || "";
82 * @param {string} actionId
85 actionIcon: function(actionId
)
87 var extension
= this._actionsById
.get(actionId
);
88 console
.assert(extension
, "No action found for actionId '" + actionId
+ "'");
89 return extension
.descriptor()["iconClass"] || "";
96 WebInspector
.ActionDelegate = function()
100 WebInspector
.ActionDelegate
.prototype = {
102 * @param {!WebInspector.Context} context
103 * @param {string} actionId
105 handleAction: function(context
, actionId
) {}
108 /** @type {!WebInspector.ActionRegistry} */
109 WebInspector
.actionRegistry
;