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.DomAgent'); | 12 goog.require('devtools.DomAgent'); |
13 goog.require('devtools.NetAgent'); | 13 goog.require('devtools.NetAgent'); |
14 | 14 |
15 devtools.ToolsAgent = function() { | 15 devtools.ToolsAgent = function() { |
16 RemoteToolsAgent.UpdateFocusedNode = | 16 RemoteToolsAgent.UpdateFocusedNode = |
17 goog.bind(this.updateFocusedNode, this); | 17 goog.bind(this.updateFocusedNode, this); |
| 18 RemoteToolsAgent.FrameNavigate = |
| 19 goog.bind(this.frameNavigate, this); |
| 20 this.domAgent_ = new devtools.DomAgent(); |
| 21 this.netAgent_ = new devtools.NetAgent(); |
| 22 this.reset(); |
18 }; | 23 }; |
19 | 24 |
20 | 25 |
21 // ToolsAgent implementation. | 26 /** |
22 devtools.ToolsAgent.prototype.updateFocusedNode = function(node_id) { | 27 * Rests tools agent to its initial state. |
23 var node = domAgent.getNodeForId(node_id); | 28 */ |
| 29 devtools.ToolsAgent.prototype.reset = function() { |
| 30 this.setEnabled(true); |
| 31 this.domAgent_.reset(); |
| 32 this.domAgent_.getDocumentElementAsync(); |
| 33 }; |
| 34 |
| 35 |
| 36 /** |
| 37 * DomAgent accessor. |
| 38 * @return {devtools.DomAgent} Dom agent instance. |
| 39 */ |
| 40 devtools.ToolsAgent.prototype.getDomAgent = function() { |
| 41 return this.domAgent_; |
| 42 }; |
| 43 |
| 44 |
| 45 /** |
| 46 * NetAgent accessor. |
| 47 * @return {devtools.NetAgent} Net agent instance. |
| 48 */ |
| 49 devtools.ToolsAgent.prototype.getNetAgent = function() { |
| 50 return this.netAgent_; |
| 51 }; |
| 52 |
| 53 |
| 54 /** |
| 55 * @see tools_agent.h |
| 56 */ |
| 57 devtools.ToolsAgent.prototype.updateFocusedNode = function(nodeId) { |
| 58 var node = this.domAgent_.getNodeForId(nodeId); |
24 WebInspector.updateFocusedNode(node); | 59 WebInspector.updateFocusedNode(node); |
25 }; | 60 }; |
26 | 61 |
27 | 62 |
28 devtools.ToolsAgent.prototype.setDomAgentEnabled = function(enabled) { | 63 /** |
29 RemoteToolsAgent.SetDomAgentEnabled(enabled); | 64 * @see tools_agent.h |
| 65 */ |
| 66 devtools.ToolsAgent.prototype.frameNavigate = function(url, topLevel) { |
| 67 this.reset(); |
| 68 WebInspector.reset(); |
30 }; | 69 }; |
31 | 70 |
32 | 71 |
33 devtools.ToolsAgent.prototype.setNetAgentEnabled = function(enabled) { | 72 /** |
34 RemoteToolsAgent.SetNetAgentEnabled(enabled); | 73 * @see tools_agent.h |
| 74 */ |
| 75 devtools.ToolsAgent.prototype.setEnabled = function(enabled) { |
| 76 RemoteToolsAgent.SetEnabled(enabled); |
| 77 }; |
| 78 |
| 79 |
| 80 |
| 81 /** |
| 82 * Evaluates js expression. |
| 83 * @param {string} expr |
| 84 */ |
| 85 devtools.ToolsAgent.prototype.evaluate = function(expr) { |
| 86 RemoteToolsAgent.evaluate(expr); |
35 }; | 87 }; |
36 | 88 |
37 | 89 |
38 // Frontend global objects. | 90 // Frontend global objects. |
39 var domAgent; | 91 var devtools.tools; |
40 var netAgent; | |
41 var toolsAgent; | |
42 | 92 |
43 var context = {}; // Used by WebCore's inspector routines. | 93 var context = {}; // Used by WebCore's inspector routines. |
44 | 94 |
45 // Overrides for existing WebInspector methods. | 95 /////////////////////////////////////////////////////////////////////////////// |
| 96 // Here and below are overrides to existing WebInspector methods only. |
46 // TODO(pfeldman): Patch WebCore and upstream changes. | 97 // TODO(pfeldman): Patch WebCore and upstream changes. |
47 var oldLoaded = WebInspector.loaded; | 98 var oldLoaded = WebInspector.loaded; |
48 WebInspector.loaded = function() { | 99 WebInspector.loaded = function() { |
49 domAgent = new devtools.DomAgent(); | 100 devtools.tools = new devtools.ToolsAgent(); |
50 netAgent = new devtools.NetAgent(); | |
51 toolsAgent = new devtools.ToolsAgent(); | |
52 | 101 |
53 Preferences.ignoreWhitespace = false; | 102 Preferences.ignoreWhitespace = false; |
54 toolsAgent.setDomAgentEnabled(true); | |
55 toolsAgent.setNetAgentEnabled(true); | |
56 oldLoaded.call(this); | 103 oldLoaded.call(this); |
57 domAgent.getDocumentElementAsync(); | 104 |
| 105 DevToolsHost.loaded(); |
58 }; | 106 }; |
59 | 107 |
60 | 108 |
61 var webkitUpdateChildren = | 109 var webkitUpdateChildren = |
62 WebInspector.ElementsTreeElement.prototype.updateChildren; | 110 WebInspector.ElementsTreeElement.prototype.updateChildren; |
63 | 111 |
| 112 |
64 WebInspector.ElementsTreeElement.prototype.updateChildren = function() { | 113 WebInspector.ElementsTreeElement.prototype.updateChildren = function() { |
65 var self = this; | 114 var self = this; |
66 domAgent.getChildNodesAsync(this.representedObject.id, function() { | 115 devtools.tools.getDomAgent().getChildNodesAsync(this.representedObject.id, |
67 webkitUpdateChildren.call(self); | 116 function() { |
68 }); | 117 webkitUpdateChildren.call(self); |
| 118 }); |
69 }; | 119 }; |
70 | 120 |
| 121 |
71 WebInspector.ElementsPanel.prototype.performSearch = function(query) { | 122 WebInspector.ElementsPanel.prototype.performSearch = function(query) { |
72 this.searchCanceled(); | 123 this.searchCanceled(); |
73 var self = this; | 124 var self = this; |
74 domAgent.performSearch(query, function(node) { | 125 devtools.tools.getDomAgent().performSearch(query, function(node) { |
75 var treeElement = self.treeOutline.findTreeElement(node); | 126 var treeElement = self.treeOutline.findTreeElement(node); |
76 if (treeElement) | 127 if (treeElement) |
77 treeElement.highlighted = true; | 128 treeElement.highlighted = true; |
78 }); | 129 }); |
79 }; | 130 }; |
80 | 131 |
81 | 132 |
82 WebInspector.ElementsPanel.prototype.searchCanceled = function() { | 133 WebInspector.ElementsPanel.prototype.searchCanceled = function() { |
83 var self = this; | 134 var self = this; |
84 domAgent.searchCanceled(function(node) { | 135 devtools.tools.getDomAgent().searchCanceled(function(node) { |
85 var treeElement = self.treeOutline.findTreeElement(node); | 136 var treeElement = self.treeOutline.findTreeElement(node); |
86 if (treeElement) | 137 if (treeElement) |
87 treeElement.highlighted = false; | 138 treeElement.highlighted = false; |
88 }); | 139 }); |
89 }; | 140 }; |
90 | 141 |
91 | 142 |
92 WebInspector.ElementsPanel.prototype.jumpToNextSearchResult = function() { | 143 WebInspector.ElementsPanel.prototype.jumpToNextSearchResult = function() { |
93 }; | 144 }; |
94 | 145 |
95 | 146 |
96 WebInspector.ElementsPanel.prototype.jumpToPreviousSearchResult = function() { | 147 WebInspector.ElementsPanel.prototype.jumpToPreviousSearchResult = function() { |
97 }; | 148 }; |
| 149 |
| 150 |
| 151 WebInspector.Console.prototype._evalInInspectedWindow = function(expr) { |
| 152 return devtools.tools.evaluate(expr); |
| 153 }; |
OLD | NEW |