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 | 9 |
| 10 #include "base/strings/string_util.h" |
9 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
10 #include "chrome/browser/chromeos/drive/file_system_util.h" | 12 #include "chrome/browser/chromeos/file_manager/app_id.h" |
| 13 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" |
| 14 #include "chrome/browser/extensions/extension_util.h" |
| 15 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
| 17 #include "content/public/browser/browser_context.h" |
12 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/storage_partition.h" |
13 #include "net/base/escape.h" | 20 #include "net/base/escape.h" |
| 21 #include "storage/browser/fileapi/file_system_url.h" |
14 | 22 |
15 using content::BrowserThread; | 23 using content::BrowserThread; |
16 | 24 |
17 namespace chromeos { | 25 namespace chromeos { |
18 | 26 |
19 GURL FilePathToExternalFileURL(const base::FilePath& path) { | 27 GURL FileSystemURLToExternalFileURL( |
20 std::string url(base::StringPrintf( | 28 const storage::FileSystemURL& file_system_url) { |
21 "%s:%s", chrome::kExternalFileScheme, path.AsUTF8Unsafe().c_str())); | 29 switch (file_system_url.type()) { |
22 return GURL(url); | 30 case storage::kFileSystemTypeDrive: |
| 31 case storage::kFileSystemTypeDeviceMediaAsFileStorage: |
| 32 case storage::kFileSystemTypeProvided: |
| 33 return GURL(base::StringPrintf( |
| 34 "%s:%s", |
| 35 chrome::kExternalFileScheme, |
| 36 file_system_url.virtual_path().AsUTF8Unsafe().c_str())); |
| 37 |
| 38 default: |
| 39 return GURL(); |
| 40 } |
23 } | 41 } |
24 | 42 |
25 base::FilePath ExternalFileURLToFilePath(const GURL& url) { | 43 base::FilePath ExternalFileURLToVirtualPath(const GURL& url) { |
26 if (!url.is_valid() || url.scheme() != chrome::kExternalFileScheme) | 44 if (!url.is_valid() || url.scheme() != chrome::kExternalFileScheme) |
27 return base::FilePath(); | 45 return base::FilePath(); |
28 std::string path_string = | 46 const std::string path_string = |
29 net::UnescapeURLComponent(url.GetContent(), net::UnescapeRule::NORMAL); | 47 net::UnescapeURLComponent(url.GetContent(), net::UnescapeRule::NORMAL); |
30 return base::FilePath::FromUTF8Unsafe(path_string); | 48 return base::FilePath::FromUTF8Unsafe(path_string); |
31 } | 49 } |
32 | 50 |
33 GURL CreateExternalFileURLFromPath(Profile* profile, | 51 GURL CreateExternalFileURLFromPath(Profile* profile, |
34 const base::FilePath& path) { | 52 const base::FilePath& path) { |
35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
36 | 54 |
37 if (!drive::util::IsUnderDriveMountPoint(path)) | 55 GURL raw_file_system_url; |
| 56 if (!file_manager::util::ConvertAbsoluteFilePathToFileSystemUrl( |
| 57 profile, |
| 58 path, |
| 59 file_manager::kFileManagerAppId, |
| 60 &raw_file_system_url)) { |
38 return GURL(); | 61 return GURL(); |
| 62 } |
39 | 63 |
40 drive::FileSystemInterface* file_system = | 64 const GURL site = extensions::util::GetSiteForExtensionId( |
41 drive::util::GetFileSystemByProfile(profile); | 65 file_manager::kFileManagerAppId, profile); |
42 if (!file_system) | 66 const storage::FileSystemURL file_system_url = |
43 return GURL(); | 67 content::BrowserContext::GetStoragePartitionForSite(profile, site) |
| 68 ->GetFileSystemContext() |
| 69 ->CrackURL(raw_file_system_url); |
44 | 70 |
45 return FilePathToExternalFileURL(drive::util::ExtractDrivePath(path)); | 71 return FileSystemURLToExternalFileURL(file_system_url); |
46 } | 72 } |
47 | 73 |
48 } // namespace chromeos | 74 } // namespace chromeos |
OLD | NEW |