Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "native_client/src/trusted/plugin/file_downloader.h" | 5 #include "native_client/src/trusted/plugin/file_downloader.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "native_client/src/include/portability_io.h" | 10 #include "native_client/src/include/portability_io.h" |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 file_io_trusted_interface_ = static_cast<const PPB_FileIOTrusted*>( | 36 file_io_trusted_interface_ = static_cast<const PPB_FileIOTrusted*>( |
| 37 pp::Module::Get()->GetBrowserInterface(PPB_FILEIOTRUSTED_INTERFACE)); | 37 pp::Module::Get()->GetBrowserInterface(PPB_FILEIOTRUSTED_INTERFACE)); |
| 38 url_loader_trusted_interface_ = static_cast<const PPB_URLLoaderTrusted*>( | 38 url_loader_trusted_interface_ = static_cast<const PPB_URLLoaderTrusted*>( |
| 39 pp::Module::Get()->GetBrowserInterface(PPB_URLLOADERTRUSTED_INTERFACE)); | 39 pp::Module::Get()->GetBrowserInterface(PPB_URLLOADERTRUSTED_INTERFACE)); |
| 40 } | 40 } |
| 41 | 41 |
| 42 | 42 |
| 43 bool FileDownloader::Open( | 43 bool FileDownloader::Open( |
| 44 const nacl::string& url, | 44 const nacl::string& url, |
| 45 DownloadFlags flags, | 45 DownloadFlags flags, |
| 46 bool allow_extension_url, | |
| 46 const pp::CompletionCallback& callback, | 47 const pp::CompletionCallback& callback, |
| 47 PP_URLLoaderTrusted_StatusCallback progress_callback) { | 48 PP_URLLoaderTrusted_StatusCallback progress_callback) { |
| 48 PLUGIN_PRINTF(("FileDownloader::Open (url=%s)\n", url.c_str())); | 49 PLUGIN_PRINTF(("FileDownloader::Open (url=%s, allow_extension_url=%d)\n", |
| 50 url.c_str(), allow_extension_url)); | |
| 49 if (callback.pp_completion_callback().func == NULL || | 51 if (callback.pp_completion_callback().func == NULL || |
| 50 instance_ == NULL || | 52 instance_ == NULL || |
| 51 file_io_trusted_interface_ == NULL) | 53 file_io_trusted_interface_ == NULL) |
| 52 return false; | 54 return false; |
| 53 | 55 |
| 54 CHECK(instance_ != NULL); | 56 CHECK(instance_ != NULL); |
| 55 open_time_ = NaClGetTimeOfDayMicroseconds(); | 57 open_time_ = NaClGetTimeOfDayMicroseconds(); |
| 56 url_to_open_ = url; | 58 url_to_open_ = url; |
| 57 url_ = url; | 59 url_ = url; |
| 58 file_open_notify_callback_ = callback; | 60 file_open_notify_callback_ = callback; |
| 59 flags_ = flags; | 61 flags_ = flags; |
| 60 buffer_.clear(); | 62 buffer_.clear(); |
| 61 pp::URLRequestInfo url_request(instance_); | 63 pp::URLRequestInfo url_request(instance_); |
| 62 | 64 |
| 63 do { | 65 do { |
| 64 // Reset the url loader and file reader. | 66 // Reset the url loader and file reader. |
| 65 // Note that we have the only reference to the underlying objects, so | 67 // Note that we have the only reference to the underlying objects, so |
| 66 // this will implicitly close any pending IO and destroy them. | 68 // this will implicitly close any pending IO and destroy them. |
| 67 url_loader_ = pp::URLLoader(instance_); | 69 url_loader_ = pp::URLLoader(instance_); |
| 68 url_scheme_ = instance_->GetUrlScheme(url); | 70 url_scheme_ = instance_->GetUrlScheme(url); |
| 69 bool grant_universal_access = false; | 71 bool grant_universal_access = false; |
| 70 if (url_scheme_ == SCHEME_CHROME_EXTENSION) { | 72 if (url_scheme_ == SCHEME_CHROME_EXTENSION) { |
| 71 if (instance_->IsForeignMIMEType()) { | 73 if (allow_extension_url) { |
| 72 // This NEXE is being used as a content type handler rather than | 74 // This NEXE has been granted rights to access URLs in the chrome |
| 73 // directly by an HTML document. In that case, the NEXE runs in the | 75 // extension scheme. |
| 74 // security context of the content it is rendering and the NEXE itself | |
| 75 // appears to be a cross-origin resource stored in a Chrome extension. | |
| 76 // We request universal access during this load so that we can read the | |
| 77 // NEXE. | |
| 78 grant_universal_access = true; | 76 grant_universal_access = true; |
| 79 } | 77 } |
| 80 } else if (url_scheme_ == SCHEME_DATA) { | 78 } else if (url_scheme_ == SCHEME_DATA) { |
| 81 // TODO(elijahtaylor) Remove this when data URIs can be read without | 79 // TODO(elijahtaylor) Remove this when data URIs can be read without |
| 82 // universal access. | 80 // universal access. |
| 83 if (streaming_to_buffer()) { | 81 if (streaming_to_buffer()) { |
| 84 grant_universal_access = true; | 82 grant_universal_access = true; |
| 85 } else { | 83 } else { |
| 86 // Open is to invoke a callback on success or failure. Schedule | 84 // Open is to invoke a callback on success or failure. Schedule |
| 87 // it asynchronously to follow PPAPI's convention and avoid reentrancy. | 85 // it asynchronously to follow PPAPI's convention and avoid reentrancy. |
| 88 pp::Core* core = pp::Module::Get()->core(); | 86 pp::Core* core = pp::Module::Get()->core(); |
| 89 core->CallOnMainThread(0, callback, PP_ERROR_NOACCESS); | 87 core->CallOnMainThread(0, callback, PP_ERROR_NOACCESS); |
| 90 PLUGIN_PRINTF(("FileDownloader::Open (pp_error=PP_ERROR_NOACCESS)\n")); | 88 PLUGIN_PRINTF(("FileDownloader::Open (pp_error=PP_ERROR_NOACCESS)\n")); |
| 91 return true; | 89 return true; |
| 92 } | 90 } |
| 93 } | 91 } |
| 94 | 92 |
| 95 if (url_loader_trusted_interface_ != NULL) { | 93 if (url_loader_trusted_interface_ != NULL) { |
| 96 if (grant_universal_access) { | 94 if (grant_universal_access) { |
| 97 url_loader_trusted_interface_->GrantUniversalAccess( | 95 url_loader_trusted_interface_->GrantUniversalAccess( |
|
jvoung - send to chromium...
2011/12/20 18:34:44
Question: can we use pp::URLRequestInfo::SetAllowC
sehr (please use chromium)
2011/12/21 00:52:38
As we discussed, we would like to make these web a
| |
| 98 url_loader_.pp_resource()); | 96 url_loader_.pp_resource()); |
| 99 } | 97 } |
| 100 if (progress_callback != NULL) { | 98 if (progress_callback != NULL) { |
| 101 url_request.SetRecordDownloadProgress(true); | 99 url_request.SetRecordDownloadProgress(true); |
| 102 url_loader_trusted_interface_->RegisterStatusCallback( | 100 url_loader_trusted_interface_->RegisterStatusCallback( |
| 103 url_loader_.pp_resource(), progress_callback); | 101 url_loader_.pp_resource(), progress_callback); |
| 104 } | 102 } |
| 105 } | 103 } |
| 106 | 104 |
| 107 // Prepare the url request. | 105 // Prepare the url request. |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 | 333 |
| 336 bool FileDownloader::streaming_to_file() const { | 334 bool FileDownloader::streaming_to_file() const { |
| 337 return (flags_ & DOWNLOAD_TO_BUFFER) == 0; | 335 return (flags_ & DOWNLOAD_TO_BUFFER) == 0; |
| 338 } | 336 } |
| 339 | 337 |
| 340 bool FileDownloader::streaming_to_buffer() const { | 338 bool FileDownloader::streaming_to_buffer() const { |
| 341 return (flags_ & DOWNLOAD_TO_BUFFER) == 1; | 339 return (flags_ & DOWNLOAD_TO_BUFFER) == 1; |
| 342 } | 340 } |
| 343 | 341 |
| 344 } // namespace plugin | 342 } // namespace plugin |
| OLD | NEW |