OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "webkit/chromeos/fileapi/cros_mount_point_provider.h" | 5 #include "webkit/chromeos/fileapi/cros_mount_point_provider.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_callback_factory.h" | 8 #include "base/memory/scoped_callback_factory.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/message_loop_proxy.h" | 11 #include "base/message_loop_proxy.h" |
12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCString.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystem.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileSystem.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
17 #include "webkit/chromeos/fileapi/file_access_permissions.h" | |
17 #include "webkit/fileapi/file_system_path_manager.h" | 18 #include "webkit/fileapi/file_system_path_manager.h" |
18 #include "webkit/glue/webkit_glue.h" | 19 #include "webkit/glue/webkit_glue.h" |
19 | 20 |
20 namespace chromeos { | 21 namespace chromeos { |
21 | 22 |
22 const char CrosMountPointProvider::kLocalName[] = "Local"; | |
23 const char CrosMountPointProvider::kLocalDirName[] = "/local/"; | |
24 | |
25 typedef struct { | 23 typedef struct { |
26 const char* local_root_path; | 24 const char* local_root_path; |
27 const char* web_root_path; | 25 const char* web_root_path; |
28 } FixedExposedPaths; | 26 } FixedExposedPaths; |
29 | 27 |
30 // Top level file system elements exposed in FileAPI in ChromeOS: | 28 // Top level file system elements exposed in FileAPI in ChromeOS: |
31 FixedExposedPaths fixed_exposed_paths[] = { | 29 FixedExposedPaths fixed_exposed_paths[] = { |
32 {"/home/chronos/user/", "Downloads"}, | 30 {"/home/chronos/user/", "Downloads"}, |
33 {"/", "media"}, | 31 {"/", "media"}, |
michaeln
2011/04/14 21:25:34
strange that media and tmp both map to the same th
zel
2011/04/14 21:46:20
Actually they don't. The mapping is following:
tm
michaeln
2011/04/14 22:36:58
ah... got it!
| |
34 {"/", "tmp"}, | 32 {"/", "tmp"}, |
35 }; | 33 }; |
36 | 34 |
35 const char CrosMountPointProvider::kExternalName[] = "External"; | |
michaeln
2011/04/14 21:25:34
should this string value be specific to CROS some
zel
2011/04/14 21:46:20
Darin said that 'external' is already part of Pepp
michaeln
2011/04/14 22:36:58
ok... i'm not so familiar with the plan for extend
zel
2011/04/14 22:53:04
I have moved all these constants to file_system_ut
| |
36 const char CrosMountPointProvider::kExternalDirName[] = "/external/"; | |
37 | |
37 CrosMountPointProvider::CrosMountPointProvider( | 38 CrosMountPointProvider::CrosMountPointProvider( |
38 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) | 39 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) |
39 : local_dir_name_(kLocalName), | 40 : special_storage_policy_(special_storage_policy), |
40 special_storage_policy_(special_storage_policy) { | 41 file_access_permissions_(new FileAccessPermissions()) { |
41 | |
42 // TODO(zelidrag): There's got to be a better way to generate UUID. | |
43 srand(time(NULL)); | |
44 std::string virtual_root; | |
45 virtual_root.append(base::StringPrintf("%hx%hx-%hx-%hx-%hx-%hx%hx%hx", | |
46 static_cast<unsigned short>(rand()), static_cast<unsigned short>(rand()), | |
47 static_cast<unsigned short>(rand()), | |
48 static_cast<unsigned short>(rand()), | |
49 static_cast<unsigned short>(rand()), | |
50 static_cast<unsigned short>(rand()), static_cast<unsigned short>(rand()), | |
51 static_cast<unsigned short>(rand()))); | |
52 | |
53 // Create virtual root node. | |
54 virtual_root_path_ = FilePath(virtual_root); | |
55 base_path_ = virtual_root_path_.Append(local_dir_name_); | |
56 | |
57 for (size_t i = 0; i < arraysize(fixed_exposed_paths); i++) { | 42 for (size_t i = 0; i < arraysize(fixed_exposed_paths); i++) { |
58 mount_point_map_.insert(std::pair<std::string, std::string>( | 43 mount_point_map_.insert(std::pair<std::string, FilePath>( |
59 std::string(fixed_exposed_paths[i].web_root_path), | 44 std::string(fixed_exposed_paths[i].web_root_path), |
60 std::string(fixed_exposed_paths[i].local_root_path))); | 45 FilePath(std::string(fixed_exposed_paths[i].local_root_path)))); |
61 } | 46 } |
62 } | 47 } |
63 | 48 |
64 CrosMountPointProvider::~CrosMountPointProvider() { | 49 CrosMountPointProvider::~CrosMountPointProvider() { |
65 } | 50 } |
66 | 51 |
67 // TODO(zelidrag) share with SandboxMountPointProvider impl. | 52 // TODO(zelidrag) share with SandboxMountPointProvider impl. |
68 std::string GetOriginIdentifierFromURL( | 53 std::string GetOriginIdentifierFromURL( |
69 const GURL& url) { | 54 const GURL& url) { |
70 WebKit::WebSecurityOrigin web_security_origin = | 55 WebKit::WebSecurityOrigin web_security_origin = |
71 WebKit::WebSecurityOrigin::createFromString(UTF8ToUTF16(url.spec())); | 56 WebKit::WebSecurityOrigin::createFromString(UTF8ToUTF16(url.spec())); |
72 return web_security_origin.databaseIdentifier().utf8(); | 57 return web_security_origin.databaseIdentifier().utf8(); |
73 } | 58 } |
74 | 59 |
75 void CrosMountPointProvider::GetFileSystemRootPath( | 60 void CrosMountPointProvider::GetFileSystemRootPath( |
76 const GURL& origin_url, | 61 const GURL& origin_url, |
77 fileapi::FileSystemType type, | 62 fileapi::FileSystemType type, |
78 bool create, | 63 bool create, |
79 fileapi::FileSystemPathManager::GetRootPathCallback* callback_ptr) { | 64 fileapi::FileSystemPathManager::GetRootPathCallback* callback_ptr) { |
80 DCHECK(type == fileapi::kFileSystemTypeLocal); | 65 DCHECK(type == fileapi::kFileSystemTypeExternal); |
81 | 66 |
82 std::string name(GetOriginIdentifierFromURL(origin_url)); | 67 std::string name(GetOriginIdentifierFromURL(origin_url)); |
83 name += ':'; | 68 name += ':'; |
84 name += CrosMountPointProvider::kLocalName; | 69 name += CrosMountPointProvider::kExternalName; |
85 | 70 |
86 FilePath root_path = FilePath(CrosMountPointProvider::kLocalDirName); | 71 FilePath root_path = FilePath(CrosMountPointProvider::kExternalDirName); |
87 callback_ptr->Run(!root_path.empty(), root_path, name); | 72 callback_ptr->Run(!root_path.empty(), root_path, name); |
88 } | 73 } |
89 | 74 |
90 // Like GetFileSystemRootPath, but synchronous, and can be called only while | 75 // Like GetFileSystemRootPath, but synchronous, and can be called only while |
91 // running on the file thread. | 76 // running on the file thread. |
92 FilePath CrosMountPointProvider::GetFileSystemRootPathOnFileThread( | 77 FilePath CrosMountPointProvider::GetFileSystemRootPathOnFileThread( |
93 const GURL& origin_url, | 78 const GURL& origin_url, |
94 fileapi::FileSystemType type, | 79 fileapi::FileSystemType type, |
95 const FilePath& virtual_path, | 80 const FilePath& virtual_path, |
96 bool create) { | 81 bool create) { |
97 DCHECK(type == fileapi::kFileSystemTypeLocal); | 82 DCHECK(type == fileapi::kFileSystemTypeExternal); |
98 | 83 |
99 std::vector<FilePath::StringType> components; | 84 std::vector<FilePath::StringType> components; |
100 virtual_path.GetComponents(&components); | 85 virtual_path.GetComponents(&components); |
101 if (components.size() < 1) { | 86 if (components.size() < 1) { |
102 return FilePath(); | 87 return FilePath(); |
103 } | 88 } |
104 | 89 |
105 // Check if this root directory is exposed by this provider. | 90 // Check if this root directory is exposed by this provider. |
106 MountPointMap::iterator iter = mount_point_map_.find(components[0]); | 91 MountPointMap::iterator iter = mount_point_map_.find(components[0]); |
107 if (iter == mount_point_map_.end()) { | 92 if (iter == mount_point_map_.end()) { |
108 return FilePath(); | 93 return FilePath(); |
109 } | 94 } |
110 | 95 |
111 return FilePath(iter->second); | 96 return iter->second; |
112 } | 97 } |
113 | 98 |
114 // TODO(zelidrag): Share this code with SandboxMountPointProvider impl. | 99 // TODO(zelidrag): Share this code with SandboxMountPointProvider impl. |
115 bool CrosMountPointProvider::IsRestrictedFileName(const FilePath& path) const { | 100 bool CrosMountPointProvider::IsRestrictedFileName(const FilePath& path) const { |
116 return false; | 101 return false; |
117 } | 102 } |
118 | 103 |
119 bool CrosMountPointProvider::IsAccessAllowed(const GURL& origin_url) { | 104 bool CrosMountPointProvider::IsAccessAllowed(const GURL& origin_url, |
120 return special_storage_policy_->IsLocalFileSystemAccessAllowed(origin_url); | 105 const FilePath& virtual_path) { |
106 std::string extension_id = origin_url.host(); | |
107 // Check first to make sure this extension has fileBrowserHander permissions. | |
108 if (!special_storage_policy_->IsFileHanlder(extension_id)) | |
109 return false; | |
110 return file_access_permissions_->HasAccessPermission(extension_id, | |
111 virtual_path); | |
112 } | |
113 | |
114 void CrosMountPointProvider::GrantFullAccessToExtension( | |
115 const std::string& extension_id) { | |
116 for (MountPointMap::const_iterator iter = mount_point_map_.begin(); | |
117 iter != mount_point_map_.end(); | |
118 ++iter) { | |
119 GrantFileAccessToExtension(extension_id, iter->second); | |
120 } | |
121 } | |
122 | |
123 void CrosMountPointProvider::GrantFileAccessToExtension( | |
124 const std::string& extension_id, const FilePath& virtual_path) { | |
michaeln
2011/04/14 21:25:34
would it make sense to test IsFileHandler() here t
zel
2011/04/14 21:46:20
The code won't let you get here unless the extensi
| |
125 // All we care about here is access from extensions access for now. | |
126 file_access_permissions_->GrantAccessPermission(extension_id, virtual_path); | |
127 } | |
128 | |
129 void CrosMountPointProvider::RevokeAccessForExtension( | |
130 const std::string& extension_id) { | |
131 file_access_permissions_->RevokePermissions(extension_id); | |
132 } | |
133 | |
134 std::vector<FilePath> CrosMountPointProvider::GetRootDirectories() const { | |
135 std::vector<FilePath> root_dirs; | |
136 for (MountPointMap::const_iterator iter = mount_point_map_.begin(); | |
137 iter != mount_point_map_.end(); | |
138 ++iter) { | |
139 root_dirs.push_back(iter->second.Append(iter->first)); | |
140 } | |
141 return root_dirs; | |
121 } | 142 } |
122 | 143 |
123 } // namespace chromeos | 144 } // namespace chromeos |
124 | 145 |
OLD | NEW |