OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 * @implements {InspectorBackendClass.Connection} | 5 * @implements {Protocol.InspectorBackend.Connection} |
6 * @unrestricted | 6 * @unrestricted |
7 */ | 7 */ |
8 SDK.MainConnection = class { | 8 SDK.MainConnection = class { |
9 /** | 9 /** |
10 * @param {!InspectorBackendClass.Connection.Params} params | 10 * @param {!Protocol.InspectorBackend.Connection.Params} params |
11 */ | 11 */ |
12 constructor(params) { | 12 constructor(params) { |
13 this._onMessage = params.onMessage; | 13 this._onMessage = params.onMessage; |
14 this._onDisconnect = params.onDisconnect; | 14 this._onDisconnect = params.onDisconnect; |
15 this._disconnected = false; | 15 this._disconnected = false; |
16 this._eventListeners = [ | 16 this._eventListeners = [ |
17 InspectorFrontendHost.events.addEventListener( | 17 InspectorFrontendHost.events.addEventListener( |
18 InspectorFrontendHostAPI.Events.DispatchMessage, this._dispatchMessage
, this), | 18 InspectorFrontendHostAPI.Events.DispatchMessage, this._dispatchMessage
, this), |
19 InspectorFrontendHost.events.addEventListener( | 19 InspectorFrontendHost.events.addEventListener( |
20 InspectorFrontendHostAPI.Events.DispatchMessageChunk, this._dispatchMe
ssageChunk, this), | 20 InspectorFrontendHostAPI.Events.DispatchMessageChunk, this._dispatchMe
ssageChunk, this), |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 */ | 72 */ |
73 function invokeMethod() { | 73 function invokeMethod() { |
74 try { | 74 try { |
75 script = script + '//# sourceURL=evaluateInWebInspector' + callId + '.js
'; | 75 script = script + '//# sourceURL=evaluateInWebInspector' + callId + '.js
'; |
76 window.eval(script); | 76 window.eval(script); |
77 } catch (e) { | 77 } catch (e) { |
78 console.error(e.stack); | 78 console.error(e.stack); |
79 } | 79 } |
80 } | 80 } |
81 | 81 |
82 InspectorBackendClass.deprecatedRunAfterPendingDispatches(invokeMethod); | 82 Protocol.InspectorBackend.deprecatedRunAfterPendingDispatches(invokeMethod); |
83 } | 83 } |
84 | 84 |
85 /** | 85 /** |
86 * @override | 86 * @override |
87 * @return {!Promise} | 87 * @return {!Promise} |
88 */ | 88 */ |
89 disconnect() { | 89 disconnect() { |
90 var onDisconnect = this._onDisconnect; | 90 var onDisconnect = this._onDisconnect; |
91 Common.EventTarget.removeEventListeners(this._eventListeners); | 91 Common.EventTarget.removeEventListeners(this._eventListeners); |
92 this._onDisconnect = null; | 92 this._onDisconnect = null; |
93 this._onMessage = null; | 93 this._onMessage = null; |
94 this._disconnected = true; | 94 this._disconnected = true; |
95 | 95 |
96 var fulfill; | 96 var fulfill; |
97 var promise = new Promise(f => fulfill = f); | 97 var promise = new Promise(f => fulfill = f); |
98 InspectorFrontendHost.reattach(() => { | 98 InspectorFrontendHost.reattach(() => { |
99 onDisconnect.call(null, 'force disconnect'); | 99 onDisconnect.call(null, 'force disconnect'); |
100 fulfill(); | 100 fulfill(); |
101 }); | 101 }); |
102 return promise; | 102 return promise; |
103 } | 103 } |
104 }; | 104 }; |
105 | 105 |
106 /** | 106 /** |
107 * @implements {InspectorBackendClass.Connection} | 107 * @implements {Protocol.InspectorBackend.Connection} |
108 * @unrestricted | 108 * @unrestricted |
109 */ | 109 */ |
110 SDK.WebSocketConnection = class { | 110 SDK.WebSocketConnection = class { |
111 /** | 111 /** |
112 * @param {string} url | 112 * @param {string} url |
113 * @param {function()} onWebSocketDisconnect | 113 * @param {function()} onWebSocketDisconnect |
114 * @param {!InspectorBackendClass.Connection.Params} params | 114 * @param {!Protocol.InspectorBackend.Connection.Params} params |
115 */ | 115 */ |
116 constructor(url, onWebSocketDisconnect, params) { | 116 constructor(url, onWebSocketDisconnect, params) { |
117 this._socket = new WebSocket(url); | 117 this._socket = new WebSocket(url); |
118 this._socket.onerror = this._onError.bind(this); | 118 this._socket.onerror = this._onError.bind(this); |
119 this._socket.onopen = this._onOpen.bind(this); | 119 this._socket.onopen = this._onOpen.bind(this); |
120 this._socket.onmessage = (messageEvent) => params.onMessage.call(null, /** @
type {string} */ (messageEvent.data)); | 120 this._socket.onmessage = (messageEvent) => params.onMessage.call(null, /** @
type {string} */ (messageEvent.data)); |
121 this._socket.onclose = this._onClose.bind(this); | 121 this._socket.onclose = this._onClose.bind(this); |
122 | 122 |
123 this._onDisconnect = params.onDisconnect; | 123 this._onDisconnect = params.onDisconnect; |
124 this._onWebSocketDisconnect = onWebSocketDisconnect; | 124 this._onWebSocketDisconnect = onWebSocketDisconnect; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 var promise = new Promise(f => fulfill = f); | 180 var promise = new Promise(f => fulfill = f); |
181 this._close(() => { | 181 this._close(() => { |
182 this._onDisconnect.call(null, 'force disconnect'); | 182 this._onDisconnect.call(null, 'force disconnect'); |
183 fulfill(); | 183 fulfill(); |
184 }); | 184 }); |
185 return promise; | 185 return promise; |
186 } | 186 } |
187 }; | 187 }; |
188 | 188 |
189 /** | 189 /** |
190 * @implements {InspectorBackendClass.Connection} | 190 * @implements {Protocol.InspectorBackend.Connection} |
191 * @unrestricted | 191 * @unrestricted |
192 */ | 192 */ |
193 SDK.StubConnection = class { | 193 SDK.StubConnection = class { |
194 /** | 194 /** |
195 * @param {!InspectorBackendClass.Connection.Params} params | 195 * @param {!Protocol.InspectorBackend.Connection.Params} params |
196 */ | 196 */ |
197 constructor(params) { | 197 constructor(params) { |
198 this._onMessage = params.onMessage; | 198 this._onMessage = params.onMessage; |
199 this._onDisconnect = params.onDisconnect; | 199 this._onDisconnect = params.onDisconnect; |
200 } | 200 } |
201 | 201 |
202 /** | 202 /** |
203 * @override | 203 * @override |
204 * @param {string} message | 204 * @param {string} message |
205 */ | 205 */ |
206 sendMessage(message) { | 206 sendMessage(message) { |
207 setTimeout(this._respondWithError.bind(this, message), 0); | 207 setTimeout(this._respondWithError.bind(this, message), 0); |
208 } | 208 } |
209 | 209 |
210 /** | 210 /** |
211 * @param {string} message | 211 * @param {string} message |
212 */ | 212 */ |
213 _respondWithError(message) { | 213 _respondWithError(message) { |
214 var messageObject = JSON.parse(message); | 214 var messageObject = JSON.parse(message); |
215 var error = { | 215 var error = { |
216 message: 'This is a stub connection, can\'t dispatch message.', | 216 message: 'This is a stub connection, can\'t dispatch message.', |
217 code: InspectorBackendClass.DevToolsStubErrorCode, | 217 code: Protocol.InspectorBackend.DevToolsStubErrorCode, |
218 data: messageObject | 218 data: messageObject |
219 }; | 219 }; |
220 this._onMessage.call(null, {id: messageObject.id, error: error}); | 220 this._onMessage.call(null, {id: messageObject.id, error: error}); |
221 } | 221 } |
222 | 222 |
223 /** | 223 /** |
224 * @override | 224 * @override |
225 * @return {!Promise} | 225 * @return {!Promise} |
226 */ | 226 */ |
227 disconnect() { | 227 disconnect() { |
228 this._onDisconnect.call(null, 'force disconnect'); | 228 this._onDisconnect.call(null, 'force disconnect'); |
229 this._onDisconnect = null; | 229 this._onDisconnect = null; |
230 this._onMessage = null; | 230 this._onMessage = null; |
231 return Promise.resolve(); | 231 return Promise.resolve(); |
232 } | 232 } |
233 }; | 233 }; |
OLD | NEW |