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

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

Issue 113836: DevTools: introduce bound object on the agent side. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 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 | « webkit/glue/devtools/js/devtools.html ('k') | webkit/glue/devtools/js/devtools_host_stub.js » ('j') | 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 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 goog.require('devtools.NetAgent');
15 14
16 15
17 /** 16 /**
18 * Dispatches raw message from the host. 17 * Dispatches raw message from the host.
19 * @param {Object} msg Message to dispatch. 18 * @param {Object} msg Message to dispatch.
20 */ 19 */
21 devtools.dispatch = function(msg) { 20 devtools.dispatch = function(msg) {
22 var delegate = msg[0]; 21 var delegate = msg[0];
23 var methodName = msg[1]; 22 var methodName = msg[1];
24 var remoteName = 'Remote' + delegate.substring(0, delegate.length - 8); 23 var remoteName = 'Remote' + delegate.substring(0, delegate.length - 8);
25 var agent = window[remoteName]; 24 var agent = window[remoteName];
26 if (!agent) { 25 if (!agent) {
27 debugPrint('No remote agent "' + remoteName + '" found.'); 26 debugPrint('No remote agent "' + remoteName + '" found.');
28 return; 27 return;
29 } 28 }
30 var method = agent[methodName]; 29 var method = agent[methodName];
31 if (!method) { 30 if (!method) {
32 debugPrint('No method "' + remoteName + '.' + methodName + '" found.'); 31 debugPrint('No method "' + remoteName + '.' + methodName + '" found.');
33 return; 32 return;
34 } 33 }
35 method.apply(this, msg.slice(2)); 34 method.apply(this, msg.slice(2));
36 }; 35 };
37 36
38 37
39 devtools.ToolsAgent = function() { 38 devtools.ToolsAgent = function() {
40 RemoteToolsAgent.DidEvaluateJavaScript = devtools.Callback.processCallback; 39 RemoteToolsAgent.DidEvaluateJavaScript = devtools.Callback.processCallback;
41 RemoteToolsAgent.DidExecuteUtilityFunction = 40 RemoteToolsAgent.DidExecuteUtilityFunction =
42 devtools.Callback.processCallback; 41 devtools.Callback.processCallback;
43 RemoteToolsAgent.UpdateFocusedNode = 42 RemoteToolsAgent.UpdateFocusedNode =
44 goog.bind(this.updateFocusedNode, this); 43 goog.bind(this.updateFocusedNode_, this);
45 RemoteToolsAgent.FrameNavigate = 44 RemoteToolsAgent.FrameNavigate =
46 goog.bind(this.frameNavigate, this); 45 goog.bind(this.frameNavigate_, this);
47 RemoteToolsAgent.AddMessageToConsole = 46 RemoteToolsAgent.AddMessageToConsole =
48 goog.bind(this.addMessageToConsole, this); 47 goog.bind(this.addMessageToConsole_, this);
48 RemoteToolsAgent.DispatchOnClient =
49 goog.bind(this.dispatchOnClient_, this);
50 RemoteToolsAgent.DidGetResourceContent =
51 devtools.Callback.processCallback;
49 this.debuggerAgent_ = new devtools.DebuggerAgent(); 52 this.debuggerAgent_ = new devtools.DebuggerAgent();
50 this.domAgent_ = new devtools.DomAgent(); 53 this.domAgent_ = new devtools.DomAgent();
51 this.netAgent_ = new devtools.NetAgent();
52 }; 54 };
53 55
54 56
55 /** 57 /**
56 * Resets tools agent to its initial state. 58 * Resets tools agent to its initial state.
57 */ 59 */
58 devtools.ToolsAgent.prototype.reset = function() { 60 devtools.ToolsAgent.prototype.reset = function() {
59 this.domAgent_.reset(); 61 this.domAgent_.reset();
60 this.netAgent_.reset();
61 this.debuggerAgent_.reset(); 62 this.debuggerAgent_.reset();
62 63
63 this.domAgent_.getDocumentElementAsync(); 64 this.domAgent_.getDocumentElementAsync();
64 }; 65 };
65 66
66 67
67 /** 68 /**
68 * @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
69 * inspected page. 70 * inspected page.
70 * @param {function(string):undefined} callback Function to call with the 71 * @param {function(string):undefined} callback Function to call with the
(...skipping 15 matching lines...) Expand all
86 /** 87 /**
87 * DomAgent accessor. 88 * DomAgent accessor.
88 * @return {devtools.DomAgent} Dom agent instance. 89 * @return {devtools.DomAgent} Dom agent instance.
89 */ 90 */
90 devtools.ToolsAgent.prototype.getDomAgent = function() { 91 devtools.ToolsAgent.prototype.getDomAgent = function() {
91 return this.domAgent_; 92 return this.domAgent_;
92 }; 93 };
93 94
94 95
95 /** 96 /**
96 * NetAgent accessor.
97 * @return {devtools.NetAgent} Net agent instance.
98 */
99 devtools.ToolsAgent.prototype.getNetAgent = function() {
100 return this.netAgent_;
101 };
102
103
104 /**
105 * @see tools_agent.h 97 * @see tools_agent.h
98 * @private
106 */ 99 */
107 devtools.ToolsAgent.prototype.updateFocusedNode = function(nodeId) { 100 devtools.ToolsAgent.prototype.updateFocusedNode_ = function(nodeId) {
108 var node = this.domAgent_.getNodeForId(nodeId); 101 var node = this.domAgent_.getNodeForId(nodeId);
109 WebInspector.updateFocusedNode(node); 102 WebInspector.updateFocusedNode(node);
110 }; 103 };
111 104
112 105
113 /** 106 /**
114 * @param {string} url Url frame navigated to. 107 * @param {string} url Url frame navigated to.
115 * @param {bool} topLevel True iff top level navigation occurred. 108 * @param {bool} topLevel True iff top level navigation occurred.
116 * @see tools_agent.h 109 * @see tools_agent.h
110 * @private
117 */ 111 */
118 devtools.ToolsAgent.prototype.frameNavigate = function(url, topLevel) { 112 devtools.ToolsAgent.prototype.frameNavigate_ = function(url, topLevel) {
119 if (topLevel) { 113 if (topLevel) {
120 this.reset(); 114 this.reset();
121 WebInspector.reset(); 115 WebInspector.reset();
122 } 116 }
123 }; 117 };
124 118
125 119
126 /** 120 /**
127 * @param {Object} message Message object to add. 121 * @param {Object} message Message object to add.
128 * @see tools_agent.h 122 * @see tools_agent.h
123 * @private
129 */ 124 */
130 devtools.ToolsAgent.prototype.addMessageToConsole = function(message) { 125 devtools.ToolsAgent.prototype.addMessageToConsole_ = function(message) {
131 var console = WebInspector.console; 126 var console = WebInspector.console;
132 if (console) { 127 if (console) {
133 console.addMessage(new WebInspector.ConsoleMessage( 128 console.addMessage(new WebInspector.ConsoleMessage(
134 message.source, message.level, message.line, message.sourceId, 129 message.source, message.level, message.line, message.sourceId,
135 undefined, 1, message.text)); 130 undefined, 1, message.text));
136 } 131 }
137 }; 132 };
138 133
139 134
140 /** 135 /**
136 * @param {string} message Serialized call to be dispatched on WebInspector.
137 * @private
138 */
139 devtools.ToolsAgent.prototype.dispatchOnClient_ = function(message) {
140 var messageObj = JSON.parse(message);
141 WebInspector.dispatch.apply(WebInspector, messageObj);
142 };
143
144
145 /**
141 * Evaluates js expression. 146 * Evaluates js expression.
142 * @param {string} expr 147 * @param {string} expr
143 */ 148 */
144 devtools.ToolsAgent.prototype.evaluate = function(expr) { 149 devtools.ToolsAgent.prototype.evaluate = function(expr) {
145 RemoteToolsAgent.evaluate(expr); 150 RemoteToolsAgent.evaluate(expr);
146 }; 151 };
147 152
148 153
149 /** 154 /**
155 * Asynchronously queries for the resource content.
156 * @param {number} identifier Resource identifier.
157 * @param {function(string):undefined} opt_callback Callback to call when
158 * result is available.
159 */
160 devtools.ToolsAgent.prototype.getResourceContentAsync = function(identifier,
161 opt_callback) {
162 var resource = WebInspector.resources[identifier];
163 if (!resource) {
164 return;
165 }
166 RemoteToolsAgent.GetResourceContent(
167 devtools.Callback.wrap(opt_callback), identifier);
168 };
169
170
171 /**
150 * Prints string to the inspector console or shows alert if the console doesn't 172 * Prints string to the inspector console or shows alert if the console doesn't
151 * exist. 173 * exist.
152 * @param {string} text 174 * @param {string} text
153 */ 175 */
154 function debugPrint(text) { 176 function debugPrint(text) {
155 var console = WebInspector.console; 177 var console = WebInspector.console;
156 if (console) { 178 if (console) {
157 console.addMessage(new WebInspector.ConsoleMessage( 179 console.addMessage(new WebInspector.ConsoleMessage(
158 '', undefined, 1, '', undefined, 1, text)); 180 '', undefined, 1, '', undefined, 1, text));
159 } else { 181 } else {
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 WebInspector.SourceView.prototype.setupSourceFrameIfNeeded = function() { 514 WebInspector.SourceView.prototype.setupSourceFrameIfNeeded = function() {
493 if (!this._frameNeedsSetup) { 515 if (!this._frameNeedsSetup) {
494 return; 516 return;
495 } 517 }
496 518
497 this.attach(); 519 this.attach();
498 520
499 var self = this; 521 var self = this;
500 var identifier = this.resource.identifier; 522 var identifier = this.resource.identifier;
501 var element = this.sourceFrame.element; 523 var element = this.sourceFrame.element;
502 var netAgent = devtools.tools.getNetAgent();
503 524
504 netAgent.getResourceContentAsync(identifier, function(source) { 525 devtools.tools.getResourceContentAsync(identifier, function(source) {
505 var resource = WebInspector.resources[identifier]; 526 var resource = WebInspector.resources[identifier];
506 if (InspectorController.addSourceToFrame(resource.mimeType, source, 527 if (InspectorController.addSourceToFrame(resource.mimeType, source,
507 element)) { 528 element)) {
508 delete self._frameNeedsSetup; 529 delete self._frameNeedsSetup;
509 if (resource.type === WebInspector.Resource.Type.Script) { 530 if (resource.type === WebInspector.Resource.Type.Script) {
510 self.sourceFrame.addEventListener('syntax highlighting complete', 531 self.sourceFrame.addEventListener('syntax highlighting complete',
511 self._syntaxHighlightingComplete, self); 532 self._syntaxHighlightingComplete, self);
512 self.sourceFrame.syntaxHighlightJavascript(); 533 self.sourceFrame.syntaxHighlightJavascript();
513 } else { 534 } else {
514 self._sourceFrameSetupFinished(); 535 self._sourceFrameSetupFinished();
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 } 918 }
898 return new originalDataGrid(columns); 919 return new originalDataGrid(columns);
899 }; 920 };
900 })(); 921 })();
901 922
902 923
903 /** 924 /**
904 * @override 925 * @override
905 * TODO(pfeldman): Add l10n. 926 * TODO(pfeldman): Add l10n.
906 */ 927 */
907 WebInspector.UIString = function(string) 928 WebInspector.UIString = function(string) {
908 {
909 return String.vsprintf(string, Array.prototype.slice.call(arguments, 1)); 929 return String.vsprintf(string, Array.prototype.slice.call(arguments, 1));
910 } 930 };
931
932
933 // There is no clear way of setting frame title yet. So sniffing main resource
934 // load.
935 (function OverrideUpdateResource() {
936 var originalUpdateResource = WebInspector.updateResource;
937 WebInspector.updateResource = function(identifier, payload) {
938 originalUpdateResource.call(this, identifier, payload);
939 var resource = this.resources[identifier];
940 if (resource && resource.mainResource && resource.finished) {
941 document.title = 'Developer Tools - ' + resource.url;
942 }
943 };
944 })();
OLDNEW
« no previous file with comments | « webkit/glue/devtools/js/devtools.html ('k') | webkit/glue/devtools/js/devtools_host_stub.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698