Chromium Code Reviews| Index: Source/devtools/front_end/ModuleManager.js |
| diff --git a/Source/devtools/front_end/ModuleManager.js b/Source/devtools/front_end/ModuleManager.js |
| index 7724d15c4131560004db64a0d0b84c03d57ff23d..8edac0a3e7259149911f38af9700f198602a4ae1 100644 |
| --- a/Source/devtools/front_end/ModuleManager.js |
| +++ b/Source/devtools/front_end/ModuleManager.js |
| @@ -60,6 +60,72 @@ WebInspector.ModuleManager = function(descriptors) |
| this._descriptorsMap[descriptors[i]["name"]] = descriptors[i]; |
| } |
| +/** |
| + * @param {!WebInspector.ModuleManager.Extension} extension |
| + * @param {?function(!Function):boolean} predicate |
| + */ |
| +WebInspector.ModuleManager._checkExtensionApplicability = function(extension, predicate) |
| +{ |
| + if (!predicate) |
| + return false; |
| + var contextTypes = /** @type {!Array.<string>|undefined} */ (extension.descriptor().contextTypes); |
| + if (!contextTypes) |
| + return true; |
| + var conjunction = !!extension.descriptor()["contextTypeConjunction"]; |
|
pfeldman
2014/04/17 10:40:25
I don't see it used. Lets not add it for now.
apavlov
2014/04/17 12:42:22
Done.
|
| + for (var i = 0; i < contextTypes.length; ++i) { |
| + var contextType = /** @type {!Function} */ (window.eval(contextTypes[i])); |
| + var isMatching = predicate(contextType); |
| + if (conjunction && !isMatching) |
| + return false; |
| + if (!conjunction && isMatching) |
| + return true; |
| + } |
| + return conjunction; |
| +} |
| + |
| +/** |
| + * @param {!WebInspector.ModuleManager.Extension} extension |
| + * @param {?Object} context |
| + * @return {boolean} |
| + */ |
| +WebInspector.ModuleManager.isExtensionApplicableToContext = function(extension, context) |
| +{ |
| + if (!context) |
| + return true; |
| + return WebInspector.ModuleManager._checkExtensionApplicability(extension, isInstanceOf); |
| + |
| + /** |
| + * @param {!Function} targetType |
| + * @return {boolean} |
| + */ |
| + function isInstanceOf(targetType) |
| + { |
| + return context instanceof targetType; |
| + } |
| +} |
| + |
| +/** |
| + * @param {!WebInspector.ModuleManager.Extension} extension |
| + * @param {!Set.<!Function>=} currentContextTypes |
| + * @return {boolean} |
| + */ |
| +WebInspector.ModuleManager.isExtensionApplicableToContextTypes = function(extension, currentContextTypes) |
| +{ |
| + if (!extension.descriptor().contextTypes) |
| + return true; |
| + |
| + return WebInspector.ModuleManager._checkExtensionApplicability(extension, currentContextTypes ? isContextTypeKnown : null); |
| + |
| + /** |
| + * @param {!Function} targetType |
| + * @return {boolean} |
| + */ |
| + function isContextTypeKnown(targetType) |
| + { |
| + return currentContextTypes.contains(targetType); |
| + } |
| +} |
| + |
| WebInspector.ModuleManager.prototype = { |
| /** |
| * @param {!Array.<string>} configuration |
| @@ -338,15 +404,7 @@ WebInspector.ModuleManager.Extension.prototype = { |
| */ |
| isApplicable: function(context) |
| { |
| - var contextTypes = /** @type {!Array.<string>|undefined} */ (this._descriptor.contextTypes); |
| - if (!contextTypes) |
| - return true; |
| - for (var i = 0; i < contextTypes.length; ++i) { |
| - var contextType = /** @type {!Function} */ (window.eval(contextTypes[i])); |
| - if (context instanceof contextType) |
| - return true; |
| - } |
| - return false; |
| + return WebInspector.ModuleManager.isExtensionApplicableToContext(this, context); |
| }, |
| /** |
| @@ -412,19 +470,4 @@ WebInspector.Revealer.prototype = { |
| reveal: function(object) {} |
| } |
| -/** |
| - * @interface |
| - */ |
| -WebInspector.ActionDelegate = function() |
| -{ |
| -} |
| - |
| -WebInspector.ActionDelegate.prototype = { |
| - /** |
| - * @param {!Event} event |
| - * @return {boolean} |
| - */ |
| - handleAction: function(event) {} |
| -} |
| - |
| WebInspector.moduleManager = new WebInspector.ModuleManager(allDescriptors); |