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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sdk/WorkerManager.js

Issue 2441933002: [DevTools] Refactor connection-related classes. (Closed)
Patch Set: test fixes Created 4 years, 2 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 20 matching lines...) Expand all
31 /** 31 /**
32 * @constructor 32 * @constructor
33 * @extends {WebInspector.SDKObject} 33 * @extends {WebInspector.SDKObject}
34 * @param {!WebInspector.Target} target 34 * @param {!WebInspector.Target} target
35 */ 35 */
36 WebInspector.WorkerManager = function(target) 36 WebInspector.WorkerManager = function(target)
37 { 37 {
38 WebInspector.SDKObject.call(this, target); 38 WebInspector.SDKObject.call(this, target);
39 target.registerWorkerDispatcher(new WebInspector.WorkerDispatcher(this)); 39 target.registerWorkerDispatcher(new WebInspector.WorkerDispatcher(this));
40 this._lastAnonymousTargetId = 0; 40 this._lastAnonymousTargetId = 0;
41 /** @type {!Map.<string, !WebInspector.WorkerConnection>} */ 41 /** @type {!Map.<string, !WebInspector.WorkerChannel>} */
42 this._connections = new Map(); 42 this._channels = new Map();
43 43
44 /** @type {!Map.<string, !WebInspector.Target>} */ 44 /** @type {!Map.<string, !WebInspector.Target>} */
45 this._targetsByWorkerId = new Map(); 45 this._targetsByWorkerId = new Map();
46 46
47 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.Event s.SuspendStateChanged, this._onSuspendStateChanged, this); 47 WebInspector.targetManager.addEventListener(WebInspector.TargetManager.Event s.SuspendStateChanged, this._onSuspendStateChanged, this);
48 this._onSuspendStateChanged(); 48 this._onSuspendStateChanged();
49 this.enable(); 49 this.enable();
50 } 50 }
51 51
52 WebInspector.WorkerManager.prototype = { 52 WebInspector.WorkerManager.prototype = {
(...skipping 17 matching lines...) Expand all
70 WebInspector.targetManager.removeEventListener(WebInspector.TargetManage r.Events.MainFrameNavigated, this._mainFrameNavigated, this); 70 WebInspector.targetManager.removeEventListener(WebInspector.TargetManage r.Events.MainFrameNavigated, this._mainFrameNavigated, this);
71 }, 71 },
72 72
73 dispose: function() 73 dispose: function()
74 { 74 {
75 this._reset(); 75 this._reset();
76 }, 76 },
77 77
78 _reset: function() 78 _reset: function()
79 { 79 {
80 for (var connection of this._connections.values()) 80 for (var channel of this._channels.values())
81 connection.close(); 81 channel.dispatchEventToListeners(InspectorBackendClass.Channel.Event s.ChannelClosed, "worker terminated");
82 this._connections.clear(); 82 this._channels.clear();
83 this._targetsByWorkerId.clear(); 83 this._targetsByWorkerId.clear();
84 }, 84 },
85 85
86 _onSuspendStateChanged: function() 86 _onSuspendStateChanged: function()
87 { 87 {
88 var suspended = WebInspector.targetManager.allTargetsSuspended(); 88 var suspended = WebInspector.targetManager.allTargetsSuspended();
89 this.target().workerAgent().setWaitForDebuggerOnStart(!suspended); 89 this.target().workerAgent().setWaitForDebuggerOnStart(!suspended);
90 }, 90 },
91 91
92 /** 92 /**
93 * @param {string} workerId 93 * @param {string} workerId
94 * @param {string} url 94 * @param {string} url
95 * @param {boolean} waitingForDebugger 95 * @param {boolean} waitingForDebugger
96 */ 96 */
97 _workerCreated: function(workerId, url, waitingForDebugger) 97 _workerCreated: function(workerId, url, waitingForDebugger)
98 { 98 {
99 var connection = new WebInspector.WorkerConnection(this, workerId); 99 var channel = new WebInspector.WorkerChannel(this, workerId);
100 this._connections.set(workerId, connection); 100 this._channels.set(workerId, channel);
101 101
102 var parsedURL = url.asParsedURL(); 102 var parsedURL = url.asParsedURL();
103 var workerName = parsedURL ? parsedURL.lastPathComponentWithFragment() : "#" + (++this._lastAnonymousTargetId); 103 var workerName = parsedURL ? parsedURL.lastPathComponentWithFragment() : "#" + (++this._lastAnonymousTargetId);
104 var target = WebInspector.targetManager.createTarget(workerName, WebInsp ector.Target.Capability.JS | WebInspector.Target.Capability.Log, connection, thi s.target()); 104 var target = WebInspector.targetManager.createTarget(workerName, WebInsp ector.Target.Capability.JS | WebInspector.Target.Capability.Log, channel, this.t arget());
105 this._targetsByWorkerId.set(workerId, target); 105 this._targetsByWorkerId.set(workerId, target);
106 106
107 // Only pause new worker if debugging SW - we are going through the 107 // Only pause new worker if debugging SW - we are going through the
108 // pause on start checkbox. 108 // pause on start checkbox.
109 var mainIsServiceWorker = WebInspector.targetManager.mainTarget().hasWor kerCapability() && !WebInspector.targetManager.mainTarget().hasBrowserCapability (); 109 var mainIsServiceWorker = WebInspector.targetManager.mainTarget().hasWor kerCapability() && !WebInspector.targetManager.mainTarget().hasBrowserCapability ();
110 if (mainIsServiceWorker && waitingForDebugger) 110 if (mainIsServiceWorker && waitingForDebugger)
111 target.debuggerAgent().pause(); 111 target.debuggerAgent().pause();
112 target.runtimeAgent().runIfWaitingForDebugger(); 112 target.runtimeAgent().runIfWaitingForDebugger();
113 }, 113 },
114 114
115 /** 115 /**
116 * @param {string} workerId 116 * @param {string} workerId
117 */ 117 */
118 _workerTerminated: function(workerId) 118 _workerTerminated: function(workerId)
119 { 119 {
120 var connection = this._connections.get(workerId); 120 var channel = this._channels.get(workerId);
121 if (connection) 121 if (channel)
122 connection._reportClosed(); 122 channel.dispatchEventToListeners(InspectorBackendClass.Channel.Event s.ChannelClosed, "worker terminated");
123 this._connections.delete(workerId); 123 this._channels.delete(workerId);
124 this._targetsByWorkerId.delete(workerId); 124 this._targetsByWorkerId.delete(workerId);
125 }, 125 },
126 126
127 /** 127 /**
128 * @param {string} workerId 128 * @param {string} workerId
129 * @param {string} message 129 * @param {string} message
130 */ 130 */
131 _dispatchMessageFromWorker: function(workerId, message) 131 _dispatchMessageFromWorker: function(workerId, message)
132 { 132 {
133 var connection = this._connections.get(workerId); 133 var channel = this._channels.get(workerId);
134 if (connection) 134 if (channel)
135 connection.dispatch(message); 135 channel.dispatchEventToListeners(InspectorBackendClass.Channel.Event s.MessageReceived, message);
136 }, 136 },
137 137
138 /** 138 /**
139 * @param {!WebInspector.Event} event 139 * @param {!WebInspector.Event} event
140 */ 140 */
141 _mainFrameNavigated: function(event) 141 _mainFrameNavigated: function(event)
142 { 142 {
143 if (event.data.target() !== this.target()) 143 if (event.data.target() !== this.target())
144 return; 144 return;
145 this._reset(); // TODO (dgozman): Probably, unnecessary. Consider remova l. 145 this._reset(); // TODO (dgozman): Probably, unnecessary. Consider remova l.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 * @param {string} message 193 * @param {string} message
194 */ 194 */
195 dispatchMessageFromWorker: function(workerId, message) 195 dispatchMessageFromWorker: function(workerId, message)
196 { 196 {
197 this._workerManager._dispatchMessageFromWorker(workerId, message); 197 this._workerManager._dispatchMessageFromWorker(workerId, message);
198 } 198 }
199 } 199 }
200 200
201 /** 201 /**
202 * @constructor 202 * @constructor
203 * @extends {InspectorBackendClass.Connection} 203 * @extends {WebInspector.Object}
204 * @implements {InspectorBackendClass.Channel}
204 * @param {!WebInspector.WorkerManager} workerManager 205 * @param {!WebInspector.WorkerManager} workerManager
205 * @param {string} workerId 206 * @param {string} workerId
206 */ 207 */
207 WebInspector.WorkerConnection = function(workerManager, workerId) 208 WebInspector.WorkerChannel = function(workerManager, workerId)
208 { 209 {
209 InspectorBackendClass.Connection.call(this); 210 WebInspector.Object.call(this);
210 // FIXME: remove resourceTreeModel and others from worker targets
211 this.suppressErrorsForDomains(["Worker", "Page", "CSS", "DOM", "DOMStorage", "Database", "Network", "IndexedDB"]);
212 this._agent = workerManager.target().workerAgent(); 211 this._agent = workerManager.target().workerAgent();
213 this._workerId = workerId; 212 this._workerId = workerId;
214 } 213 }
215 214
216 WebInspector.WorkerConnection.prototype = { 215 WebInspector.WorkerChannel.prototype = {
217 /** 216 /**
218 * @override 217 * @override
219 * @param {!Object} messageObject 218 * @param {string} message
220 */ 219 */
221 sendMessage: function(messageObject) 220 sendMessage: function(message)
222 { 221 {
223 this._agent.sendMessageToWorker(this._workerId, JSON.stringify(messageOb ject)); 222 this._agent.sendMessageToWorker(this._workerId, message);
224 }, 223 },
225 224
226 _reportClosed: function() 225 /**
226 * @override
227 * @param {function()} callback
228 */
229 reconnect: function(callback)
227 { 230 {
228 this.connectionClosed("worker_terminated"); 231 throw new Error("Not implemented");
229 }, 232 },
230 233
231 __proto__: InspectorBackendClass.Connection.prototype 234 __proto__: WebInspector.Object.prototype
232 } 235 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698