Chromium Code Reviews| 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 } | 15 } |
| 15 | 16 |
| 16 WebInspector.MainConnection.prototype = { | 17 WebInspector.MainConnection.prototype = { |
| 17 /** | 18 /** |
| 18 * @override | 19 * @override |
| 19 * @param {!Object} messageObject | 20 * @param {!Object} messageObject |
| 20 */ | 21 */ |
| 21 sendMessage: function(messageObject) | 22 sendMessage: function(messageObject) |
| 22 { | 23 { |
| 23 var message = JSON.stringify(messageObject); | 24 var message = JSON.stringify(messageObject); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 44 this._messageSize = messageSize; | 45 this._messageSize = messageSize; |
| 45 } | 46 } |
| 46 this._messageBuffer += messageChunk; | 47 this._messageBuffer += messageChunk; |
| 47 if (this._messageBuffer.length === this._messageSize) { | 48 if (this._messageBuffer.length === this._messageSize) { |
| 48 this.dispatch(this._messageBuffer); | 49 this.dispatch(this._messageBuffer); |
| 49 this._messageBuffer = ""; | 50 this._messageBuffer = ""; |
| 50 this._messageSize = 0; | 51 this._messageSize = 0; |
| 51 } | 52 } |
| 52 }, | 53 }, |
| 53 | 54 |
| 55 /** | |
| 56 * @param {!WebInspector.Event} event | |
| 57 */ | |
| 58 _evaluateForTestInFrontend: function(event) | |
| 59 { | |
| 60 if (!InspectorFrontendHost.isUnderTest()) | |
| 61 return; | |
| 62 | |
| 63 var callId = /** @type {number} */ (event.data["callId"]); | |
| 64 var script = /** @type {number} */ (event.data["script"]); | |
| 65 | |
| 66 /** | |
| 67 * @suppressGlobalPropertiesCheck | |
| 68 */ | |
| 69 function invokeMethod() | |
| 70 { | |
| 71 try { | |
| 72 script = script + "//# sourceURL=evaluateInWebInspector" + callI d + ".js"; | |
| 73 window.eval(script); | |
| 74 } catch (e) { | |
| 75 console.error(e.stack); | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 this.deprecatedRunAfterPendingDispatches(invokeMethod); | |
| 80 }, | |
| 81 | |
| 82 /** | |
| 83 * @override | |
| 84 */ | |
| 85 forceClose: function() | |
| 86 { | |
| 87 InspectorFrontendHost.events.removeEventListener(InspectorFrontendHostAP I.Events.DispatchMessage, this._dispatchMessage, this); | |
| 88 InspectorFrontendHost.events.removeEventListener(InspectorFrontendHostAP I.Events.DispatchMessageChunk, this._dispatchMessageChunk, this); | |
| 89 InspectorFrontendHost.events.removeEventListener(InspectorFrontendHostAP I.Events.EvaluateForTestInFrontend, this._evaluateForTestInFrontend, this); | |
| 90 }, | |
| 91 | |
| 54 __proto__: InspectorBackendClass.Connection.prototype | 92 __proto__: InspectorBackendClass.Connection.prototype |
| 55 } | 93 } |
| 56 | 94 |
| 57 /** | 95 /** |
| 58 * @constructor | 96 * @constructor |
| 59 * @extends {InspectorBackendClass.Connection} | 97 * @extends {InspectorBackendClass.Connection} |
| 60 * @param {string} url | 98 * @param {string} url |
| 61 * @param {function(!InspectorBackendClass.Connection)} onConnectionReady | 99 * @param {function(!InspectorBackendClass.Connection)} onConnectionReady |
| 62 */ | 100 */ |
| 63 WebInspector.WebSocketConnection = function(url, onConnectionReady) | 101 WebInspector.WebSocketConnection = function(url, onConnectionReady) |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 93 /** | 131 /** |
| 94 * @param {!Event} error | 132 * @param {!Event} error |
| 95 */ | 133 */ |
| 96 _onError: function(error) | 134 _onError: function(error) |
| 97 { | 135 { |
| 98 console.error(error); | 136 console.error(error); |
| 99 }, | 137 }, |
| 100 | 138 |
| 101 /** | 139 /** |
| 102 * @override | 140 * @override |
| 141 */ | |
| 142 forceClose: function() | |
| 143 { | |
| 144 this._socket.close(); | |
| 145 }, | |
| 146 | |
| 147 /** | |
| 148 * @override | |
| 103 * @param {!Object} messageObject | 149 * @param {!Object} messageObject |
| 104 */ | 150 */ |
| 105 sendMessage: function(messageObject) | 151 sendMessage: function(messageObject) |
| 106 { | 152 { |
| 107 var message = JSON.stringify(messageObject); | 153 var message = JSON.stringify(messageObject); |
| 108 this._socket.send(message); | 154 this._socket.send(message); |
| 109 }, | 155 }, |
| 110 | 156 |
| 111 __proto__: InspectorBackendClass.Connection.prototype | 157 __proto__: InspectorBackendClass.Connection.prototype |
| 112 } | 158 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 134 * @param {!Object} messageObject | 180 * @param {!Object} messageObject |
| 135 */ | 181 */ |
| 136 _respondWithError: function(messageObject) | 182 _respondWithError: function(messageObject) |
| 137 { | 183 { |
| 138 var error = { message: "This is a stub connection, can't dispatch messag e.", code: InspectorBackendClass.DevToolsStubErrorCode, data: messageObject }; | 184 var error = { message: "This is a stub connection, can't dispatch messag e.", code: InspectorBackendClass.DevToolsStubErrorCode, data: messageObject }; |
| 139 this.dispatch({ id: messageObject.id, error: error }); | 185 this.dispatch({ id: messageObject.id, error: error }); |
| 140 }, | 186 }, |
| 141 | 187 |
| 142 __proto__: InspectorBackendClass.Connection.prototype | 188 __proto__: InspectorBackendClass.Connection.prototype |
| 143 } | 189 } |
| 190 | |
| 191 | |
| 192 /** | |
| 193 * @constructor | |
| 194 * @param {function(string)} dispatchCallback | |
| 195 * @param {function()} yieldCallback | |
| 196 */ | |
| 197 WebInspector.RawProtocolConnection = function(dispatchCallback, yieldCallback) | |
| 198 { | |
| 199 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.DispatchMessage, this._dispatchMessage, this); | |
| 200 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.DispatchMessageChunk, this._dispatchMessageChunk, this); | |
| 201 this._dispatchCallback = dispatchCallback; | |
| 202 this._yieldCallback = yieldCallback; | |
| 203 } | |
| 204 | |
| 205 WebInspector.RawProtocolConnection.prototype = { | |
| 206 /** | |
| 207 * @param {string} message | |
| 208 */ | |
| 209 send: function(message) | |
| 210 { | |
| 211 InspectorFrontendHost.sendMessageToBackend(message); | |
| 212 }, | |
| 213 | |
| 214 /** | |
| 215 * @param {!WebInspector.Event} event | |
| 216 */ | |
| 217 _dispatchMessage: function(event) | |
| 218 { | |
| 219 this._dispatchCallback(/** @type {string} */ (event.data)); | |
| 220 }, | |
| 221 | |
| 222 /** | |
| 223 * @param {!WebInspector.Event} event | |
| 224 */ | |
| 225 _dispatchMessageChunk: function(event) | |
| 226 { | |
| 227 var messageChunk = /** @type {string} */ (event.data["messageChunk"]); | |
| 228 var messageSize = /** @type {number} */ (event.data["messageSize"]); | |
| 229 if (messageSize) { | |
| 230 this._messageBuffer = ""; | |
| 231 this._messageSize = messageSize; | |
| 232 } | |
| 233 this._messageBuffer += messageChunk; | |
| 234 if (this._messageBuffer.length === this._messageSize) { | |
| 235 this._dispatchCallback(this._messageBuffer); | |
| 236 this._messageBuffer = ""; | |
| 237 this._messageSize = 0; | |
| 238 } | |
| 239 }, | |
| 240 | |
| 241 yield: function() | |
| 242 { | |
| 243 InspectorFrontendHost.events.removeEventListener(InspectorFrontendHostAP I.Events.DispatchMessage, this._dispatchMessage, this); | |
| 244 InspectorFrontendHost.events.removeEventListener(InspectorFrontendHostAP I.Events.DispatchMessageChunk, this._dispatchMessageChunk, this); | |
| 245 this._yieldCallback(); | |
|
dgozman
2016/10/15 00:26:26
Mark this as closed (disallow send and dispatch).
| |
| 246 } | |
| 247 } | |
| OLD | NEW |