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_request_job.h" | 5 #include "chrome/browser/chromeos/fileapi/external_file_url_request_job.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "storage/browser/fileapi/file_system_operation_runner.h" | 30 #include "storage/browser/fileapi/file_system_operation_runner.h" |
31 | 31 |
32 using content::BrowserThread; | 32 using content::BrowserThread; |
33 | 33 |
34 namespace chromeos { | 34 namespace chromeos { |
35 namespace { | 35 namespace { |
36 | 36 |
37 const char kMimeTypeForRFC822[] = "message/rfc822"; | 37 const char kMimeTypeForRFC822[] = "message/rfc822"; |
38 const char kMimeTypeForMHTML[] = "multipart/related"; | 38 const char kMimeTypeForMHTML[] = "multipart/related"; |
39 | 39 |
40 // Check if the |url| points a valid location or not. | |
41 bool IsValidURL(const storage::FileSystemURL& url) { | |
42 switch (url.type()) { | |
43 case storage::kFileSystemTypeDrive: { | |
44 const base::FilePath my_drive_path = | |
45 drive::util::GetDriveMyDriveRootPath(); | |
46 const base::FilePath drive_other_path = | |
47 drive::util::GetDriveGrandRootPath().Append( | |
48 drive::util::kDriveOtherDirName); | |
49 const base::FilePath url_drive_path = | |
50 drive::util::ExtractDrivePathFromFileSystemUrl(url); | |
51 return my_drive_path == url_drive_path || | |
52 my_drive_path.IsParent(url_drive_path) || | |
53 drive_other_path.IsParent(url_drive_path); | |
54 } | |
55 default: | |
56 return false; | |
57 } | |
58 } | |
59 | |
60 // Helper for obtaining FileSystemContext, FileSystemURL, and mime type on the | 40 // Helper for obtaining FileSystemContext, FileSystemURL, and mime type on the |
61 // UI thread. | 41 // UI thread. |
62 class URLHelper { | 42 class URLHelper { |
63 public: | 43 public: |
64 // The scoped pointer to control lifetime of the instance itself. The pointer | 44 // The scoped pointer to control lifetime of the instance itself. The pointer |
65 // is passed to callback functions and binds the lifetime of the instance to | 45 // is passed to callback functions and binds the lifetime of the instance to |
66 // the callback's lifetime. | 46 // the callback's lifetime. |
67 typedef scoped_ptr<URLHelper> Lifetime; | 47 typedef scoped_ptr<URLHelper> Lifetime; |
68 | 48 |
69 URLHelper(void* profile_id, | 49 URLHelper(void* profile_id, |
(...skipping 19 matching lines...) Expand all Loading... |
89 } | 69 } |
90 content::StoragePartition* const storage = | 70 content::StoragePartition* const storage = |
91 content::BrowserContext::GetStoragePartitionForSite(profile, url_); | 71 content::BrowserContext::GetStoragePartitionForSite(profile, url_); |
92 DCHECK(storage); | 72 DCHECK(storage); |
93 | 73 |
94 scoped_refptr<storage::FileSystemContext> context = | 74 scoped_refptr<storage::FileSystemContext> context = |
95 storage->GetFileSystemContext(); | 75 storage->GetFileSystemContext(); |
96 DCHECK(context.get()); | 76 DCHECK(context.get()); |
97 | 77 |
98 // Obtain the absolute path in the file system. | 78 // Obtain the absolute path in the file system. |
99 base::FilePath path = drive::util::GetDriveMountPointPath(profile); | 79 const base::FilePath virtual_path = |
100 drive::util::GetDriveGrandRootPath().AppendRelativePath( | 80 ExternalFileURLToVirtualPath(profile, url_); |
101 ExternalFileURLToFilePath(url_), &path); | |
102 | |
103 storage::ExternalFileSystemBackend* const backend = | |
104 context->external_backend(); | |
105 DCHECK(backend); | |
106 | |
107 // Obtain the virtual path. | |
108 base::FilePath virtual_path; | |
109 if (!backend->GetVirtualPath(path, &virtual_path)) { | |
110 ReplyResult(net::ERR_FILE_NOT_FOUND); | |
111 return; | |
112 } | |
113 | 81 |
114 // Obtain the file system URL. | 82 // Obtain the file system URL. |
115 // TODO(hirono): After removing MHTML support, stop to use the special | 83 // TODO(hirono): After removing MHTML support, stop to use the special |
116 | |
117 // drive: scheme and use filesystem: URL directly. crbug.com/415455 | 84 // drive: scheme and use filesystem: URL directly. crbug.com/415455 |
118 file_system_url_ = context->CreateCrackedFileSystemURL( | 85 file_system_url_ = context->CreateCrackedFileSystemURL( |
119 GURL(std::string(chrome::kExternalFileScheme) + ":"), | 86 GURL(std::string(chrome::kExternalFileScheme) + ":"), |
120 storage::kFileSystemTypeExternal, | 87 storage::kFileSystemTypeExternal, |
121 virtual_path); | 88 virtual_path); |
122 if (!IsValidURL(file_system_url_)) { | 89 |
| 90 // Check if the obtained path providing external file URL or not. |
| 91 if (FileSystemURLToExternalFileURL(file_system_url_).is_empty()) { |
123 ReplyResult(net::ERR_INVALID_URL); | 92 ReplyResult(net::ERR_INVALID_URL); |
124 return; | 93 return; |
125 } | 94 } |
126 | 95 |
127 file_system_context_ = context; | 96 file_system_context_ = context; |
128 | 97 |
129 extensions::app_file_handler_util::GetMimeTypeForLocalPath( | 98 extensions::app_file_handler_util::GetMimeTypeForLocalPath( |
130 profile, | 99 profile, |
131 file_system_url_.path(), | 100 file_system_url_.path(), |
132 base::Bind(&URLHelper::OnGotMimeTypeOnUIThread, | 101 base::Bind(&URLHelper::OnGotMimeTypeOnUIThread, |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 NotifyDone( | 347 NotifyDone( |
379 net::URLRequestStatus(net::URLRequestStatus::FAILED, read_result)); | 348 net::URLRequestStatus(net::URLRequestStatus::FAILED, read_result)); |
380 } | 349 } |
381 | 350 |
382 remaining_bytes_ -= read_result; | 351 remaining_bytes_ -= read_result; |
383 SetStatus(net::URLRequestStatus()); // Clear the IO_PENDING status. | 352 SetStatus(net::URLRequestStatus()); // Clear the IO_PENDING status. |
384 NotifyReadComplete(read_result); | 353 NotifyReadComplete(read_result); |
385 } | 354 } |
386 | 355 |
387 } // namespace chromeos | 356 } // namespace chromeos |
OLD | NEW |