Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/devtools/render_view_devtools_agent_host.h" | 5 #include "content/browser/devtools/render_view_devtools_agent_host.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "content/browser/child_process_security_policy_impl.h" | 10 #include "content/browser/child_process_security_policy_impl.h" |
| 11 #include "content/browser/devtools/devtools_manager_impl.h" | 11 #include "content/browser/devtools/devtools_manager_impl.h" |
| 12 #include "content/browser/devtools/devtools_protocol.h" | |
| 12 #include "content/browser/devtools/render_view_devtools_agent_host.h" | 13 #include "content/browser/devtools/render_view_devtools_agent_host.h" |
| 13 #include "content/browser/renderer_host/render_process_host_impl.h" | 14 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 14 #include "content/browser/renderer_host/render_view_host_impl.h" | 15 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 15 #include "content/browser/site_instance_impl.h" | 16 #include "content/browser/site_instance_impl.h" |
| 16 #include "content/browser/web_contents/web_contents_impl.h" | 17 #include "content/browser/web_contents/web_contents_impl.h" |
| 17 #include "content/common/devtools_messages.h" | 18 #include "content/common/devtools_messages.h" |
| 18 #include "content/public/browser/content_browser_client.h" | 19 #include "content/public/browser/content_browser_client.h" |
| 19 #include "content/public/browser/javascript_dialog_manager.h" | 20 #include "content/public/browser/javascript_dialog_manager.h" |
| 20 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
| 21 #include "content/public/browser/notification_types.h" | 22 #include "content/public/browser/notification_types.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 agent_host_->RenderViewHostDestroyed(rvh); | 64 agent_host_->RenderViewHostDestroyed(rvh); |
| 64 } | 65 } |
| 65 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | 66 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { |
| 66 return agent_host_->OnRvhMessageReceived(message); | 67 return agent_host_->OnRvhMessageReceived(message); |
| 67 } | 68 } |
| 68 private: | 69 private: |
| 69 RenderViewDevToolsAgentHost* agent_host_; | 70 RenderViewDevToolsAgentHost* agent_host_; |
| 70 DISALLOW_COPY_AND_ASSIGN(DevToolsAgentHostRvhObserver); | 71 DISALLOW_COPY_AND_ASSIGN(DevToolsAgentHostRvhObserver); |
| 71 }; | 72 }; |
| 72 | 73 |
| 74 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.
| |
| 75 public: | |
| 76 explicit RendererOverridesHandler( | |
| 77 const DevToolsProtocol::Notifier& notifier, | |
| 78 DevToolsAgentHost* agent) | |
| 79 : DevToolsProtocol::Handler(notifier), | |
| 80 agent_(agent) { | |
| 81 RegisterCommandHandler( | |
| 82 "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
| |
| 83 base::Bind( | |
| 84 &RendererOverridesHandler::GrantPermissionsForSetFileInputFiles, | |
| 85 base::Unretained(this))); | |
| 86 } | |
| 87 virtual ~RendererOverridesHandler() {} | |
| 88 | |
| 89 private: | |
| 90 scoped_ptr<DevToolsProtocol::Response> GrantPermissionsForSetFileInputFiles( | |
| 91 DevToolsProtocol::Command* command) { | |
| 92 const base::ListValue* file_list; | |
| 93 if (!command->params()->GetList("files", &file_list)) { | |
| 94 return command->ErrorResponse( | |
| 95 DevToolsProtocol::kErrorInvalidParams, | |
| 96 "Missing or invalid 'files' parameter"); | |
| 97 } | |
| 98 for (size_t i = 0; i < file_list->GetSize(); ++i) { | |
| 99 base::FilePath::StringType file; | |
| 100 if (!file_list->GetString(i, &file)) { | |
| 101 return command->ErrorResponse( | |
| 102 DevToolsProtocol::kErrorInvalidParams, | |
| 103 "'files' must be a list of strings"); | |
| 104 } | |
| 105 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile( | |
| 106 agent_->GetRenderViewHost()->GetProcess()->GetID(), | |
| 107 base::FilePath(file)); | |
| 108 } | |
| 109 return scoped_ptr<DevToolsProtocol::Response>(); | |
| 110 } | |
| 111 | |
| 112 DevToolsAgentHost* agent_; | |
| 113 }; | |
| 114 | |
| 73 // static | 115 // static |
| 74 scoped_refptr<DevToolsAgentHost> | 116 scoped_refptr<DevToolsAgentHost> |
| 75 DevToolsAgentHost::GetFor(RenderViewHost* rvh) { | 117 DevToolsAgentHost::GetFor(RenderViewHost* rvh) { |
| 76 RenderViewDevToolsAgentHost* result = FindAgentHost(rvh); | 118 RenderViewDevToolsAgentHost* result = FindAgentHost(rvh); |
| 77 if (!result) | 119 if (!result) |
| 78 result = new RenderViewDevToolsAgentHost(rvh); | 120 result = new RenderViewDevToolsAgentHost(rvh); |
| 79 return result; | 121 return result; |
| 80 } | 122 } |
| 81 | 123 |
| 82 // static | 124 // static |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 DevToolsAgentHost::ConnectRenderViewHost(cookie, current); | 176 DevToolsAgentHost::ConnectRenderViewHost(cookie, current); |
| 135 } | 177 } |
| 136 | 178 |
| 137 RenderViewDevToolsAgentHost::RenderViewDevToolsAgentHost( | 179 RenderViewDevToolsAgentHost::RenderViewDevToolsAgentHost( |
| 138 RenderViewHost* rvh) { | 180 RenderViewHost* rvh) { |
| 139 ConnectRenderViewHost(rvh, false); | 181 ConnectRenderViewHost(rvh, false); |
| 140 g_instances.Get().push_back(this); | 182 g_instances.Get().push_back(this); |
| 141 RenderViewHostDelegate* delegate = render_view_host_->GetDelegate(); | 183 RenderViewHostDelegate* delegate = render_view_host_->GetDelegate(); |
| 142 if (delegate && delegate->GetAsWebContents()) | 184 if (delegate && delegate->GetAsWebContents()) |
| 143 Observe(delegate->GetAsWebContents()); | 185 Observe(delegate->GetAsWebContents()); |
| 186 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.
| |
| 187 base::Bind(&RenderViewDevToolsAgentHost::OnDispatchOnInspectorFrontend, | |
| 188 base::Unretained(this)), | |
| 189 this)); | |
| 144 } | 190 } |
| 145 | 191 |
| 146 RenderViewHost* RenderViewDevToolsAgentHost::GetRenderViewHost() { | 192 RenderViewHost* RenderViewDevToolsAgentHost::GetRenderViewHost() { |
| 147 return render_view_host_; | 193 return render_view_host_; |
| 148 } | 194 } |
| 149 | 195 |
| 150 void RenderViewDevToolsAgentHost::DispatchOnInspectorBackend( | 196 void RenderViewDevToolsAgentHost::DispatchOnInspectorBackend( |
| 151 const std::string& message) { | 197 const std::string& message) { |
| 152 DevToolsAgentHostImpl::DispatchOnInspectorBackend(message); | 198 std::string error_message; |
| 199 scoped_ptr<DevToolsProtocol::Command> command( | |
| 200 DevToolsProtocol::ParseCommand(message, &error_message)); | |
| 201 if (!command) { | |
| 202 OnDispatchOnInspectorFrontend(error_message); | |
| 203 return; | |
| 204 } | |
| 205 | |
| 206 scoped_ptr<DevToolsProtocol::Response> overridden_response( | |
| 207 overrides_handler_->HandleCommand(command.get())); | |
| 208 if (overridden_response) | |
| 209 OnDispatchOnInspectorFrontend(overridden_response->Serialize()); | |
| 210 else | |
| 211 DevToolsAgentHostImpl::DispatchOnInspectorBackend(message); | |
| 153 } | 212 } |
| 154 | 213 |
| 155 void RenderViewDevToolsAgentHost::SendMessageToAgent(IPC::Message* msg) { | 214 void RenderViewDevToolsAgentHost::SendMessageToAgent(IPC::Message* msg) { |
| 156 msg->set_routing_id(render_view_host_->GetRoutingID()); | 215 msg->set_routing_id(render_view_host_->GetRoutingID()); |
| 157 render_view_host_->Send(msg); | 216 render_view_host_->Send(msg); |
| 158 } | 217 } |
| 159 | 218 |
| 160 void RenderViewDevToolsAgentHost::NotifyClientAttaching() { | 219 void RenderViewDevToolsAgentHost::NotifyClientAttaching() { |
| 161 if (!render_view_host_) | 220 if (!render_view_host_) |
| 162 return; | 221 return; |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 JavaScriptDialogManager* manager = | 411 JavaScriptDialogManager* manager = |
| 353 web_contents->GetDelegate()->GetJavaScriptDialogManager(); | 412 web_contents->GetDelegate()->GetJavaScriptDialogManager(); |
| 354 if (!manager) | 413 if (!manager) |
| 355 return false; | 414 return false; |
| 356 return manager->HandleJavaScriptDialog(web_contents, accept); | 415 return manager->HandleJavaScriptDialog(web_contents, accept); |
| 357 } | 416 } |
| 358 return false; | 417 return false; |
| 359 } | 418 } |
| 360 | 419 |
| 361 } // namespace content | 420 } // namespace content |
| OLD | NEW |