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 })); |
+ } |
+} |