| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/chromeos/fileapi/external_file_url_util.h" | 5 #include "chrome/browser/chromeos/fileapi/external_file_url_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 type == storage::kFileSystemTypeProvided; | 30 type == storage::kFileSystemTypeProvided; |
| 31 } | 31 } |
| 32 | 32 |
| 33 GURL FileSystemURLToExternalFileURL( | 33 GURL FileSystemURLToExternalFileURL( |
| 34 const storage::FileSystemURL& file_system_url) { | 34 const storage::FileSystemURL& file_system_url) { |
| 35 if (file_system_url.mount_type() != storage::kFileSystemTypeExternal || | 35 if (file_system_url.mount_type() != storage::kFileSystemTypeExternal || |
| 36 !IsExternalFileURLType(file_system_url.type())) { | 36 !IsExternalFileURLType(file_system_url.type())) { |
| 37 return GURL(); | 37 return GURL(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 return GURL(base::StringPrintf( | 40 return VirtualPathToExternalFileURL(file_system_url.virtual_path()); |
| 41 "%s:%s", | |
| 42 content::kExternalFileScheme, | |
| 43 file_system_url.virtual_path().AsUTF8Unsafe().c_str())); | |
| 44 } | 41 } |
| 45 | 42 |
| 46 base::FilePath ExternalFileURLToVirtualPath(const GURL& url) { | 43 base::FilePath ExternalFileURLToVirtualPath(const GURL& url) { |
| 47 if (!url.is_valid() || url.scheme() != content::kExternalFileScheme) | 44 if (!url.is_valid() || url.scheme() != content::kExternalFileScheme) |
| 48 return base::FilePath(); | 45 return base::FilePath(); |
| 49 const std::string path_string = | 46 const std::string path_string = |
| 50 net::UnescapeURLComponent(url.GetContent(), net::UnescapeRule::NORMAL); | 47 net::UnescapeURLComponent(url.GetContent(), net::UnescapeRule::NORMAL); |
| 51 return base::FilePath::FromUTF8Unsafe(path_string); | 48 return base::FilePath::FromUTF8Unsafe(path_string); |
| 52 } | 49 } |
| 53 | 50 |
| 51 GURL VirtualPathToExternalFileURL(const base::FilePath& virtual_path) { |
| 52 return GURL(base::StringPrintf("%s:%s", content::kExternalFileScheme, |
| 53 virtual_path.AsUTF8Unsafe().c_str())); |
| 54 } |
| 55 |
| 54 GURL CreateExternalFileURLFromPath(Profile* profile, | 56 GURL CreateExternalFileURLFromPath(Profile* profile, |
| 55 const base::FilePath& path) { | 57 const base::FilePath& path) { |
| 56 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 58 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 57 | 59 |
| 58 GURL raw_file_system_url; | 60 GURL raw_file_system_url; |
| 59 if (!file_manager::util::ConvertAbsoluteFilePathToFileSystemUrl( | 61 if (!file_manager::util::ConvertAbsoluteFilePathToFileSystemUrl( |
| 60 profile, | 62 profile, |
| 61 path, | 63 path, |
| 62 file_manager::kFileManagerAppId, | 64 file_manager::kFileManagerAppId, |
| 63 &raw_file_system_url)) { | 65 &raw_file_system_url)) { |
| 64 return GURL(); | 66 return GURL(); |
| 65 } | 67 } |
| 66 | 68 |
| 67 const storage::FileSystemURL file_system_url = | 69 const storage::FileSystemURL file_system_url = |
| 68 file_manager::util::GetFileSystemContextForExtensionId( | 70 file_manager::util::GetFileSystemContextForExtensionId( |
| 69 profile, file_manager::kFileManagerAppId) | 71 profile, file_manager::kFileManagerAppId) |
| 70 ->CrackURL(raw_file_system_url); | 72 ->CrackURL(raw_file_system_url); |
| 71 if (!file_system_url.is_valid()) | 73 if (!file_system_url.is_valid()) |
| 72 return GURL(); | 74 return GURL(); |
| 73 | 75 |
| 74 return FileSystemURLToExternalFileURL(file_system_url); | 76 return FileSystemURLToExternalFileURL(file_system_url); |
| 75 } | 77 } |
| 76 | 78 |
| 77 } // namespace chromeos | 79 } // namespace chromeos |
| OLD | NEW |