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

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
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..5aebab3b8cdf56ec9a8cec76b090fc49a832b6ac
--- /dev/null
+++ b/Source/devtools/front_end/main/FrontendWebSocketAPI.js
@@ -0,0 +1,73 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
dgozman 2015/09/08 22:32:16 2015
pfeldman 2015/09/09 00:50:30 Done.
+// 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);
+ WebInspector.workspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeContentCommitted, this._sourceCodeContentCommitted, this);
+}
+
+WebInspector.FrontendWebSocketAPI.prototype = {
+ /**
+ * @param {!WebInspector.Event} event
+ */
+ _onFrontendAPIMessage: function(event)
+ {
+ var message = JSON.parse(/** @type {string} */ (event.data));
dgozman 2015/09/08 22:32:16 It's annotated as object in devtools.js. Why strin
pfeldman 2015/09/09 00:50:30 Done.
+ this._dispatchFrontendAPIMessage(message["id"], message["method"], message["params"] || null);
+ },
+
+ /**
+ * @param {number} id
+ * @param {string} method
+ * @param {?Object} params
+ */
+ _dispatchFrontendAPIMessage: function(id, method, params)
+ {
+ 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();
+ }
+ InspectorFrontendHost.sendFrontendAPINotification(JSON.stringify({id: id}));
dgozman 2015/09/08 22:32:16 Extract this into |_respondToFrontendAPIMessage(id
pfeldman 2015/09/09 00:50:29 Acknowledged.
+ break;
+ default:
+ WebInspector.console.log("Unhandled API message: " + method);
+ }
+ },
+
+ /**
+ * @param {!WebInspector.Event} event
+ */
+ _sourceCodeContentCommitted: function(event)
+ {
+ var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data["uiSourceCode"]);
+ var content = /** @type {string} */ (event.data["content"]);
+ var url = uiSourceCode.originURL();
+ if (url.startsWith("file://"))
+ url = url.substring(7);
+ this._issueFrontendAPINotification("Frontend.bufferUpdated", { file: url, buffer: content });
+ },
+
+ /**
+ * @param {string} method
+ * @param {?Object} params
+ */
+ _issueFrontendAPINotification: function(method, params)
+ {
+ InspectorFrontendHost.sendFrontendAPINotification(JSON.stringify({ method: method, params: params }));
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698