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

Side by Side Diff: webkit/glue/webdevtoolsagent_impl.cc

Issue 287009: Move WebDevToolsAgent{Delegate} into the WebKit API.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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/webdevtoolsagent_impl.h ('k') | webkit/glue/webview.h » ('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 #include "config.h" 5 #include "config.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "Document.h" 9 #include "Document.h"
10 #include "EventListener.h" 10 #include "EventListener.h"
11 #include "InspectorBackend.h" 11 #include "InspectorBackend.h"
12 #include "InspectorController.h" 12 #include "InspectorController.h"
13 #include "InspectorFrontend.h" 13 #include "InspectorFrontend.h"
14 #include "InspectorResource.h" 14 #include "InspectorResource.h"
15 #include "Node.h" 15 #include "Node.h"
16 #include "Page.h" 16 #include "Page.h"
17 #include "PlatformString.h" 17 #include "PlatformString.h"
18 #include "ScriptObject.h" 18 #include "ScriptObject.h"
19 #include "ScriptState.h" 19 #include "ScriptState.h"
20 #include "ScriptValue.h" 20 #include "ScriptValue.h"
21 #include "V8Binding.h" 21 #include "V8Binding.h"
22 #include "V8Proxy.h" 22 #include "V8Proxy.h"
23 #include "V8Utilities.h" 23 #include "V8Utilities.h"
24 #include <wtf/OwnPtr.h> 24 #include <wtf/OwnPtr.h>
25 #undef LOG 25 #undef LOG
26 26
27 #include "webkit/api/public/WebDataSource.h" 27 #include "webkit/api/public/WebDataSource.h"
28 #include "webkit/api/public/WebDevToolsAgentClient.h"
28 #include "webkit/api/public/WebURL.h" 29 #include "webkit/api/public/WebURL.h"
29 #include "webkit/api/public/WebURLRequest.h" 30 #include "webkit/api/public/WebURLRequest.h"
30 #include "webkit/glue/devtools/bound_object.h" 31 #include "webkit/glue/devtools/bound_object.h"
31 #include "webkit/glue/devtools/debugger_agent_impl.h" 32 #include "webkit/glue/devtools/debugger_agent_impl.h"
32 #include "webkit/glue/devtools/debugger_agent_manager.h" 33 #include "webkit/glue/devtools/debugger_agent_manager.h"
33 #include "webkit/glue/glue_util.h" 34 #include "webkit/glue/glue_util.h"
34 #include "webkit/glue/webdevtoolsagent_delegate.h"
35 #include "webkit/glue/webdevtoolsagent_impl.h" 35 #include "webkit/glue/webdevtoolsagent_impl.h"
36 #include "webkit/glue/webview_impl.h" 36 #include "webkit/glue/webview_impl.h"
37 37
38 using WebCore::Document; 38 using WebCore::Document;
39 using WebCore::InspectorBackend; 39 using WebCore::InspectorBackend;
40 using WebCore::InspectorController; 40 using WebCore::InspectorController;
41 using WebCore::InspectorFrontend; 41 using WebCore::InspectorFrontend;
42 using WebCore::InspectorResource; 42 using WebCore::InspectorResource;
43 using WebCore::Node; 43 using WebCore::Node;
44 using WebCore::Page; 44 using WebCore::Page;
45 using WebCore::SafeAllocation; 45 using WebCore::SafeAllocation;
46 using WebCore::ScriptObject; 46 using WebCore::ScriptObject;
47 using WebCore::ScriptState; 47 using WebCore::ScriptState;
48 using WebCore::ScriptValue; 48 using WebCore::ScriptValue;
49 using WebCore::String; 49 using WebCore::String;
50 using WebCore::V8ClassIndex; 50 using WebCore::V8ClassIndex;
51 using WebCore::V8DOMWrapper; 51 using WebCore::V8DOMWrapper;
52 using WebCore::V8Proxy; 52 using WebCore::V8Proxy;
53 using WebKit::WebDataSource; 53 using WebKit::WebDataSource;
54 using WebKit::WebDevToolsAgentClient;
54 using WebKit::WebFrame; 55 using WebKit::WebFrame;
56 using WebKit::WebPoint;
55 using WebKit::WebString; 57 using WebKit::WebString;
56 using WebKit::WebURL; 58 using WebKit::WebURL;
57 using WebKit::WebURLRequest; 59 using WebKit::WebURLRequest;
58 60
59 namespace { 61 namespace {
60 62
61 void InspectorBackendWeakReferenceCallback(v8::Persistent<v8::Value> object, 63 void InspectorBackendWeakReferenceCallback(v8::Persistent<v8::Value> object,
62 void* parameter) { 64 void* parameter) {
63 InspectorBackend* backend = static_cast<InspectorBackend*>(parameter); 65 InspectorBackend* backend = static_cast<InspectorBackend*>(parameter);
64 backend->deref(); 66 backend->deref();
65 object.Dispose(); 67 object.Dispose();
66 } 68 }
67 69
68 void SetApuAgentEnabledInUtilityContext(v8::Handle<v8::Context> context, 70 void SetApuAgentEnabledInUtilityContext(v8::Handle<v8::Context> context,
69 bool enabled) { 71 bool enabled) {
70 v8::HandleScope handle_scope; 72 v8::HandleScope handle_scope;
71 v8::Context::Scope context_scope(context); 73 v8::Context::Scope context_scope(context);
72 v8::Handle<v8::Object> dispatcher = v8::Local<v8::Object>::Cast( 74 v8::Handle<v8::Object> dispatcher = v8::Local<v8::Object>::Cast(
73 context->Global()->Get(v8::String::New("ApuAgentDispatcher"))); 75 context->Global()->Get(v8::String::New("ApuAgentDispatcher")));
74 if (dispatcher.IsEmpty()) { 76 if (dispatcher.IsEmpty()) {
75 return; 77 return;
76 } 78 }
77 dispatcher->Set(v8::String::New("enabled"), v8::Boolean::New(enabled)); 79 dispatcher->Set(v8::String::New("enabled"), v8::Boolean::New(enabled));
78 } 80 }
79 81
80 } // namespace 82 } // namespace
81 83
82 WebDevToolsAgentImpl::WebDevToolsAgentImpl( 84 WebDevToolsAgentImpl::WebDevToolsAgentImpl(
83 WebViewImpl* web_view_impl, 85 WebViewImpl* web_view_impl,
84 WebDevToolsAgentDelegate* delegate) 86 WebDevToolsAgentClient* client)
85 : host_id_(delegate->GetHostId()), 87 : host_id_(client->hostIdentifier()),
86 delegate_(delegate), 88 client_(client),
87 web_view_impl_(web_view_impl), 89 web_view_impl_(web_view_impl),
88 apu_agent_enabled_(false), 90 apu_agent_enabled_(false),
89 resource_tracking_was_enabled_(false), 91 resource_tracking_was_enabled_(false),
90 attached_(false) { 92 attached_(false) {
91 debugger_agent_delegate_stub_.set(new DebuggerAgentDelegateStub(this)); 93 debugger_agent_delegate_stub_.set(new DebuggerAgentDelegateStub(this));
92 tools_agent_delegate_stub_.set(new ToolsAgentDelegateStub(this)); 94 tools_agent_delegate_stub_.set(new ToolsAgentDelegateStub(this));
93 tools_agent_native_delegate_stub_.set(new ToolsAgentNativeDelegateStub(this)); 95 tools_agent_native_delegate_stub_.set(new ToolsAgentNativeDelegateStub(this));
94 apu_agent_delegate_stub_.set(new ApuAgentDelegateStub(this)); 96 apu_agent_delegate_stub_.set(new ApuAgentDelegateStub(this));
95 } 97 }
96 98
(...skipping 10 matching lines...) Expand all
107 } 109 }
108 110
109 void WebDevToolsAgentImpl::UnhideResourcesPanelIfNecessary() { 111 void WebDevToolsAgentImpl::UnhideResourcesPanelIfNecessary() {
110 InspectorController* ic = web_view_impl_->page()->inspectorController(); 112 InspectorController* ic = web_view_impl_->page()->inspectorController();
111 ic->ensureResourceTrackingSettingsLoaded(); 113 ic->ensureResourceTrackingSettingsLoaded();
112 String command = String::format("[\"setResourcesPanelEnabled\", %s]", 114 String command = String::format("[\"setResourcesPanelEnabled\", %s]",
113 ic->resourceTrackingEnabled() ? "true" : "false"); 115 ic->resourceTrackingEnabled() ? "true" : "false");
114 tools_agent_delegate_stub_->DispatchOnClient(command); 116 tools_agent_delegate_stub_->DispatchOnClient(command);
115 } 117 }
116 118
117 void WebDevToolsAgentImpl::Attach() { 119 void WebDevToolsAgentImpl::attach() {
118 if (attached_) { 120 if (attached_) {
119 return; 121 return;
120 } 122 }
121 debugger_agent_impl_.set( 123 debugger_agent_impl_.set(
122 new DebuggerAgentImpl(web_view_impl_, 124 new DebuggerAgentImpl(web_view_impl_,
123 debugger_agent_delegate_stub_.get(), 125 debugger_agent_delegate_stub_.get(),
124 this)); 126 this));
125 ResetInspectorFrontendProxy(); 127 ResetInspectorFrontendProxy();
126 UnhideResourcesPanelIfNecessary(); 128 UnhideResourcesPanelIfNecessary();
127 // Allow controller to send messages to the frontend. 129 // Allow controller to send messages to the frontend.
128 InspectorController* ic = web_view_impl_->page()->inspectorController(); 130 InspectorController* ic = web_view_impl_->page()->inspectorController();
129 ic->setWindowVisible(true, false); 131 ic->setWindowVisible(true, false);
130 attached_ = true; 132 attached_ = true;
131 } 133 }
132 134
133 void WebDevToolsAgentImpl::Detach() { 135 void WebDevToolsAgentImpl::detach() {
134 // Prevent controller from sending messages to the frontend. 136 // Prevent controller from sending messages to the frontend.
135 InspectorController* ic = web_view_impl_->page()->inspectorController(); 137 InspectorController* ic = web_view_impl_->page()->inspectorController();
136 ic->hideHighlight(); 138 ic->hideHighlight();
137 ic->close(); 139 ic->close();
138 DisposeUtilityContext(); 140 DisposeUtilityContext();
139 inspector_frontend_script_state_.clear(); 141 inspector_frontend_script_state_.clear();
140 devtools_agent_host_.set(NULL); 142 devtools_agent_host_.set(NULL);
141 debugger_agent_impl_.set(NULL); 143 debugger_agent_impl_.set(NULL);
142 attached_ = false; 144 attached_ = false;
143 } 145 }
144 146
145 void WebDevToolsAgentImpl::OnNavigate() { 147 void WebDevToolsAgentImpl::didNavigate() {
146 DebuggerAgentManager::OnNavigate(); 148 DebuggerAgentManager::OnNavigate();
147 } 149 }
148 150
149 void WebDevToolsAgentImpl::DidCommitLoadForFrame( 151 void WebDevToolsAgentImpl::DidCommitLoadForFrame(
150 WebViewImpl* webview, 152 WebViewImpl* webview,
151 WebFrame* frame, 153 WebFrame* frame,
152 bool is_new_navigation) { 154 bool is_new_navigation) {
153 if (!attached_) { 155 if (!attached_) {
154 return; 156 return;
155 } 157 }
(...skipping 13 matching lines...) Expand all
169 171
170 void WebDevToolsAgentImpl::WindowObjectCleared(WebFrameImpl* webframe) { 172 void WebDevToolsAgentImpl::WindowObjectCleared(WebFrameImpl* webframe) {
171 DebuggerAgentManager::SetHostId(webframe, host_id_); 173 DebuggerAgentManager::SetHostId(webframe, host_id_);
172 if (attached_) { 174 if (attached_) {
173 // Push context id into the client if it is already attached. 175 // Push context id into the client if it is already attached.
174 debugger_agent_delegate_stub_->SetContextId(host_id_); 176 debugger_agent_delegate_stub_->SetContextId(host_id_);
175 } 177 }
176 } 178 }
177 179
178 void WebDevToolsAgentImpl::ForceRepaint() { 180 void WebDevToolsAgentImpl::ForceRepaint() {
179 delegate_->ForceRepaint(); 181 client_->forceRepaint();
180 } 182 }
181 183
182 void WebDevToolsAgentImpl::DispatchOnInspectorController( 184 void WebDevToolsAgentImpl::DispatchOnInspectorController(
183 int call_id, 185 int call_id,
184 const String& function_name, 186 const String& function_name,
185 const String& json_args) { 187 const String& json_args) {
186 String result; 188 String result;
187 String exception; 189 String exception;
188 result = debugger_agent_impl_->ExecuteUtilityFunction(utility_context_, 190 result = debugger_agent_impl_->ExecuteUtilityFunction(utility_context_,
189 call_id, "InspectorControllerDispatcher", function_name, json_args, 191 call_id, "InspectorControllerDispatcher", function_name, json_args,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 if (page) { 225 if (page) {
224 RefPtr<InspectorResource> resource = 226 RefPtr<InspectorResource> resource =
225 page->inspectorController()->resources().get(identifier); 227 page->inspectorController()->resources().get(identifier);
226 if (resource.get()) { 228 if (resource.get()) {
227 content = resource->sourceString(); 229 content = resource->sourceString();
228 } 230 }
229 } 231 }
230 tools_agent_native_delegate_stub_->DidGetResourceContent(call_id, content); 232 tools_agent_native_delegate_stub_->DidGetResourceContent(call_id, content);
231 } 233 }
232 234
233 void WebDevToolsAgentImpl::SetApuAgentEnabled(bool enable) { 235 void WebDevToolsAgentImpl::dispatchMessageFromFrontend(
234 apu_agent_enabled_ = enable;
235 SetApuAgentEnabledInUtilityContext(utility_context_, enable);
236 InspectorController* ic = web_view_impl_->page()->inspectorController();
237 if (enable) {
238 resource_tracking_was_enabled_ = ic->resourceTrackingEnabled();
239 ic->startTimelineProfiler();
240 if (!resource_tracking_was_enabled_) {
241 // TODO(knorton): Introduce some kind of agents dependency here so that
242 // user could turn off resource tracking while apu agent is on.
243 ic->enableResourceTracking(false);
244 }
245 } else {
246 ic->stopTimelineProfiler();
247 if (!resource_tracking_was_enabled_) {
248 ic->disableResourceTracking(false);
249 }
250 resource_tracking_was_enabled_ = false;
251 }
252 }
253
254 void WebDevToolsAgentImpl::DispatchMessageFromClient(
255 const WebString& class_name, 236 const WebString& class_name,
256 const WebString& method_name, 237 const WebString& method_name,
257 const WebString& param1, 238 const WebString& param1,
258 const WebString& param2, 239 const WebString& param2,
259 const WebString& param3) { 240 const WebString& param3) {
260 if (ToolsAgentDispatch::Dispatch( 241 if (ToolsAgentDispatch::Dispatch(
261 this, 242 this,
262 webkit_glue::WebStringToString(class_name), 243 webkit_glue::WebStringToString(class_name),
263 webkit_glue::WebStringToString(method_name), 244 webkit_glue::WebStringToString(method_name),
264 webkit_glue::WebStringToString(param1), 245 webkit_glue::WebStringToString(param1),
(...skipping 11 matching lines...) Expand all
276 debugger_agent_impl_.get(), 257 debugger_agent_impl_.get(),
277 webkit_glue::WebStringToString(class_name), 258 webkit_glue::WebStringToString(class_name),
278 webkit_glue::WebStringToString(method_name), 259 webkit_glue::WebStringToString(method_name),
279 webkit_glue::WebStringToString(param1), 260 webkit_glue::WebStringToString(param1),
280 webkit_glue::WebStringToString(param2), 261 webkit_glue::WebStringToString(param2),
281 webkit_glue::WebStringToString(param3))) { 262 webkit_glue::WebStringToString(param3))) {
282 return; 263 return;
283 } 264 }
284 } 265 }
285 266
286 void WebDevToolsAgentImpl::InspectElement(int x, int y) { 267 void WebDevToolsAgentImpl::inspectElementAt(const WebPoint& point) {
287 Node* node = web_view_impl_->GetNodeForWindowPos(x, y); 268 web_view_impl_->inspectElementAt(point);
288 if (!node) { 269 }
289 return; 270
271 void WebDevToolsAgentImpl::setApuAgentEnabled(bool enable) {
272 apu_agent_enabled_ = enable;
273 SetApuAgentEnabledInUtilityContext(utility_context_, enable);
274 InspectorController* ic = web_view_impl_->page()->inspectorController();
275 if (enable) {
276 resource_tracking_was_enabled_ = ic->resourceTrackingEnabled();
277 ic->startTimelineProfiler();
278 if (!resource_tracking_was_enabled_) {
279 // TODO(knorton): Introduce some kind of agents dependency here so that
280 // user could turn off resource tracking while apu agent is on.
281 ic->enableResourceTracking(false);
282 }
283 } else {
284 ic->stopTimelineProfiler();
285 if (!resource_tracking_was_enabled_) {
286 ic->disableResourceTracking(false);
287 }
288 resource_tracking_was_enabled_ = false;
290 } 289 }
291 InspectorController* ic = web_view_impl_->page()->inspectorController();
292 ic->inspect(node);
293 } 290 }
294 291
295 void WebDevToolsAgentImpl::SendRpcMessage( 292 void WebDevToolsAgentImpl::SendRpcMessage(
296 const String& class_name, 293 const String& class_name,
297 const String& method_name, 294 const String& method_name,
298 const String& param1, 295 const String& param1,
299 const String& param2, 296 const String& param2,
300 const String& param3) { 297 const String& param3) {
301 delegate_->SendMessageToClient( 298 client_->sendMessageToFrontend(
302 webkit_glue::StringToWebString(class_name), 299 webkit_glue::StringToWebString(class_name),
303 webkit_glue::StringToWebString(method_name), 300 webkit_glue::StringToWebString(method_name),
304 webkit_glue::StringToWebString(param1), 301 webkit_glue::StringToWebString(param1),
305 webkit_glue::StringToWebString(param2), 302 webkit_glue::StringToWebString(param2),
306 webkit_glue::StringToWebString(param3)); 303 webkit_glue::StringToWebString(param3));
307 } 304 }
308 305
309 void WebDevToolsAgentImpl::InitDevToolsAgentHost() { 306 void WebDevToolsAgentImpl::InitDevToolsAgentHost() {
310 devtools_agent_host_.set( 307 devtools_agent_host_.set(
311 new BoundObject(utility_context_, this, "DevToolsAgentHost")); 308 new BoundObject(utility_context_, this, "DevToolsAgentHost"));
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 String message = WebCore::toWebCoreStringWithNullCheck(args[0]); 397 String message = WebCore::toWebCoreStringWithNullCheck(args[0]);
401 if (message.isEmpty() || exception_catcher.HasCaught()) { 398 if (message.isEmpty() || exception_catcher.HasCaught()) {
402 return v8::Undefined(); 399 return v8::Undefined();
403 } 400 }
404 WebDevToolsAgentImpl* agent = static_cast<WebDevToolsAgentImpl*>( 401 WebDevToolsAgentImpl* agent = static_cast<WebDevToolsAgentImpl*>(
405 v8::External::Cast(*args.Data())->Value()); 402 v8::External::Cast(*args.Data())->Value());
406 agent->apu_agent_delegate_stub_->DispatchToApu(message); 403 agent->apu_agent_delegate_stub_->DispatchToApu(message);
407 return v8::Undefined(); 404 return v8::Undefined();
408 } 405 }
409 406
407 namespace WebKit {
408
410 // static 409 // static
411 void WebDevToolsAgent::ExecuteDebuggerCommand( 410 void WebDevToolsAgent::executeDebuggerCommand(
412 const WebString& command, 411 const WebString& command,
413 int caller_id) { 412 int caller_id) {
414 DebuggerAgentManager::ExecuteDebuggerCommand( 413 DebuggerAgentManager::ExecuteDebuggerCommand(
415 webkit_glue::WebStringToString(command), caller_id); 414 webkit_glue::WebStringToString(command), caller_id);
416 } 415 }
417 416
418 // static 417 // static
419 void WebDevToolsAgent::SetMessageLoopDispatchHandler( 418 void WebDevToolsAgent::setMessageLoopDispatchHandler(
420 MessageLoopDispatchHandler handler) { 419 MessageLoopDispatchHandler handler) {
421 DebuggerAgentManager::SetMessageLoopDispatchHandler(handler); 420 DebuggerAgentManager::SetMessageLoopDispatchHandler(handler);
422 } 421 }
422
423 } // namespace WebKit
OLDNEW
« no previous file with comments | « webkit/glue/webdevtoolsagent_impl.h ('k') | webkit/glue/webview.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698