Chromium Code Reviews| Index: content/browser/devtools/render_view_devtools_agent_host.cc |
| diff --git a/content/browser/devtools/render_view_devtools_agent_host.cc b/content/browser/devtools/render_view_devtools_agent_host.cc |
| index 2dc0b741a0f871e0a1c58e9f07dc5d8409dcf959..2f95dc44a7dfd02f486d6702498dfcd0d6f15ffc 100644 |
| --- a/content/browser/devtools/render_view_devtools_agent_host.cc |
| +++ b/content/browser/devtools/render_view_devtools_agent_host.cc |
| @@ -9,6 +9,7 @@ |
| #include "base/lazy_instance.h" |
| #include "content/browser/child_process_security_policy_impl.h" |
| #include "content/browser/devtools/devtools_manager_impl.h" |
| +#include "content/browser/devtools/devtools_protocol.h" |
| #include "content/browser/devtools/render_view_devtools_agent_host.h" |
| #include "content/browser/renderer_host/render_process_host_impl.h" |
| #include "content/browser/renderer_host/render_view_host_impl.h" |
| @@ -70,6 +71,47 @@ class DevToolsAgentHostRvhObserver : public RenderViewHostObserver { |
| DISALLOW_COPY_AND_ASSIGN(DevToolsAgentHostRvhObserver); |
| }; |
| +class RendererOverridesHandler : public DevToolsProtocol::Handler { |
|
pfeldman
2013/02/13 17:38:24
Since we expect it to grow, I would immediately de
kkania
2013/02/13 19:17:19
Done.
|
| + public: |
| + explicit RendererOverridesHandler( |
| + const DevToolsProtocol::Notifier& notifier, |
| + DevToolsAgentHost* agent) |
| + : DevToolsProtocol::Handler(notifier), |
| + agent_(agent) { |
| + RegisterCommandHandler( |
| + "DOM.setFileInputFiles", |
|
pfeldman
2013/02/13 17:38:24
You would then be able to declare constants for th
kkania
2013/02/13 19:17:19
I don't see the benefit of declaring a constant if
|
| + base::Bind( |
| + &RendererOverridesHandler::GrantPermissionsForSetFileInputFiles, |
| + base::Unretained(this))); |
| + } |
| + virtual ~RendererOverridesHandler() {} |
| + |
| + private: |
| + scoped_ptr<DevToolsProtocol::Response> GrantPermissionsForSetFileInputFiles( |
| + DevToolsProtocol::Command* command) { |
| + const base::ListValue* file_list; |
| + if (!command->params()->GetList("files", &file_list)) { |
| + return command->ErrorResponse( |
| + DevToolsProtocol::kErrorInvalidParams, |
| + "Missing or invalid 'files' parameter"); |
| + } |
| + for (size_t i = 0; i < file_list->GetSize(); ++i) { |
| + base::FilePath::StringType file; |
| + if (!file_list->GetString(i, &file)) { |
| + return command->ErrorResponse( |
| + DevToolsProtocol::kErrorInvalidParams, |
| + "'files' must be a list of strings"); |
| + } |
| + ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile( |
| + agent_->GetRenderViewHost()->GetProcess()->GetID(), |
| + base::FilePath(file)); |
| + } |
| + return scoped_ptr<DevToolsProtocol::Response>(); |
| + } |
| + |
| + DevToolsAgentHost* agent_; |
| +}; |
| + |
| // static |
| scoped_refptr<DevToolsAgentHost> |
| DevToolsAgentHost::GetFor(RenderViewHost* rvh) { |
| @@ -141,6 +183,10 @@ RenderViewDevToolsAgentHost::RenderViewDevToolsAgentHost( |
| RenderViewHostDelegate* delegate = render_view_host_->GetDelegate(); |
| if (delegate && delegate->GetAsWebContents()) |
| Observe(delegate->GetAsWebContents()); |
| + overrides_handler_.reset(new RendererOverridesHandler( |
|
pfeldman
2013/02/13 17:38:24
That's the one I was talking about: it does not re
kkania
2013/02/13 19:17:19
Done.
|
| + base::Bind(&RenderViewDevToolsAgentHost::OnDispatchOnInspectorFrontend, |
| + base::Unretained(this)), |
| + this)); |
| } |
| RenderViewHost* RenderViewDevToolsAgentHost::GetRenderViewHost() { |
| @@ -149,7 +195,20 @@ RenderViewHost* RenderViewDevToolsAgentHost::GetRenderViewHost() { |
| void RenderViewDevToolsAgentHost::DispatchOnInspectorBackend( |
| const std::string& message) { |
| - DevToolsAgentHostImpl::DispatchOnInspectorBackend(message); |
| + std::string error_message; |
| + scoped_ptr<DevToolsProtocol::Command> command( |
| + DevToolsProtocol::ParseCommand(message, &error_message)); |
| + if (!command) { |
| + OnDispatchOnInspectorFrontend(error_message); |
| + return; |
| + } |
| + |
| + scoped_ptr<DevToolsProtocol::Response> overridden_response( |
| + overrides_handler_->HandleCommand(command.get())); |
| + if (overridden_response) |
| + OnDispatchOnInspectorFrontend(overridden_response->Serialize()); |
| + else |
| + DevToolsAgentHostImpl::DispatchOnInspectorBackend(message); |
| } |
| void RenderViewDevToolsAgentHost::SendMessageToAgent(IPC::Message* msg) { |