OLD | NEW |
1 // Copyright (c) 2011 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 "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" |
11 #include "native_client/src/shared/platform/nacl_check.h" | 11 #include "native_client/src/shared/platform/nacl_check.h" |
(...skipping 24 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, | |
47 const pp::CompletionCallback& callback, | 46 const pp::CompletionCallback& callback, |
48 PP_URLLoaderTrusted_StatusCallback progress_callback) { | 47 PP_URLLoaderTrusted_StatusCallback progress_callback) { |
49 PLUGIN_PRINTF(("FileDownloader::Open (url=%s, allow_extension_url=%d)\n", | 48 PLUGIN_PRINTF(("FileDownloader::Open (url=%s)\n", url.c_str())); |
50 url.c_str(), allow_extension_url)); | |
51 if (callback.pp_completion_callback().func == NULL || | 49 if (callback.pp_completion_callback().func == NULL || |
52 instance_ == NULL || | 50 instance_ == NULL || |
53 file_io_trusted_interface_ == NULL) | 51 file_io_trusted_interface_ == NULL) |
54 return false; | 52 return false; |
55 | 53 |
56 CHECK(instance_ != NULL); | 54 CHECK(instance_ != NULL); |
57 open_time_ = NaClGetTimeOfDayMicroseconds(); | 55 open_time_ = NaClGetTimeOfDayMicroseconds(); |
58 url_to_open_ = url; | 56 url_to_open_ = url; |
59 url_ = url; | 57 url_ = url; |
60 file_open_notify_callback_ = callback; | 58 file_open_notify_callback_ = callback; |
61 flags_ = flags; | 59 flags_ = flags; |
62 buffer_.clear(); | 60 buffer_.clear(); |
63 pp::URLRequestInfo url_request(instance_); | 61 pp::URLRequestInfo url_request(instance_); |
64 | 62 |
65 do { | 63 do { |
66 // Reset the url loader and file reader. | 64 // Reset the url loader and file reader. |
67 // Note that we have the only reference to the underlying objects, so | 65 // Note that we have the only reference to the underlying objects, so |
68 // this will implicitly close any pending IO and destroy them. | 66 // this will implicitly close any pending IO and destroy them. |
69 url_loader_ = pp::URLLoader(instance_); | 67 url_loader_ = pp::URLLoader(instance_); |
70 url_scheme_ = instance_->GetUrlScheme(url); | 68 url_scheme_ = instance_->GetUrlScheme(url); |
71 bool grant_universal_access = false; | 69 bool grant_universal_access = false; |
72 if (url_scheme_ == SCHEME_CHROME_EXTENSION) { | 70 if (url_scheme_ == SCHEME_CHROME_EXTENSION) { |
73 if (allow_extension_url) { | 71 // Use CORS to access URLs in the chrome extension scheme. If the files |
74 // This NEXE has been granted rights to access URLs in the chrome | 72 // are truly restricted, then they should not be listed as a |
75 // extension scheme. | 73 // web_accessible_resource in the extension manifest. |
76 grant_universal_access = true; | 74 url_request.SetAllowCrossOriginRequests(true); |
77 } | |
78 } else if (url_scheme_ == SCHEME_DATA) { | 75 } else if (url_scheme_ == SCHEME_DATA) { |
79 // TODO(elijahtaylor) Remove this when data URIs can be read without | 76 // TODO(elijahtaylor) Remove this when data URIs can be read without |
80 // universal access. | 77 // universal access. |
| 78 // https://bugs.webkit.org/show_bug.cgi?id=17352 |
81 if (streaming_to_buffer()) { | 79 if (streaming_to_buffer()) { |
82 grant_universal_access = true; | 80 grant_universal_access = true; |
83 } else { | 81 } else { |
84 // Open is to invoke a callback on success or failure. Schedule | 82 // Open is to invoke a callback on success or failure. Schedule |
85 // it asynchronously to follow PPAPI's convention and avoid reentrancy. | 83 // it asynchronously to follow PPAPI's convention and avoid reentrancy. |
86 pp::Core* core = pp::Module::Get()->core(); | 84 pp::Core* core = pp::Module::Get()->core(); |
87 core->CallOnMainThread(0, callback, PP_ERROR_NOACCESS); | 85 core->CallOnMainThread(0, callback, PP_ERROR_NOACCESS); |
88 PLUGIN_PRINTF(("FileDownloader::Open (pp_error=PP_ERROR_NOACCESS)\n")); | 86 PLUGIN_PRINTF(("FileDownloader::Open (pp_error=PP_ERROR_NOACCESS)\n")); |
89 return true; | 87 return true; |
90 } | 88 } |
91 } | 89 } |
92 | 90 |
93 if (url_loader_trusted_interface_ != NULL) { | 91 if (url_loader_trusted_interface_ != NULL) { |
94 if (grant_universal_access) { | 92 if (grant_universal_access) { |
95 // TODO(sehr,jvoung): this should use | 93 // TODO(sehr,jvoung): See if we can remove this -- currently |
96 // pp::URLRequestInfo::SetAllowCrossOriginRequests() when | 94 // only used for data URIs. |
97 // support for web accessible resources is added to extensions. | |
98 url_loader_trusted_interface_->GrantUniversalAccess( | 95 url_loader_trusted_interface_->GrantUniversalAccess( |
99 url_loader_.pp_resource()); | 96 url_loader_.pp_resource()); |
100 } | 97 } |
101 if (progress_callback != NULL) { | 98 if (progress_callback != NULL) { |
102 url_request.SetRecordDownloadProgress(true); | 99 url_request.SetRecordDownloadProgress(true); |
103 url_loader_trusted_interface_->RegisterStatusCallback( | 100 url_loader_trusted_interface_->RegisterStatusCallback( |
104 url_loader_.pp_resource(), progress_callback); | 101 url_loader_.pp_resource(), progress_callback); |
105 } | 102 } |
106 } | 103 } |
107 | 104 |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 | 333 |
337 bool FileDownloader::streaming_to_file() const { | 334 bool FileDownloader::streaming_to_file() const { |
338 return (flags_ & DOWNLOAD_TO_BUFFER) == 0; | 335 return (flags_ & DOWNLOAD_TO_BUFFER) == 0; |
339 } | 336 } |
340 | 337 |
341 bool FileDownloader::streaming_to_buffer() const { | 338 bool FileDownloader::streaming_to_buffer() const { |
342 return (flags_ & DOWNLOAD_TO_BUFFER) == 1; | 339 return (flags_ & DOWNLOAD_TO_BUFFER) == 1; |
343 } | 340 } |
344 | 341 |
345 } // namespace plugin | 342 } // namespace plugin |
OLD | NEW |