Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: Source/devtools/front_end/common/ModuleManager.js

Issue 268293003: DevTools: Get rid of WebInspector.panels (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 this._cachedTypeClasses = {}; 53 this._cachedTypeClasses = {};
54 54
55 /** 55 /**
56 * @type {!Object.<string, !WebInspector.ModuleManager.ModuleDescriptor>} 56 * @type {!Object.<string, !WebInspector.ModuleManager.ModuleDescriptor>}
57 */ 57 */
58 this._descriptorsMap = {}; 58 this._descriptorsMap = {};
59 for (var i = 0; i < descriptors.length; ++i) 59 for (var i = 0; i < descriptors.length; ++i)
60 this._descriptorsMap[descriptors[i]["name"]] = descriptors[i]; 60 this._descriptorsMap[descriptors[i]["name"]] = descriptors[i];
61 } 61 }
62 62
63 /**
64 * @param {!WebInspector.ModuleManager.Extension} extension
65 * @param {?function(!Function):boolean} predicate
66 */
67 WebInspector.ModuleManager._checkExtensionApplicability = function(extension, pr edicate)
68 {
69 if (!predicate)
70 return false;
71 var contextTypes = /** @type {!Array.<string>|undefined} */ (extension.descr iptor().contextTypes);
72 if (!contextTypes)
73 return true;
74 for (var i = 0; i < contextTypes.length; ++i) {
75 var contextType = /** @type {!Function} */ (window.eval(contextTypes[i]) );
76 var isMatching = predicate(contextType);
77 if (isMatching)
78 return true;
79 }
80 return false;
81 }
82
83 /**
84 * @param {!WebInspector.ModuleManager.Extension} extension
85 * @param {?Object} context
86 * @return {boolean}
87 */
88 WebInspector.ModuleManager.isExtensionApplicableToContext = function(extension, context)
89 {
90 if (!context)
91 return true;
92 return WebInspector.ModuleManager._checkExtensionApplicability(extension, is InstanceOf);
93
94 /**
95 * @param {!Function} targetType
96 * @return {boolean}
97 */
98 function isInstanceOf(targetType)
99 {
100 return context instanceof targetType;
101 }
102 }
103
104 /**
105 * @param {!WebInspector.ModuleManager.Extension} extension
106 * @param {!Set.<!Function>=} currentContextTypes
107 * @return {boolean}
108 */
109 WebInspector.ModuleManager.isExtensionApplicableToContextTypes = function(extens ion, currentContextTypes)
110 {
111 if (!extension.descriptor().contextTypes)
112 return true;
113
114 return WebInspector.ModuleManager._checkExtensionApplicability(extension, cu rrentContextTypes ? isContextTypeKnown : null);
115
116 /**
117 * @param {!Function} targetType
118 * @return {boolean}
119 */
120 function isContextTypeKnown(targetType)
121 {
122 return currentContextTypes.contains(targetType);
123 }
124 }
125
126 WebInspector.ModuleManager.prototype = { 63 WebInspector.ModuleManager.prototype = {
127 /** 64 /**
128 * @param {!Array.<string>} configuration 65 * @param {!Array.<string>} configuration
129 */ 66 */
130 registerModules: function(configuration) 67 registerModules: function(configuration)
131 { 68 {
132 for (var i = 0; i < configuration.length; ++i) 69 for (var i = 0; i < configuration.length; ++i)
133 this.registerModule(configuration[i]); 70 this.registerModule(configuration[i]);
134 }, 71 },
135 72
(...skipping 17 matching lines...) Expand all
153 90
154 /** 91 /**
155 * @param {string} moduleName 92 * @param {string} moduleName
156 */ 93 */
157 loadModule: function(moduleName) 94 loadModule: function(moduleName)
158 { 95 {
159 this._modulesMap[moduleName]._load(); 96 this._modulesMap[moduleName]._load();
160 }, 97 },
161 98
162 /** 99 /**
100 * @param {!WebInspector.ModuleManager.Extension} extension
101 * @param {?function(function(new:Object)):boolean} predicate
102 * @return {boolean}
103 */
104 _checkExtensionApplicability: function(extension, predicate)
105 {
106 if (!predicate)
107 return false;
108 var contextTypes = /** @type {!Array.<string>|undefined} */ (extension.d escriptor().contextTypes);
109 if (!contextTypes)
110 return true;
111 for (var i = 0; i < contextTypes.length; ++i) {
112 var contextType = this._resolve(contextTypes[i]);
113 var isMatching = !!contextType && predicate(contextType);
114 if (isMatching)
115 return true;
116 }
117 return false;
118 },
119
120 /**
121 * @param {!WebInspector.ModuleManager.Extension} extension
122 * @param {?Object} context
123 * @return {boolean}
124 */
125 isExtensionApplicableToContext: function(extension, context)
126 {
127 if (!context)
128 return true;
129 return this._checkExtensionApplicability(extension, isInstanceOf);
130
131 /**
132 * @param {!Function} targetType
133 * @return {boolean}
134 */
135 function isInstanceOf(targetType)
136 {
137 return context instanceof targetType;
138 }
139 },
140
141 /**
142 * @param {!WebInspector.ModuleManager.Extension} extension
143 * @param {!Set.<!Function>=} currentContextTypes
144 * @return {boolean}
145 */
146 isExtensionApplicableToContextTypes: function(extension, currentContextTypes )
147 {
148 if (!extension.descriptor().contextTypes)
149 return true;
150
151 return this._checkExtensionApplicability(extension, currentContextTypes ? isContextTypeKnown : null);
152
153 /**
154 * @param {!Function} targetType
155 * @return {boolean}
156 */
157 function isContextTypeKnown(targetType)
158 {
159 return currentContextTypes.contains(targetType);
160 }
161 },
162
163 /**
163 * @param {string|!Function} type 164 * @param {string|!Function} type
164 * @param {?Object=} context 165 * @param {?Object=} context
165 * @return {!Array.<!WebInspector.ModuleManager.Extension>} 166 * @return {!Array.<!WebInspector.ModuleManager.Extension>}
166 */ 167 */
167 extensions: function(type, context) 168 extensions: function(type, context)
168 { 169 {
169 /** 170 /**
170 * @param {!WebInspector.ModuleManager.Extension} extension 171 * @param {!WebInspector.ModuleManager.Extension} extension
171 * @return {boolean} 172 * @return {boolean}
172 */ 173 */
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 if (name2 in orderForName) 247 if (name2 in orderForName)
247 return 1; 248 return 1;
248 return name1.compareTo(name2); 249 return name1.compareTo(name2);
249 } 250 }
250 return result; 251 return result;
251 }, 252 },
252 253
253 /** 254 /**
254 * @return {?function(new:Object)} 255 * @return {?function(new:Object)}
255 */ 256 */
256 resolve: function(typeName) 257 _resolve: function(typeName)
257 { 258 {
258 if (!this._cachedTypeClasses[typeName]) { 259 if (!this._cachedTypeClasses[typeName]) {
259 var path = typeName.substring(1).split("."); 260 var path = typeName.split(".");
260 var object = window; 261 var object = window;
261 for (var i = 0; object && (i < path.length); ++i) 262 for (var i = 0; object && (i < path.length); ++i)
262 object = object[path[i]]; 263 object = object[path[i]];
263 if (object) 264 if (object)
264 this._cachedTypeClasses[typeName] = /** @type function(new:Objec t) */(object); 265 this._cachedTypeClasses[typeName] = /** @type function(new:Objec t) */(object);
265 } 266 }
266 return this._cachedTypeClasses[typeName]; 267 return this._cachedTypeClasses[typeName];
267 } 268 }
268
269 } 269 }
270 270
271 /** 271 /**
272 * @constructor 272 * @constructor
273 */ 273 */
274 WebInspector.ModuleManager.ModuleDescriptor = function() 274 WebInspector.ModuleManager.ModuleDescriptor = function()
275 { 275 {
276 /** 276 /**
277 * @type {string} 277 * @type {string}
278 */ 278 */
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 return this._module; 401 return this._module;
402 }, 402 },
403 403
404 /** 404 /**
405 * @return {?function(new:Object)} 405 * @return {?function(new:Object)}
406 */ 406 */
407 _typeClass: function() 407 _typeClass: function()
408 { 408 {
409 if (!this._hasTypeClass) 409 if (!this._hasTypeClass)
410 return null; 410 return null;
411 return this._module._manager.resolve(this._type); 411 return this._module._manager._resolve(this._type.substring(1));
412 }, 412 },
413 413
414 /** 414 /**
415 * @param {?Object} context 415 * @param {?Object} context
416 * @return {boolean} 416 * @return {boolean}
417 */ 417 */
418 isApplicable: function(context) 418 isApplicable: function(context)
419 { 419 {
420 return WebInspector.ModuleManager.isExtensionApplicableToContext(this, c ontext); 420 return this._module._manager.isExtensionApplicableToContext(this, contex t);
421 }, 421 },
422 422
423 /** 423 /**
424 * @return {?Object} 424 * @return {?Object}
425 */ 425 */
426 instance: function() 426 instance: function()
427 { 427 {
428 if (!this._className) 428 if (!this._className)
429 return null; 429 return null;
430 430
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 } 477 }
478 478
479 WebInspector.Revealer.prototype = { 479 WebInspector.Revealer.prototype = {
480 /** 480 /**
481 * @param {!Object} object 481 * @param {!Object} object
482 */ 482 */
483 reveal: function(object) {} 483 reveal: function(object) {}
484 } 484 }
485 485
486 WebInspector.moduleManager = new WebInspector.ModuleManager(allDescriptors); 486 WebInspector.moduleManager = new WebInspector.ModuleManager(allDescriptors);
OLDNEW
« no previous file with comments | « Source/devtools/front_end/Main.js ('k') | Source/devtools/front_end/extensions/ExtensionServer.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698