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/plugins/ppapi/ppb_file_ref_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
11 #include "ppapi/thunk/enter.h" | |
12 #include "ppapi/thunk/ppb_file_system_api.h" | |
13 #include "webkit/plugins/ppapi/common.h" | 11 #include "webkit/plugins/ppapi/common.h" |
14 #include "webkit/plugins/ppapi/file_callbacks.h" | 12 #include "webkit/plugins/ppapi/file_callbacks.h" |
15 #include "webkit/plugins/ppapi/plugin_delegate.h" | 13 #include "webkit/plugins/ppapi/plugin_delegate.h" |
16 #include "webkit/plugins/ppapi/plugin_module.h" | 14 #include "webkit/plugins/ppapi/plugin_module.h" |
17 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 15 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
18 #include "webkit/plugins/ppapi/ppb_directory_reader_impl.h" | 16 #include "webkit/plugins/ppapi/ppb_directory_reader_impl.h" |
19 #include "webkit/plugins/ppapi/ppb_file_system_impl.h" | 17 #include "webkit/plugins/ppapi/ppb_file_system_impl.h" |
20 #include "webkit/plugins/ppapi/var.h" | 18 #include "webkit/plugins/ppapi/var.h" |
21 | 19 |
22 using ppapi::thunk::EnterResourceNoLock; | |
23 using ppapi::thunk::PPB_FileRef_API; | |
24 using ppapi::thunk::PPB_FileSystem_API; | |
25 | |
26 namespace webkit { | 20 namespace webkit { |
27 namespace ppapi { | 21 namespace ppapi { |
28 | 22 |
29 namespace { | 23 namespace { |
30 | 24 |
31 bool IsValidLocalPath(const std::string& path) { | 25 bool IsValidLocalPath(const std::string& path) { |
32 // The path must start with '/' | 26 // The path must start with '/' |
33 if (path.empty() || path[0] != '/') | 27 if (path.empty() || path[0] != '/') |
34 return false; | 28 return false; |
35 | 29 |
36 // The path must contain valid UTF-8 characters. | 30 // The path must contain valid UTF-8 characters. |
37 if (!IsStringUTF8(path)) | 31 if (!IsStringUTF8(path)) |
38 return false; | 32 return false; |
39 | 33 |
40 return true; | 34 return true; |
41 } | 35 } |
42 | 36 |
43 void TrimTrailingSlash(std::string* path) { | 37 void TrimTrailingSlash(std::string* path) { |
44 // If this path ends with a slash, then normalize it away unless path is the | 38 // If this path ends with a slash, then normalize it away unless path is the |
45 // root path. | 39 // root path. |
46 if (path->size() > 1 && path->at(path->size() - 1) == '/') | 40 if (path->size() > 1 && path->at(path->size() - 1) == '/') |
47 path->erase(path->size() - 1, 1); | 41 path->erase(path->size() - 1, 1); |
48 } | 42 } |
49 | 43 |
| 44 PP_Resource Create(PP_Resource file_system_id, const char* path) { |
| 45 scoped_refptr<PPB_FileSystem_Impl> file_system( |
| 46 Resource::GetAs<PPB_FileSystem_Impl>(file_system_id)); |
| 47 if (!file_system) |
| 48 return 0; |
| 49 |
| 50 if (!file_system->instance()) |
| 51 return 0; |
| 52 |
| 53 std::string validated_path(path); |
| 54 if (!IsValidLocalPath(validated_path)) |
| 55 return 0; |
| 56 TrimTrailingSlash(&validated_path); |
| 57 |
| 58 PPB_FileRef_Impl* file_ref = |
| 59 new PPB_FileRef_Impl(file_system->instance(), |
| 60 file_system, validated_path); |
| 61 return file_ref->GetReference(); |
| 62 } |
| 63 |
| 64 PP_Bool IsFileRef(PP_Resource resource) { |
| 65 return BoolToPPBool(!!Resource::GetAs<PPB_FileRef_Impl>(resource)); |
| 66 } |
| 67 |
| 68 PP_FileSystemType_Dev GetFileSystemType(PP_Resource file_ref_id) { |
| 69 scoped_refptr<PPB_FileRef_Impl> file_ref( |
| 70 Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); |
| 71 if (!file_ref) |
| 72 return PP_FILESYSTEMTYPE_INVALID; |
| 73 return file_ref->GetFileSystemType(); |
| 74 } |
| 75 |
| 76 PP_Var GetName(PP_Resource file_ref_id) { |
| 77 scoped_refptr<PPB_FileRef_Impl> file_ref( |
| 78 Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); |
| 79 if (!file_ref) |
| 80 return PP_MakeUndefined(); |
| 81 return StringVar::StringToPPVar(file_ref->instance()->module(), |
| 82 file_ref->GetName()); |
| 83 } |
| 84 |
| 85 PP_Var GetPath(PP_Resource file_ref_id) { |
| 86 scoped_refptr<PPB_FileRef_Impl> file_ref( |
| 87 Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); |
| 88 if (!file_ref) |
| 89 return PP_MakeUndefined(); |
| 90 |
| 91 if (file_ref->GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) |
| 92 return PP_MakeUndefined(); |
| 93 |
| 94 return StringVar::StringToPPVar(file_ref->instance()->module(), |
| 95 file_ref->GetPath()); |
| 96 } |
| 97 |
| 98 PP_Resource GetParent(PP_Resource file_ref_id) { |
| 99 scoped_refptr<PPB_FileRef_Impl> file_ref( |
| 100 Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); |
| 101 if (!file_ref) |
| 102 return 0; |
| 103 |
| 104 if (file_ref->GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) |
| 105 return 0; |
| 106 |
| 107 scoped_refptr<PPB_FileRef_Impl> parent_ref(file_ref->GetParent()); |
| 108 if (!parent_ref) |
| 109 return 0; |
| 110 |
| 111 return parent_ref->GetReference(); |
| 112 } |
| 113 |
| 114 int32_t MakeDirectory(PP_Resource directory_ref_id, |
| 115 PP_Bool make_ancestors, |
| 116 PP_CompletionCallback callback) { |
| 117 scoped_refptr<PPB_FileRef_Impl> directory_ref( |
| 118 Resource::GetAs<PPB_FileRef_Impl>(directory_ref_id)); |
| 119 if (!directory_ref) |
| 120 return PP_ERROR_BADRESOURCE; |
| 121 |
| 122 scoped_refptr<PPB_FileSystem_Impl> file_system = |
| 123 directory_ref->GetFileSystem(); |
| 124 if (!file_system || !file_system->opened() || |
| 125 (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL)) |
| 126 return PP_ERROR_NOACCESS; |
| 127 |
| 128 PluginInstance* instance = file_system->instance(); |
| 129 if (!instance->delegate()->MakeDirectory( |
| 130 directory_ref->GetFileSystemURL(), PPBoolToBool(make_ancestors), |
| 131 new FileCallbacks(instance->module()->AsWeakPtr(), directory_ref_id, |
| 132 callback, NULL, NULL, NULL))) |
| 133 return PP_ERROR_FAILED; |
| 134 |
| 135 return PP_OK_COMPLETIONPENDING; |
| 136 } |
| 137 |
| 138 int32_t Touch(PP_Resource file_ref_id, |
| 139 PP_Time last_access_time, |
| 140 PP_Time last_modified_time, |
| 141 PP_CompletionCallback callback) { |
| 142 scoped_refptr<PPB_FileRef_Impl> file_ref( |
| 143 Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); |
| 144 if (!file_ref) |
| 145 return PP_ERROR_BADRESOURCE; |
| 146 |
| 147 scoped_refptr<PPB_FileSystem_Impl> file_system = file_ref->GetFileSystem(); |
| 148 if (!file_system || !file_system->opened() || |
| 149 (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL)) |
| 150 return PP_ERROR_NOACCESS; |
| 151 |
| 152 PluginInstance* instance = file_system->instance(); |
| 153 if (!instance->delegate()->Touch( |
| 154 file_ref->GetFileSystemURL(), |
| 155 base::Time::FromDoubleT(last_access_time), |
| 156 base::Time::FromDoubleT(last_modified_time), |
| 157 new FileCallbacks(instance->module()->AsWeakPtr(), file_ref_id, |
| 158 callback, NULL, NULL, NULL))) |
| 159 return PP_ERROR_FAILED; |
| 160 |
| 161 return PP_OK_COMPLETIONPENDING; |
| 162 } |
| 163 |
| 164 int32_t Delete(PP_Resource file_ref_id, |
| 165 PP_CompletionCallback callback) { |
| 166 scoped_refptr<PPB_FileRef_Impl> file_ref( |
| 167 Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); |
| 168 if (!file_ref) |
| 169 return PP_ERROR_BADRESOURCE; |
| 170 |
| 171 scoped_refptr<PPB_FileSystem_Impl> file_system = file_ref->GetFileSystem(); |
| 172 if (!file_system || !file_system->opened() || |
| 173 (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL)) |
| 174 return PP_ERROR_NOACCESS; |
| 175 |
| 176 PluginInstance* instance = file_system->instance(); |
| 177 if (!instance->delegate()->Delete( |
| 178 file_ref->GetFileSystemURL(), |
| 179 new FileCallbacks(instance->module()->AsWeakPtr(), file_ref_id, |
| 180 callback, NULL, NULL, NULL))) |
| 181 return PP_ERROR_FAILED; |
| 182 |
| 183 return PP_OK_COMPLETIONPENDING; |
| 184 } |
| 185 |
| 186 int32_t Rename(PP_Resource file_ref_id, |
| 187 PP_Resource new_file_ref_id, |
| 188 PP_CompletionCallback callback) { |
| 189 scoped_refptr<PPB_FileRef_Impl> file_ref( |
| 190 Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); |
| 191 if (!file_ref) |
| 192 return PP_ERROR_BADRESOURCE; |
| 193 |
| 194 scoped_refptr<PPB_FileRef_Impl> new_file_ref( |
| 195 Resource::GetAs<PPB_FileRef_Impl>(new_file_ref_id)); |
| 196 if (!new_file_ref) |
| 197 return PP_ERROR_BADRESOURCE; |
| 198 |
| 199 scoped_refptr<PPB_FileSystem_Impl> file_system = file_ref->GetFileSystem(); |
| 200 if (!file_system || !file_system->opened() || |
| 201 (file_system != new_file_ref->GetFileSystem()) || |
| 202 (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL)) |
| 203 return PP_ERROR_NOACCESS; |
| 204 |
| 205 // TODO(viettrungluu): Also cancel when the new file ref is destroyed? |
| 206 // http://crbug.com/67624 |
| 207 PluginInstance* instance = file_system->instance(); |
| 208 if (!instance->delegate()->Rename( |
| 209 file_ref->GetFileSystemURL(), new_file_ref->GetFileSystemURL(), |
| 210 new FileCallbacks(instance->module()->AsWeakPtr(), file_ref_id, |
| 211 callback, NULL, NULL, NULL))) |
| 212 return PP_ERROR_FAILED; |
| 213 |
| 214 return PP_OK_COMPLETIONPENDING; |
| 215 } |
| 216 |
| 217 const PPB_FileRef_Dev ppb_fileref = { |
| 218 &Create, |
| 219 &IsFileRef, |
| 220 &GetFileSystemType, |
| 221 &GetName, |
| 222 &GetPath, |
| 223 &GetParent, |
| 224 &MakeDirectory, |
| 225 &Touch, |
| 226 &Delete, |
| 227 &Rename |
| 228 }; |
| 229 |
50 } // namespace | 230 } // namespace |
51 | 231 |
52 PPB_FileRef_Impl::PPB_FileRef_Impl() | 232 PPB_FileRef_Impl::PPB_FileRef_Impl() |
53 : Resource(NULL), | 233 : Resource(NULL), |
54 file_system_(NULL) { | 234 file_system_(NULL) { |
55 } | 235 } |
56 | 236 |
57 PPB_FileRef_Impl::PPB_FileRef_Impl( | 237 PPB_FileRef_Impl::PPB_FileRef_Impl( |
58 PluginInstance* instance, | 238 PluginInstance* instance, |
59 scoped_refptr<PPB_FileSystem_Impl> file_system, | 239 scoped_refptr<PPB_FileSystem_Impl> file_system, |
60 const std::string& validated_path) | 240 const std::string& validated_path) |
61 : Resource(instance), | 241 : Resource(instance), |
62 file_system_(file_system), | 242 file_system_(file_system), |
63 virtual_path_(validated_path) { | 243 virtual_path_(validated_path) { |
64 } | 244 } |
65 | 245 |
66 PPB_FileRef_Impl::PPB_FileRef_Impl(PluginInstance* instance, | 246 PPB_FileRef_Impl::PPB_FileRef_Impl(PluginInstance* instance, |
67 const FilePath& external_file_path) | 247 const FilePath& external_file_path) |
68 : Resource(instance), | 248 : Resource(instance), |
69 file_system_(NULL), | 249 file_system_(NULL), |
70 system_path_(external_file_path) { | 250 system_path_(external_file_path) { |
71 } | 251 } |
72 | 252 |
73 PPB_FileRef_Impl::~PPB_FileRef_Impl() { | 253 PPB_FileRef_Impl::~PPB_FileRef_Impl() { |
74 } | 254 } |
75 | 255 |
76 // static | 256 // static |
77 PP_Resource PPB_FileRef_Impl::Create(PP_Resource pp_file_system, | 257 const PPB_FileRef_Dev* PPB_FileRef_Impl::GetInterface() { |
78 const char* path) { | 258 return &ppb_fileref; |
79 EnterResourceNoLock<PPB_FileSystem_API> enter(pp_file_system, true); | |
80 if (enter.failed()) | |
81 return 0; | |
82 | |
83 PPB_FileSystem_Impl* file_system = | |
84 static_cast<PPB_FileSystem_Impl*>(enter.object()); | |
85 if (!file_system->instance()) | |
86 return 0; | |
87 | |
88 std::string validated_path(path); | |
89 if (!IsValidLocalPath(validated_path)) | |
90 return 0; | |
91 TrimTrailingSlash(&validated_path); | |
92 | |
93 PPB_FileRef_Impl* file_ref = | |
94 new PPB_FileRef_Impl(file_system->instance(), | |
95 file_system, validated_path); | |
96 return file_ref->GetReference(); | |
97 } | |
98 | |
99 PPB_FileRef_API* PPB_FileRef_Impl::AsPPB_FileRef_API() { | |
100 return this; | |
101 } | 259 } |
102 | 260 |
103 PPB_FileRef_Impl* PPB_FileRef_Impl::AsPPB_FileRef_Impl() { | 261 PPB_FileRef_Impl* PPB_FileRef_Impl::AsPPB_FileRef_Impl() { |
104 return this; | 262 return this; |
105 } | 263 } |
106 | 264 |
107 PP_FileSystemType_Dev PPB_FileRef_Impl::GetFileSystemType() const { | 265 std::string PPB_FileRef_Impl::GetName() const { |
108 // When the file ref exists but there's no explicit filesystem object | |
109 // associated with it, that means it's an "external" filesystem. | |
110 if (!file_system_) | |
111 return PP_FILESYSTEMTYPE_EXTERNAL; | |
112 return file_system_->type(); | |
113 } | |
114 | |
115 PP_Var PPB_FileRef_Impl::GetName() const { | |
116 std::string result; | |
117 if (GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) { | 266 if (GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) { |
118 FilePath::StringType path = system_path_.value(); | 267 FilePath::StringType path = system_path_.value(); |
119 size_t pos = path.rfind(FilePath::kSeparators[0]); | 268 size_t pos = path.rfind(FilePath::kSeparators[0]); |
120 DCHECK(pos != FilePath::StringType::npos); | 269 DCHECK(pos != FilePath::StringType::npos); |
121 #if defined(OS_WIN) | 270 #if defined(OS_WIN) |
122 result = WideToUTF8(path.substr(pos + 1)); | 271 return WideToUTF8(path.substr(pos + 1)); |
123 #elif defined(OS_POSIX) | 272 #elif defined(OS_POSIX) |
124 result = path.substr(pos + 1); | 273 return path.substr(pos + 1); |
125 #else | 274 #else |
126 #error "Unsupported platform." | 275 #error "Unsupported platform." |
127 #endif | 276 #endif |
128 } else if (virtual_path_.size() == 1 && virtual_path_[0] == '/') { | |
129 result = virtual_path_; | |
130 } else { | |
131 // There should always be a leading slash at least! | |
132 size_t pos = virtual_path_.rfind('/'); | |
133 DCHECK(pos != std::string::npos); | |
134 result = virtual_path_.substr(pos + 1); | |
135 } | 277 } |
136 | 278 |
137 return StringVar::StringToPPVar(instance()->module(), result); | 279 if (virtual_path_.size() == 1 && virtual_path_[0] == '/') |
138 } | 280 return virtual_path_; |
139 | |
140 PP_Var PPB_FileRef_Impl::GetPath() const { | |
141 if (GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) | |
142 return PP_MakeUndefined(); | |
143 return StringVar::StringToPPVar(instance()->module(), virtual_path_); | |
144 } | |
145 | |
146 PP_Resource PPB_FileRef_Impl::GetParent() { | |
147 if (GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) | |
148 return 0; | |
149 | 281 |
150 // There should always be a leading slash at least! | 282 // There should always be a leading slash at least! |
151 size_t pos = virtual_path_.rfind('/'); | 283 size_t pos = virtual_path_.rfind('/'); |
| 284 DCHECK(pos != std::string::npos); |
| 285 |
| 286 return virtual_path_.substr(pos + 1); |
| 287 } |
| 288 |
| 289 scoped_refptr<PPB_FileRef_Impl> PPB_FileRef_Impl::GetParent() { |
| 290 if (GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) |
| 291 return new PPB_FileRef_Impl(); |
| 292 |
| 293 // There should always be a leading slash at least! |
| 294 size_t pos = virtual_path_.rfind('/'); |
152 DCHECK(pos != std::string::npos); | 295 DCHECK(pos != std::string::npos); |
153 | 296 |
154 // If the path is "/foo", then we want to include the slash. | 297 // If the path is "/foo", then we want to include the slash. |
155 if (pos == 0) | 298 if (pos == 0) |
156 pos++; | 299 pos++; |
157 std::string parent_path = virtual_path_.substr(0, pos); | 300 std::string parent_path = virtual_path_.substr(0, pos); |
158 | 301 |
159 scoped_refptr<PPB_FileRef_Impl> parent_ref( | 302 PPB_FileRef_Impl* parent_ref = new PPB_FileRef_Impl(instance(), file_system_, |
160 new PPB_FileRef_Impl(instance(), file_system_, parent_path)); | 303 parent_path); |
161 return parent_ref->GetReference(); | 304 return parent_ref; |
162 } | 305 } |
163 | 306 |
164 int32_t PPB_FileRef_Impl::MakeDirectory(PP_Bool make_ancestors, | 307 scoped_refptr<PPB_FileSystem_Impl> PPB_FileRef_Impl::GetFileSystem() const { |
165 PP_CompletionCallback callback) { | 308 return file_system_; |
166 if (!IsValidNonExternalFileSystem()) | |
167 return PP_ERROR_NOACCESS; | |
168 if (!instance()->delegate()->MakeDirectory( | |
169 GetFileSystemURL(), PP_ToBool(make_ancestors), | |
170 new FileCallbacks(instance()->module()->AsWeakPtr(), | |
171 GetReferenceNoAddRef(), callback, | |
172 NULL, NULL, NULL))) | |
173 return PP_ERROR_FAILED; | |
174 return PP_OK_COMPLETIONPENDING; | |
175 } | 309 } |
176 | 310 |
177 int32_t PPB_FileRef_Impl::Touch(PP_Time last_access_time, | 311 PP_FileSystemType_Dev PPB_FileRef_Impl::GetFileSystemType() const { |
178 PP_Time last_modified_time, | 312 // When the file ref exists but there's no explicit filesystem object |
179 PP_CompletionCallback callback) { | 313 // associated with it, that means it's an "external" filesystem. |
180 if (!IsValidNonExternalFileSystem()) | 314 if (!file_system_) |
181 return PP_ERROR_NOACCESS; | 315 return PP_FILESYSTEMTYPE_EXTERNAL; |
182 if (!instance()->delegate()->Touch( | 316 |
183 GetFileSystemURL(), | 317 return file_system_->type(); |
184 base::Time::FromDoubleT(last_access_time), | |
185 base::Time::FromDoubleT(last_modified_time), | |
186 new FileCallbacks(instance()->module()->AsWeakPtr(), | |
187 GetReferenceNoAddRef(), callback, | |
188 NULL, NULL, NULL))) | |
189 return PP_ERROR_FAILED; | |
190 return PP_OK_COMPLETIONPENDING; | |
191 } | 318 } |
192 | 319 |
193 int32_t PPB_FileRef_Impl::Delete(PP_CompletionCallback callback) { | 320 std::string PPB_FileRef_Impl::GetPath() const { |
194 if (!IsValidNonExternalFileSystem()) | 321 return virtual_path_; |
195 return PP_ERROR_NOACCESS; | |
196 if (!instance()->delegate()->Delete( | |
197 GetFileSystemURL(), | |
198 new FileCallbacks(instance()->module()->AsWeakPtr(), | |
199 GetReferenceNoAddRef(), callback, | |
200 NULL, NULL, NULL))) | |
201 return PP_ERROR_FAILED; | |
202 return PP_OK_COMPLETIONPENDING; | |
203 } | |
204 | |
205 int32_t PPB_FileRef_Impl::Rename(PP_Resource new_pp_file_ref, | |
206 PP_CompletionCallback callback) { | |
207 EnterResourceNoLock<PPB_FileRef_API> enter(new_pp_file_ref, true); | |
208 if (enter.failed()) | |
209 return PP_ERROR_BADRESOURCE; | |
210 PPB_FileRef_Impl* new_file_ref = | |
211 static_cast<PPB_FileRef_Impl*>(enter.object()); | |
212 | |
213 if (!IsValidNonExternalFileSystem() || | |
214 file_system_.get() != new_file_ref->file_system_.get()) | |
215 return PP_ERROR_NOACCESS; | |
216 | |
217 // TODO(viettrungluu): Also cancel when the new file ref is destroyed? | |
218 // http://crbug.com/67624 | |
219 if (!instance()->delegate()->Rename( | |
220 GetFileSystemURL(), new_file_ref->GetFileSystemURL(), | |
221 new FileCallbacks(instance()->module()->AsWeakPtr(), | |
222 GetReferenceNoAddRef(), callback, | |
223 NULL, NULL, NULL))) | |
224 return PP_ERROR_FAILED; | |
225 return PP_OK_COMPLETIONPENDING; | |
226 } | 322 } |
227 | 323 |
228 FilePath PPB_FileRef_Impl::GetSystemPath() const { | 324 FilePath PPB_FileRef_Impl::GetSystemPath() const { |
229 if (GetFileSystemType() != PP_FILESYSTEMTYPE_EXTERNAL) { | 325 if (GetFileSystemType() != PP_FILESYSTEMTYPE_EXTERNAL) { |
230 NOTREACHED(); | 326 NOTREACHED(); |
231 return FilePath(); | 327 return FilePath(); |
232 } | 328 } |
233 return system_path_; | 329 return system_path_; |
234 } | 330 } |
235 | 331 |
236 GURL PPB_FileRef_Impl::GetFileSystemURL() const { | 332 GURL PPB_FileRef_Impl::GetFileSystemURL() const { |
237 if (GetFileSystemType() != PP_FILESYSTEMTYPE_LOCALPERSISTENT && | 333 if (GetFileSystemType() != PP_FILESYSTEMTYPE_LOCALPERSISTENT && |
238 GetFileSystemType() != PP_FILESYSTEMTYPE_LOCALTEMPORARY) { | 334 GetFileSystemType() != PP_FILESYSTEMTYPE_LOCALTEMPORARY) { |
239 NOTREACHED(); | 335 NOTREACHED(); |
240 return GURL(); | 336 return GURL(); |
241 } | 337 } |
242 if (!virtual_path_.size()) | 338 if (!virtual_path_.size()) |
243 return file_system_->root_url(); | 339 return file_system_->root_url(); |
244 // Since |virtual_path_| starts with a '/', it looks like an absolute path. | 340 // Since |virtual_path_| starts with a '/', it looks like an absolute path. |
245 // We need to trim off the '/' before calling Resolve, as FileSystem URLs | 341 // We need to trim off the '/' before calling Resolve, as FileSystem URLs |
246 // start with a storage type identifier that looks like a path segment. | 342 // start with a storage type identifier that looks like a path segment. |
247 // TODO(ericu): Switch this to use Resolve after fixing GURL to understand | 343 // TODO(ericu): Switch this to use Resolve after fixing GURL to understand |
248 // FileSystem URLs. | 344 // FileSystem URLs. |
249 return GURL(file_system_->root_url().spec() + virtual_path_.substr(1)); | 345 return GURL(file_system_->root_url().spec() + virtual_path_.substr(1)); |
250 } | 346 } |
251 | 347 |
252 bool PPB_FileRef_Impl::IsValidNonExternalFileSystem() const { | |
253 return file_system_ && file_system_->opened() && | |
254 file_system_->type() != PP_FILESYSTEMTYPE_EXTERNAL; | |
255 } | |
256 | |
257 } // namespace ppapi | 348 } // namespace ppapi |
258 } // namespace webkit | 349 } // namespace webkit |
OLD | NEW |