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

Side by Side Diff: chrome/browser/chromeos/fileapi/external_file_url_request_job.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_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
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
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 = ExternalFileURLToVirtualPath(url_);
100 drive::util::GetDriveGrandRootPath().AppendRelativePath(
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 80
114 // Obtain the file system URL. 81 // Obtain the file system URL.
115 // TODO(hirono): After removing MHTML support, stop to use the special 82 // TODO(hirono): After removing MHTML support, stop to use the special
116
117 // drive: scheme and use filesystem: URL directly. crbug.com/415455 83 // drive: scheme and use filesystem: URL directly. crbug.com/415455
118 file_system_url_ = context->CreateCrackedFileSystemURL( 84 file_system_url_ = context->CreateCrackedFileSystemURL(
119 GURL(std::string(chrome::kExternalFileScheme) + ":"), 85 GURL(std::string(chrome::kExternalFileScheme) + ":"),
120 storage::kFileSystemTypeExternal, 86 storage::kFileSystemTypeExternal,
121 virtual_path); 87 virtual_path);
122 if (!IsValidURL(file_system_url_)) { 88
89 // Check if the obtained path providing external file URL or not.
90 if (FileSystemURLToExternalFileURL(file_system_url_).is_empty()) {
123 ReplyResult(net::ERR_INVALID_URL); 91 ReplyResult(net::ERR_INVALID_URL);
124 return; 92 return;
125 } 93 }
126 94
127 file_system_context_ = context; 95 file_system_context_ = context;
128 96
129 extensions::app_file_handler_util::GetMimeTypeForLocalPath( 97 extensions::app_file_handler_util::GetMimeTypeForLocalPath(
130 profile, 98 profile,
131 file_system_url_.path(), 99 file_system_url_.path(),
132 base::Bind(&URLHelper::OnGotMimeTypeOnUIThread, 100 base::Bind(&URLHelper::OnGotMimeTypeOnUIThread,
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 NotifyDone( 348 NotifyDone(
381 net::URLRequestStatus(net::URLRequestStatus::FAILED, read_result)); 349 net::URLRequestStatus(net::URLRequestStatus::FAILED, read_result));
382 } 350 }
383 351
384 remaining_bytes_ -= read_result; 352 remaining_bytes_ -= read_result;
385 SetStatus(net::URLRequestStatus()); // Clear the IO_PENDING status. 353 SetStatus(net::URLRequestStatus()); // Clear the IO_PENDING status.
386 NotifyReadComplete(read_result); 354 NotifyReadComplete(read_result);
387 } 355 }
388 356
389 } // namespace chromeos 357 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698