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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/ui/Context.js

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 /** 4 /**
5 * @unrestricted 5 * @unrestricted
6 */ 6 */
7 WebInspector.Context = class { 7 UI.Context = class {
8 constructor() { 8 constructor() {
9 this._flavors = new Map(); 9 this._flavors = new Map();
10 this._eventDispatchers = new Map(); 10 this._eventDispatchers = new Map();
11 } 11 }
12 12
13 /** 13 /**
14 * @param {function(new:T, ...)} flavorType 14 * @param {function(new:T, ...)} flavorType
15 * @param {?T} flavorValue 15 * @param {?T} flavorValue
16 * @template T 16 * @template T
17 */ 17 */
18 setFlavor(flavorType, flavorValue) { 18 setFlavor(flavorType, flavorValue) {
19 var value = this._flavors.get(flavorType) || null; 19 var value = this._flavors.get(flavorType) || null;
20 if (value === flavorValue) 20 if (value === flavorValue)
21 return; 21 return;
22 if (flavorValue) 22 if (flavorValue)
23 this._flavors.set(flavorType, flavorValue); 23 this._flavors.set(flavorType, flavorValue);
24 else 24 else
25 this._flavors.remove(flavorType); 25 this._flavors.remove(flavorType);
26 26
27 this._dispatchFlavorChange(flavorType, flavorValue); 27 this._dispatchFlavorChange(flavorType, flavorValue);
28 } 28 }
29 29
30 /** 30 /**
31 * @param {function(new:T, ...)} flavorType 31 * @param {function(new:T, ...)} flavorType
32 * @param {?T} flavorValue 32 * @param {?T} flavorValue
33 * @template T 33 * @template T
34 */ 34 */
35 _dispatchFlavorChange(flavorType, flavorValue) { 35 _dispatchFlavorChange(flavorType, flavorValue) {
36 for (var extension of self.runtime.extensions(WebInspector.ContextFlavorList ener)) { 36 for (var extension of self.runtime.extensions(UI.ContextFlavorListener)) {
37 if (extension.hasContextType(flavorType)) 37 if (extension.hasContextType(flavorType))
38 extension.instance().then( 38 extension.instance().then(
39 instance => /** @type {!WebInspector.ContextFlavorListener} */ (inst ance).flavorChanged(flavorValue)); 39 instance => /** @type {!UI.ContextFlavorListener} */ (instance).flav orChanged(flavorValue));
40 } 40 }
41 var dispatcher = this._eventDispatchers.get(flavorType); 41 var dispatcher = this._eventDispatchers.get(flavorType);
42 if (!dispatcher) 42 if (!dispatcher)
43 return; 43 return;
44 dispatcher.dispatchEventToListeners(WebInspector.Context.Events.FlavorChange d, flavorValue); 44 dispatcher.dispatchEventToListeners(UI.Context.Events.FlavorChanged, flavorV alue);
45 } 45 }
46 46
47 /** 47 /**
48 * @param {function(new:Object, ...)} flavorType 48 * @param {function(new:Object, ...)} flavorType
49 * @param {function(!WebInspector.Event)} listener 49 * @param {function(!Common.Event)} listener
50 * @param {!Object=} thisObject 50 * @param {!Object=} thisObject
51 */ 51 */
52 addFlavorChangeListener(flavorType, listener, thisObject) { 52 addFlavorChangeListener(flavorType, listener, thisObject) {
53 var dispatcher = this._eventDispatchers.get(flavorType); 53 var dispatcher = this._eventDispatchers.get(flavorType);
54 if (!dispatcher) { 54 if (!dispatcher) {
55 dispatcher = new WebInspector.Object(); 55 dispatcher = new Common.Object();
56 this._eventDispatchers.set(flavorType, dispatcher); 56 this._eventDispatchers.set(flavorType, dispatcher);
57 } 57 }
58 dispatcher.addEventListener(WebInspector.Context.Events.FlavorChanged, liste ner, thisObject); 58 dispatcher.addEventListener(UI.Context.Events.FlavorChanged, listener, thisO bject);
59 } 59 }
60 60
61 /** 61 /**
62 * @param {function(new:Object, ...)} flavorType 62 * @param {function(new:Object, ...)} flavorType
63 * @param {function(!WebInspector.Event)} listener 63 * @param {function(!Common.Event)} listener
64 * @param {!Object=} thisObject 64 * @param {!Object=} thisObject
65 */ 65 */
66 removeFlavorChangeListener(flavorType, listener, thisObject) { 66 removeFlavorChangeListener(flavorType, listener, thisObject) {
67 var dispatcher = this._eventDispatchers.get(flavorType); 67 var dispatcher = this._eventDispatchers.get(flavorType);
68 if (!dispatcher) 68 if (!dispatcher)
69 return; 69 return;
70 dispatcher.removeEventListener(WebInspector.Context.Events.FlavorChanged, li stener, thisObject); 70 dispatcher.removeEventListener(UI.Context.Events.FlavorChanged, listener, th isObject);
71 if (!dispatcher.hasEventListeners(WebInspector.Context.Events.FlavorChanged) ) 71 if (!dispatcher.hasEventListeners(UI.Context.Events.FlavorChanged))
72 this._eventDispatchers.remove(flavorType); 72 this._eventDispatchers.remove(flavorType);
73 } 73 }
74 74
75 /** 75 /**
76 * @param {function(new:T, ...)} flavorType 76 * @param {function(new:T, ...)} flavorType
77 * @return {?T} 77 * @return {?T}
78 * @template T 78 * @template T
79 */ 79 */
80 flavor(flavorType) { 80 flavor(flavorType) {
81 return this._flavors.get(flavorType) || null; 81 return this._flavors.get(flavorType) || null;
(...skipping 17 matching lines...) Expand all
99 extensions.forEach(function(extension) { 99 extensions.forEach(function(extension) {
100 if (self.runtime.isExtensionApplicableToContextTypes(extension, availableF lavors)) 100 if (self.runtime.isExtensionApplicableToContextTypes(extension, availableF lavors))
101 targetExtensionSet.add(extension); 101 targetExtensionSet.add(extension);
102 }); 102 });
103 103
104 return targetExtensionSet; 104 return targetExtensionSet;
105 } 105 }
106 }; 106 };
107 107
108 /** @enum {symbol} */ 108 /** @enum {symbol} */
109 WebInspector.Context.Events = { 109 UI.Context.Events = {
110 FlavorChanged: Symbol('FlavorChanged') 110 FlavorChanged: Symbol('FlavorChanged')
111 }; 111 };
112 112
113 /** 113 /**
114 * @interface 114 * @interface
115 */ 115 */
116 WebInspector.ContextFlavorListener = function() {}; 116 UI.ContextFlavorListener = function() {};
117 117
118 WebInspector.ContextFlavorListener.prototype = { 118 UI.ContextFlavorListener.prototype = {
119 /** 119 /**
120 * @param {?Object} object 120 * @param {?Object} object
121 */ 121 */
122 flavorChanged: function(object) {} 122 flavorChanged: function(object) {}
123 }; 123 };
124 124
125 WebInspector.context = new WebInspector.Context(); 125 UI.context = new UI.Context();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698