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

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

Issue 615523002: Files.app: Stop to use file system URLs having externalfile:// scheme origin internally. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 #include <vector>
9 9
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "chrome/browser/chromeos/file_manager/app_id.h" 12 #include "chrome/browser/chromeos/file_manager/app_id.h"
13 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" 13 #include "chrome/browser/chromeos/file_manager/fileapi_util.h"
14 #include "chrome/browser/extensions/extension_util.h" 14 #include "chrome/browser/extensions/extension_util.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
17 #include "content/public/browser/browser_context.h" 17 #include "content/public/browser/browser_context.h"
18 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/storage_partition.h" 19 #include "content/public/browser/storage_partition.h"
20 #include "net/base/escape.h" 20 #include "net/base/escape.h"
21 #include "storage/browser/fileapi/file_system_url.h" 21 #include "storage/browser/fileapi/file_system_url.h"
22 22
23 using content::BrowserThread; 23 using content::BrowserThread;
24 24
25 namespace chromeos { 25 namespace chromeos {
26 26
27 bool IsExternalFileURLType(storage::FileSystemType type) {
28 return type == storage::kFileSystemTypeDrive ||
29 type == storage::kFileSystemTypeDeviceMediaAsFileStorage ||
30 type == storage::kFileSystemTypeProvided;
31 }
32
27 GURL FileSystemURLToExternalFileURL( 33 GURL FileSystemURLToExternalFileURL(
28 const storage::FileSystemURL& file_system_url) { 34 const storage::FileSystemURL& file_system_url) {
29 if (file_system_url.mount_type() != storage::kFileSystemTypeExternal) 35 if (file_system_url.mount_type() != storage::kFileSystemTypeExternal ||
36 !IsExternalFileURLType(file_system_url.type())) {
30 return GURL(); 37 return GURL();
38 }
31 39
32 switch (file_system_url.type()) { 40 return GURL(base::StringPrintf(
33 case storage::kFileSystemTypeDrive: 41 "%s:%s",
34 case storage::kFileSystemTypeDeviceMediaAsFileStorage: 42 chrome::kExternalFileScheme,
35 case storage::kFileSystemTypeProvided: 43 file_system_url.virtual_path().AsUTF8Unsafe().c_str()));
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 }
44 } 44 }
45 45
46 base::FilePath ExternalFileURLToVirtualPath(const GURL& url) { 46 base::FilePath ExternalFileURLToVirtualPath(const GURL& url) {
47 if (!url.is_valid() || url.scheme() != chrome::kExternalFileScheme) 47 if (!url.is_valid() || url.scheme() != chrome::kExternalFileScheme)
48 return base::FilePath(); 48 return base::FilePath();
49 const std::string path_string = 49 const std::string path_string =
50 net::UnescapeURLComponent(url.GetContent(), net::UnescapeRule::NORMAL); 50 net::UnescapeURLComponent(url.GetContent(), net::UnescapeRule::NORMAL);
51 return base::FilePath::FromUTF8Unsafe(path_string); 51 return base::FilePath::FromUTF8Unsafe(path_string);
52 } 52 }
53 53
(...skipping 14 matching lines...) Expand all
68 file_manager::util::GetFileSystemContextForExtensionId( 68 file_manager::util::GetFileSystemContextForExtensionId(
69 profile, file_manager::kFileManagerAppId) 69 profile, file_manager::kFileManagerAppId)
70 ->CrackURL(raw_file_system_url); 70 ->CrackURL(raw_file_system_url);
71 if (!file_system_url.is_valid()) 71 if (!file_system_url.is_valid())
72 return GURL(); 72 return GURL();
73 73
74 return FileSystemURLToExternalFileURL(file_system_url); 74 return FileSystemURLToExternalFileURL(file_system_url);
75 } 75 }
76 76
77 } // namespace chromeos 77 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698