OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/browser/fileapi/file_system_dir_url_request_job.h" | 5 #include "webkit/browser/fileapi/file_system_dir_url_request_job.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/platform_file.h" | 12 #include "base/platform_file.h" |
13 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "net/base/io_buffer.h" | 17 #include "net/base/io_buffer.h" |
18 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
19 #include "net/base/net_util.h" | 19 #include "net/base/net_util.h" |
20 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
21 #include "url/gurl.h" | 21 #include "url/gurl.h" |
22 #include "webkit/browser/fileapi/file_system_context.h" | 22 #include "webkit/browser/fileapi/file_system_context.h" |
23 #include "webkit/browser/fileapi/file_system_operation_runner.h" | 23 #include "webkit/browser/fileapi/file_system_operation_runner.h" |
24 #include "webkit/browser/fileapi/file_system_url.h" | 24 #include "webkit/browser/fileapi/file_system_url.h" |
25 #include "webkit/common/fileapi/directory_entry.h" | 25 #include "webkit/common/fileapi/directory_entry.h" |
| 26 #include "webkit/common/fileapi/file_system_util.h" |
26 | 27 |
27 using net::NetworkDelegate; | 28 using net::NetworkDelegate; |
28 using net::URLRequest; | 29 using net::URLRequest; |
29 using net::URLRequestJob; | 30 using net::URLRequestJob; |
30 using net::URLRequestStatus; | 31 using net::URLRequestStatus; |
31 | 32 |
32 namespace fileapi { | 33 namespace fileapi { |
33 | 34 |
34 FileSystemDirURLRequestJob::FileSystemDirURLRequestJob( | 35 FileSystemDirURLRequestJob::FileSystemDirURLRequestJob( |
35 URLRequest* request, | 36 URLRequest* request, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 74 |
74 bool FileSystemDirURLRequestJob::GetCharset(std::string* charset) { | 75 bool FileSystemDirURLRequestJob::GetCharset(std::string* charset) { |
75 *charset = "utf-8"; | 76 *charset = "utf-8"; |
76 return true; | 77 return true; |
77 } | 78 } |
78 | 79 |
79 void FileSystemDirURLRequestJob::StartAsync() { | 80 void FileSystemDirURLRequestJob::StartAsync() { |
80 if (!request_) | 81 if (!request_) |
81 return; | 82 return; |
82 url_ = file_system_context_->CrackURL(request_->url()); | 83 url_ = file_system_context_->CrackURL(request_->url()); |
| 84 if (!file_system_context_->CanServeURLRequest(url_)) { |
| 85 // In incognito mode the API is not usable and there should be no data. |
| 86 if (url_.is_valid() && VirtualPath::IsRootPath(url_.virtual_path())) { |
| 87 // Return an empty directory if the filesystem root is queried. |
| 88 DidReadDirectory(base::PLATFORM_FILE_OK, |
| 89 std::vector<DirectoryEntry>(), |
| 90 false); |
| 91 return; |
| 92 } |
| 93 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, |
| 94 net::ERR_FILE_NOT_FOUND)); |
| 95 return; |
| 96 } |
83 file_system_context_->operation_runner()->ReadDirectory( | 97 file_system_context_->operation_runner()->ReadDirectory( |
84 url_, | 98 url_, |
85 base::Bind(&FileSystemDirURLRequestJob::DidReadDirectory, this)); | 99 base::Bind(&FileSystemDirURLRequestJob::DidReadDirectory, this)); |
86 } | 100 } |
87 | 101 |
88 void FileSystemDirURLRequestJob::DidReadDirectory( | 102 void FileSystemDirURLRequestJob::DidReadDirectory( |
89 base::PlatformFileError result, | 103 base::PlatformFileError result, |
90 const std::vector<DirectoryEntry>& entries, | 104 const std::vector<DirectoryEntry>& entries, |
91 bool has_more) { | 105 bool has_more) { |
92 if (result != base::PLATFORM_FILE_OK) { | 106 if (result != base::PLATFORM_FILE_OK) { |
(...skipping 28 matching lines...) Expand all Loading... |
121 file_system_context_->operation_runner()->ReadDirectory( | 135 file_system_context_->operation_runner()->ReadDirectory( |
122 url_, | 136 url_, |
123 base::Bind(&FileSystemDirURLRequestJob::DidReadDirectory, this)); | 137 base::Bind(&FileSystemDirURLRequestJob::DidReadDirectory, this)); |
124 } else { | 138 } else { |
125 set_expected_content_size(data_.size()); | 139 set_expected_content_size(data_.size()); |
126 NotifyHeadersComplete(); | 140 NotifyHeadersComplete(); |
127 } | 141 } |
128 } | 142 } |
129 | 143 |
130 } // namespace fileapi | 144 } // namespace fileapi |
OLD | NEW |