| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/devtools/renderer_overrides_handler.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" |
| 11 #include "base/file_path.h" |
| 12 #include "base/stringprintf.h" |
| 13 #include "base/values.h" |
| 14 #include "content/browser/child_process_security_policy_impl.h" |
| 15 #include "content/public/browser/devtools_agent_host.h" |
| 16 #include "content/public/browser/render_process_host.h" |
| 17 #include "content/public/browser/render_view_host.h" |
| 18 |
| 19 namespace content { |
| 20 |
| 21 namespace { |
| 22 |
| 23 const char kFileInputCommand[] = "DOM.setFileInputFiles"; |
| 24 const char kFileInputFilesParam[] = "files"; |
| 25 |
| 26 } // namespace |
| 27 |
| 28 RendererOverridesHandler::RendererOverridesHandler(DevToolsAgentHost* agent) |
| 29 : agent_(agent) { |
| 30 RegisterCommandHandler( |
| 31 kFileInputCommand, |
| 32 base::Bind( |
| 33 &RendererOverridesHandler::GrantPermissionsForSetFileInputFiles, |
| 34 base::Unretained(this))); |
| 35 } |
| 36 |
| 37 RendererOverridesHandler::~RendererOverridesHandler() {} |
| 38 |
| 39 scoped_ptr<DevToolsProtocol::Response> |
| 40 RendererOverridesHandler::GrantPermissionsForSetFileInputFiles( |
| 41 DevToolsProtocol::Command* command) { |
| 42 const base::ListValue* file_list; |
| 43 if (!command->params()->GetList(kFileInputFilesParam, &file_list)) { |
| 44 return command->ErrorResponse( |
| 45 DevToolsProtocol::kErrorInvalidParams, |
| 46 base::StringPrintf("Missing or invalid '%s' parameter", |
| 47 kFileInputFilesParam)); |
| 48 } |
| 49 for (size_t i = 0; i < file_list->GetSize(); ++i) { |
| 50 base::FilePath::StringType file; |
| 51 if (!file_list->GetString(i, &file)) { |
| 52 return command->ErrorResponse( |
| 53 DevToolsProtocol::kErrorInvalidParams, |
| 54 base::StringPrintf("'%s' must be a list of strings", |
| 55 kFileInputFilesParam)); |
| 56 } |
| 57 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile( |
| 58 agent_->GetRenderViewHost()->GetProcess()->GetID(), |
| 59 base::FilePath(file)); |
| 60 } |
| 61 return scoped_ptr<DevToolsProtocol::Response>(); |
| 62 } |
| 63 |
| 64 } // namespace content |
| OLD | NEW |