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

Side by Side Diff: Source/devtools/front_end/sdk/LiveEditSupport.js

Issue 352953002: DevTools: properly support targets in LiveEditSupport (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix test Created 6 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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(error, errorData, script);
99 return; 103 return;
100 } 104 }
101 WebInspector.LiveEditSupport.logSuccess(); 105 WebInspector.LiveEditSupport.logSuccess();
102 } 106 }
103 } 107 },
108
109 __proto__: WebInspector.TargetAware.prototype
104 } 110 }
105 111
106 /** 112 /**
113 * @param {!WebInspector.UISourceCode} uiSourceCode
114 * @return {?WebInspector.LiveEditSupport}
115 */
116 WebInspector.LiveEditSupport.liveEditSupportForUISourceCode = function(uiSourceC ode)
117 {
118 var projectId = uiSourceCode.project().id();
119 var target;
120 var targets = WebInspector.targetManager.targets();
121 for (var i = 0; i < targets.length; ++i) {
122 if (projectId === WebInspector.DefaultScriptMapping.projectIdForTarget(t argets[i])) {
123 target = targets[i];
124 break;
125 }
126 }
127 return target ? target.debuggerScriptMapping.liveEditSupport() : null;
128 }
129
130 /**
107 * @param {?string} error 131 * @param {?string} error
108 * @param {!DebuggerAgent.SetScriptSourceError=} errorData 132 * @param {!DebuggerAgent.SetScriptSourceError=} errorData
109 * @param {!WebInspector.Script=} contextScript 133 * @param {!WebInspector.Script=} contextScript
110 */ 134 */
111 WebInspector.LiveEditSupport.logDetailedError = function(error, errorData, conte xtScript) 135 WebInspector.LiveEditSupport.logDetailedError = function(error, errorData, conte xtScript)
112 { 136 {
113 var warningLevel = WebInspector.ConsoleMessage.MessageLevel.Warning; 137 var warningLevel = WebInspector.ConsoleMessage.MessageLevel.Warning;
114 if (!errorData) { 138 if (!errorData) {
115 if (error) 139 if (error)
116 WebInspector.messageSink.addMessage(WebInspector.UIString("LiveEdit failed: %s", error), warningLevel); 140 WebInspector.messageSink.addMessage(WebInspector.UIString("LiveEdit failed: %s", error), warningLevel);
117 return; 141 return;
118 } 142 }
119 var compileError = errorData.compileError; 143 var compileError = errorData.compileError;
120 if (compileError) { 144 if (compileError) {
121 var location = contextScript ? WebInspector.UIString(" at %s:%d:%d", con textScript.sourceURL, compileError.lineNumber, compileError.columnNumber) : ""; 145 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); 146 var message = WebInspector.UIString("LiveEdit compile failed: %s%s", com pileError.message, location);
123 WebInspector.messageSink.addErrorMessage(message); 147 WebInspector.messageSink.addErrorMessage(message);
124 } else { 148 } else {
125 WebInspector.messageSink.addMessage(WebInspector.UIString("Unknown LiveE dit error: %s; %s", JSON.stringify(errorData), error), warningLevel); 149 WebInspector.messageSink.addMessage(WebInspector.UIString("Unknown LiveE dit error: %s; %s", JSON.stringify(errorData), error), warningLevel);
126 } 150 }
127 } 151 }
128 152
129 WebInspector.LiveEditSupport.logSuccess = function() 153 WebInspector.LiveEditSupport.logSuccess = function()
130 { 154 {
131 WebInspector.messageSink.addMessage(WebInspector.UIString("Recompilation and update succeeded.")); 155 WebInspector.messageSink.addMessage(WebInspector.UIString("Recompilation and update succeeded."));
132 } 156 }
133
134 /** @type {!WebInspector.LiveEditSupport} */
135 WebInspector.liveEditSupport;
OLDNEW
« no previous file with comments | « Source/devtools/front_end/sdk/DefaultScriptMapping.js ('k') | Source/devtools/front_end/sdk/ResourceScriptMapping.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698