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 #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/WebDevToolsAgentClient.h" |
29 #include "webkit/api/public/WebFrame.h" | 29 #include "webkit/api/public/WebFrame.h" |
| 30 #include "webkit/api/public/WebString.h" |
30 #include "webkit/api/public/WebURL.h" | 31 #include "webkit/api/public/WebURL.h" |
31 #include "webkit/api/public/WebURLRequest.h" | 32 #include "webkit/api/public/WebURLRequest.h" |
32 #include "webkit/api/src/WebViewImpl.h" | 33 #include "webkit/api/src/WebViewImpl.h" |
33 #include "webkit/glue/devtools/bound_object.h" | 34 #include "webkit/glue/devtools/bound_object.h" |
34 #include "webkit/glue/devtools/debugger_agent_impl.h" | 35 #include "webkit/glue/devtools/debugger_agent_impl.h" |
35 #include "webkit/glue/devtools/debugger_agent_manager.h" | 36 #include "webkit/glue/devtools/debugger_agent_manager.h" |
36 #include "webkit/glue/glue_util.h" | 37 #include "webkit/glue/glue_util.h" |
37 #include "webkit/glue/webdevtoolsagent_impl.h" | 38 #include "webkit/glue/webdevtoolsagent_impl.h" |
38 | 39 |
39 using WebCore::Document; | 40 using WebCore::Document; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 v8::HandleScope handle_scope; | 76 v8::HandleScope handle_scope; |
76 v8::Context::Scope context_scope(context); | 77 v8::Context::Scope context_scope(context); |
77 v8::Handle<v8::Object> dispatcher = v8::Local<v8::Object>::Cast( | 78 v8::Handle<v8::Object> dispatcher = v8::Local<v8::Object>::Cast( |
78 context->Global()->Get(v8::String::New("ApuAgentDispatcher"))); | 79 context->Global()->Get(v8::String::New("ApuAgentDispatcher"))); |
79 if (dispatcher.IsEmpty()) { | 80 if (dispatcher.IsEmpty()) { |
80 return; | 81 return; |
81 } | 82 } |
82 dispatcher->Set(v8::String::New("enabled"), v8::Boolean::New(enabled)); | 83 dispatcher->Set(v8::String::New("enabled"), v8::Boolean::New(enabled)); |
83 } | 84 } |
84 | 85 |
| 86 // TODO(pfeldman): Make this public in WebDevToolsAgent API. |
| 87 static const char kApuAgentFeatureName[] = "apu-agent"; |
| 88 |
| 89 // Keep these in sync with the ones in inject_dispatch.js. |
| 90 static const char kTimelineFeatureName[] = "timeline-profiler"; |
| 91 static const char kResourceTrackingFeatureName[] = "resource-tracking"; |
| 92 |
85 } // namespace | 93 } // namespace |
86 | 94 |
87 WebDevToolsAgentImpl::WebDevToolsAgentImpl( | 95 WebDevToolsAgentImpl::WebDevToolsAgentImpl( |
88 WebViewImpl* web_view_impl, | 96 WebViewImpl* web_view_impl, |
89 WebDevToolsAgentClient* client) | 97 WebDevToolsAgentClient* client) |
90 : host_id_(client->hostIdentifier()), | 98 : host_id_(client->hostIdentifier()), |
91 client_(client), | 99 client_(client), |
92 web_view_impl_(web_view_impl), | 100 web_view_impl_(web_view_impl), |
93 apu_agent_enabled_(false), | 101 apu_agent_enabled_(false), |
94 resource_tracking_was_enabled_(false), | 102 resource_tracking_was_enabled_(false), |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 webkit_glue::WebStringToString(param2), | 272 webkit_glue::WebStringToString(param2), |
265 webkit_glue::WebStringToString(param3))) { | 273 webkit_glue::WebStringToString(param3))) { |
266 return; | 274 return; |
267 } | 275 } |
268 } | 276 } |
269 | 277 |
270 void WebDevToolsAgentImpl::inspectElementAt(const WebPoint& point) { | 278 void WebDevToolsAgentImpl::inspectElementAt(const WebPoint& point) { |
271 web_view_impl_->inspectElementAt(point); | 279 web_view_impl_->inspectElementAt(point); |
272 } | 280 } |
273 | 281 |
274 void WebDevToolsAgentImpl::setApuAgentEnabled(bool enable) { | 282 void WebDevToolsAgentImpl::setRuntimeFeatureEnabled(const WebString& wfeature, |
275 apu_agent_enabled_ = enable; | 283 bool enabled) { |
276 SetApuAgentEnabledInUtilityContext(utility_context_, enable); | 284 String feature = webkit_glue::WebStringToString(wfeature); |
277 InspectorController* ic = web_view_impl_->page()->inspectorController(); | 285 if (feature == kApuAgentFeatureName) { |
278 if (enable) { | 286 setApuAgentEnabled(enabled); |
279 resource_tracking_was_enabled_ = ic->resourceTrackingEnabled(); | 287 } else if (feature == kTimelineFeatureName) { |
280 ic->startTimelineProfiler(); | 288 InspectorController* ic = web_view_impl_->page()->inspectorController(); |
281 if (!resource_tracking_was_enabled_) { | 289 if (enabled) |
282 // TODO(knorton): Introduce some kind of agents dependency here so that | 290 ic->startTimelineProfiler(); |
283 // user could turn off resource tracking while apu agent is on. | 291 else |
284 ic->enableResourceTracking(false, false); | 292 ic->stopTimelineProfiler(); |
285 } | 293 } else if (feature == kResourceTrackingFeatureName) { |
286 } else { | 294 InspectorController* ic = web_view_impl_->page()->inspectorController(); |
287 ic->stopTimelineProfiler(); | 295 if (enabled) |
288 if (!resource_tracking_was_enabled_) { | 296 ic->enableResourceTracking(false /* not sticky */, false /* no reload */); |
289 ic->disableResourceTracking(false); | 297 else |
290 } | 298 ic->disableResourceTracking(false /* not sticky */); |
291 resource_tracking_was_enabled_ = false; | |
292 } | 299 } |
293 } | 300 } |
294 | 301 |
295 void WebDevToolsAgentImpl::SendRpcMessage( | 302 void WebDevToolsAgentImpl::SendRpcMessage( |
296 const String& class_name, | 303 const String& class_name, |
297 const String& method_name, | 304 const String& method_name, |
298 const String& param1, | 305 const String& param1, |
299 const String& param2, | 306 const String& param2, |
300 const String& param3) { | 307 const String& param3) { |
301 client_->sendMessageToFrontend( | 308 client_->sendMessageToFrontend( |
302 webkit_glue::StringToWebString(class_name), | 309 webkit_glue::StringToWebString(class_name), |
303 webkit_glue::StringToWebString(method_name), | 310 webkit_glue::StringToWebString(method_name), |
304 webkit_glue::StringToWebString(param1), | 311 webkit_glue::StringToWebString(param1), |
305 webkit_glue::StringToWebString(param2), | 312 webkit_glue::StringToWebString(param2), |
306 webkit_glue::StringToWebString(param3)); | 313 webkit_glue::StringToWebString(param3)); |
307 } | 314 } |
308 | 315 |
309 void WebDevToolsAgentImpl::InitDevToolsAgentHost() { | 316 void WebDevToolsAgentImpl::InitDevToolsAgentHost() { |
310 devtools_agent_host_.set( | 317 devtools_agent_host_.set( |
311 new BoundObject(utility_context_, this, "DevToolsAgentHost")); | 318 new BoundObject(utility_context_, this, "DevToolsAgentHost")); |
312 devtools_agent_host_->AddProtoFunction( | 319 devtools_agent_host_->AddProtoFunction( |
313 "dispatch", | 320 "dispatch", |
314 WebDevToolsAgentImpl::JsDispatchOnClient); | 321 WebDevToolsAgentImpl::JsDispatchOnClient); |
315 devtools_agent_host_->AddProtoFunction( | 322 devtools_agent_host_->AddProtoFunction( |
316 "dispatchToApu", | 323 "dispatchToApu", |
317 WebDevToolsAgentImpl::JsDispatchToApu); | 324 WebDevToolsAgentImpl::JsDispatchToApu); |
| 325 devtools_agent_host_->AddProtoFunction( |
| 326 "runtimeFeatureStateChanged", |
| 327 WebDevToolsAgentImpl::JsOnRuntimeFeatureStateChanged); |
318 devtools_agent_host_->Build(); | 328 devtools_agent_host_->Build(); |
319 | 329 |
320 v8::HandleScope scope; | 330 v8::HandleScope scope; |
321 v8::Context::Scope utility_scope(utility_context_); | 331 v8::Context::Scope utility_scope(utility_context_); |
322 // Call custom code to create inspector backend wrapper in the utility context | 332 // Call custom code to create inspector backend wrapper in the utility context |
323 // instead of calling V8DOMWrapper::convertToV8Object that would create the | 333 // instead of calling V8DOMWrapper::convertToV8Object that would create the |
324 // wrapper in the Page main frame context. | 334 // wrapper in the Page main frame context. |
325 v8::Handle<v8::Object> backend_wrapper = CreateInspectorBackendV8Wrapper(); | 335 v8::Handle<v8::Object> backend_wrapper = CreateInspectorBackendV8Wrapper(); |
326 if (backend_wrapper.IsEmpty()) { | 336 if (backend_wrapper.IsEmpty()) { |
327 return; | 337 return; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 v8::Handle<v8::Object> injected_script = v8::Local<v8::Object>::Cast( | 382 v8::Handle<v8::Object> injected_script = v8::Local<v8::Object>::Cast( |
373 utility_context_->Global()->Get(v8::String::New("InjectedScript"))); | 383 utility_context_->Global()->Get(v8::String::New("InjectedScript"))); |
374 ScriptState* state = inspector_frontend_script_state_.get(); | 384 ScriptState* state = inspector_frontend_script_state_.get(); |
375 InspectorController* ic = web_view_impl_->page()->inspectorController(); | 385 InspectorController* ic = web_view_impl_->page()->inspectorController(); |
376 ic->setFrontendProxyObject( | 386 ic->setFrontendProxyObject( |
377 state, | 387 state, |
378 ScriptObject(state, utility_context_->Global()), | 388 ScriptObject(state, utility_context_->Global()), |
379 ScriptObject(state, injected_script)); | 389 ScriptObject(state, injected_script)); |
380 } | 390 } |
381 | 391 |
| 392 void WebDevToolsAgentImpl::setApuAgentEnabled(bool enabled) { |
| 393 apu_agent_enabled_ = enabled; |
| 394 SetApuAgentEnabledInUtilityContext(utility_context_, enabled); |
| 395 InspectorController* ic = web_view_impl_->page()->inspectorController(); |
| 396 if (enabled) { |
| 397 resource_tracking_was_enabled_ = ic->resourceTrackingEnabled(); |
| 398 ic->startTimelineProfiler(); |
| 399 if (!resource_tracking_was_enabled_) { |
| 400 // TODO(knorton): Introduce some kind of agents dependency here so that |
| 401 // user could turn off resource tracking while apu agent is on. |
| 402 ic->enableResourceTracking(false, false); |
| 403 } |
| 404 } else { |
| 405 ic->stopTimelineProfiler(); |
| 406 if (!resource_tracking_was_enabled_) { |
| 407 ic->disableResourceTracking(false); |
| 408 } |
| 409 resource_tracking_was_enabled_ = false; |
| 410 } |
| 411 client_->runtimeFeatureStateChanged( |
| 412 webkit_glue::StringToWebString(kApuAgentFeatureName), |
| 413 enabled); |
| 414 } |
| 415 |
382 // static | 416 // static |
383 v8::Handle<v8::Value> WebDevToolsAgentImpl::JsDispatchOnClient( | 417 v8::Handle<v8::Value> WebDevToolsAgentImpl::JsDispatchOnClient( |
384 const v8::Arguments& args) { | 418 const v8::Arguments& args) { |
385 v8::TryCatch exception_catcher; | 419 v8::TryCatch exception_catcher; |
386 String message = WebCore::toWebCoreStringWithNullCheck(args[0]); | 420 String message = WebCore::toWebCoreStringWithNullCheck(args[0]); |
387 if (message.isEmpty() || exception_catcher.HasCaught()) { | 421 if (message.isEmpty() || exception_catcher.HasCaught()) { |
388 return v8::Undefined(); | 422 return v8::Undefined(); |
389 } | 423 } |
390 WebDevToolsAgentImpl* agent = static_cast<WebDevToolsAgentImpl*>( | 424 WebDevToolsAgentImpl* agent = static_cast<WebDevToolsAgentImpl*>( |
391 v8::External::Cast(*args.Data())->Value()); | 425 v8::External::Cast(*args.Data())->Value()); |
392 agent->tools_agent_delegate_stub_->DispatchOnClient(message); | 426 agent->tools_agent_delegate_stub_->DispatchOnClient(message); |
393 return v8::Undefined(); | 427 return v8::Undefined(); |
394 } | 428 } |
395 | 429 |
396 // static | 430 // static |
397 v8::Handle<v8::Value> WebDevToolsAgentImpl::JsDispatchToApu( | 431 v8::Handle<v8::Value> WebDevToolsAgentImpl::JsDispatchToApu( |
398 const v8::Arguments& args) { | 432 const v8::Arguments& args) { |
399 v8::TryCatch exception_catcher; | 433 v8::TryCatch exception_catcher; |
400 String message = WebCore::toWebCoreStringWithNullCheck(args[0]); | 434 String message = WebCore::toWebCoreStringWithNullCheck(args[0]); |
401 if (message.isEmpty() || exception_catcher.HasCaught()) { | 435 if (message.isEmpty() || exception_catcher.HasCaught()) { |
402 return v8::Undefined(); | 436 return v8::Undefined(); |
403 } | 437 } |
404 WebDevToolsAgentImpl* agent = static_cast<WebDevToolsAgentImpl*>( | 438 WebDevToolsAgentImpl* agent = static_cast<WebDevToolsAgentImpl*>( |
405 v8::External::Cast(*args.Data())->Value()); | 439 v8::External::Cast(*args.Data())->Value()); |
406 agent->apu_agent_delegate_stub_->DispatchToApu(message); | 440 agent->apu_agent_delegate_stub_->DispatchToApu(message); |
407 return v8::Undefined(); | 441 return v8::Undefined(); |
408 } | 442 } |
409 | 443 |
| 444 // static |
| 445 v8::Handle<v8::Value> WebDevToolsAgentImpl::JsOnRuntimeFeatureStateChanged( |
| 446 const v8::Arguments& args) { |
| 447 v8::TryCatch exception_catcher; |
| 448 String feature = WebCore::toWebCoreStringWithNullCheck(args[0]); |
| 449 bool enabled = args[1]->ToBoolean()->Value(); |
| 450 if (feature.isEmpty() || exception_catcher.HasCaught()) { |
| 451 return v8::Undefined(); |
| 452 } |
| 453 WebDevToolsAgentImpl* agent = static_cast<WebDevToolsAgentImpl*>( |
| 454 v8::External::Cast(*args.Data())->Value()); |
| 455 agent->client_->runtimeFeatureStateChanged( |
| 456 webkit_glue::StringToWebString(feature), |
| 457 enabled); |
| 458 return v8::Undefined(); |
| 459 } |
| 460 |
410 namespace WebKit { | 461 namespace WebKit { |
411 | 462 |
412 // static | 463 // static |
413 void WebDevToolsAgent::executeDebuggerCommand( | 464 void WebDevToolsAgent::executeDebuggerCommand( |
414 const WebString& command, | 465 const WebString& command, |
415 int caller_id) { | 466 int caller_id) { |
416 DebuggerAgentManager::ExecuteDebuggerCommand( | 467 DebuggerAgentManager::ExecuteDebuggerCommand( |
417 webkit_glue::WebStringToString(command), caller_id); | 468 webkit_glue::WebStringToString(command), caller_id); |
418 } | 469 } |
419 | 470 |
420 // static | 471 // static |
421 void WebDevToolsAgent::setMessageLoopDispatchHandler( | 472 void WebDevToolsAgent::setMessageLoopDispatchHandler( |
422 MessageLoopDispatchHandler handler) { | 473 MessageLoopDispatchHandler handler) { |
423 DebuggerAgentManager::SetMessageLoopDispatchHandler(handler); | 474 DebuggerAgentManager::SetMessageLoopDispatchHandler(handler); |
424 } | 475 } |
425 | 476 |
426 } // namespace WebKit | 477 } // namespace WebKit |
OLD | NEW |