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 "base/values.h" | |
10 #include "content/browser/child_process_security_policy_impl.h" | 11 #include "content/browser/child_process_security_policy_impl.h" |
11 #include "content/browser/devtools/devtools_manager_impl.h" | 12 #include "content/browser/devtools/devtools_manager_impl.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" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 g_instances.Get().push_back(this); | 141 g_instances.Get().push_back(this); |
141 RenderViewHostDelegate* delegate = render_view_host_->GetDelegate(); | 142 RenderViewHostDelegate* delegate = render_view_host_->GetDelegate(); |
142 if (delegate && delegate->GetAsWebContents()) | 143 if (delegate && delegate->GetAsWebContents()) |
143 Observe(delegate->GetAsWebContents()); | 144 Observe(delegate->GetAsWebContents()); |
144 } | 145 } |
145 | 146 |
146 RenderViewHost* RenderViewDevToolsAgentHost::GetRenderViewHost() { | 147 RenderViewHost* RenderViewDevToolsAgentHost::GetRenderViewHost() { |
147 return render_view_host_; | 148 return render_view_host_; |
148 } | 149 } |
149 | 150 |
151 void RenderViewDevToolsAgentHost::DispatchOnInspectorBackend( | |
152 const std::string& message) { | |
153 std::string error; | |
154 scoped_ptr<DevToolsProtocol::Command> command( | |
155 DevToolsProtocol::ParseCommand(message, &error)); | |
156 if (!command) { | |
157 OnDispatchOnInspectorFrontend(error); | |
158 return; | |
159 } | |
160 | |
161 scoped_ptr<DevToolsProtocol::Response> early_response; | |
162 if (command->method() == "DOM.setFileInputFiles") | |
pfeldman
2013/02/12 15:03:27
I think we could reuse DomainHandler from DevTools
| |
163 early_response = GrantSetFileInputFilesPermissions(*command); | |
164 | |
165 if (early_response) | |
166 OnDispatchOnInspectorFrontend(early_response->Serialize()); | |
167 else | |
168 DevToolsAgentHostImpl::DispatchOnInspectorBackend(message); | |
169 } | |
170 | |
150 void RenderViewDevToolsAgentHost::SendMessageToAgent(IPC::Message* msg) { | 171 void RenderViewDevToolsAgentHost::SendMessageToAgent(IPC::Message* msg) { |
151 msg->set_routing_id(render_view_host_->GetRoutingID()); | 172 msg->set_routing_id(render_view_host_->GetRoutingID()); |
152 render_view_host_->Send(msg); | 173 render_view_host_->Send(msg); |
153 } | 174 } |
154 | 175 |
155 void RenderViewDevToolsAgentHost::NotifyClientAttaching() { | 176 void RenderViewDevToolsAgentHost::NotifyClientAttaching() { |
156 if (!render_view_host_) | 177 if (!render_view_host_) |
157 return; | 178 return; |
158 | 179 |
159 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadRawCookies( | 180 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadRawCookies( |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 if (web_contents) { | 367 if (web_contents) { |
347 JavaScriptDialogManager* manager = | 368 JavaScriptDialogManager* manager = |
348 web_contents->GetDelegate()->GetJavaScriptDialogManager(); | 369 web_contents->GetDelegate()->GetJavaScriptDialogManager(); |
349 if (!manager) | 370 if (!manager) |
350 return false; | 371 return false; |
351 return manager->HandleJavaScriptDialog(web_contents, accept); | 372 return manager->HandleJavaScriptDialog(web_contents, accept); |
352 } | 373 } |
353 return false; | 374 return false; |
354 } | 375 } |
355 | 376 |
377 scoped_ptr<DevToolsProtocol::Response> | |
378 RenderViewDevToolsAgentHost::GrantSetFileInputFilesPermissions( | |
379 const DevToolsProtocol::Command& command) { | |
380 const base::ListValue* file_list; | |
381 if (!command.params()->GetList("files", &file_list)) { | |
382 return command.ErrorResponse( | |
383 DevToolsProtocol::kErrorInvalidParams, | |
384 "Missing or invalid 'files' parameter"); | |
385 } | |
386 for (size_t i = 0; i < file_list->GetSize(); ++i) { | |
387 base::FilePath::StringType file; | |
388 if (!file_list->GetString(i, &file)) { | |
389 return command.ErrorResponse( | |
390 DevToolsProtocol::kErrorInvalidParams, | |
391 "'files' must be a list of strings"); | |
392 } | |
393 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile( | |
394 render_view_host_->GetProcess()->GetID(), base::FilePath(file)); | |
395 } | |
396 return scoped_ptr<DevToolsProtocol::Response>(); | |
397 } | |
398 | |
356 } // namespace content | 399 } // namespace content |
OLD | NEW |