| 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 "ppapi/native_client/src/trusted/plugin/file_downloader.h" | 5 #include "ppapi/native_client/src/trusted/plugin/file_downloader.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 PP_URLLoaderTrusted_StatusCallback progress_callback) { | 121 PP_URLLoaderTrusted_StatusCallback progress_callback) { |
| 122 PLUGIN_PRINTF(("FileDownloader::Open (url=%s)\n", url.c_str())); | 122 PLUGIN_PRINTF(("FileDownloader::Open (url=%s)\n", url.c_str())); |
| 123 if (callback.pp_completion_callback().func == NULL || | 123 if (callback.pp_completion_callback().func == NULL || |
| 124 instance_ == NULL || | 124 instance_ == NULL || |
| 125 file_io_private_interface_ == NULL) | 125 file_io_private_interface_ == NULL) |
| 126 return false; | 126 return false; |
| 127 | 127 |
| 128 CHECK(instance_ != NULL); | 128 CHECK(instance_ != NULL); |
| 129 open_time_ = NaClGetTimeOfDayMicroseconds(); | 129 open_time_ = NaClGetTimeOfDayMicroseconds(); |
| 130 status_code_ = -1; | 130 status_code_ = -1; |
| 131 url_to_open_ = url; | |
| 132 url_ = url; | 131 url_ = url; |
| 133 file_open_notify_callback_ = callback; | 132 file_open_notify_callback_ = callback; |
| 134 mode_ = mode; | 133 mode_ = mode; |
| 135 buffer_.clear(); | 134 buffer_.clear(); |
| 136 file_info_.FreeResources(); | 135 file_info_.FreeResources(); |
| 137 pp::URLRequestInfo url_request(instance_); | 136 pp::URLRequestInfo url_request(instance_); |
| 138 | 137 |
| 139 // Allow CORS. | 138 // Allow CORS. |
| 140 // Note that "SetAllowCrossOriginRequests" (currently) has the side effect of | 139 // Note that "SetAllowCrossOriginRequests" (currently) has the side effect of |
| 141 // preventing credentials from being sent on same-origin requests. We | 140 // preventing credentials from being sent on same-origin requests. We |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 | 208 |
| 210 void FileDownloader::OpenFast(const nacl::string& url, | 209 void FileDownloader::OpenFast(const nacl::string& url, |
| 211 PP_FileHandle file_handle, | 210 PP_FileHandle file_handle, |
| 212 uint64_t file_token_lo, uint64_t file_token_hi) { | 211 uint64_t file_token_lo, uint64_t file_token_hi) { |
| 213 PLUGIN_PRINTF(("FileDownloader::OpenFast (url=%s)\n", url.c_str())); | 212 PLUGIN_PRINTF(("FileDownloader::OpenFast (url=%s)\n", url.c_str())); |
| 214 | 213 |
| 215 file_info_.FreeResources(); | 214 file_info_.FreeResources(); |
| 216 CHECK(instance_ != NULL); | 215 CHECK(instance_ != NULL); |
| 217 open_time_ = NaClGetTimeOfDayMicroseconds(); | 216 open_time_ = NaClGetTimeOfDayMicroseconds(); |
| 218 status_code_ = NACL_HTTP_STATUS_OK; | 217 status_code_ = NACL_HTTP_STATUS_OK; |
| 219 url_to_open_ = url; | |
| 220 url_ = url; | 218 url_ = url; |
| 221 mode_ = DOWNLOAD_NONE; | 219 mode_ = DOWNLOAD_NONE; |
| 222 if (not_streaming() && file_handle != PP_kInvalidFileHandle) { | 220 if (not_streaming() && file_handle != PP_kInvalidFileHandle) { |
| 223 NaClFileInfo tmp_info = NoFileInfo(); | 221 NaClFileInfo tmp_info = NoFileInfo(); |
| 224 tmp_info.desc = ConvertFileDescriptor(file_handle); | 222 tmp_info.desc = ConvertFileDescriptor(file_handle); |
| 225 tmp_info.file_token.lo = file_token_lo; | 223 tmp_info.file_token.lo = file_token_lo; |
| 226 tmp_info.file_token.hi = file_token_hi; | 224 tmp_info.file_token.hi = file_token_hi; |
| 227 file_info_.TakeOwnership(&tmp_info); | 225 file_info_.TakeOwnership(&tmp_info); |
| 228 } | 226 } |
| 229 } | 227 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 257 "FileDownloader::InitialResponseIsValid (url_response_=NULL)\n")); | 255 "FileDownloader::InitialResponseIsValid (url_response_=NULL)\n")); |
| 258 return false; | 256 return false; |
| 259 } | 257 } |
| 260 | 258 |
| 261 pp::Var full_url = url_response_.GetURL(); | 259 pp::Var full_url = url_response_.GetURL(); |
| 262 if (!full_url.is_string()) { | 260 if (!full_url.is_string()) { |
| 263 PLUGIN_PRINTF(( | 261 PLUGIN_PRINTF(( |
| 264 "FileDownloader::InitialResponseIsValid (url is not a string)\n")); | 262 "FileDownloader::InitialResponseIsValid (url is not a string)\n")); |
| 265 return false; | 263 return false; |
| 266 } | 264 } |
| 267 url_ = full_url.AsString(); | 265 full_url_ = full_url.AsString(); |
| 268 | 266 |
| 269 // Note that URLs in the data-URI scheme produce different error | 267 // Note that URLs in the data-URI scheme produce different error |
| 270 // codes than other schemes. This is because data-URI are really a | 268 // codes than other schemes. This is because data-URI are really a |
| 271 // special kind of file scheme, and therefore do not produce HTTP | 269 // special kind of file scheme, and therefore do not produce HTTP |
| 272 // status codes. | 270 // status codes. |
| 273 bool status_ok = false; | 271 bool status_ok = false; |
| 274 status_code_ = url_response_.GetStatusCode(); | 272 status_code_ = url_response_.GetStatusCode(); |
| 275 switch (url_scheme_) { | 273 switch (url_scheme_) { |
| 276 case SCHEME_CHROME_EXTENSION: | 274 case SCHEME_CHROME_EXTENSION: |
| 277 PLUGIN_PRINTF(("FileDownloader::InitialResponseIsValid (chrome-extension " | 275 PLUGIN_PRINTF(("FileDownloader::InitialResponseIsValid (chrome-extension " |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 url_response_.GetStatusCode() == kExtensionUrlRequestStatusOk); | 362 url_response_.GetStatusCode() == kExtensionUrlRequestStatusOk); |
| 365 | 363 |
| 366 // Record the full url from the response. | 364 // Record the full url from the response. |
| 367 pp::Var full_url = url_response_.GetURL(); | 365 pp::Var full_url = url_response_.GetURL(); |
| 368 PLUGIN_PRINTF(("FileDownloader::URLLoadFinishNotify (full_url=%s)\n", | 366 PLUGIN_PRINTF(("FileDownloader::URLLoadFinishNotify (full_url=%s)\n", |
| 369 full_url.DebugString().c_str())); | 367 full_url.DebugString().c_str())); |
| 370 if (!full_url.is_string()) { | 368 if (!full_url.is_string()) { |
| 371 stream_finish_callback_.RunAndClear(PP_ERROR_FAILED); | 369 stream_finish_callback_.RunAndClear(PP_ERROR_FAILED); |
| 372 return; | 370 return; |
| 373 } | 371 } |
| 374 url_ = full_url.AsString(); | 372 full_url_ = full_url.AsString(); |
| 375 | 373 |
| 376 // The file is now fully downloaded. | 374 // The file is now fully downloaded. |
| 377 pp::FileRef file(url_response_.GetBodyAsFileRef()); | 375 pp::FileRef file(url_response_.GetBodyAsFileRef()); |
| 378 if (file.is_null()) { | 376 if (file.is_null()) { |
| 379 PLUGIN_PRINTF(("FileDownloader::URLLoadFinishNotify (file=NULL)\n")); | 377 PLUGIN_PRINTF(("FileDownloader::URLLoadFinishNotify (file=NULL)\n")); |
| 380 stream_finish_callback_.RunAndClear(PP_ERROR_FAILED); | 378 stream_finish_callback_.RunAndClear(PP_ERROR_FAILED); |
| 381 return; | 379 return; |
| 382 } | 380 } |
| 383 | 381 |
| 384 // Open the file providing an optional callback. | 382 // Open the file providing an optional callback. |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 if (pp_error == PP_OK) { | 488 if (pp_error == PP_OK) { |
| 491 NaClFileInfo tmp_info = NoFileInfo(); | 489 NaClFileInfo tmp_info = NoFileInfo(); |
| 492 tmp_info.desc = ConvertFileDescriptor(handle); | 490 tmp_info.desc = ConvertFileDescriptor(handle); |
| 493 file_info_.TakeOwnership(&tmp_info); | 491 file_info_.TakeOwnership(&tmp_info); |
| 494 } | 492 } |
| 495 | 493 |
| 496 stream_finish_callback_.RunAndClear(pp_error); | 494 stream_finish_callback_.RunAndClear(pp_error); |
| 497 } | 495 } |
| 498 | 496 |
| 499 } // namespace plugin | 497 } // namespace plugin |
| OLD | NEW |