Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: chrome/browser/chromeos/fileapi/external_file_url_util.cc

Issue 589473002: Files.app: Enable externalfile: protocol for MTP volumes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 DCHECK(file_system_url.mount_type() == storage::kFileSystemTypeExternal);
22 return GURL(url); 30
31 switch (file_system_url.type()) {
32 case storage::kFileSystemTypeDrive:
33 case storage::kFileSystemTypeDeviceMediaAsFileStorage:
34 case storage::kFileSystemTypeProvided:
35 return GURL(base::StringPrintf(
36 "%s:%s",
37 chrome::kExternalFileScheme,
38 file_system_url.virtual_path().AsUTF8Unsafe().c_str()));
39
40 default:
41 return GURL();
42 }
23 } 43 }
24 44
25 base::FilePath ExternalFileURLToFilePath(const GURL& url) { 45 base::FilePath ExternalFileURLToVirtualPath(const GURL& url) {
26 if (!url.is_valid() || url.scheme() != chrome::kExternalFileScheme) 46 if (!url.is_valid() || url.scheme() != chrome::kExternalFileScheme)
27 return base::FilePath(); 47 return base::FilePath();
28 std::string path_string = 48 const std::string path_string =
29 net::UnescapeURLComponent(url.GetContent(), net::UnescapeRule::NORMAL); 49 net::UnescapeURLComponent(url.GetContent(), net::UnescapeRule::NORMAL);
30 return base::FilePath::FromUTF8Unsafe(path_string); 50 return base::FilePath::FromUTF8Unsafe(path_string);
31 } 51 }
32 52
33 GURL CreateExternalFileURLFromPath(Profile* profile, 53 GURL CreateExternalFileURLFromPath(Profile* profile,
34 const base::FilePath& path) { 54 const base::FilePath& path) {
35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
36 56
37 if (!drive::util::IsUnderDriveMountPoint(path)) 57 GURL raw_file_system_url;
58 if (!file_manager::util::ConvertAbsoluteFilePathToFileSystemUrl(
mtomasz 2014/09/25 09:53:11 Why do we return the file system url as GURL inste
hirono 2014/09/25 11:01:53 Not sure, but in other usages, FileSystemURL is no
mtomasz 2014/09/26 00:27:13 Ah got it. In general I think we should avoid crea
59 profile,
60 path,
61 file_manager::kFileManagerAppId,
62 &raw_file_system_url)) {
38 return GURL(); 63 return GURL();
64 }
39 65
40 drive::FileSystemInterface* file_system = 66 const GURL site = extensions::util::GetSiteForExtensionId(
41 drive::util::GetFileSystemByProfile(profile); 67 file_manager::kFileManagerAppId, profile);
42 if (!file_system) 68 const storage::FileSystemURL file_system_url =
43 return GURL(); 69 content::BrowserContext::GetStoragePartitionForSite(profile, site)
70 ->GetFileSystemContext()
71 ->CrackURL(raw_file_system_url);
44 72
45 return FilePathToExternalFileURL(drive::util::ExtractDrivePath(path)); 73 return FileSystemURLToExternalFileURL(file_system_url);
46 } 74 }
47 75
48 } // namespace chromeos 76 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698