| 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 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @implements {InspectorBackendClass.Connection} | 7 * @implements {Protocol.Connection} |
| 8 * @param {!InspectorBackendClass.Connection.Params} params | 8 * @param {!Protocol.Connection.Params} params |
| 9 */ | 9 */ |
| 10 WebInspector.MainConnection = function(params) | 10 WebInspector.MainConnection = function(params) |
| 11 { | 11 { |
| 12 this._onMessage = params.onMessage; | 12 this._onMessage = params.onMessage; |
| 13 this._onDisconnect = params.onDisconnect; | 13 this._onDisconnect = params.onDisconnect; |
| 14 this._disconnected = false; | 14 this._disconnected = false; |
| 15 this._eventListeners = [ | 15 this._eventListeners = [ |
| 16 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.E
vents.DispatchMessage, this._dispatchMessage, this), | 16 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.E
vents.DispatchMessage, this._dispatchMessage, this), |
| 17 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.E
vents.DispatchMessageChunk, this._dispatchMessageChunk, this), | 17 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.E
vents.DispatchMessageChunk, this._dispatchMessageChunk, this), |
| 18 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.E
vents.EvaluateForTestInFrontend, this._evaluateForTestInFrontend, this), | 18 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.E
vents.EvaluateForTestInFrontend, this._evaluateForTestInFrontend, this), |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 function invokeMethod() | 75 function invokeMethod() |
| 76 { | 76 { |
| 77 try { | 77 try { |
| 78 script = script + "//# sourceURL=evaluateInWebInspector" + callI
d + ".js"; | 78 script = script + "//# sourceURL=evaluateInWebInspector" + callI
d + ".js"; |
| 79 window.eval(script); | 79 window.eval(script); |
| 80 } catch (e) { | 80 } catch (e) { |
| 81 console.error(e.stack); | 81 console.error(e.stack); |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 | 84 |
| 85 InspectorBackendClass.deprecatedRunAfterPendingDispatches(invokeMethod); | 85 Protocol.deprecatedRunAfterPendingDispatches(invokeMethod); |
| 86 }, | 86 }, |
| 87 | 87 |
| 88 /** | 88 /** |
| 89 * @override | 89 * @override |
| 90 * @return {!Promise} | 90 * @return {!Promise} |
| 91 */ | 91 */ |
| 92 disconnect: function() | 92 disconnect: function() |
| 93 { | 93 { |
| 94 var onDisconnect = this._onDisconnect; | 94 var onDisconnect = this._onDisconnect; |
| 95 WebInspector.EventTarget.removeEventListeners(this._eventListeners); | 95 WebInspector.EventTarget.removeEventListeners(this._eventListeners); |
| 96 this._onDisconnect = null; | 96 this._onDisconnect = null; |
| 97 this._onMessage = null; | 97 this._onMessage = null; |
| 98 this._disconnected = true; | 98 this._disconnected = true; |
| 99 | 99 |
| 100 var fulfill; | 100 var fulfill; |
| 101 var promise = new Promise(f => fulfill = f); | 101 var promise = new Promise(f => fulfill = f); |
| 102 InspectorFrontendHost.reattach(() => { | 102 InspectorFrontendHost.reattach(() => { |
| 103 onDisconnect.call(null, "force disconnect"); | 103 onDisconnect.call(null, "force disconnect"); |
| 104 fulfill(); | 104 fulfill(); |
| 105 }); | 105 }); |
| 106 return promise; | 106 return promise; |
| 107 }, | 107 }, |
| 108 }; | 108 }; |
| 109 | 109 |
| 110 /** | 110 /** |
| 111 * @constructor | 111 * @constructor |
| 112 * @implements {InspectorBackendClass.Connection} | 112 * @implements {Protocol.Connection} |
| 113 * @param {string} url | 113 * @param {string} url |
| 114 * @param {!InspectorBackendClass.Connection.Params} params | 114 * @param {!Protocol.Connection.Params} params |
| 115 */ | 115 */ |
| 116 WebInspector.WebSocketConnection = function(url, params) | 116 WebInspector.WebSocketConnection = function(url, params) |
| 117 { | 117 { |
| 118 this._socket = new WebSocket(url); | 118 this._socket = new WebSocket(url); |
| 119 this._socket.onerror = this._onError.bind(this); | 119 this._socket.onerror = this._onError.bind(this); |
| 120 this._socket.onopen = this._onOpen.bind(this); | 120 this._socket.onopen = this._onOpen.bind(this); |
| 121 this._socket.onmessage = (messageEvent) => params.onMessage.call(null, /** @
type {string} */ (messageEvent.data)); | 121 this._socket.onmessage = (messageEvent) => params.onMessage.call(null, /** @
type {string} */ (messageEvent.data)); |
| 122 this._onDisconnect = params.onDisconnect; | 122 this._onDisconnect = params.onDisconnect; |
| 123 this._socket.onclose = params.onDisconnect.bind(null, "websocket closed"); | 123 this._socket.onclose = params.onDisconnect.bind(null, "websocket closed"); |
| 124 | 124 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 disconnect: function() | 172 disconnect: function() |
| 173 { | 173 { |
| 174 this._onDisconnect.call(null, "force disconnect"); | 174 this._onDisconnect.call(null, "force disconnect"); |
| 175 this._close(); | 175 this._close(); |
| 176 return Promise.resolve(); | 176 return Promise.resolve(); |
| 177 } | 177 } |
| 178 }; | 178 }; |
| 179 | 179 |
| 180 /** | 180 /** |
| 181 * @constructor | 181 * @constructor |
| 182 * @implements {InspectorBackendClass.Connection} | 182 * @implements {Protocol.Connection} |
| 183 * @param {!InspectorBackendClass.Connection.Params} params | 183 * @param {!Protocol.Connection.Params} params |
| 184 */ | 184 */ |
| 185 WebInspector.StubConnection = function(params) | 185 WebInspector.StubConnection = function(params) |
| 186 { | 186 { |
| 187 this._onMessage = params.onMessage; | 187 this._onMessage = params.onMessage; |
| 188 this._onDisconnect = params.onDisconnect; | 188 this._onDisconnect = params.onDisconnect; |
| 189 }; | 189 }; |
| 190 | 190 |
| 191 WebInspector.StubConnection.prototype = { | 191 WebInspector.StubConnection.prototype = { |
| 192 /** | 192 /** |
| 193 * @override | 193 * @override |
| 194 * @param {string} message | 194 * @param {string} message |
| 195 */ | 195 */ |
| 196 sendMessage: function(message) | 196 sendMessage: function(message) |
| 197 { | 197 { |
| 198 setTimeout(this._respondWithError.bind(this, message), 0); | 198 setTimeout(this._respondWithError.bind(this, message), 0); |
| 199 }, | 199 }, |
| 200 | 200 |
| 201 /** | 201 /** |
| 202 * @param {string} message | 202 * @param {string} message |
| 203 */ | 203 */ |
| 204 _respondWithError: function(message) | 204 _respondWithError: function(message) |
| 205 { | 205 { |
| 206 var messageObject = JSON.parse(message); | 206 var messageObject = JSON.parse(message); |
| 207 var error = { message: "This is a stub connection, can't dispatch messag
e.", code: InspectorBackendClass.DevToolsStubErrorCode, data: messageObject }; | 207 var error = { message: "This is a stub connection, can't dispatch messag
e.", code: Protocol.StubErrorCode, data: messageObject }; |
| 208 this._onMessage.call(null, { id: messageObject.id, error: error }); | 208 this._onMessage.call(null, { id: messageObject.id, error: error }); |
| 209 }, | 209 }, |
| 210 | 210 |
| 211 /** | 211 /** |
| 212 * @override | 212 * @override |
| 213 * @return {!Promise} | 213 * @return {!Promise} |
| 214 */ | 214 */ |
| 215 disconnect: function() | 215 disconnect: function() |
| 216 { | 216 { |
| 217 this._onDisconnect.call(null, "force disconnect"); | 217 this._onDisconnect.call(null, "force disconnect"); |
| 218 this._onDisconnect = null; | 218 this._onDisconnect = null; |
| 219 this._onMessage = null; | 219 this._onMessage = null; |
| 220 return Promise.resolve(); | 220 return Promise.resolve(); |
| 221 }, | 221 }, |
| 222 }; | 222 }; |
| OLD | NEW |