Chromium Code Reviews| Index: third_party/WebKit/Source/devtools/front_end/sdk/Connections.js |
| diff --git a/third_party/WebKit/Source/devtools/front_end/main/Connections.js b/third_party/WebKit/Source/devtools/front_end/sdk/Connections.js |
| similarity index 54% |
| rename from third_party/WebKit/Source/devtools/front_end/main/Connections.js |
| rename to third_party/WebKit/Source/devtools/front_end/sdk/Connections.js |
| index fbab8df5cadac50c903c31f034125fc5f9b89d76..c7737dc9b05f8a1afe8817432b3ac11d138dd49a 100644 |
| --- a/third_party/WebKit/Source/devtools/front_end/main/Connections.js |
| +++ b/third_party/WebKit/Source/devtools/front_end/sdk/Connections.js |
| @@ -11,6 +11,7 @@ WebInspector.MainConnection = function() |
| InspectorBackendClass.Connection.call(this); |
| InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Events.DispatchMessage, this._dispatchMessage, this); |
| InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Events.DispatchMessageChunk, this._dispatchMessageChunk, this); |
| + InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Events.EvaluateForTestInFrontend, this._evaluateForTestInFrontend, this); |
| } |
| WebInspector.MainConnection.prototype = { |
| @@ -51,6 +52,43 @@ WebInspector.MainConnection.prototype = { |
| } |
| }, |
| + /** |
| + * @param {!WebInspector.Event} event |
| + */ |
| + _evaluateForTestInFrontend: function(event) |
| + { |
| + if (!InspectorFrontendHost.isUnderTest()) |
| + return; |
| + |
| + var callId = /** @type {number} */ (event.data["callId"]); |
| + var script = /** @type {number} */ (event.data["script"]); |
| + |
| + /** |
| + * @suppressGlobalPropertiesCheck |
| + */ |
| + function invokeMethod() |
| + { |
| + try { |
| + script = script + "//# sourceURL=evaluateInWebInspector" + callId + ".js"; |
| + window.eval(script); |
| + } catch (e) { |
| + console.error(e.stack); |
| + } |
| + } |
| + |
| + this.deprecatedRunAfterPendingDispatches(invokeMethod); |
| + }, |
| + |
| + /** |
| + * @override |
| + */ |
| + forceClose: function() |
| + { |
| + InspectorFrontendHost.events.removeEventListener(InspectorFrontendHostAPI.Events.DispatchMessage, this._dispatchMessage, this); |
| + InspectorFrontendHost.events.removeEventListener(InspectorFrontendHostAPI.Events.DispatchMessageChunk, this._dispatchMessageChunk, this); |
| + InspectorFrontendHost.events.removeEventListener(InspectorFrontendHostAPI.Events.EvaluateForTestInFrontend, this._evaluateForTestInFrontend, this); |
| + }, |
| + |
| __proto__: InspectorBackendClass.Connection.prototype |
| } |
| @@ -100,6 +138,14 @@ WebInspector.WebSocketConnection.prototype = { |
| /** |
| * @override |
| + */ |
| + forceClose: function() |
| + { |
| + this._socket.close(); |
| + }, |
| + |
| + /** |
| + * @override |
| * @param {!Object} messageObject |
| */ |
| sendMessage: function(messageObject) |
| @@ -141,3 +187,61 @@ WebInspector.StubConnection.prototype = { |
| __proto__: InspectorBackendClass.Connection.prototype |
| } |
| + |
| + |
| +/** |
| + * @constructor |
| + * @param {function(string)} dispatchCallback |
| + * @param {function()} yieldCallback |
| + */ |
| +WebInspector.RawProtocolConnection = function(dispatchCallback, yieldCallback) |
| +{ |
| + InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Events.DispatchMessage, this._dispatchMessage, this); |
| + InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Events.DispatchMessageChunk, this._dispatchMessageChunk, this); |
| + this._dispatchCallback = dispatchCallback; |
| + this._yieldCallback = yieldCallback; |
| +} |
| + |
| +WebInspector.RawProtocolConnection.prototype = { |
| + /** |
| + * @param {string} message |
| + */ |
| + send: function(message) |
| + { |
| + InspectorFrontendHost.sendMessageToBackend(message); |
| + }, |
| + |
| + /** |
| + * @param {!WebInspector.Event} event |
| + */ |
| + _dispatchMessage: function(event) |
| + { |
| + this._dispatchCallback(/** @type {string} */ (event.data)); |
| + }, |
| + |
| + /** |
| + * @param {!WebInspector.Event} event |
| + */ |
| + _dispatchMessageChunk: function(event) |
| + { |
| + var messageChunk = /** @type {string} */ (event.data["messageChunk"]); |
| + var messageSize = /** @type {number} */ (event.data["messageSize"]); |
| + if (messageSize) { |
| + this._messageBuffer = ""; |
| + this._messageSize = messageSize; |
| + } |
| + this._messageBuffer += messageChunk; |
| + if (this._messageBuffer.length === this._messageSize) { |
| + this._dispatchCallback(this._messageBuffer); |
| + this._messageBuffer = ""; |
| + this._messageSize = 0; |
| + } |
| + }, |
| + |
| + yield: function() |
| + { |
| + InspectorFrontendHost.events.removeEventListener(InspectorFrontendHostAPI.Events.DispatchMessage, this._dispatchMessage, this); |
| + InspectorFrontendHost.events.removeEventListener(InspectorFrontendHostAPI.Events.DispatchMessageChunk, this._dispatchMessageChunk, this); |
| + this._yieldCallback(); |
|
dgozman
2016/10/15 00:26:26
Mark this as closed (disallow send and dispatch).
|
| + } |
| +} |