Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
|
dgozman
2015/09/08 22:32:16
2015
pfeldman
2015/09/09 00:50:30
Done.
| |
| 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 WebInspector.workspace.addEventListener(WebInspector.Workspace.Events.UISour ceCodeContentCommitted, this._sourceCodeContentCommitted, this); | |
| 12 } | |
| 13 | |
| 14 WebInspector.FrontendWebSocketAPI.prototype = { | |
| 15 /** | |
| 16 * @param {!WebInspector.Event} event | |
| 17 */ | |
| 18 _onFrontendAPIMessage: function(event) | |
| 19 { | |
| 20 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.
| |
| 21 this._dispatchFrontendAPIMessage(message["id"], message["method"], messa ge["params"] || null); | |
| 22 }, | |
| 23 | |
| 24 /** | |
| 25 * @param {number} id | |
| 26 * @param {string} method | |
| 27 * @param {?Object} params | |
| 28 */ | |
| 29 _dispatchFrontendAPIMessage: function(id, method, params) | |
| 30 { | |
| 31 switch (method) { | |
| 32 case "Frontend.updateBuffer": | |
| 33 var file = params["file"]; | |
| 34 var buffer = params["buffer"]; | |
| 35 var save = params["save"]; | |
| 36 var uiSourceCode = WebInspector.workspace.filesystemUISourceCode("fi le://" + file); | |
| 37 if (uiSourceCode) { | |
| 38 if (buffer !== uiSourceCode.workingCopy()) | |
| 39 uiSourceCode.setWorkingCopy(buffer); | |
| 40 if (save && uiSourceCode.workingCopy()) | |
| 41 uiSourceCode.commitWorkingCopy(); | |
| 42 else if (uiSourceCode.workingCopy() === uiSourceCode.content()) | |
| 43 uiSourceCode.resetWorkingCopy(); | |
| 44 } | |
| 45 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.
| |
| 46 break; | |
| 47 default: | |
| 48 WebInspector.console.log("Unhandled API message: " + method); | |
| 49 } | |
| 50 }, | |
| 51 | |
| 52 /** | |
| 53 * @param {!WebInspector.Event} event | |
| 54 */ | |
| 55 _sourceCodeContentCommitted: function(event) | |
| 56 { | |
| 57 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.data ["uiSourceCode"]); | |
| 58 var content = /** @type {string} */ (event.data["content"]); | |
| 59 var url = uiSourceCode.originURL(); | |
| 60 if (url.startsWith("file://")) | |
| 61 url = url.substring(7); | |
| 62 this._issueFrontendAPINotification("Frontend.bufferUpdated", { file: url , buffer: content }); | |
| 63 }, | |
| 64 | |
| 65 /** | |
| 66 * @param {string} method | |
| 67 * @param {?Object} params | |
| 68 */ | |
| 69 _issueFrontendAPINotification: function(method, params) | |
| 70 { | |
| 71 InspectorFrontendHost.sendFrontendAPINotification(JSON.stringify({ metho d: method, params: params })); | |
| 72 } | |
| 73 } | |
| OLD | NEW |