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 "chrome/browser/extensions/api/file_system/file_system_api.h" | 5 #include "chrome/browser/extensions/api/file_system/file_system_api.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "chrome/common/extensions/api/file_system.h" | |
9 #include "content/public/browser/child_process_security_policy.h" | 8 #include "content/public/browser/child_process_security_policy.h" |
10 #include "content/public/browser/render_view_host.h" | 9 #include "content/public/browser/render_view_host.h" |
11 #include "content/public/browser/render_process_host.h" | 10 #include "content/public/browser/render_process_host.h" |
12 #include "webkit/fileapi/file_system_util.h" | 11 #include "webkit/fileapi/file_system_util.h" |
13 #include "webkit/fileapi/isolated_context.h" | 12 #include "webkit/fileapi/isolated_context.h" |
14 | 13 |
15 namespace GetDisplayPath = extensions::api::file_system::GetDisplayPath; | |
16 | |
17 namespace extensions { | 14 namespace extensions { |
18 | 15 |
19 const char kInvalidParameters[] = "Invalid parameters"; | 16 const char kInvalidParameters[] = "Invalid parameters"; |
20 const char kSecurityError[] = "Security error"; | 17 const char kSecurityError[] = "Security error"; |
21 | 18 |
22 bool FileSystemGetDisplayPathFunction::RunImpl() { | 19 bool FileSystemGetDisplayPathFunction::RunImpl() { |
23 scoped_ptr<GetDisplayPath::Params> params(GetDisplayPath::Params::Create( | 20 std::string filesystem_name; |
24 *args_)); | 21 std::string filesystem_path; |
25 EXTENSION_FUNCTION_VALIDATE(params.get()); | 22 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &filesystem_name)); |
| 23 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &filesystem_path)); |
26 | 24 |
27 std::string filesystem_id; | 25 std::string filesystem_id; |
28 if (!fileapi::CrackIsolatedFileSystemName(params->fsname, &filesystem_id)) { | 26 if (!fileapi::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id)) { |
29 error_ = kInvalidParameters; | 27 error_ = kInvalidParameters; |
30 return false; | 28 return false; |
31 } | 29 } |
32 | 30 |
33 fileapi::IsolatedContext* context = fileapi::IsolatedContext::GetInstance(); | 31 fileapi::IsolatedContext* context = fileapi::IsolatedContext::GetInstance(); |
34 FilePath relative_path = FilePath::FromUTF8Unsafe(params->fspath); | 32 FilePath relative_path = FilePath::FromUTF8Unsafe(filesystem_path); |
35 FilePath virtual_path = context->CreateVirtualPath(filesystem_id, | 33 FilePath virtual_path = context->CreateVirtualPath(filesystem_id, |
36 relative_path); | 34 relative_path); |
37 FilePath file_path; | 35 FilePath file_path; |
38 if (!context->CrackIsolatedPath(virtual_path, | 36 if (!context->CrackIsolatedPath(virtual_path, |
39 &filesystem_id, | 37 &filesystem_id, |
40 NULL, | 38 NULL, |
41 &file_path)) { | 39 &file_path)) { |
42 error_ = kInvalidParameters; | 40 error_ = kInvalidParameters; |
43 return false; | 41 return false; |
44 } | 42 } |
45 | 43 |
46 // Only return the display path if the process has read access to the | 44 // Only return the display path if the process has read access to the |
47 // filesystem. | 45 // filesystem. |
48 content::ChildProcessSecurityPolicy* policy = | 46 content::ChildProcessSecurityPolicy* policy = |
49 content::ChildProcessSecurityPolicy::GetInstance(); | 47 content::ChildProcessSecurityPolicy::GetInstance(); |
50 if (!policy->CanReadFileSystem(render_view_host_->GetProcess()->GetID(), | 48 if (!policy->CanReadFileSystem(render_view_host_->GetProcess()->GetID(), |
51 filesystem_id)) { | 49 filesystem_id)) { |
52 error_ = kSecurityError; | 50 error_ = kSecurityError; |
53 return false; | 51 return false; |
54 } | 52 } |
55 | 53 |
56 result_.reset(base::Value::CreateStringValue(file_path.value())); | 54 result_.reset(base::Value::CreateStringValue(file_path.value())); |
57 return true; | 55 return true; |
58 } | 56 } |
59 | 57 |
60 } // namespace extensions | 58 } // namespace extensions |
OLD | NEW |