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

Side by Side Diff: Source/devtools/front_end/main/FrontendWebSocketAPI.js

Issue 1314853006: DevTools: expose wired front-end API for editors interop [blink] (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 3 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 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 */
8 WebInspector.FrontendWebSocketAPI = function()
9 {
10 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.DispatchFrontendAPIMessage, this._onFrontendAPIMessage, this);
11 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.FrontendAPIAttached, this._onAttach, this);
12 InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Event s.FrontendAPIDetached, this._onDetach, this);
13 }
14
15 WebInspector.FrontendWebSocketAPI.prototype = {
16 _onAttach: function()
17 {
18 WebInspector.workspace.addEventListener(WebInspector.Workspace.Events.UI SourceCodeContentCommitted, this._workingCopyChanged, this);
19 WebInspector.workspace.addEventListener(WebInspector.Workspace.Events.UI SourceCodeWorkingCopyChanged, this._workingCopyChanged, this);
20 },
21
22 _onDetach: function()
23 {
24 WebInspector.workspace.removeEventListener(WebInspector.Workspace.Events .UISourceCodeContentCommitted, this._workingCopyChanged, this);
25 WebInspector.workspace.removeEventListener(WebInspector.Workspace.Events .UISourceCodeWorkingCopyChanged, this._workingCopyChanged, this);
26 },
27
28 /**
29 * @param {!WebInspector.Event} event
30 */
31 _onFrontendAPIMessage: function(event)
32 {
33 var message = JSON.parse(/** @type {string} */ (event.data));
34 this._dispatchFrontendAPIMessage(message["id"], message["method"], messa ge["params"] || null);
35 },
36
37 /**
38 * @param {number} id
39 * @param {string} method
40 * @param {?Object} params
41 */
42 _dispatchFrontendAPIMessage: function(id, method, params)
43 {
44 this._dispatchingFrontendMessage = true;
45 switch (method) {
46 case "Frontend.updateBuffer":
47 var file = params["file"];
48 var buffer = params["buffer"];
49 var save = params["save"];
50 var uiSourceCode = WebInspector.workspace.filesystemUISourceCode("fi le://" + file);
51 if (uiSourceCode) {
52 if (buffer !== uiSourceCode.workingCopy())
53 uiSourceCode.setWorkingCopy(buffer);
54 if (save && uiSourceCode.workingCopy())
55 uiSourceCode.commitWorkingCopy();
56 else if (uiSourceCode.workingCopy() === uiSourceCode.content())
57 uiSourceCode.resetWorkingCopy();
58 }
59 this._issueResponse(id);
60 break;
61 default:
62 WebInspector.console.log("Unhandled API message: " + method);
63 }
64 this._dispatchingFrontendMessage = false;
65 },
66
67 /**
68 * @param {!WebInspector.Event} event
69 */
70 _workingCopyChanged: function(event)
71 {
72 if (this._dispatchingFrontendMessage)
73 return;
74 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data ["uiSourceCode"]);
75 var url = uiSourceCode.originURL();
76 if (url.startsWith("file://"))
77 url = url.substring(7);
78 this._issueFrontendAPINotification("Frontend.bufferUpdated", { file: url , buffer: uiSourceCode.workingCopy() });
79 },
80
81 /**
82 * @param {number} id
83 * @param {!Object=} params
84 */
85 _issueResponse: function(id, params)
86 {
87 var object = {id: id};
88 if (params)
89 object.params = params;
90 InspectorFrontendHost.sendFrontendAPINotification(JSON.stringify(object) );
91 },
92
93 /**
94 * @param {string} method
95 * @param {?Object} params
96 */
97 _issueFrontendAPINotification: function(method, params)
98 {
99 InspectorFrontendHost.sendFrontendAPINotification(JSON.stringify({ metho d: method, params: params }));
100 }
101 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/host/InspectorFrontendHostAPI.js ('k') | Source/devtools/front_end/main/Main.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698