OLD | NEW |
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 Tools is a main class that wires all components of the | 6 * @fileoverview Tools is a main class that wires all components of the |
7 * DevTools frontend together. It is also responsible for overriding existing | 7 * DevTools frontend together. It is also responsible for overriding existing |
8 * WebInspector functionality while it is getting upstreamed into WebCore. | 8 * WebInspector functionality while it is getting upstreamed into WebCore. |
9 */ | 9 */ |
10 goog.provide('devtools.Tools'); | 10 goog.provide('devtools.Tools'); |
11 | 11 |
12 goog.require('devtools.DebuggerAgent'); | 12 goog.require('devtools.DebuggerAgent'); |
13 goog.require('devtools.DomAgent'); | 13 goog.require('devtools.DomAgent'); |
14 | 14 |
15 | 15 |
16 /** | 16 /** |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 this.domAgent_ = new devtools.DomAgent(); | 53 this.domAgent_ = new devtools.DomAgent(); |
54 }; | 54 }; |
55 | 55 |
56 | 56 |
57 /** | 57 /** |
58 * Resets tools agent to its initial state. | 58 * Resets tools agent to its initial state. |
59 */ | 59 */ |
60 devtools.ToolsAgent.prototype.reset = function() { | 60 devtools.ToolsAgent.prototype.reset = function() { |
61 this.domAgent_.reset(); | 61 this.domAgent_.reset(); |
62 this.debuggerAgent_.reset(); | 62 this.debuggerAgent_.reset(); |
63 | 63 |
64 this.domAgent_.getDocumentElementAsync(); | 64 this.domAgent_.getDocumentElementAsync(); |
65 }; | 65 }; |
66 | 66 |
67 | 67 |
68 /** | 68 /** |
69 * @param {string} script Script exression to be evaluated in the context of the | 69 * @param {string} script Script exression to be evaluated in the context of the |
70 * inspected page. | 70 * inspected page. |
71 * @param {function(string):undefined} callback Function to call with the | 71 * @param {function(string):undefined} callback Function to call with the |
72 * result. | 72 * result. |
73 */ | 73 */ |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 * @param {string} expr | 147 * @param {string} expr |
148 */ | 148 */ |
149 devtools.ToolsAgent.prototype.evaluate = function(expr) { | 149 devtools.ToolsAgent.prototype.evaluate = function(expr) { |
150 RemoteToolsAgent.evaluate(expr); | 150 RemoteToolsAgent.evaluate(expr); |
151 }; | 151 }; |
152 | 152 |
153 | 153 |
154 /** | 154 /** |
155 * Asynchronously queries for the resource content. | 155 * Asynchronously queries for the resource content. |
156 * @param {number} identifier Resource identifier. | 156 * @param {number} identifier Resource identifier. |
157 * @param {function(string):undefined} opt_callback Callback to call when | 157 * @param {function(string):undefined} opt_callback Callback to call when |
158 * result is available. | 158 * result is available. |
159 */ | 159 */ |
160 devtools.ToolsAgent.prototype.getResourceContentAsync = function(identifier, | 160 devtools.ToolsAgent.prototype.getResourceContentAsync = function(identifier, |
161 opt_callback) { | 161 opt_callback) { |
162 var resource = WebInspector.resources[identifier]; | 162 var resource = WebInspector.resources[identifier]; |
163 if (!resource) { | 163 if (!resource) { |
164 return; | 164 return; |
165 } | 165 } |
166 RemoteToolsAgent.GetResourceContent( | 166 RemoteToolsAgent.GetResourceContent( |
167 devtools.Callback.wrap(opt_callback), identifier); | 167 devtools.Callback.wrap(opt_callback), identifier); |
168 }; | 168 }; |
169 | 169 |
170 | 170 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 goog.bind(this.performSearchCallback_, this)); | 234 goog.bind(this.performSearchCallback_, this)); |
235 }; | 235 }; |
236 | 236 |
237 | 237 |
238 WebInspector.ElementsPanel.prototype.performSearchCallback_ = function(nodes) { | 238 WebInspector.ElementsPanel.prototype.performSearchCallback_ = function(nodes) { |
239 for (var i = 0; i < nodes.length; ++i) { | 239 for (var i = 0; i < nodes.length; ++i) { |
240 var treeElement = this.treeOutline.findTreeElement(nodes[i]); | 240 var treeElement = this.treeOutline.findTreeElement(nodes[i]); |
241 if (treeElement) | 241 if (treeElement) |
242 treeElement.highlighted = true; | 242 treeElement.highlighted = true; |
243 } | 243 } |
244 | 244 |
245 if (nodes.length) { | 245 if (nodes.length) { |
246 this.currentSearchResultIndex_ = 0; | 246 this.currentSearchResultIndex_ = 0; |
247 this.focusedDOMNode = nodes[0]; | 247 this.focusedDOMNode = nodes[0]; |
248 } | 248 } |
249 | 249 |
250 this.searchResultCount_ = nodes.length; | 250 this.searchResultCount_ = nodes.length; |
251 }; | 251 }; |
252 | 252 |
253 | 253 |
254 /** | 254 /** |
255 * @override | 255 * @override |
256 */ | 256 */ |
257 WebInspector.ElementsPanel.prototype.searchCanceled = function() { | 257 WebInspector.ElementsPanel.prototype.searchCanceled = function() { |
258 this.currentSearchResultIndex_ = 0; | 258 this.currentSearchResultIndex_ = 0; |
259 this.searchResultCount_ = 0; | 259 this.searchResultCount_ = 0; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 * Temporarily sets style fetched from the inspectable tab to the currently | 354 * Temporarily sets style fetched from the inspectable tab to the currently |
355 * focused node, invokes updateUI callback and clears the styles. | 355 * focused node, invokes updateUI callback and clears the styles. |
356 * @param {function(Node):undefined} updateUI Callback to call while styles are | 356 * @param {function(Node):undefined} updateUI Callback to call while styles are |
357 * set. | 357 * set. |
358 */ | 358 */ |
359 WebInspector.ElementsPanel.prototype.invokeWithStyleSet_ = | 359 WebInspector.ElementsPanel.prototype.invokeWithStyleSet_ = |
360 function(updateUI) { | 360 function(updateUI) { |
361 var node = this.focusedDOMNode; | 361 var node = this.focusedDOMNode; |
362 if (node && node.nodeType === Node.TEXT_NODE && node.parentNode) | 362 if (node && node.nodeType === Node.TEXT_NODE && node.parentNode) |
363 node = node.parentNode; | 363 node = node.parentNode; |
364 | 364 |
365 if (node && node.nodeType == Node.ELEMENT_NODE) { | 365 if (node && node.nodeType == Node.ELEMENT_NODE) { |
366 var callback = function(stylesStr) { | 366 var callback = function(stylesStr) { |
367 var styles = JSON.parse(stylesStr); | 367 var styles = JSON.parse(stylesStr); |
368 if (!styles.computedStyle) { | 368 if (!styles.computedStyle) { |
369 return; | 369 return; |
370 } | 370 } |
371 node.setStyles(styles.computedStyle, styles.inlineStyle, | 371 node.setStyles(styles.computedStyle, styles.inlineStyle, |
372 styles.styleAttributes, styles.matchedCSSRules); | 372 styles.styleAttributes, styles.matchedCSSRules); |
373 updateUI(node); | 373 updateUI(node); |
374 node.clearStyles(); | 374 node.clearStyles(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 WebInspector.PropertiesSidebarPane.prototype.update = function(object) { | 418 WebInspector.PropertiesSidebarPane.prototype.update = function(object) { |
419 var body = this.bodyElement; | 419 var body = this.bodyElement; |
420 body.removeChildren(); | 420 body.removeChildren(); |
421 | 421 |
422 this.sections = []; | 422 this.sections = []; |
423 | 423 |
424 if (!object) { | 424 if (!object) { |
425 return; | 425 return; |
426 } | 426 } |
427 | 427 |
428 | 428 |
429 var self = this; | 429 var self = this; |
430 devtools.tools.getDomAgent().getNodePrototypesAsync(object.id_, | 430 devtools.tools.getDomAgent().getNodePrototypesAsync(object.id_, |
431 function(json) { | 431 function(json) { |
432 // Get array of prototype user-friendly names. | 432 // Get array of prototype user-friendly names. |
433 var prototypes = JSON.parse(json); | 433 var prototypes = JSON.parse(json); |
434 for (var i = 0; i < prototypes.length; ++i) { | 434 for (var i = 0; i < prototypes.length; ++i) { |
435 var prototype = {}; | 435 var prototype = {}; |
436 prototype.id_ = object.id_; | 436 prototype.id_ = object.id_; |
437 prototype.protoDepth_ = i; | 437 prototype.protoDepth_ = i; |
438 var section = new WebInspector.SidebarObjectPropertiesSection( | 438 var section = new WebInspector.SidebarObjectPropertiesSection( |
439 prototype, | 439 prototype, |
440 prototypes[i]); | 440 prototypes[i]); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 | 490 |
491 | 491 |
492 /** | 492 /** |
493 * @override | 493 * @override |
494 */ | 494 */ |
495 WebInspector.SidebarObjectPropertyTreeElement.prototype.onpopulate = | 495 WebInspector.SidebarObjectPropertyTreeElement.prototype.onpopulate = |
496 function() { | 496 function() { |
497 var nodeId = this.parentObject.devtools$$nodeId_; | 497 var nodeId = this.parentObject.devtools$$nodeId_; |
498 var path = this.parentObject.devtools$$path_.slice(0); | 498 var path = this.parentObject.devtools$$path_.slice(0); |
499 path.push(this.propertyName); | 499 path.push(this.propertyName); |
500 devtools.tools.getDomAgent().getNodePropertiesAsync(nodeId, path, -1, | 500 devtools.tools.getDomAgent().getNodePropertiesAsync(nodeId, path, -1, |
501 goog.partial( | 501 goog.partial( |
502 WebInspector.didGetNodePropertiesAsync_, | 502 WebInspector.didGetNodePropertiesAsync_, |
503 this, | 503 this, |
504 this.treeOutline.section.treeElementConstructor, | 504 this.treeOutline.section.treeElementConstructor, |
505 nodeId, path)); | 505 nodeId, path)); |
506 }; | 506 }; |
507 | 507 |
508 | 508 |
509 /** | 509 /** |
510 * This override is necessary for starting highlighting after the resource | 510 * This override is necessary for starting highlighting after the resource |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 /** | 543 /** |
544 * This override is necessary for adding script source asynchronously. | 544 * This override is necessary for adding script source asynchronously. |
545 * @override | 545 * @override |
546 */ | 546 */ |
547 WebInspector.ScriptView.prototype.setupSourceFrameIfNeeded = function() { | 547 WebInspector.ScriptView.prototype.setupSourceFrameIfNeeded = function() { |
548 if (!this._frameNeedsSetup) { | 548 if (!this._frameNeedsSetup) { |
549 return; | 549 return; |
550 } | 550 } |
551 | 551 |
552 this.attach(); | 552 this.attach(); |
553 | 553 |
554 if (this.script.source) { | 554 if (this.script.source) { |
555 this.didResolveScriptSource_(); | 555 this.didResolveScriptSource_(); |
556 } else { | 556 } else { |
557 var self = this; | 557 var self = this; |
558 devtools.tools.getDebuggerAgent().resolveScriptSource( | 558 devtools.tools.getDebuggerAgent().resolveScriptSource( |
559 this.script.sourceID, | 559 this.script.sourceID, |
560 function(source) { | 560 function(source) { |
561 self.script.source = source || '<source is not available>'; | 561 self.script.source = source || '<source is not available>'; |
562 self.didResolveScriptSource_(); | 562 self.didResolveScriptSource_(); |
563 }); | 563 }); |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 WebInspector.DataGrid = function(columns) { | 914 WebInspector.DataGrid = function(columns) { |
915 if (('average' in columns) && ('calls' in columns)) { | 915 if (('average' in columns) && ('calls' in columns)) { |
916 delete columns['average']; | 916 delete columns['average']; |
917 delete columns['calls']; | 917 delete columns['calls']; |
918 } | 918 } |
919 return new originalDataGrid(columns); | 919 return new originalDataGrid(columns); |
920 }; | 920 }; |
921 })(); | 921 })(); |
922 | 922 |
923 | 923 |
| 924 // WebKit's profiler displays milliseconds with high resolution (shows |
| 925 // three digits after the decimal point). We never have such resolution, |
| 926 // as our minimal sampling rate is 1 ms. So we are disabling high resolution |
| 927 // to avoid visual clutter caused by meaningless ".000" parts. |
| 928 (function InterceptTimeDisplayInProfiler() { |
| 929 var originalDataGetter = |
| 930 WebInspector.ProfileDataGridNode.prototype.__lookupGetter__('data'); |
| 931 WebInspector.ProfileDataGridNode.prototype.__defineGetter__('data', |
| 932 function() { |
| 933 var oldNumberSecondsToString = Number.secondsToString; |
| 934 Number.secondsToString = function(seconds, formatterFunction) { |
| 935 return oldNumberSecondsToString(seconds, formatterFunction, false); |
| 936 }; |
| 937 var data = originalDataGetter.call(this); |
| 938 Number.secondsToString = oldNumberSecondsToString; |
| 939 return data; |
| 940 }); |
| 941 })(); |
| 942 |
| 943 |
924 /** | 944 /** |
925 * @override | 945 * @override |
926 * TODO(pfeldman): Add l10n. | 946 * TODO(pfeldman): Add l10n. |
927 */ | 947 */ |
928 WebInspector.UIString = function(string) { | 948 WebInspector.UIString = function(string) { |
929 return String.vsprintf(string, Array.prototype.slice.call(arguments, 1)); | 949 return String.vsprintf(string, Array.prototype.slice.call(arguments, 1)); |
930 }; | 950 }; |
931 | 951 |
932 | 952 |
933 // There is no clear way of setting frame title yet. So sniffing main resource | 953 // There is no clear way of setting frame title yet. So sniffing main resource |
934 // load. | 954 // load. |
935 (function OverrideUpdateResource() { | 955 (function OverrideUpdateResource() { |
936 var originalUpdateResource = WebInspector.updateResource; | 956 var originalUpdateResource = WebInspector.updateResource; |
937 WebInspector.updateResource = function(identifier, payload) { | 957 WebInspector.updateResource = function(identifier, payload) { |
938 originalUpdateResource.call(this, identifier, payload); | 958 originalUpdateResource.call(this, identifier, payload); |
939 var resource = this.resources[identifier]; | 959 var resource = this.resources[identifier]; |
940 if (resource && resource.mainResource && resource.finished) { | 960 if (resource && resource.mainResource && resource.finished) { |
941 document.title = 'Developer Tools - ' + resource.url; | 961 document.title = 'Developer Tools - ' + resource.url; |
942 } | 962 } |
943 }; | 963 }; |
944 })(); | 964 })(); |
OLD | NEW |