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 12 matching lines...) Expand all Loading... |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 /** | 31 /** |
32 * @constructor | 32 * @constructor |
| 33 * @extends {WebInspector.TargetAware} |
| 34 * @param {!WebInspector.Target} target |
33 * @param {!WebInspector.Workspace} workspace | 35 * @param {!WebInspector.Workspace} workspace |
34 */ | 36 */ |
35 WebInspector.LiveEditSupport = function(workspace) | 37 WebInspector.LiveEditSupport = function(target, workspace) |
36 { | 38 { |
| 39 WebInspector.TargetAware.call(this, target); |
37 this._workspace = workspace; | 40 this._workspace = workspace; |
38 this._projectId = "liveedit:"; | 41 this._projectId = "liveedit:" + target.id(); |
39 this._projectDelegate = new WebInspector.DebuggerProjectDelegate(workspace,
this._projectId, WebInspector.projectTypes.LiveEdit); | 42 this._projectDelegate = new WebInspector.DebuggerProjectDelegate(workspace,
this._projectId, WebInspector.projectTypes.LiveEdit); |
40 WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Event
s.GlobalObjectCleared, this._debuggerReset, this); | 43 target.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.Glob
alObjectCleared, this._debuggerReset, this); |
41 this._debuggerReset(); | 44 this._debuggerReset(); |
42 } | 45 } |
43 | 46 |
44 WebInspector.LiveEditSupport.prototype = { | 47 WebInspector.LiveEditSupport.prototype = { |
45 /** | 48 /** |
46 * @param {!WebInspector.UISourceCode} uiSourceCode | 49 * @param {!WebInspector.UISourceCode} uiSourceCode |
47 * @return {!WebInspector.UISourceCode} | 50 * @return {!WebInspector.UISourceCode} |
48 */ | 51 */ |
49 uiSourceCodeForLiveEdit: function(uiSourceCode) | 52 uiSourceCodeForLiveEdit: function(uiSourceCode) |
50 { | 53 { |
51 var rawLocation = uiSourceCode.uiLocationToRawLocation(WebInspector.targ
etManager.targets()[0], 0, 0); | 54 var rawLocation = uiSourceCode.uiLocationToRawLocation(this.target(), 0,
0); |
52 var debuggerModelLocation = /** @type {!WebInspector.DebuggerModel.Locat
ion} */ (rawLocation); | 55 var debuggerModelLocation = /** @type {!WebInspector.DebuggerModel.Locat
ion} */ (rawLocation); |
53 var script = debuggerModelLocation.script(); | 56 var script = debuggerModelLocation.script(); |
54 var uiLocation = script.rawLocationToUILocation(0, 0); | 57 var uiLocation = script.rawLocationToUILocation(0, 0); |
55 | 58 |
56 // FIXME: Support live editing of scripts mapped to some file. | 59 // FIXME: Support live editing of scripts mapped to some file. |
57 if (uiLocation.uiSourceCode !== uiSourceCode) | 60 if (uiLocation.uiSourceCode !== uiSourceCode) |
58 return uiLocation.uiSourceCode; | 61 return uiLocation.uiSourceCode; |
59 if (this._uiSourceCodeForScriptId[script.scriptId]) | 62 if (this._uiSourceCodeForScriptId[script.scriptId]) |
60 return this._uiSourceCodeForScriptId[script.scriptId]; | 63 return this._uiSourceCodeForScriptId[script.scriptId]; |
61 | 64 |
(...skipping 16 matching lines...) Expand all Loading... |
78 this._projectDelegate.reset(); | 81 this._projectDelegate.reset(); |
79 }, | 82 }, |
80 | 83 |
81 /** | 84 /** |
82 * @param {!WebInspector.Event} event | 85 * @param {!WebInspector.Event} event |
83 */ | 86 */ |
84 _workingCopyCommitted: function(event) | 87 _workingCopyCommitted: function(event) |
85 { | 88 { |
86 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.targ
et); | 89 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (event.targ
et); |
87 var scriptId = /** @type {string} */ (this._scriptIdForUISourceCode.get(
uiSourceCode)); | 90 var scriptId = /** @type {string} */ (this._scriptIdForUISourceCode.get(
uiSourceCode)); |
88 WebInspector.debuggerModel.setScriptSource(scriptId, uiSourceCode.workin
gCopy(), innerCallback); | 91 this.target().debuggerModel.setScriptSource(scriptId, uiSourceCode.worki
ngCopy(), innerCallback.bind(this)); |
89 | 92 |
90 /** | 93 /** |
| 94 * @this {WebInspector.LiveEditSupport} |
91 * @param {?string} error | 95 * @param {?string} error |
92 * @param {!DebuggerAgent.SetScriptSourceError=} errorData | 96 * @param {!DebuggerAgent.SetScriptSourceError=} errorData |
93 */ | 97 */ |
94 function innerCallback(error, errorData) | 98 function innerCallback(error, errorData) |
95 { | 99 { |
96 if (error) { | 100 if (error) { |
97 var script = WebInspector.debuggerModel.scriptForId(scriptId); | 101 var script = this.target().debuggerModel.scriptForId(scriptId); |
98 WebInspector.LiveEditSupport.logDetailedError(error, errorData,
script); | 102 WebInspector.LiveEditSupport.logDetailedError(this.target(), err
or, errorData, script); |
99 return; | 103 return; |
100 } | 104 } |
101 WebInspector.LiveEditSupport.logSuccess(); | 105 WebInspector.LiveEditSupport.logSuccess(this.target()); |
102 } | 106 } |
103 } | 107 }, |
| 108 |
| 109 __proto__: WebInspector.TargetAware.prototype |
104 } | 110 } |
105 | 111 |
106 /** | 112 /** |
107 * @param {?string} error | 113 * @param {!WebInspector.Target} target |
108 * @param {!DebuggerAgent.SetScriptSourceError=} errorData | 114 * @param {?string} error |
109 * @param {!WebInspector.Script=} contextScript | 115 * @param {!DebuggerAgent.SetScriptSourceError=} errorData |
110 */ | 116 * @param {!WebInspector.Script=} contextScript |
111 WebInspector.LiveEditSupport.logDetailedError = function(error, errorData, conte
xtScript) | 117 */ |
| 118 WebInspector.LiveEditSupport.logDetailedError = function(target, error, errorDat
a, contextScript) |
112 { | 119 { |
113 var warningLevel = WebInspector.ConsoleMessage.MessageLevel.Warning; | 120 var warningLevel = WebInspector.ConsoleMessage.MessageLevel.Warning; |
114 if (!errorData) { | 121 if (!errorData) { |
115 if (error) | 122 if (error) |
116 WebInspector.messageSink.addMessage(WebInspector.UIString("LiveEdit
failed: %s", error), warningLevel); | 123 target.consoleModel.log(WebInspector.UIString("LiveEdit failed: %s",
error), warningLevel, false); |
117 return; | 124 return; |
118 } | 125 } |
119 var compileError = errorData.compileError; | 126 var compileError = errorData.compileError; |
120 if (compileError) { | 127 if (compileError) { |
121 var location = contextScript ? WebInspector.UIString(" at %s:%d:%d", con
textScript.sourceURL, compileError.lineNumber, compileError.columnNumber) : ""; | 128 var location = contextScript ? WebInspector.UIString(" at %s:%d:%d", con
textScript.sourceURL, compileError.lineNumber, compileError.columnNumber) : ""; |
122 var message = WebInspector.UIString("LiveEdit compile failed: %s%s", com
pileError.message, location); | 129 var message = WebInspector.UIString("LiveEdit compile failed: %s%s", com
pileError.message, location); |
123 WebInspector.messageSink.addErrorMessage(message); | 130 target.consoleModel.log(message, WebInspector.ConsoleMessage.MessageLeve
l.Error, false); |
124 } else { | 131 } else { |
125 WebInspector.messageSink.addMessage(WebInspector.UIString("Unknown LiveE
dit error: %s; %s", JSON.stringify(errorData), error), warningLevel); | 132 target.consoleModel.log(WebInspector.UIString("Unknown LiveEdit error: %
s; %s", JSON.stringify(errorData), error), warningLevel, false); |
126 } | 133 } |
127 } | 134 } |
128 | 135 |
129 WebInspector.LiveEditSupport.logSuccess = function() | 136 /** |
| 137 * @param {!WebInspector.Target} target |
| 138 */ |
| 139 WebInspector.LiveEditSupport.logSuccess = function(target) |
130 { | 140 { |
131 WebInspector.messageSink.addMessage(WebInspector.UIString("Recompilation and
update succeeded.")); | 141 target.consoleModel.log(WebInspector.UIString("Recompilation and update succ
eeded."), WebInspector.ConsoleMessage.MessageLevel.Debug, false); |
132 } | 142 } |
133 | |
134 /** @type {!WebInspector.LiveEditSupport} */ | |
135 WebInspector.liveEditSupport; | |
OLD | NEW |