| 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 * @extends {InspectorBackendClass.Connection} | 7 * @extends {InspectorBackendClass.Connection} |
| 8 */ | 8 */ |
| 9 WebInspector.MainConnection = function() | 9 WebInspector.MainConnection = function() |
| 10 { | 10 { |
| 11 InspectorBackendClass.Connection.call(this); | 11 InspectorBackendClass.Connection.call(this); |
| 12 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.DispatchMessage, this._dispatchMessage, this); | 12 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.DispatchMessage, this._dispatchMessage, this); |
| 13 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.DispatchMessageChunk, this._dispatchMessageChunk, this); | 13 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.DispatchMessageChunk, this._dispatchMessageChunk, this); |
| 14 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.EvaluateForTestInFrontend, this._evaluateForTestInFrontend, this); | 14 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.EvaluateForTestInFrontend, this._evaluateForTestInFrontend, this); |
| 15 } | 15 }; |
| 16 | 16 |
| 17 WebInspector.MainConnection.prototype = { | 17 WebInspector.MainConnection.prototype = { |
| 18 /** | 18 /** |
| 19 * @override | 19 * @override |
| 20 * @param {!Object} messageObject | 20 * @param {!Object} messageObject |
| 21 */ | 21 */ |
| 22 sendMessage: function(messageObject) | 22 sendMessage: function(messageObject) |
| 23 { | 23 { |
| 24 var message = JSON.stringify(messageObject); | 24 var message = JSON.stringify(messageObject); |
| 25 InspectorFrontendHost.sendMessageToBackend(message); | 25 InspectorFrontendHost.sendMessageToBackend(message); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 * @override | 83 * @override |
| 84 */ | 84 */ |
| 85 forceClose: function() | 85 forceClose: function() |
| 86 { | 86 { |
| 87 InspectorFrontendHost.events.removeEventListener(InspectorFrontendHostAP
I.Events.DispatchMessage, this._dispatchMessage, this); | 87 InspectorFrontendHost.events.removeEventListener(InspectorFrontendHostAP
I.Events.DispatchMessage, this._dispatchMessage, this); |
| 88 InspectorFrontendHost.events.removeEventListener(InspectorFrontendHostAP
I.Events.DispatchMessageChunk, this._dispatchMessageChunk, this); | 88 InspectorFrontendHost.events.removeEventListener(InspectorFrontendHostAP
I.Events.DispatchMessageChunk, this._dispatchMessageChunk, this); |
| 89 InspectorFrontendHost.events.removeEventListener(InspectorFrontendHostAP
I.Events.EvaluateForTestInFrontend, this._evaluateForTestInFrontend, this); | 89 InspectorFrontendHost.events.removeEventListener(InspectorFrontendHostAP
I.Events.EvaluateForTestInFrontend, this._evaluateForTestInFrontend, this); |
| 90 }, | 90 }, |
| 91 | 91 |
| 92 __proto__: InspectorBackendClass.Connection.prototype | 92 __proto__: InspectorBackendClass.Connection.prototype |
| 93 } | 93 }; |
| 94 | 94 |
| 95 /** | 95 /** |
| 96 * @constructor | 96 * @constructor |
| 97 * @extends {InspectorBackendClass.Connection} | 97 * @extends {InspectorBackendClass.Connection} |
| 98 * @param {string} url | 98 * @param {string} url |
| 99 * @param {function(!InspectorBackendClass.Connection)} onConnectionReady | 99 * @param {function(!InspectorBackendClass.Connection)} onConnectionReady |
| 100 */ | 100 */ |
| 101 WebInspector.WebSocketConnection = function(url, onConnectionReady) | 101 WebInspector.WebSocketConnection = function(url, onConnectionReady) |
| 102 { | 102 { |
| 103 InspectorBackendClass.Connection.call(this); | 103 InspectorBackendClass.Connection.call(this); |
| 104 this._socket = new WebSocket(url); | 104 this._socket = new WebSocket(url); |
| 105 this._socket.onmessage = this._onMessage.bind(this); | 105 this._socket.onmessage = this._onMessage.bind(this); |
| 106 this._socket.onerror = this._onError.bind(this); | 106 this._socket.onerror = this._onError.bind(this); |
| 107 this._socket.onopen = onConnectionReady.bind(null, this); | 107 this._socket.onopen = onConnectionReady.bind(null, this); |
| 108 this._socket.onclose = this.connectionClosed.bind(this, "websocket_closed"); | 108 this._socket.onclose = this.connectionClosed.bind(this, "websocket_closed"); |
| 109 } | 109 }; |
| 110 | 110 |
| 111 /** | 111 /** |
| 112 * @param {string} url | 112 * @param {string} url |
| 113 * @return {!Promise<!InspectorBackendClass.Connection>} | 113 * @return {!Promise<!InspectorBackendClass.Connection>} |
| 114 */ | 114 */ |
| 115 WebInspector.WebSocketConnection.Create = function(url) | 115 WebInspector.WebSocketConnection.Create = function(url) |
| 116 { | 116 { |
| 117 var fulfill; | 117 var fulfill; |
| 118 var result = new Promise(resolve => fulfill = resolve); | 118 var result = new Promise(resolve => fulfill = resolve); |
| 119 new WebInspector.WebSocketConnection(url, fulfill); | 119 new WebInspector.WebSocketConnection(url, fulfill); |
| 120 return result; | 120 return result; |
| 121 } | 121 }; |
| 122 | 122 |
| 123 WebInspector.WebSocketConnection.prototype = { | 123 WebInspector.WebSocketConnection.prototype = { |
| 124 | 124 |
| 125 /** | 125 /** |
| 126 * @param {!MessageEvent} message | 126 * @param {!MessageEvent} message |
| 127 */ | 127 */ |
| 128 _onMessage: function(message) | 128 _onMessage: function(message) |
| 129 { | 129 { |
| 130 var data = /** @type {string} */ (message.data); | 130 var data = /** @type {string} */ (message.data); |
| 131 this.dispatch(data); | 131 this.dispatch(data); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 151 * @override | 151 * @override |
| 152 * @param {!Object} messageObject | 152 * @param {!Object} messageObject |
| 153 */ | 153 */ |
| 154 sendMessage: function(messageObject) | 154 sendMessage: function(messageObject) |
| 155 { | 155 { |
| 156 var message = JSON.stringify(messageObject); | 156 var message = JSON.stringify(messageObject); |
| 157 this._socket.send(message); | 157 this._socket.send(message); |
| 158 }, | 158 }, |
| 159 | 159 |
| 160 __proto__: InspectorBackendClass.Connection.prototype | 160 __proto__: InspectorBackendClass.Connection.prototype |
| 161 } | 161 }; |
| 162 | 162 |
| 163 /** | 163 /** |
| 164 * @constructor | 164 * @constructor |
| 165 * @extends {InspectorBackendClass.Connection} | 165 * @extends {InspectorBackendClass.Connection} |
| 166 */ | 166 */ |
| 167 WebInspector.StubConnection = function() | 167 WebInspector.StubConnection = function() |
| 168 { | 168 { |
| 169 InspectorBackendClass.Connection.call(this); | 169 InspectorBackendClass.Connection.call(this); |
| 170 } | 170 }; |
| 171 | 171 |
| 172 WebInspector.StubConnection.prototype = { | 172 WebInspector.StubConnection.prototype = { |
| 173 /** | 173 /** |
| 174 * @override | 174 * @override |
| 175 * @param {!Object} messageObject | 175 * @param {!Object} messageObject |
| 176 */ | 176 */ |
| 177 sendMessage: function(messageObject) | 177 sendMessage: function(messageObject) |
| 178 { | 178 { |
| 179 setTimeout(this._respondWithError.bind(this, messageObject), 0); | 179 setTimeout(this._respondWithError.bind(this, messageObject), 0); |
| 180 }, | 180 }, |
| 181 | 181 |
| 182 /** | 182 /** |
| 183 * @param {!Object} messageObject | 183 * @param {!Object} messageObject |
| 184 */ | 184 */ |
| 185 _respondWithError: function(messageObject) | 185 _respondWithError: function(messageObject) |
| 186 { | 186 { |
| 187 var error = { message: "This is a stub connection, can't dispatch messag
e.", code: InspectorBackendClass.DevToolsStubErrorCode, data: messageObject }; | 187 var error = { message: "This is a stub connection, can't dispatch messag
e.", code: InspectorBackendClass.DevToolsStubErrorCode, data: messageObject }; |
| 188 this.dispatch({ id: messageObject.id, error: error }); | 188 this.dispatch({ id: messageObject.id, error: error }); |
| 189 }, | 189 }, |
| 190 | 190 |
| 191 __proto__: InspectorBackendClass.Connection.prototype | 191 __proto__: InspectorBackendClass.Connection.prototype |
| 192 } | 192 }; |
| 193 | 193 |
| 194 | 194 |
| 195 /** | 195 /** |
| 196 * @constructor | 196 * @constructor |
| 197 * @param {function(string)} dispatchCallback | 197 * @param {function(string)} dispatchCallback |
| 198 * @param {function()} yieldCallback | 198 * @param {function()} yieldCallback |
| 199 */ | 199 */ |
| 200 WebInspector.RawProtocolConnection = function(dispatchCallback, yieldCallback) | 200 WebInspector.RawProtocolConnection = function(dispatchCallback, yieldCallback) |
| 201 { | 201 { |
| 202 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.DispatchMessage, this._dispatchMessage, this); | 202 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.DispatchMessage, this._dispatchMessage, this); |
| 203 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.DispatchMessageChunk, this._dispatchMessageChunk, this); | 203 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event
s.DispatchMessageChunk, this._dispatchMessageChunk, this); |
| 204 this._dispatchCallback = dispatchCallback; | 204 this._dispatchCallback = dispatchCallback; |
| 205 this._yieldCallback = yieldCallback; | 205 this._yieldCallback = yieldCallback; |
| 206 this._isClosed = false; | 206 this._isClosed = false; |
| 207 } | 207 }; |
| 208 | 208 |
| 209 WebInspector.RawProtocolConnection.prototype = { | 209 WebInspector.RawProtocolConnection.prototype = { |
| 210 /** | 210 /** |
| 211 * @param {string} message | 211 * @param {string} message |
| 212 */ | 212 */ |
| 213 send: function(message) | 213 send: function(message) |
| 214 { | 214 { |
| 215 if (this._isClosed) | 215 if (this._isClosed) |
| 216 return; | 216 return; |
| 217 InspectorFrontendHost.sendMessageToBackend(message); | 217 InspectorFrontendHost.sendMessageToBackend(message); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 245 }, | 245 }, |
| 246 | 246 |
| 247 yieldConnection: function() | 247 yieldConnection: function() |
| 248 { | 248 { |
| 249 InspectorFrontendHost.events.removeEventListener(InspectorFrontendHostAP
I.Events.DispatchMessage, this._dispatchMessage, this); | 249 InspectorFrontendHost.events.removeEventListener(InspectorFrontendHostAP
I.Events.DispatchMessage, this._dispatchMessage, this); |
| 250 InspectorFrontendHost.events.removeEventListener(InspectorFrontendHostAP
I.Events.DispatchMessageChunk, this._dispatchMessageChunk, this); | 250 InspectorFrontendHost.events.removeEventListener(InspectorFrontendHostAP
I.Events.DispatchMessageChunk, this._dispatchMessageChunk, this); |
| 251 this._isClosed = true; | 251 this._isClosed = true; |
| 252 delete this._dispatchCallback; | 252 delete this._dispatchCallback; |
| 253 this._yieldCallback(); | 253 this._yieldCallback(); |
| 254 } | 254 } |
| 255 } | 255 }; |
| OLD | NEW |