Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 1 | // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "content/browser/file_url_loader_factory.h" |
| 6 | |
| 7 | #include <memory> |
| 8 | #include <string> |
| 9 | #include <utility> |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 10 | #include <vector> |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 11 | |
| 12 | #include "base/bind.h" |
| 13 | #include "base/files/file.h" |
| 14 | #include "base/files/file_path.h" |
| 15 | #include "base/files/file_util.h" |
| 16 | #include "base/macros.h" |
| 17 | #include "base/numerics/safe_conversions.h" |
| 18 | #include "base/strings/string16.h" |
| 19 | #include "base/strings/string_util.h" |
| 20 | #include "base/strings/sys_string_conversions.h" |
| 21 | #include "base/strings/utf_string_conversions.h" |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 22 | #include "base/task_scheduler/post_task.h" |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 23 | #include "base/time/time.h" |
| 24 | #include "build/build_config.h" |
| 25 | #include "content/public/browser/content_browser_client.h" |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 26 | #include "content/public/browser/file_url_loader.h" |
Matt Menke | fcbb1bd7 | 2018-01-31 21:53:12 | [diff] [blame] | 27 | #include "content/public/common/content_client.h" |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 28 | #include "mojo/public/cpp/bindings/strong_binding.h" |
| 29 | #include "mojo/public/cpp/system/data_pipe.h" |
| 30 | #include "mojo/public/cpp/system/file_data_pipe_producer.h" |
| 31 | #include "mojo/public/cpp/system/string_data_pipe_producer.h" |
| 32 | #include "net/base/directory_lister.h" |
| 33 | #include "net/base/directory_listing.h" |
| 34 | #include "net/base/filename_util.h" |
| 35 | #include "net/base/mime_sniffer.h" |
| 36 | #include "net/base/mime_util.h" |
| 37 | #include "net/base/net_errors.h" |
| 38 | #include "net/http/http_byte_range.h" |
| 39 | #include "net/http/http_util.h" |
| 40 | #include "net/url_request/redirect_info.h" |
John Abd-El-Malek | 1df6179 | 2018-01-12 20:40:45 | [diff] [blame] | 41 | #include "services/network/public/cpp/resource_request.h" |
Ken Rockot | 54311e6 | 2018-02-10 19:01:52 | [diff] [blame] | 42 | #include "services/network/public/mojom/url_loader.mojom.h" |
Chris Mumford | b5df8ef2 | 2017-12-20 17:47:42 | [diff] [blame] | 43 | #include "storage/common/fileapi/file_system_util.h" |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 44 | #include "url/gurl.h" |
| 45 | |
| 46 | #if defined(OS_WIN) |
| 47 | #include "base/win/shortcut.h" |
| 48 | #endif |
| 49 | |
| 50 | namespace content { |
| 51 | namespace { |
| 52 | |
| 53 | constexpr size_t kDefaultFileUrlPipeSize = 65536; |
| 54 | |
| 55 | // Because this makes things simpler. |
| 56 | static_assert(kDefaultFileUrlPipeSize >= net::kMaxBytesToSniff, |
| 57 | "Default file data pipe size must be at least as large as a MIME-" |
| 58 | "type sniffing buffer."); |
| 59 | |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 60 | // Policy to control how a FileURLLoader will handle directory URLs. |
| 61 | enum class DirectoryLoadingPolicy { |
| 62 | // File paths which refer to directories are allowed and will load as an |
| 63 | // HTML directory listing. |
| 64 | kRespondWithListing, |
| 65 | |
| 66 | // File paths which refer to directories are treated as non-existent and |
| 67 | // will result in FILE_NOT_FOUND errors. |
| 68 | kFail, |
| 69 | }; |
| 70 | |
| 71 | // Policy to control whether or not file access constraints imposed by content |
| 72 | // or its embedder should be honored by a FileURLLoader. |
| 73 | enum class FileAccessPolicy { |
| 74 | // Enforces file acccess policy defined by content and/or its embedder. |
| 75 | kRestricted, |
| 76 | |
| 77 | // Ignores file access policy, allowing contents to be loaded from any |
| 78 | // resolvable file path given. |
| 79 | kUnrestricted, |
| 80 | }; |
| 81 | |
| 82 | // Policy to control whether or not a FileURLLoader should follow filesystem |
| 83 | // links (e.g. Windows shortcuts) where applicable. |
| 84 | enum class LinkFollowingPolicy { |
| 85 | kFollow, |
| 86 | kDoNotFollow, |
| 87 | }; |
| 88 | |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 89 | class FileURLDirectoryLoader |
John Abd-El-Malek | b165dc5 | 2018-01-18 17:12:18 | [diff] [blame] | 90 | : public network::mojom::URLLoader, |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 91 | public net::DirectoryLister::DirectoryListerDelegate { |
| 92 | public: |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 93 | static void CreateAndStart( |
| 94 | const base::FilePath& profile_path, |
| 95 | const network::ResourceRequest& request, |
| 96 | network::mojom::URLLoaderRequest loader, |
| 97 | network::mojom::URLLoaderClientPtrInfo client_info, |
| 98 | std::unique_ptr<FileURLLoaderObserver> observer, |
| 99 | scoped_refptr<net::HttpResponseHeaders> response_headers) { |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 100 | // Owns itself. Will live as long as its URLLoader and URLLoaderClientPtr |
| 101 | // bindings are alive - essentially until either the client gives up or all |
| 102 | // file data has been sent to it. |
| 103 | auto* file_url_loader = new FileURLDirectoryLoader; |
| 104 | file_url_loader->Start(profile_path, request, std::move(loader), |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 105 | std::move(client_info), std::move(observer), |
| 106 | std::move(response_headers)); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 107 | } |
| 108 | |
John Abd-El-Malek | b165dc5 | 2018-01-18 17:12:18 | [diff] [blame] | 109 | // network::mojom::URLLoader: |
Chong Zhang | f19dde9 | 2018-05-23 04:33:59 | [diff] [blame] | 110 | void FollowRedirect(const base::Optional<net::HttpRequestHeaders>& |
| 111 | modified_request_headers) override {} |
arthursonzogni | 2e1524a7 | 2017-12-18 16:53:26 | [diff] [blame] | 112 | void ProceedWithResponse() override { NOTREACHED(); } |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 113 | void SetPriority(net::RequestPriority priority, |
| 114 | int32_t intra_priority_value) override {} |
| 115 | void PauseReadingBodyFromNet() override {} |
| 116 | void ResumeReadingBodyFromNet() override {} |
| 117 | |
| 118 | private: |
| 119 | FileURLDirectoryLoader() : binding_(this) {} |
| 120 | ~FileURLDirectoryLoader() override = default; |
| 121 | |
| 122 | void Start(const base::FilePath& profile_path, |
John Abd-El-Malek | 1df6179 | 2018-01-12 20:40:45 | [diff] [blame] | 123 | const network::ResourceRequest& request, |
John Abd-El-Malek | b165dc5 | 2018-01-18 17:12:18 | [diff] [blame] | 124 | network::mojom::URLLoaderRequest loader, |
| 125 | network::mojom::URLLoaderClientPtrInfo client_info, |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 126 | std::unique_ptr<content::FileURLLoaderObserver> observer, |
| 127 | scoped_refptr<net::HttpResponseHeaders> response_headers) { |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 128 | binding_.Bind(std::move(loader)); |
| 129 | binding_.set_connection_error_handler(base::BindOnce( |
| 130 | &FileURLDirectoryLoader::OnConnectionError, base::Unretained(this))); |
| 131 | |
John Abd-El-Malek | b165dc5 | 2018-01-18 17:12:18 | [diff] [blame] | 132 | network::mojom::URLLoaderClientPtr client; |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 133 | client.Bind(std::move(client_info)); |
| 134 | |
| 135 | if (!net::FileURLToFilePath(request.url, &path_)) { |
Takashi Toyoshima | aa27866 | 2017-11-20 11:11:26 | [diff] [blame] | 136 | client->OnComplete(network::URLLoaderCompletionStatus(net::ERR_FAILED)); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 137 | return; |
| 138 | } |
| 139 | |
| 140 | base::File::Info info; |
| 141 | if (!base::GetFileInfo(path_, &info) || !info.is_directory) { |
Takashi Toyoshima | aa27866 | 2017-11-20 11:11:26 | [diff] [blame] | 142 | client->OnComplete( |
| 143 | network::URLLoaderCompletionStatus(net::ERR_FILE_NOT_FOUND)); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 144 | return; |
| 145 | } |
| 146 | |
| 147 | if (!GetContentClient()->browser()->IsFileAccessAllowed( |
| 148 | path_, base::MakeAbsoluteFilePath(path_), profile_path)) { |
Takashi Toyoshima | aa27866 | 2017-11-20 11:11:26 | [diff] [blame] | 149 | client->OnComplete( |
| 150 | network::URLLoaderCompletionStatus(net::ERR_ACCESS_DENIED)); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 151 | return; |
| 152 | } |
| 153 | |
| 154 | mojo::DataPipe pipe(kDefaultFileUrlPipeSize); |
| 155 | if (!pipe.consumer_handle.is_valid()) { |
Takashi Toyoshima | aa27866 | 2017-11-20 11:11:26 | [diff] [blame] | 156 | client->OnComplete(network::URLLoaderCompletionStatus(net::ERR_FAILED)); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 157 | return; |
| 158 | } |
| 159 | |
John Abd-El-Malek | 4624803 | 2018-01-17 19:11:23 | [diff] [blame] | 160 | network::ResourceResponseHead head; |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 161 | head.mime_type = "text/html"; |
| 162 | head.charset = "utf-8"; |
Marijn Kruisselbrink | 9ebd7ba | 2018-06-11 23:18:04 | [diff] [blame^] | 163 | client->OnReceiveResponse(head); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 164 | client->OnStartLoadingResponseBody(std::move(pipe.consumer_handle)); |
| 165 | client_ = std::move(client); |
| 166 | |
| 167 | lister_ = std::make_unique<net::DirectoryLister>(path_, this); |
| 168 | lister_->Start(); |
| 169 | |
| 170 | data_producer_ = std::make_unique<mojo::StringDataPipeProducer>( |
| 171 | std::move(pipe.producer_handle)); |
| 172 | } |
| 173 | |
| 174 | void OnConnectionError() { |
| 175 | binding_.Close(); |
| 176 | MaybeDeleteSelf(); |
| 177 | } |
| 178 | |
| 179 | void MaybeDeleteSelf() { |
| 180 | if (!binding_.is_bound() && !client_.is_bound() && !lister_) |
| 181 | delete this; |
| 182 | } |
| 183 | |
| 184 | // net::DirectoryLister::DirectoryListerDelegate: |
| 185 | void OnListFile( |
| 186 | const net::DirectoryLister::DirectoryListerData& data) override { |
| 187 | if (!wrote_header_) { |
| 188 | wrote_header_ = true; |
| 189 | |
| 190 | #if defined(OS_WIN) |
| 191 | const base::string16& title = path_.value(); |
Fabrice de Gans-Riberi | 91fa3505 | 2018-05-07 19:33:48 | [diff] [blame] | 192 | #elif defined(OS_POSIX) || defined(OS_FUCHSIA) |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 193 | const base::string16& title = |
| 194 | base::WideToUTF16(base::SysNativeMBToWide(path_.value())); |
| 195 | #endif |
| 196 | pending_data_.append(net::GetDirectoryListingHeader(title)); |
| 197 | |
| 198 | // If not a top-level directory, add a link to the parent directory. To |
| 199 | // figure this out, first normalize |path_| by stripping trailing |
| 200 | // separators. Then compare the result to its DirName(). For the top-level |
| 201 | // directory, e.g. "/" or "c:\\", the normalized path is equal to its own |
| 202 | // DirName(). |
| 203 | base::FilePath stripped_path = path_.StripTrailingSeparators(); |
| 204 | if (stripped_path != stripped_path.DirName()) |
| 205 | pending_data_.append(net::GetParentDirectoryLink()); |
| 206 | } |
| 207 | |
| 208 | // Skip current / parent links from the listing. |
| 209 | base::FilePath filename = data.info.GetName(); |
| 210 | if (filename.value() != base::FilePath::kCurrentDirectory && |
| 211 | filename.value() != base::FilePath::kParentDirectory) { |
| 212 | #if defined(OS_WIN) |
| 213 | std::string raw_bytes; // Empty on Windows means UTF-8 encoded name. |
Fabrice de Gans-Riberi | 91fa3505 | 2018-05-07 19:33:48 | [diff] [blame] | 214 | #elif defined(OS_POSIX) || defined(OS_FUCHSIA) |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 215 | const std::string& raw_bytes = filename.value(); |
| 216 | #endif |
| 217 | pending_data_.append(net::GetDirectoryListingEntry( |
| 218 | filename.LossyDisplayName(), raw_bytes, data.info.IsDirectory(), |
| 219 | data.info.GetSize(), data.info.GetLastModifiedTime())); |
| 220 | } |
| 221 | |
| 222 | MaybeTransferPendingData(); |
| 223 | } |
| 224 | |
| 225 | void OnListDone(int error) override { |
| 226 | listing_result_ = error; |
| 227 | lister_.reset(); |
| 228 | MaybeDeleteSelf(); |
| 229 | } |
| 230 | |
| 231 | void MaybeTransferPendingData() { |
| 232 | if (transfer_in_progress_) |
| 233 | return; |
| 234 | |
| 235 | transfer_in_progress_ = true; |
| 236 | data_producer_->Write(pending_data_, |
Daniel Murphy | 0ecba61 | 2018-02-07 20:56:18 | [diff] [blame] | 237 | mojo::StringDataPipeProducer::AsyncWritingMode:: |
| 238 | STRING_MAY_BE_INVALIDATED_BEFORE_COMPLETION, |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 239 | base::BindOnce(&FileURLDirectoryLoader::OnDataWritten, |
| 240 | base::Unretained(this))); |
| 241 | // The producer above will have already copied any parts of |pending_data_| |
| 242 | // that couldn't be written immediately, so we can wipe it out here to begin |
| 243 | // accumulating more data. |
| 244 | pending_data_.clear(); |
| 245 | } |
| 246 | |
| 247 | void OnDataWritten(MojoResult result) { |
| 248 | transfer_in_progress_ = false; |
| 249 | |
| 250 | int completion_status; |
| 251 | if (result == MOJO_RESULT_OK) { |
| 252 | if (!pending_data_.empty()) { |
| 253 | // Keep flushing the data buffer as long as it's non-empty and pipe |
| 254 | // writes are succeeding. |
| 255 | MaybeTransferPendingData(); |
| 256 | return; |
| 257 | } |
| 258 | |
| 259 | // If there's no pending data but the lister is still active, we simply |
| 260 | // wait for more listing results. |
| 261 | if (lister_) |
| 262 | return; |
| 263 | |
| 264 | // At this point we know the listing is complete and all available data |
| 265 | // has been transferred. We inherit the status of the listing operation. |
| 266 | completion_status = listing_result_; |
| 267 | } else { |
| 268 | completion_status = net::ERR_FAILED; |
| 269 | } |
| 270 | |
arthursonzogni | 3a4ca9f | 2017-12-07 17:58:34 | [diff] [blame] | 271 | // All the data has been written now. Close the data pipe. The consumer will |
| 272 | // be notified that there will be no more data to read from now. |
| 273 | data_producer_.reset(); |
| 274 | |
Takashi Toyoshima | aa27866 | 2017-11-20 11:11:26 | [diff] [blame] | 275 | client_->OnComplete(network::URLLoaderCompletionStatus(completion_status)); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 276 | client_.reset(); |
arthursonzogni | 3a4ca9f | 2017-12-07 17:58:34 | [diff] [blame] | 277 | |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 278 | MaybeDeleteSelf(); |
| 279 | } |
| 280 | |
| 281 | base::FilePath path_; |
| 282 | std::unique_ptr<net::DirectoryLister> lister_; |
| 283 | bool wrote_header_ = false; |
| 284 | int listing_result_; |
| 285 | |
John Abd-El-Malek | b165dc5 | 2018-01-18 17:12:18 | [diff] [blame] | 286 | mojo::Binding<network::mojom::URLLoader> binding_; |
| 287 | network::mojom::URLLoaderClientPtr client_; |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 288 | |
| 289 | std::unique_ptr<mojo::StringDataPipeProducer> data_producer_; |
| 290 | std::string pending_data_; |
| 291 | bool transfer_in_progress_ = false; |
| 292 | |
| 293 | DISALLOW_COPY_AND_ASSIGN(FileURLDirectoryLoader); |
| 294 | }; |
| 295 | |
John Abd-El-Malek | b165dc5 | 2018-01-18 17:12:18 | [diff] [blame] | 296 | class FileURLLoader : public network::mojom::URLLoader { |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 297 | public: |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 298 | static void CreateAndStart( |
| 299 | const base::FilePath& profile_path, |
| 300 | const network::ResourceRequest& request, |
| 301 | network::mojom::URLLoaderRequest loader, |
| 302 | network::mojom::URLLoaderClientPtrInfo client_info, |
| 303 | DirectoryLoadingPolicy directory_loading_policy, |
| 304 | FileAccessPolicy file_access_policy, |
| 305 | LinkFollowingPolicy link_following_policy, |
| 306 | std::unique_ptr<FileURLLoaderObserver> observer, |
| 307 | scoped_refptr<net::HttpResponseHeaders> extra_response_headers) { |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 308 | // Owns itself. Will live as long as its URLLoader and URLLoaderClientPtr |
| 309 | // bindings are alive - essentially until either the client gives up or all |
| 310 | // file data has been sent to it. |
| 311 | auto* file_url_loader = new FileURLLoader; |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 312 | file_url_loader->Start( |
| 313 | profile_path, request, std::move(loader), std::move(client_info), |
| 314 | directory_loading_policy, file_access_policy, link_following_policy, |
| 315 | std::move(observer), std::move(extra_response_headers)); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 316 | } |
| 317 | |
John Abd-El-Malek | b165dc5 | 2018-01-18 17:12:18 | [diff] [blame] | 318 | // network::mojom::URLLoader: |
Chong Zhang | f19dde9 | 2018-05-23 04:33:59 | [diff] [blame] | 319 | void FollowRedirect(const base::Optional<net::HttpRequestHeaders>& |
| 320 | modified_request_headers) override {} |
arthursonzogni | 2e1524a7 | 2017-12-18 16:53:26 | [diff] [blame] | 321 | void ProceedWithResponse() override {} |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 322 | void SetPriority(net::RequestPriority priority, |
| 323 | int32_t intra_priority_value) override {} |
| 324 | void PauseReadingBodyFromNet() override {} |
| 325 | void ResumeReadingBodyFromNet() override {} |
| 326 | |
| 327 | private: |
| 328 | FileURLLoader() : binding_(this) {} |
| 329 | ~FileURLLoader() override = default; |
| 330 | |
| 331 | void Start(const base::FilePath& profile_path, |
John Abd-El-Malek | 1df6179 | 2018-01-12 20:40:45 | [diff] [blame] | 332 | const network::ResourceRequest& request, |
John Abd-El-Malek | b165dc5 | 2018-01-18 17:12:18 | [diff] [blame] | 333 | network::mojom::URLLoaderRequest loader, |
| 334 | network::mojom::URLLoaderClientPtrInfo client_info, |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 335 | DirectoryLoadingPolicy directory_loading_policy, |
| 336 | FileAccessPolicy file_access_policy, |
Chris Mumford | b5df8ef2 | 2017-12-20 17:47:42 | [diff] [blame] | 337 | LinkFollowingPolicy link_following_policy, |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 338 | std::unique_ptr<FileURLLoaderObserver> observer, |
| 339 | scoped_refptr<net::HttpResponseHeaders> extra_response_headers) { |
John Abd-El-Malek | 4624803 | 2018-01-17 19:11:23 | [diff] [blame] | 340 | network::ResourceResponseHead head; |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 341 | head.request_start = base::TimeTicks::Now(); |
| 342 | head.response_start = base::TimeTicks::Now(); |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 343 | head.headers = extra_response_headers; |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 344 | binding_.Bind(std::move(loader)); |
| 345 | binding_.set_connection_error_handler(base::BindOnce( |
| 346 | &FileURLLoader::OnConnectionError, base::Unretained(this))); |
| 347 | |
John Abd-El-Malek | b165dc5 | 2018-01-18 17:12:18 | [diff] [blame] | 348 | network::mojom::URLLoaderClientPtr client; |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 349 | client.Bind(std::move(client_info)); |
| 350 | |
| 351 | base::FilePath path; |
| 352 | if (!net::FileURLToFilePath(request.url, &path)) { |
Takashi Toyoshima | aa27866 | 2017-11-20 11:11:26 | [diff] [blame] | 353 | client->OnComplete(network::URLLoaderCompletionStatus(net::ERR_FAILED)); |
Chris Mumford | b5df8ef2 | 2017-12-20 17:47:42 | [diff] [blame] | 354 | if (observer) |
| 355 | observer->OnDoneReading(); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 356 | return; |
| 357 | } |
| 358 | |
| 359 | base::File::Info info; |
| 360 | if (!base::GetFileInfo(path, &info)) { |
Takashi Toyoshima | aa27866 | 2017-11-20 11:11:26 | [diff] [blame] | 361 | client->OnComplete( |
| 362 | network::URLLoaderCompletionStatus(net::ERR_FILE_NOT_FOUND)); |
Chris Mumford | b5df8ef2 | 2017-12-20 17:47:42 | [diff] [blame] | 363 | if (observer) |
| 364 | observer->OnDoneReading(); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 365 | return; |
| 366 | } |
| 367 | |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 368 | if (info.is_directory) { |
| 369 | if (directory_loading_policy == DirectoryLoadingPolicy::kFail) { |
Takashi Toyoshima | aa27866 | 2017-11-20 11:11:26 | [diff] [blame] | 370 | client->OnComplete( |
| 371 | network::URLLoaderCompletionStatus(net::ERR_FILE_NOT_FOUND)); |
Chris Mumford | b5df8ef2 | 2017-12-20 17:47:42 | [diff] [blame] | 372 | if (observer) |
| 373 | observer->OnDoneReading(); |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 374 | return; |
| 375 | } |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 376 | |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 377 | DCHECK_EQ(directory_loading_policy, |
| 378 | DirectoryLoadingPolicy::kRespondWithListing); |
| 379 | |
| 380 | GURL directory_url = request.url; |
| 381 | if (!path.EndsWithSeparator()) { |
| 382 | // If the named path is a directory with no trailing slash, redirect to |
| 383 | // the same path, but with a trailing slash. |
| 384 | std::string new_path = directory_url.path() + '/'; |
| 385 | GURL::Replacements replacements; |
| 386 | replacements.SetPathStr(new_path); |
| 387 | directory_url = directory_url.ReplaceComponents(replacements); |
| 388 | |
| 389 | net::RedirectInfo redirect_info; |
| 390 | redirect_info.new_method = "GET"; |
| 391 | redirect_info.status_code = 301; |
| 392 | redirect_info.new_url = directory_url; |
| 393 | head.encoded_data_length = 0; |
| 394 | client->OnReceiveRedirect(redirect_info, head); |
| 395 | } |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 396 | |
| 397 | // Restart the request with a directory loader. |
John Abd-El-Malek | 1df6179 | 2018-01-12 20:40:45 | [diff] [blame] | 398 | network::ResourceRequest new_request = request; |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 399 | new_request.url = directory_url; |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 400 | FileURLDirectoryLoader::CreateAndStart( |
Chris Mumford | b5df8ef2 | 2017-12-20 17:47:42 | [diff] [blame] | 401 | profile_path, new_request, binding_.Unbind(), client.PassInterface(), |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 402 | std::move(observer), std::move(extra_response_headers)); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 403 | MaybeDeleteSelf(); |
| 404 | return; |
| 405 | } |
| 406 | |
| 407 | #if defined(OS_WIN) |
| 408 | base::FilePath shortcut_target; |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 409 | if (link_following_policy == LinkFollowingPolicy::kFollow && |
| 410 | base::LowerCaseEqualsASCII(path.Extension(), ".lnk") && |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 411 | base::win::ResolveShortcut(path, &shortcut_target, nullptr)) { |
| 412 | // Follow Windows shortcuts |
| 413 | GURL new_url = net::FilePathToFileURL(shortcut_target); |
| 414 | |
| 415 | net::RedirectInfo redirect_info; |
| 416 | redirect_info.new_method = "GET"; |
| 417 | redirect_info.status_code = 301; |
| 418 | redirect_info.new_url = new_url; |
| 419 | head.encoded_data_length = 0; |
| 420 | client->OnReceiveRedirect(redirect_info, head); |
| 421 | |
| 422 | // Restart the request with the new URL. |
John Abd-El-Malek | 1df6179 | 2018-01-12 20:40:45 | [diff] [blame] | 423 | network::ResourceRequest new_request = request; |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 424 | new_request.url = redirect_info.new_url; |
| 425 | return Start(profile_path, request, binding_.Unbind(), |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 426 | client.PassInterface(), directory_loading_policy, |
Chris Mumford | b5df8ef2 | 2017-12-20 17:47:42 | [diff] [blame] | 427 | file_access_policy, link_following_policy, |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 428 | std::move(observer), std::move(extra_response_headers)); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 429 | } |
| 430 | #endif // defined(OS_WIN) |
| 431 | |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 432 | if (file_access_policy == FileAccessPolicy::kRestricted && |
| 433 | !GetContentClient()->browser()->IsFileAccessAllowed( |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 434 | path, base::MakeAbsoluteFilePath(path), profile_path)) { |
Takashi Toyoshima | aa27866 | 2017-11-20 11:11:26 | [diff] [blame] | 435 | client->OnComplete( |
| 436 | network::URLLoaderCompletionStatus(net::ERR_ACCESS_DENIED)); |
Chris Mumford | b5df8ef2 | 2017-12-20 17:47:42 | [diff] [blame] | 437 | if (observer) |
| 438 | observer->OnDoneReading(); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 439 | return; |
| 440 | } |
| 441 | |
| 442 | mojo::DataPipe pipe(kDefaultFileUrlPipeSize); |
| 443 | if (!pipe.consumer_handle.is_valid()) { |
Takashi Toyoshima | aa27866 | 2017-11-20 11:11:26 | [diff] [blame] | 444 | client->OnComplete(network::URLLoaderCompletionStatus(net::ERR_FAILED)); |
Chris Mumford | b5df8ef2 | 2017-12-20 17:47:42 | [diff] [blame] | 445 | if (observer) |
| 446 | observer->OnDoneReading(); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 447 | return; |
| 448 | } |
| 449 | |
| 450 | // Should never be possible for this to be a directory. If FileURLLoader |
| 451 | // is used to respond to a directory request, it must be because the URL |
| 452 | // path didn't have a trailing path separator. In that case we finish with |
| 453 | // a redirect above which will in turn be handled by FileURLDirectoryLoader. |
| 454 | DCHECK(!info.is_directory); |
Chris Mumford | b5df8ef2 | 2017-12-20 17:47:42 | [diff] [blame] | 455 | if (observer) |
| 456 | observer->OnStart(); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 457 | |
| 458 | base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ); |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 459 | if (!file.IsValid()) { |
Mikhail Atuchin | 9af3ff8c | 2018-04-19 21:15:10 | [diff] [blame] | 460 | if (observer) { |
| 461 | observer->OnBytesRead(nullptr, 0u, file.error_details()); |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 462 | observer->OnDoneReading(); |
Mikhail Atuchin | 9af3ff8c | 2018-04-19 21:15:10 | [diff] [blame] | 463 | } |
| 464 | net::Error net_error = net::FileErrorToNetError(file.error_details()); |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 465 | client->OnComplete(network::URLLoaderCompletionStatus(net_error)); |
| 466 | MaybeDeleteSelf(); |
| 467 | return; |
| 468 | } |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 469 | char initial_read_buffer[net::kMaxBytesToSniff]; |
| 470 | int initial_read_result = |
| 471 | file.ReadAtCurrentPos(initial_read_buffer, net::kMaxBytesToSniff); |
| 472 | if (initial_read_result < 0) { |
Chris Mumford | b5df8ef2 | 2017-12-20 17:47:42 | [diff] [blame] | 473 | base::File::Error read_error = base::File::GetLastFileError(); |
| 474 | DCHECK_NE(base::File::FILE_OK, read_error); |
| 475 | if (observer) { |
Mikhail Atuchin | 9af3ff8c | 2018-04-19 21:15:10 | [diff] [blame] | 476 | // This can happen when the file is unreadable (which can happen during |
| 477 | // corruption). We need to be sure to inform |
| 478 | // the observer that we've finished reading so that it can proceed. |
Chris Mumford | b5df8ef2 | 2017-12-20 17:47:42 | [diff] [blame] | 479 | observer->OnBytesRead(nullptr, 0u, read_error); |
| 480 | observer->OnDoneReading(); |
| 481 | } |
Mikhail Atuchin | 9af3ff8c | 2018-04-19 21:15:10 | [diff] [blame] | 482 | net::Error net_error = net::FileErrorToNetError(read_error); |
Chris Mumford | b5df8ef2 | 2017-12-20 17:47:42 | [diff] [blame] | 483 | client->OnComplete(network::URLLoaderCompletionStatus(net_error)); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 484 | return; |
Chris Mumford | b5df8ef2 | 2017-12-20 17:47:42 | [diff] [blame] | 485 | } else if (observer) { |
| 486 | observer->OnBytesRead(initial_read_buffer, initial_read_result, |
| 487 | base::File::FILE_OK); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 488 | } |
| 489 | size_t initial_read_size = static_cast<size_t>(initial_read_result); |
| 490 | |
| 491 | std::string range_header; |
| 492 | net::HttpByteRange byte_range; |
| 493 | if (request.headers.GetHeader(net::HttpRequestHeaders::kRange, |
| 494 | &range_header)) { |
| 495 | // Handle a simple Range header for a single range. |
| 496 | std::vector<net::HttpByteRange> ranges; |
| 497 | bool fail = false; |
| 498 | if (net::HttpUtil::ParseRangeHeader(range_header, &ranges) && |
| 499 | ranges.size() == 1) { |
| 500 | byte_range = ranges[0]; |
| 501 | if (!byte_range.ComputeBounds(info.size)) |
| 502 | fail = true; |
| 503 | } else { |
| 504 | fail = true; |
| 505 | } |
| 506 | |
| 507 | if (fail) { |
Takashi Toyoshima | aa27866 | 2017-11-20 11:11:26 | [diff] [blame] | 508 | client->OnComplete(network::URLLoaderCompletionStatus( |
| 509 | net::ERR_REQUEST_RANGE_NOT_SATISFIABLE)); |
Chris Mumford | b5df8ef2 | 2017-12-20 17:47:42 | [diff] [blame] | 510 | if (observer) |
| 511 | observer->OnDoneReading(); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 512 | return; |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | size_t first_byte_to_send = 0; |
| 517 | size_t total_bytes_to_send = static_cast<size_t>(info.size); |
| 518 | if (byte_range.IsValid()) { |
| 519 | first_byte_to_send = |
| 520 | static_cast<size_t>(byte_range.first_byte_position()); |
| 521 | total_bytes_to_send = |
| 522 | static_cast<size_t>(byte_range.last_byte_position()) - |
| 523 | first_byte_to_send + 1; |
| 524 | } |
| 525 | |
| 526 | head.content_length = base::saturated_cast<int64_t>(total_bytes_to_send); |
| 527 | |
| 528 | if (first_byte_to_send < initial_read_size) { |
| 529 | // Write any data we read for MIME sniffing, constraining by range where |
| 530 | // applicable. This will always fit in the pipe (see assertion near |
| 531 | // |kDefaultFileUrlPipeSize| definition). |
| 532 | uint32_t write_size = std::min( |
| 533 | static_cast<uint32_t>(initial_read_size - first_byte_to_send), |
| 534 | static_cast<uint32_t>(total_bytes_to_send)); |
| 535 | const uint32_t expected_write_size = write_size; |
| 536 | MojoResult result = pipe.producer_handle->WriteData( |
| 537 | &initial_read_buffer[first_byte_to_send], &write_size, |
| 538 | MOJO_WRITE_DATA_FLAG_NONE); |
| 539 | if (result != MOJO_RESULT_OK || write_size != expected_write_size) { |
Chris Mumford | b5df8ef2 | 2017-12-20 17:47:42 | [diff] [blame] | 540 | OnFileWritten(std::move(observer), result); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 541 | return; |
| 542 | } |
| 543 | |
| 544 | // Discount the bytes we just sent from the total range. |
| 545 | first_byte_to_send = initial_read_size; |
| 546 | total_bytes_to_send -= write_size; |
| 547 | } |
| 548 | |
| 549 | if (!net::GetMimeTypeFromFile(path, &head.mime_type)) { |
Matt Menke | fcbb1bd7 | 2018-01-31 21:53:12 | [diff] [blame] | 550 | net::SniffMimeType( |
| 551 | initial_read_buffer, initial_read_result, request.url, head.mime_type, |
| 552 | GetContentClient()->browser()->ForceSniffingFileUrlsForHtml() |
| 553 | ? net::ForceSniffFileUrlsForHtml::kEnabled |
| 554 | : net::ForceSniffFileUrlsForHtml::kDisabled, |
| 555 | &head.mime_type); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 556 | } |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 557 | if (head.headers) { |
| 558 | head.headers->AddHeader( |
| 559 | base::StringPrintf("%s: %s", net::HttpRequestHeaders::kContentType, |
| 560 | head.mime_type.c_str())); |
| 561 | } |
Marijn Kruisselbrink | 9ebd7ba | 2018-06-11 23:18:04 | [diff] [blame^] | 562 | client->OnReceiveResponse(head); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 563 | client->OnStartLoadingResponseBody(std::move(pipe.consumer_handle)); |
| 564 | client_ = std::move(client); |
| 565 | |
| 566 | if (total_bytes_to_send == 0) { |
| 567 | // There's definitely no more data, so we're already done. |
Chris Mumford | b5df8ef2 | 2017-12-20 17:47:42 | [diff] [blame] | 568 | OnFileWritten(std::move(observer), MOJO_RESULT_OK); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 569 | return; |
| 570 | } |
| 571 | |
| 572 | // In case of a range request, seek to the appropriate position before |
| 573 | // sending the remaining bytes asynchronously. Under normal conditions |
| 574 | // (i.e., no range request) this Seek is effectively a no-op. |
Chris Mumford | b5df8ef2 | 2017-12-20 17:47:42 | [diff] [blame] | 575 | int new_position = file.Seek(base::File::FROM_BEGIN, |
| 576 | static_cast<int64_t>(first_byte_to_send)); |
| 577 | if (observer) |
| 578 | observer->OnSeekComplete(new_position); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 579 | |
| 580 | data_producer_ = std::make_unique<mojo::FileDataPipeProducer>( |
Chris Mumford | b5df8ef2 | 2017-12-20 17:47:42 | [diff] [blame] | 581 | std::move(pipe.producer_handle), std::move(observer)); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 582 | data_producer_->WriteFromFile( |
| 583 | std::move(file), total_bytes_to_send, |
Chris Mumford | b5df8ef2 | 2017-12-20 17:47:42 | [diff] [blame] | 584 | base::BindOnce(&FileURLLoader::OnFileWritten, base::Unretained(this), |
| 585 | nullptr)); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | void OnConnectionError() { |
| 589 | binding_.Close(); |
| 590 | MaybeDeleteSelf(); |
| 591 | } |
| 592 | |
| 593 | void MaybeDeleteSelf() { |
| 594 | if (!binding_.is_bound() && !client_.is_bound()) |
| 595 | delete this; |
| 596 | } |
| 597 | |
Chris Mumford | b5df8ef2 | 2017-12-20 17:47:42 | [diff] [blame] | 598 | void OnFileWritten(std::unique_ptr<FileURLLoaderObserver> observer, |
| 599 | MojoResult result) { |
arthursonzogni | 3a4ca9f | 2017-12-07 17:58:34 | [diff] [blame] | 600 | // All the data has been written now. Close the data pipe. The consumer will |
| 601 | // be notified that there will be no more data to read from now. |
| 602 | data_producer_.reset(); |
Chris Mumford | b5df8ef2 | 2017-12-20 17:47:42 | [diff] [blame] | 603 | if (observer) |
| 604 | observer->OnDoneReading(); |
arthursonzogni | 3a4ca9f | 2017-12-07 17:58:34 | [diff] [blame] | 605 | |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 606 | if (result == MOJO_RESULT_OK) |
Takashi Toyoshima | aa27866 | 2017-11-20 11:11:26 | [diff] [blame] | 607 | client_->OnComplete(network::URLLoaderCompletionStatus(net::OK)); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 608 | else |
Takashi Toyoshima | aa27866 | 2017-11-20 11:11:26 | [diff] [blame] | 609 | client_->OnComplete(network::URLLoaderCompletionStatus(net::ERR_FAILED)); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 610 | client_.reset(); |
| 611 | MaybeDeleteSelf(); |
| 612 | } |
| 613 | |
| 614 | std::unique_ptr<mojo::FileDataPipeProducer> data_producer_; |
John Abd-El-Malek | b165dc5 | 2018-01-18 17:12:18 | [diff] [blame] | 615 | mojo::Binding<network::mojom::URLLoader> binding_; |
| 616 | network::mojom::URLLoaderClientPtr client_; |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 617 | |
| 618 | DISALLOW_COPY_AND_ASSIGN(FileURLLoader); |
| 619 | }; |
| 620 | |
| 621 | } // namespace |
| 622 | |
| 623 | FileURLLoaderFactory::FileURLLoaderFactory( |
| 624 | const base::FilePath& profile_path, |
| 625 | scoped_refptr<base::SequencedTaskRunner> task_runner) |
| 626 | : profile_path_(profile_path), task_runner_(std::move(task_runner)) {} |
| 627 | |
| 628 | FileURLLoaderFactory::~FileURLLoaderFactory() = default; |
| 629 | |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 630 | void FileURLLoaderFactory::CreateLoaderAndStart( |
John Abd-El-Malek | b165dc5 | 2018-01-18 17:12:18 | [diff] [blame] | 631 | network::mojom::URLLoaderRequest loader, |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 632 | int32_t routing_id, |
| 633 | int32_t request_id, |
| 634 | uint32_t options, |
John Abd-El-Malek | 1df6179 | 2018-01-12 20:40:45 | [diff] [blame] | 635 | const network::ResourceRequest& request, |
John Abd-El-Malek | b165dc5 | 2018-01-18 17:12:18 | [diff] [blame] | 636 | network::mojom::URLLoaderClientPtr client, |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 637 | const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) { |
| 638 | base::FilePath file_path; |
| 639 | const bool is_file = net::FileURLToFilePath(request.url, &file_path); |
| 640 | if (is_file && file_path.EndsWithSeparator() && file_path.IsAbsolute()) { |
| 641 | task_runner_->PostTask( |
| 642 | FROM_HERE, |
| 643 | base::BindOnce(&FileURLDirectoryLoader::CreateAndStart, profile_path_, |
Chris Mumford | b5df8ef2 | 2017-12-20 17:47:42 | [diff] [blame] | 644 | request, std::move(loader), client.PassInterface(), |
Chris Mumford | 8f81266 | 2018-02-22 00:27:57 | [diff] [blame] | 645 | std::unique_ptr<FileURLLoaderObserver>(), nullptr)); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 646 | } else { |
| 647 | task_runner_->PostTask( |
| 648 | FROM_HERE, |
| 649 | base::BindOnce(&FileURLLoader::CreateAndStart, profile_path_, request, |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 650 | std::move(loader), client.PassInterface(), |
| 651 | DirectoryLoadingPolicy::kRespondWithListing, |
| 652 | FileAccessPolicy::kRestricted, |
Chris Mumford | b5df8ef2 | 2017-12-20 17:47:42 | [diff] [blame] | 653 | LinkFollowingPolicy::kFollow, |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 654 | std::unique_ptr<FileURLLoaderObserver>(), |
| 655 | nullptr /* extra_response_headers */)); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 656 | } |
| 657 | } |
| 658 | |
John Abd-El-Malek | b165dc5 | 2018-01-18 17:12:18 | [diff] [blame] | 659 | void FileURLLoaderFactory::Clone( |
| 660 | network::mojom::URLLoaderFactoryRequest loader) { |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 661 | bindings_.AddBinding(this, std::move(loader)); |
| 662 | } |
| 663 | |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 664 | void CreateFileURLLoader( |
| 665 | const network::ResourceRequest& request, |
| 666 | network::mojom::URLLoaderRequest loader, |
| 667 | network::mojom::URLLoaderClientPtr client, |
| 668 | std::unique_ptr<FileURLLoaderObserver> observer, |
| 669 | scoped_refptr<net::HttpResponseHeaders> extra_response_headers) { |
Ken Rockot | 6414c4d9 | 2017-11-08 19:58:32 | [diff] [blame] | 670 | auto task_runner = base::CreateSequencedTaskRunnerWithTraits( |
| 671 | {base::MayBlock(), base::TaskPriority::BACKGROUND, |
| 672 | base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}); |
| 673 | task_runner->PostTask( |
| 674 | FROM_HERE, |
| 675 | base::BindOnce(&FileURLLoader::CreateAndStart, base::FilePath(), request, |
| 676 | std::move(loader), client.PassInterface(), |
| 677 | DirectoryLoadingPolicy::kFail, |
| 678 | FileAccessPolicy::kUnrestricted, |
Ken Rockot | a0dfaca1 | 2018-02-15 07:26:25 | [diff] [blame] | 679 | LinkFollowingPolicy::kDoNotFollow, std::move(observer), |
| 680 | std::move(extra_response_headers))); |
Ken Rockot | 314714c | 2017-11-05 23:36:24 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | } // namespace content |