diff options
Diffstat (limited to 'webkit/glue')
-rw-r--r-- | webkit/glue/devtools/js/inject_dispatch.js | 12 | ||||
-rw-r--r-- | webkit/glue/webdevtoolsagent_impl.cc | 87 | ||||
-rw-r--r-- | webkit/glue/webdevtoolsagent_impl.h | 8 |
3 files changed, 88 insertions, 19 deletions
diff --git a/webkit/glue/devtools/js/inject_dispatch.js b/webkit/glue/devtools/js/inject_dispatch.js index a6127580..fa7fb10 100644 --- a/webkit/glue/devtools/js/inject_dispatch.js +++ b/webkit/glue/devtools/js/inject_dispatch.js @@ -61,6 +61,18 @@ function dispatch(method, var_args) { return; } + // Sniff some inspector controller state changes in order to support + // cross-navigation instrumentation. Keep names in sync with + // webdevtoolsagent_impl. + if (method == 'timelineProfilerWasStarted') + DevToolsAgentHost.runtimeFeatureStateChanged('timeline-profiler', true); + else if (method == 'timelineProfilerWasStopped') + DevToolsAgentHost.runtimeFeatureStateChanged('timeline-profiler', false); + else if (method == 'resourceTrackingWasEnabled') + DevToolsAgentHost.runtimeFeatureStateChanged('resource-tracking', true); + else if (method == 'resourceTrackingWasDisabled') + DevToolsAgentHost.runtimeFeatureStateChanged('resource-tracking', false); + if (ApuAgentDispatcher.enabled) { ApuAgentDispatcher.dispatchToApu(method, args); return; diff --git a/webkit/glue/webdevtoolsagent_impl.cc b/webkit/glue/webdevtoolsagent_impl.cc index ea84c14..3e0b768 100644 --- a/webkit/glue/webdevtoolsagent_impl.cc +++ b/webkit/glue/webdevtoolsagent_impl.cc @@ -27,6 +27,7 @@ #include "webkit/api/public/WebDataSource.h" #include "webkit/api/public/WebDevToolsAgentClient.h" #include "webkit/api/public/WebFrame.h" +#include "webkit/api/public/WebString.h" #include "webkit/api/public/WebURL.h" #include "webkit/api/public/WebURLRequest.h" #include "webkit/api/src/WebViewImpl.h" @@ -82,6 +83,13 @@ void SetApuAgentEnabledInUtilityContext(v8::Handle<v8::Context> context, dispatcher->Set(v8::String::New("enabled"), v8::Boolean::New(enabled)); } +// TODO(pfeldman): Make this public in WebDevToolsAgent API. +static const char kApuAgentFeatureName[] = "apu-agent"; + +// Keep these in sync with the ones in inject_dispatch.js. +static const char kTimelineFeatureName[] = "timeline-profiler"; +static const char kResourceTrackingFeatureName[] = "resource-tracking"; + } // namespace WebDevToolsAgentImpl::WebDevToolsAgentImpl( @@ -271,24 +279,23 @@ void WebDevToolsAgentImpl::inspectElementAt(const WebPoint& point) { web_view_impl_->inspectElementAt(point); } -void WebDevToolsAgentImpl::setApuAgentEnabled(bool enable) { - apu_agent_enabled_ = enable; - SetApuAgentEnabledInUtilityContext(utility_context_, enable); - InspectorController* ic = web_view_impl_->page()->inspectorController(); - if (enable) { - resource_tracking_was_enabled_ = ic->resourceTrackingEnabled(); - ic->startTimelineProfiler(); - if (!resource_tracking_was_enabled_) { - // TODO(knorton): Introduce some kind of agents dependency here so that - // user could turn off resource tracking while apu agent is on. - ic->enableResourceTracking(false, false); - } - } else { - ic->stopTimelineProfiler(); - if (!resource_tracking_was_enabled_) { - ic->disableResourceTracking(false); - } - resource_tracking_was_enabled_ = false; +void WebDevToolsAgentImpl::setRuntimeFeatureEnabled(const WebString& wfeature, + bool enabled) { + String feature = webkit_glue::WebStringToString(wfeature); + if (feature == kApuAgentFeatureName) { + setApuAgentEnabled(enabled); + } else if (feature == kTimelineFeatureName) { + InspectorController* ic = web_view_impl_->page()->inspectorController(); + if (enabled) + ic->startTimelineProfiler(); + else + ic->stopTimelineProfiler(); + } else if (feature == kResourceTrackingFeatureName) { + InspectorController* ic = web_view_impl_->page()->inspectorController(); + if (enabled) + ic->enableResourceTracking(false /* not sticky */, false /* no reload */); + else + ic->disableResourceTracking(false /* not sticky */); } } @@ -315,6 +322,9 @@ void WebDevToolsAgentImpl::InitDevToolsAgentHost() { devtools_agent_host_->AddProtoFunction( "dispatchToApu", WebDevToolsAgentImpl::JsDispatchToApu); + devtools_agent_host_->AddProtoFunction( + "runtimeFeatureStateChanged", + WebDevToolsAgentImpl::JsOnRuntimeFeatureStateChanged); devtools_agent_host_->Build(); v8::HandleScope scope; @@ -379,6 +389,30 @@ void WebDevToolsAgentImpl::ResetInspectorFrontendProxy() { ScriptObject(state, injected_script)); } +void WebDevToolsAgentImpl::setApuAgentEnabled(bool enabled) { + apu_agent_enabled_ = enabled; + SetApuAgentEnabledInUtilityContext(utility_context_, enabled); + InspectorController* ic = web_view_impl_->page()->inspectorController(); + if (enabled) { + resource_tracking_was_enabled_ = ic->resourceTrackingEnabled(); + ic->startTimelineProfiler(); + if (!resource_tracking_was_enabled_) { + // TODO(knorton): Introduce some kind of agents dependency here so that + // user could turn off resource tracking while apu agent is on. + ic->enableResourceTracking(false, false); + } + } else { + ic->stopTimelineProfiler(); + if (!resource_tracking_was_enabled_) { + ic->disableResourceTracking(false); + } + resource_tracking_was_enabled_ = false; + } + client_->runtimeFeatureStateChanged( + webkit_glue::StringToWebString(kApuAgentFeatureName), + enabled); +} + // static v8::Handle<v8::Value> WebDevToolsAgentImpl::JsDispatchOnClient( const v8::Arguments& args) { @@ -407,6 +441,23 @@ v8::Handle<v8::Value> WebDevToolsAgentImpl::JsDispatchToApu( return v8::Undefined(); } +// static +v8::Handle<v8::Value> WebDevToolsAgentImpl::JsOnRuntimeFeatureStateChanged( + const v8::Arguments& args) { + v8::TryCatch exception_catcher; + String feature = WebCore::toWebCoreStringWithNullCheck(args[0]); + bool enabled = args[1]->ToBoolean()->Value(); + if (feature.isEmpty() || exception_catcher.HasCaught()) { + return v8::Undefined(); + } + WebDevToolsAgentImpl* agent = static_cast<WebDevToolsAgentImpl*>( + v8::External::Cast(*args.Data())->Value()); + agent->client_->runtimeFeatureStateChanged( + webkit_glue::StringToWebString(feature), + enabled); + return v8::Undefined(); +} + namespace WebKit { // static diff --git a/webkit/glue/webdevtoolsagent_impl.h b/webkit/glue/webdevtoolsagent_impl.h index 7db9762..3771378 100644 --- a/webkit/glue/webdevtoolsagent_impl.h +++ b/webkit/glue/webdevtoolsagent_impl.h @@ -26,6 +26,7 @@ namespace WebKit { class WebDevToolsAgentClient; class WebFrame; class WebFrameImpl; +class WebString; class WebViewImpl; } @@ -67,7 +68,8 @@ class WebDevToolsAgentImpl : public WebKit::WebDevToolsAgent, const WebKit::WebString& param2, const WebKit::WebString& param3); virtual void inspectElementAt(const WebKit::WebPoint& point); - virtual void setApuAgentEnabled(bool enable); + virtual void setRuntimeFeatureEnabled(const WebKit::WebString& feature, + bool enabled); // DevToolsRpc::Delegate implementation. void SendRpcMessage(const WebCore::String& class_name, @@ -91,11 +93,15 @@ class WebDevToolsAgentImpl : public WebKit::WebDevToolsAgent, private: static v8::Handle<v8::Value> JsDispatchOnClient(const v8::Arguments& args); static v8::Handle<v8::Value> JsDispatchToApu(const v8::Arguments& args); + static v8::Handle<v8::Value> JsOnRuntimeFeatureStateChanged( + const v8::Arguments& args); + void DisposeUtilityContext(); void UnhideResourcesPanelIfNecessary(); void InitDevToolsAgentHost(); void ResetInspectorFrontendProxy(); + void setApuAgentEnabled(bool enabled); // Creates InspectorBackend v8 wrapper in the utility context so that it's // methods prototype is Function.protoype object from the utility context. |