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

Side by Side Diff: webkit/glue/devtools/js/debugger_agent.js

Issue 131036: Preserve breakpoints on page reload (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview Provides communication interface to remote v8 debugger. See 6 * @fileoverview Provides communication interface to remote v8 debugger. See
7 * protocol decription at http://code.google.com/p/v8/wiki/DebuggerProtocol 7 * protocol decription at http://code.google.com/p/v8/wiki/DebuggerProtocol
8 */ 8 */
9 goog.provide('devtools.DebuggerAgent'); 9 goog.provide('devtools.DebuggerAgent');
10 10
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 * Whether profiling session is started. 72 * Whether profiling session is started.
73 * @type {boolean} 73 * @type {boolean}
74 */ 74 */
75 this.isProfilingStarted_ = false; 75 this.isProfilingStarted_ = false;
76 76
77 /** 77 /**
78 * Profiler processor instance. 78 * Profiler processor instance.
79 * @type {devtools.profiler.Processor} 79 * @type {devtools.profiler.Processor}
80 */ 80 */
81 this.profilerProcessor_ = new devtools.profiler.Processor(); 81 this.profilerProcessor_ = new devtools.profiler.Processor();
82
83 /**
84 * Container of all breakpoints set using resource URL. These breakpoints
85 * survive page reload. Breakpoints set by script id(for scripts that don't
86 * have URLs) are stored in ScriptInfo objects.
87 * @type {Object}
88 */
89 this.urlToBreakpoints_ = {};
82 }; 90 };
83 91
84 92
85 /** 93 /**
86 * Resets debugger agent to its initial state. 94 * Resets debugger agent to its initial state.
87 */ 95 */
88 devtools.DebuggerAgent.prototype.reset = function() { 96 devtools.DebuggerAgent.prototype.reset = function() {
89 this.scriptsCacheInitialized_ = false; 97 this.scriptsCacheInitialized_ = false;
90 this.contextId_ = null; 98 this.contextId_ = null;
91 this.parsedScripts_ = {}; 99 this.parsedScripts_ = {};
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 * @param {number} line Number of the line for the breakpoint. 184 * @param {number} line Number of the line for the breakpoint.
177 */ 185 */
178 devtools.DebuggerAgent.prototype.addBreakpoint = function(sourceId, line) { 186 devtools.DebuggerAgent.prototype.addBreakpoint = function(sourceId, line) {
179 var script = this.parsedScripts_[sourceId]; 187 var script = this.parsedScripts_[sourceId];
180 if (!script) { 188 if (!script) {
181 return; 189 return;
182 } 190 }
183 191
184 line = devtools.DebuggerAgent.webkitToV8LineNumber_(line); 192 line = devtools.DebuggerAgent.webkitToV8LineNumber_(line);
185 193
186 var breakpointInfo = script.getBreakpointInfo(line); 194 var commandArguments;
187 if (breakpointInfo) { 195 if (script.getUrl()) {
188 return; 196 var breakpoints = this.urlToBreakpoints_[script.getUrl()];
197 if (breakpoints && breakpoints[line]) {
198 return;
199 }
200 if (!breakpoints) {
201 breakpoints = {};
202 this.urlToBreakpoints_[script.getUrl()] = breakpoints;
203 }
204
205 var breakpointInfo = new devtools.BreakpointInfo(line);
206 breakpoints[line] = breakpointInfo;
207
208 commandArguments = {
209 'type': 'script',
210 'target': script.getUrl(),
211 'line': line
212 };
213 } else {
214 var breakpointInfo = script.getBreakpointInfo(line);
215 if (breakpointInfo) {
216 return;
217 }
218
219 breakpointInfo = new devtools.BreakpointInfo(line);
220 script.addBreakpointInfo(breakpointInfo);
221
222 commandArguments = {
223 'type': 'scriptId',
224 'target': sourceId,
225 'line': line
226 };
189 } 227 }
190 228
191 breakpointInfo = new devtools.BreakpointInfo(sourceId, line); 229 var cmd = new devtools.DebugCommand('setbreakpoint', commandArguments);
192 script.addBreakpointInfo(breakpointInfo);
193
194 var cmd = new devtools.DebugCommand('setbreakpoint', {
195 'type': 'scriptId',
196 'target': sourceId,
197 'line': line
198 });
199 230
200 this.requestNumberToBreakpointInfo_[cmd.getSequenceNumber()] = breakpointInfo; 231 this.requestNumberToBreakpointInfo_[cmd.getSequenceNumber()] = breakpointInfo;
201 232
202 devtools.DebuggerAgent.sendCommand_(cmd); 233 devtools.DebuggerAgent.sendCommand_(cmd);
203 }; 234 };
204 235
205 236
206 /** 237 /**
207 * @param {number} sourceId Id of the script fot the breakpoint. 238 * @param {number} sourceId Id of the script fot the breakpoint.
208 * @param {number} line Number of the line for the breakpoint. 239 * @param {number} line Number of the line for the breakpoint.
209 */ 240 */
210 devtools.DebuggerAgent.prototype.removeBreakpoint = function(sourceId, line) { 241 devtools.DebuggerAgent.prototype.removeBreakpoint = function(sourceId, line) {
211 var script = this.parsedScripts_[sourceId]; 242 var script = this.parsedScripts_[sourceId];
212 if (!script) { 243 if (!script) {
213 return; 244 return;
214 } 245 }
215 246
216 line = devtools.DebuggerAgent.webkitToV8LineNumber_(line); 247 line = devtools.DebuggerAgent.webkitToV8LineNumber_(line);
217 248
218 var breakpointInfo = script.getBreakpointInfo(line); 249 var breakpointInfo;
219 script.removeBreakpointInfo(breakpointInfo); 250 if (script.getUrl()) {
251 var breakpoints = this.urlToBreakpoints_[script.getUrl()];
252 breakpointInfo = breakpoints[line];
253 delete breakpoints[line];
254 } else {
255 breakpointInfo = script.getBreakpointInfo(line);
256 script.removeBreakpointInfo(breakpointInfo);
257 }
258
220 breakpointInfo.markAsRemoved(); 259 breakpointInfo.markAsRemoved();
221 260
222 var id = breakpointInfo.getV8Id(); 261 var id = breakpointInfo.getV8Id();
223 262
224 // If we don't know id of this breakpoint in the v8 debugger we cannot send 263 // If we don't know id of this breakpoint in the v8 debugger we cannot send
225 // 'clearbreakpoint' request. In that case it will be removed in 264 // 'clearbreakpoint' request. In that case it will be removed in
226 // 'setbreakpoint' response handler when we learn the id. 265 // 'setbreakpoint' response handler when we learn the id.
227 if (id != -1) { 266 if (id != -1) {
228 this.requestClearBreakpoint_(id); 267 this.requestClearBreakpoint_(id);
229 } 268 }
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 * Adds the script info to the local cache. This method assumes that the script 716 * Adds the script info to the local cache. This method assumes that the script
678 * is not in the cache yet. 717 * is not in the cache yet.
679 * @param {Object} script Script json object from the debugger message. 718 * @param {Object} script Script json object from the debugger message.
680 * @param {devtools.DebuggerMessage} msg Debugger message containing the script 719 * @param {devtools.DebuggerMessage} msg Debugger message containing the script
681 * data. 720 * data.
682 */ 721 */
683 devtools.DebuggerAgent.prototype.addScriptInfo_ = function(script, msg) { 722 devtools.DebuggerAgent.prototype.addScriptInfo_ = function(script, msg) {
684 var context = msg.lookup(script.context.ref); 723 var context = msg.lookup(script.context.ref);
685 var contextType = context.data.type; 724 var contextType = context.data.type;
686 this.parsedScripts_[script.id] = new devtools.ScriptInfo( 725 this.parsedScripts_[script.id] = new devtools.ScriptInfo(
687 script.id, script.lineOffset, contextType); 726 script.id, script.name, script.lineOffset, contextType);
688 WebInspector.parsedScriptSource( 727 WebInspector.parsedScriptSource(
689 script.id, script.name, script.source, script.lineOffset); 728 script.id, script.name, script.source, script.lineOffset);
690 }; 729 };
691 730
692 731
693 /** 732 /**
694 * @param {devtools.DebuggerMessage} msg 733 * @param {devtools.DebuggerMessage} msg
695 */ 734 */
696 devtools.DebuggerAgent.prototype.handleClearBreakpointResponse_ = function( 735 devtools.DebuggerAgent.prototype.handleClearBreakpointResponse_ = function(
697 msg) { 736 msg) {
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 * @param {number} line Resource line number in v8. 928 * @param {number} line Resource line number in v8.
890 * @return {number} The line number in Web Inspector. 929 * @return {number} The line number in Web Inspector.
891 */ 930 */
892 devtools.DebuggerAgent.v8ToWwebkitLineNumber_ = function(line) { 931 devtools.DebuggerAgent.v8ToWwebkitLineNumber_ = function(line) {
893 return line + 1; 932 return line + 1;
894 }; 933 };
895 934
896 935
897 /** 936 /**
898 * @param {number} scriptId Id of the script. 937 * @param {number} scriptId Id of the script.
938 * @param {?string} url Script resource URL if any.
899 * @param {number} lineOffset First line 0-based offset in the containing 939 * @param {number} lineOffset First line 0-based offset in the containing
900 * document. 940 * document.
901 * @param {string} contextType Type of the script's context: 941 * @param {string} contextType Type of the script's context:
902 * "page" - regular script from html page 942 * "page" - regular script from html page
903 * "injected" - extension content script 943 * "injected" - extension content script
904 * @constructor 944 * @constructor
905 */ 945 */
906 devtools.ScriptInfo = function(scriptId, lineOffset, contextType) { 946 devtools.ScriptInfo = function(scriptId, url, lineOffset, contextType) {
907 this.scriptId_ = scriptId; 947 this.scriptId_ = scriptId;
908 this.lineOffset_ = lineOffset; 948 this.lineOffset_ = lineOffset;
909 this.contextType_ = contextType; 949 this.contextType_ = contextType;
950 this.url_ = url;
910 951
911 this.lineToBreakpointInfo_ = {}; 952 this.lineToBreakpointInfo_ = {};
912 }; 953 };
913 954
914 955
915 /** 956 /**
916 * @return {number} 957 * @return {number}
917 */ 958 */
918 devtools.ScriptInfo.prototype.getLineOffset = function() { 959 devtools.ScriptInfo.prototype.getLineOffset = function() {
919 return this.lineOffset_; 960 return this.lineOffset_;
920 }; 961 };
921 962
922 963
923 /** 964 /**
924 * @return {string} 965 * @return {string}
925 */ 966 */
926 devtools.ScriptInfo.prototype.getContextType = function() { 967 devtools.ScriptInfo.prototype.getContextType = function() {
927 return this.contextType_; 968 return this.contextType_;
928 }; 969 };
929 970
930 971
931 /** 972 /**
973 * @return {?string}
974 */
975 devtools.ScriptInfo.prototype.getUrl = function() {
976 return this.url_;
977 };
978
979
980 /**
932 * @param {number} line 0-based line number in the script. 981 * @param {number} line 0-based line number in the script.
933 * @return {?devtools.BreakpointInfo} Information on a breakpoint at the 982 * @return {?devtools.BreakpointInfo} Information on a breakpoint at the
934 * specified line in the script or undefined if there is no breakpoint at 983 * specified line in the script or undefined if there is no breakpoint at
935 * that line. 984 * that line.
936 */ 985 */
937 devtools.ScriptInfo.prototype.getBreakpointInfo = function(line) { 986 devtools.ScriptInfo.prototype.getBreakpointInfo = function(line) {
938 return this.lineToBreakpointInfo_[line]; 987 return this.lineToBreakpointInfo_[line];
939 }; 988 };
940 989
941 990
(...skipping 10 matching lines...) Expand all
952 * @param {devtools.BreakpointInfo} breakpoint Breakpoint info to be removed. 1001 * @param {devtools.BreakpointInfo} breakpoint Breakpoint info to be removed.
953 */ 1002 */
954 devtools.ScriptInfo.prototype.removeBreakpointInfo = function(breakpoint) { 1003 devtools.ScriptInfo.prototype.removeBreakpointInfo = function(breakpoint) {
955 var line = breakpoint.getLine(); 1004 var line = breakpoint.getLine();
956 delete this.lineToBreakpointInfo_[line]; 1005 delete this.lineToBreakpointInfo_[line];
957 }; 1006 };
958 1007
959 1008
960 1009
961 /** 1010 /**
962 * @param {number} scriptId Id of the owning script.
963 * @param {number} line Breakpoint 0-based line number in the containing script. 1011 * @param {number} line Breakpoint 0-based line number in the containing script.
964 * @constructor 1012 * @constructor
965 */ 1013 */
966 devtools.BreakpointInfo = function(sourceId, line) { 1014 devtools.BreakpointInfo = function(line) {
967 this.sourceId_ = sourceId;
968 this.line_ = line; 1015 this.line_ = line;
969 this.v8id_ = -1; 1016 this.v8id_ = -1;
970 this.removed_ = false; 1017 this.removed_ = false;
971 }; 1018 };
972 1019
973 1020
974 /** 1021 /**
975 * @return {number} 1022 * @return {number}
976 */ 1023 */
977 devtools.BreakpointInfo.prototype.getSourceId = function(n) {
978 return this.sourceId_;
979 };
980
981
982 /**
983 * @return {number}
984 */
985 devtools.BreakpointInfo.prototype.getLine = function(n) { 1024 devtools.BreakpointInfo.prototype.getLine = function(n) {
986 return this.line_; 1025 return this.line_;
987 }; 1026 };
988 1027
989 1028
990 /** 1029 /**
991 * @return {number} Unique identifier of this breakpoint in the v8 debugger. 1030 * @return {number} Unique identifier of this breakpoint in the v8 debugger.
992 */ 1031 */
993 devtools.BreakpointInfo.prototype.getV8Id = function(n) { 1032 devtools.BreakpointInfo.prototype.getV8Id = function(n) {
994 return this.v8id_; 1033 return this.v8id_;
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 1231
1193 1232
1194 /** 1233 /**
1195 * @param {number} handle Object handle. 1234 * @param {number} handle Object handle.
1196 * @return {?Object} Returns the object with the handle if it was sent in this 1235 * @return {?Object} Returns the object with the handle if it was sent in this
1197 * message(some objects referenced by handles may be missing in the message). 1236 * message(some objects referenced by handles may be missing in the message).
1198 */ 1237 */
1199 devtools.DebuggerMessage.prototype.lookup = function(handle) { 1238 devtools.DebuggerMessage.prototype.lookup = function(handle) {
1200 return this.refs_[handle]; 1239 return this.refs_[handle];
1201 }; 1240 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698