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

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 test. 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 if (file_system_url.mount_type() != storage::kFileSystemTypeExternal)
22 return GURL(url); 30 return GURL();
31
32 switch (file_system_url.type()) {
33 case storage::kFileSystemTypeDrive:
34 case storage::kFileSystemTypeDeviceMediaAsFileStorage:
35 case storage::kFileSystemTypeProvided:
36 return GURL(base::StringPrintf(
37 "%s:%s",
38 chrome::kExternalFileScheme,
39 file_system_url.virtual_path().AsUTF8Unsafe().c_str()));
40
41 default:
42 return GURL();
43 }
23 } 44 }
24 45
25 base::FilePath ExternalFileURLToFilePath(const GURL& url) { 46 base::FilePath ExternalFileURLToVirtualPath(const GURL& url) {
26 if (!url.is_valid() || url.scheme() != chrome::kExternalFileScheme) 47 if (!url.is_valid() || url.scheme() != chrome::kExternalFileScheme)
27 return base::FilePath(); 48 return base::FilePath();
28 std::string path_string = 49 const std::string path_string =
29 net::UnescapeURLComponent(url.GetContent(), net::UnescapeRule::NORMAL); 50 net::UnescapeURLComponent(url.GetContent(), net::UnescapeRule::NORMAL);
30 return base::FilePath::FromUTF8Unsafe(path_string); 51 return base::FilePath::FromUTF8Unsafe(path_string);
31 } 52 }
32 53
33 GURL CreateExternalFileURLFromPath(Profile* profile, 54 GURL CreateExternalFileURLFromPath(Profile* profile,
34 const base::FilePath& path) { 55 const base::FilePath& path) {
35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 56 DCHECK_CURRENTLY_ON(BrowserThread::UI);
36 57
37 if (!drive::util::IsUnderDriveMountPoint(path)) 58 GURL raw_file_system_url;
59 if (!file_manager::util::ConvertAbsoluteFilePathToFileSystemUrl(
60 profile,
61 path,
62 file_manager::kFileManagerAppId,
63 &raw_file_system_url)) {
64 return GURL();
65 }
66
67 const storage::FileSystemURL file_system_url =
68 file_manager::util::GetFileSystemContextForExtensionId(
69 profile, file_manager::kFileManagerAppId)
70 ->CrackURL(raw_file_system_url);
71 if (!file_system_url.is_valid())
38 return GURL(); 72 return GURL();
39 73
40 drive::FileSystemInterface* file_system = 74 return FileSystemURLToExternalFileURL(file_system_url);
41 drive::util::GetFileSystemByProfile(profile);
42 if (!file_system)
43 return GURL();
44
45 return FilePathToExternalFileURL(drive::util::ExtractDrivePath(path));
46 } 75 }
47 76
48 } // namespace chromeos 77 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698