Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/main/Connections.js

Issue 2421913003: DevTools: allow reattaching main target live. (Closed)
Patch Set: link fixed Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 /**
6 * @constructor
7 * @extends {InspectorBackendClass.Connection}
8 */
9 WebInspector.MainConnection = function()
10 {
11 InspectorBackendClass.Connection.call(this);
12 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.DispatchMessage, this._dispatchMessage, this);
13 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.DispatchMessageChunk, this._dispatchMessageChunk, this);
14 }
15
16 WebInspector.MainConnection.prototype = {
17 /**
18 * @override
19 * @param {!Object} messageObject
20 */
21 sendMessage: function(messageObject)
22 {
23 var message = JSON.stringify(messageObject);
24 InspectorFrontendHost.sendMessageToBackend(message);
25 },
26
27 /**
28 * @param {!WebInspector.Event} event
29 */
30 _dispatchMessage: function(event)
31 {
32 this.dispatch(/** @type {string} */ (event.data));
33 },
34
35 /**
36 * @param {!WebInspector.Event} event
37 */
38 _dispatchMessageChunk: function(event)
39 {
40 var messageChunk = /** @type {string} */ (event.data["messageChunk"]);
41 var messageSize = /** @type {number} */ (event.data["messageSize"]);
42 if (messageSize) {
43 this._messageBuffer = "";
44 this._messageSize = messageSize;
45 }
46 this._messageBuffer += messageChunk;
47 if (this._messageBuffer.length === this._messageSize) {
48 this.dispatch(this._messageBuffer);
49 this._messageBuffer = "";
50 this._messageSize = 0;
51 }
52 },
53
54 __proto__: InspectorBackendClass.Connection.prototype
55 }
56
57 /**
58 * @constructor
59 * @extends {InspectorBackendClass.Connection}
60 * @param {string} url
61 * @param {function(!InspectorBackendClass.Connection)} onConnectionReady
62 */
63 WebInspector.WebSocketConnection = function(url, onConnectionReady)
64 {
65 InspectorBackendClass.Connection.call(this);
66 this._socket = new WebSocket(url);
67 this._socket.onmessage = this._onMessage.bind(this);
68 this._socket.onerror = this._onError.bind(this);
69 this._socket.onopen = onConnectionReady.bind(null, this);
70 this._socket.onclose = this.connectionClosed.bind(this, "websocket_closed");
71 }
72
73 /**
74 * @param {string} url
75 * @param {function(!InspectorBackendClass.Connection)} onConnectionReady
76 */
77 WebInspector.WebSocketConnection.Create = function(url, onConnectionReady)
78 {
79 new WebInspector.WebSocketConnection(url, onConnectionReady);
80 }
81
82 WebInspector.WebSocketConnection.prototype = {
83
84 /**
85 * @param {!MessageEvent} message
86 */
87 _onMessage: function(message)
88 {
89 var data = /** @type {string} */ (message.data);
90 this.dispatch(data);
91 },
92
93 /**
94 * @param {!Event} error
95 */
96 _onError: function(error)
97 {
98 console.error(error);
99 },
100
101 /**
102 * @override
103 * @param {!Object} messageObject
104 */
105 sendMessage: function(messageObject)
106 {
107 var message = JSON.stringify(messageObject);
108 this._socket.send(message);
109 },
110
111 __proto__: InspectorBackendClass.Connection.prototype
112 }
113
114 /**
115 * @constructor
116 * @extends {InspectorBackendClass.Connection}
117 */
118 WebInspector.StubConnection = function()
119 {
120 InspectorBackendClass.Connection.call(this);
121 }
122
123 WebInspector.StubConnection.prototype = {
124 /**
125 * @override
126 * @param {!Object} messageObject
127 */
128 sendMessage: function(messageObject)
129 {
130 setTimeout(this._respondWithError.bind(this, messageObject), 0);
131 },
132
133 /**
134 * @param {!Object} messageObject
135 */
136 _respondWithError: function(messageObject)
137 {
138 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 });
140 },
141
142 __proto__: InspectorBackendClass.Connection.prototype
143 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698