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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/devtools/front_end/main/FrontendWebSocketAPI.js
diff --git a/Source/devtools/front_end/main/FrontendWebSocketAPI.js b/Source/devtools/front_end/main/FrontendWebSocketAPI.js
new file mode 100644
index 0000000000000000000000000000000000000000..3a1813093832e8835510d413d322c0226ae3ba00
--- /dev/null
+++ b/Source/devtools/front_end/main/FrontendWebSocketAPI.js
@@ -0,0 +1,101 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * @constructor
+ */
+WebInspector.FrontendWebSocketAPI = function()
+{
+ InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Events.DispatchFrontendAPIMessage, this._onFrontendAPIMessage, this);
+ InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Events.FrontendAPIAttached, this._onAttach, this);
+ InspectorFrontendHost.events.addEventListener(InspectorFrontendHostAPI.Events.FrontendAPIDetached, this._onDetach, this);
+}
+
+WebInspector.FrontendWebSocketAPI.prototype = {
+ _onAttach: function()
+ {
+ WebInspector.workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeContentCommitted, this._workingCopyChanged, this);
+ WebInspector.workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeWorkingCopyChanged, this._workingCopyChanged, this);
+ },
+
+ _onDetach: function()
+ {
+ WebInspector.workspace.removeEventListener(WebInspector.Workspace.Events.UISourceCodeContentCommitted, this._workingCopyChanged, this);
+ WebInspector.workspace.removeEventListener(WebInspector.Workspace.Events.UISourceCodeWorkingCopyChanged, this._workingCopyChanged, this);
+ },
+
+ /**
+ * @param {!WebInspector.Event} event
+ */
+ _onFrontendAPIMessage: function(event)
+ {
+ var message = JSON.parse(/** @type {string} */ (event.data));
+ this._dispatchFrontendAPIMessage(message["id"], message["method"], message["params"] || null);
+ },
+
+ /**
+ * @param {number} id
+ * @param {string} method
+ * @param {?Object} params
+ */
+ _dispatchFrontendAPIMessage: function(id, method, params)
+ {
+ this._dispatchingFrontendMessage = true;
+ switch (method) {
+ case "Frontend.updateBuffer":
+ var file = params["file"];
+ var buffer = params["buffer"];
+ var save = params["save"];
+ var uiSourceCode = WebInspector.workspace.filesystemUISourceCode("file://" + file);
+ if (uiSourceCode) {
+ if (buffer !== uiSourceCode.workingCopy())
+ uiSourceCode.setWorkingCopy(buffer);
+ if (save && uiSourceCode.workingCopy())
+ uiSourceCode.commitWorkingCopy();
+ else if (uiSourceCode.workingCopy() === uiSourceCode.content())
+ uiSourceCode.resetWorkingCopy();
+ }
+ this._issueResponse(id);
+ break;
+ default:
+ WebInspector.console.log("Unhandled API message: " + method);
+ }
+ this._dispatchingFrontendMessage = false;
+ },
+
+ /**
+ * @param {!WebInspector.Event} event
+ */
+ _workingCopyChanged: function(event)
+ {
+ if (this._dispatchingFrontendMessage)
+ return;
+ var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data["uiSourceCode"]);
+ var url = uiSourceCode.originURL();
+ if (url.startsWith("file://"))
+ url = url.substring(7);
+ this._issueFrontendAPINotification("Frontend.bufferUpdated", { file: url, buffer: uiSourceCode.workingCopy() });
+ },
+
+ /**
+ * @param {number} id
+ * @param {!Object=} params
+ */
+ _issueResponse: function(id, params)
+ {
+ var object = {id: id};
+ if (params)
+ object.params = params;
+ InspectorFrontendHost.sendFrontendAPINotification(JSON.stringify(object));
+ },
+
+ /**
+ * @param {string} method
+ * @param {?Object} params
+ */
+ _issueFrontendAPINotification: function(method, params)
+ {
+ InspectorFrontendHost.sendFrontendAPINotification(JSON.stringify({ method: method, params: params }));
+ }
+}
« 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