| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 var uiLocation = script.rawLocationToUILocation(0, 0); | 52 var uiLocation = script.rawLocationToUILocation(0, 0); |
| 53 | 53 |
| 54 // FIXME: Support live editing of scripts mapped to some file. | 54 // FIXME: Support live editing of scripts mapped to some file. |
| 55 if (uiLocation.uiSourceCode !== uiSourceCode) | 55 if (uiLocation.uiSourceCode !== uiSourceCode) |
| 56 return uiLocation.uiSourceCode; | 56 return uiLocation.uiSourceCode; |
| 57 if (this._uiSourceCodeForScriptId[script.scriptId]) | 57 if (this._uiSourceCodeForScriptId[script.scriptId]) |
| 58 return this._uiSourceCodeForScriptId[script.scriptId]; | 58 return this._uiSourceCodeForScriptId[script.scriptId]; |
| 59 | 59 |
| 60 console.assert(!script.isInlineScript()); | 60 console.assert(!script.isInlineScript()); |
| 61 var liveEditUISourceCode = this._workspaceProvider.addUniqueFileForURL(s
cript.sourceURL, script, true, script.isContentScript); | 61 var liveEditUISourceCode = this._workspaceProvider.addUniqueFileForURL(s
cript.sourceURL, script, true, script.isContentScript); |
| 62 liveEditUISourceCode.addEventListener(WebInspector.UISourceCode.Events.W
orkingCopyCommitted, this._workingCopyCommitted, this); |
| 62 | 63 |
| 63 liveEditUISourceCode.setScriptFile(new WebInspector.LiveEditScriptFile(u
iSourceCode, liveEditUISourceCode, script.scriptId)); | |
| 64 this._uiSourceCodeForScriptId[script.scriptId] = liveEditUISourceCode; | 64 this._uiSourceCodeForScriptId[script.scriptId] = liveEditUISourceCode; |
| 65 this._scriptIdForUISourceCode.put(liveEditUISourceCode, script.scriptId)
; | 65 this._scriptIdForUISourceCode.put(liveEditUISourceCode, script.scriptId)
; |
| 66 return liveEditUISourceCode; | 66 return liveEditUISourceCode; |
| 67 }, | 67 }, |
| 68 | 68 |
| 69 _debuggerReset: function() | 69 _debuggerReset: function() |
| 70 { | 70 { |
| 71 /** @type {!Object.<string, !WebInspector.UISourceCode>} */ | 71 /** @type {!Object.<string, !WebInspector.UISourceCode>} */ |
| 72 this._uiSourceCodeForScriptId = {}; | 72 this._uiSourceCodeForScriptId = {}; |
| 73 /** @type {!Map.<!WebInspector.UISourceCode, string>} */ | 73 /** @type {!Map.<!WebInspector.UISourceCode, string>} */ |
| 74 this._scriptIdForUISourceCode = new Map(); | 74 this._scriptIdForUISourceCode = new Map(); |
| 75 this._workspaceProvider.reset(); | 75 this._workspaceProvider.reset(); |
| 76 }, | 76 }, |
| 77 |
| 78 /** |
| 79 * @param {!WebInspector.Event} event |
| 80 */ |
| 81 _workingCopyCommitted: function(event) |
| 82 { |
| 83 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.targ
et); |
| 84 var scriptId = /** @type {string} */ (this._scriptIdForUISourceCode.get(
uiSourceCode)); |
| 85 WebInspector.debuggerModel.setScriptSource(scriptId, uiSourceCode.workin
gCopy(), innerCallback); |
| 86 |
| 87 /** |
| 88 * @param {?string} error |
| 89 * @param {!DebuggerAgent.SetScriptSourceError=} errorData |
| 90 */ |
| 91 function innerCallback(error, errorData) |
| 92 { |
| 93 if (error) { |
| 94 var script = WebInspector.debuggerModel.scriptForId(scriptId); |
| 95 WebInspector.LiveEditSupport.logDetailedError(error, errorData,
script); |
| 96 return; |
| 97 } |
| 98 WebInspector.LiveEditSupport.logSuccess(); |
| 99 } |
| 100 } |
| 77 } | 101 } |
| 78 | 102 |
| 79 /** | 103 /** |
| 80 * @param {?string} error | 104 * @param {?string} error |
| 81 * @param {!DebuggerAgent.SetScriptSourceError=} errorData | 105 * @param {!DebuggerAgent.SetScriptSourceError=} errorData |
| 82 * @param {!WebInspector.Script=} contextScript | 106 * @param {!WebInspector.Script=} contextScript |
| 83 */ | 107 */ |
| 84 WebInspector.LiveEditSupport.logDetailedError = function(error, errorData, conte
xtScript) | 108 WebInspector.LiveEditSupport.logDetailedError = function(error, errorData, conte
xtScript) |
| 85 { | 109 { |
| 86 var warningLevel = WebInspector.ConsoleMessage.MessageLevel.Warning; | 110 var warningLevel = WebInspector.ConsoleMessage.MessageLevel.Warning; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 97 } else { | 121 } else { |
| 98 WebInspector.console.log(WebInspector.UIString("Unknown LiveEdit error:
%s; %s", JSON.stringify(errorData), error), warningLevel, false); | 122 WebInspector.console.log(WebInspector.UIString("Unknown LiveEdit error:
%s; %s", JSON.stringify(errorData), error), warningLevel, false); |
| 99 } | 123 } |
| 100 } | 124 } |
| 101 | 125 |
| 102 WebInspector.LiveEditSupport.logSuccess = function() | 126 WebInspector.LiveEditSupport.logSuccess = function() |
| 103 { | 127 { |
| 104 WebInspector.console.log(WebInspector.UIString("Recompilation and update suc
ceeded."), WebInspector.ConsoleMessage.MessageLevel.Debug, false); | 128 WebInspector.console.log(WebInspector.UIString("Recompilation and update suc
ceeded."), WebInspector.ConsoleMessage.MessageLevel.Debug, false); |
| 105 } | 129 } |
| 106 | 130 |
| 107 /** | |
| 108 * @constructor | |
| 109 * @implements {WebInspector.ScriptFile} | |
| 110 * @extends {WebInspector.Object} | |
| 111 * @param {!WebInspector.UISourceCode} uiSourceCode | |
| 112 * @param {!WebInspector.UISourceCode} liveEditUISourceCode | |
| 113 * @param {string} scriptId | |
| 114 */ | |
| 115 WebInspector.LiveEditScriptFile = function(uiSourceCode, liveEditUISourceCode, s
criptId) | |
| 116 { | |
| 117 WebInspector.ScriptFile.call(this); | |
| 118 this._uiSourceCode = uiSourceCode; | |
| 119 this._liveEditUISourceCode = liveEditUISourceCode; | |
| 120 this._scriptId = scriptId; | |
| 121 this._liveEditUISourceCode.addEventListener(WebInspector.UISourceCode.Events
.WorkingCopyCommitted, this._workingCopyCommitted, this); | |
| 122 } | |
| 123 | |
| 124 WebInspector.LiveEditScriptFile.prototype = { | |
| 125 _workingCopyCommitted: function(event) | |
| 126 { | |
| 127 /** | |
| 128 * @param {?string} error | |
| 129 * @param {!DebuggerAgent.SetScriptSourceError=} errorData | |
| 130 * @this {WebInspector.LiveEditScriptFile} | |
| 131 */ | |
| 132 function innerCallback(error, errorData) | |
| 133 { | |
| 134 if (error) { | |
| 135 var script = WebInspector.debuggerModel.scriptForId(this._script
Id); | |
| 136 WebInspector.LiveEditSupport.logDetailedError(error, errorData,
script); | |
| 137 return; | |
| 138 } | |
| 139 WebInspector.LiveEditSupport.logSuccess(); | |
| 140 } | |
| 141 | |
| 142 var script = WebInspector.debuggerModel.scriptForId(this._scriptId); | |
| 143 WebInspector.debuggerModel.setScriptSource(script.scriptId, this._liveEd
itUISourceCode.workingCopy(), innerCallback.bind(this)); | |
| 144 }, | |
| 145 | |
| 146 /** | |
| 147 * @return {boolean} | |
| 148 */ | |
| 149 hasDivergedFromVM: function() | |
| 150 { | |
| 151 return true; | |
| 152 }, | |
| 153 | |
| 154 /** | |
| 155 * @return {boolean} | |
| 156 */ | |
| 157 isDivergingFromVM: function() | |
| 158 { | |
| 159 return false; | |
| 160 }, | |
| 161 | |
| 162 /** | |
| 163 * @return {boolean} | |
| 164 */ | |
| 165 isMergingToVM: function() | |
| 166 { | |
| 167 return false; | |
| 168 }, | |
| 169 | |
| 170 checkMapping: function() | |
| 171 { | |
| 172 }, | |
| 173 | |
| 174 __proto__: WebInspector.Object.prototype | |
| 175 } | |
| 176 | |
| 177 /** @type {!WebInspector.LiveEditSupport} */ | 131 /** @type {!WebInspector.LiveEditSupport} */ |
| 178 WebInspector.liveEditSupport; | 132 WebInspector.liveEditSupport; |
| OLD | NEW |