Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: ppapi/native_client/src/trusted/plugin/file_downloader.cc

Issue 8974020: Change pnacl to read all resources from the extension. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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) {
95 // TODO(sehr,jvoung): this should use
96 // pp::URLRequestInfo::SetAllowCrossOriginRequests() when
97 // support for web accessible resources is added to extensions.
97 url_loader_trusted_interface_->GrantUniversalAccess( 98 url_loader_trusted_interface_->GrantUniversalAccess(
98 url_loader_.pp_resource()); 99 url_loader_.pp_resource());
99 } 100 }
100 if (progress_callback != NULL) { 101 if (progress_callback != NULL) {
101 url_request.SetRecordDownloadProgress(true); 102 url_request.SetRecordDownloadProgress(true);
102 url_loader_trusted_interface_->RegisterStatusCallback( 103 url_loader_trusted_interface_->RegisterStatusCallback(
103 url_loader_.pp_resource(), progress_callback); 104 url_loader_.pp_resource(), progress_callback);
104 } 105 }
105 } 106 }
106 107
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 336
336 bool FileDownloader::streaming_to_file() const { 337 bool FileDownloader::streaming_to_file() const {
337 return (flags_ & DOWNLOAD_TO_BUFFER) == 0; 338 return (flags_ & DOWNLOAD_TO_BUFFER) == 0;
338 } 339 }
339 340
340 bool FileDownloader::streaming_to_buffer() const { 341 bool FileDownloader::streaming_to_buffer() const {
341 return (flags_ & DOWNLOAD_TO_BUFFER) == 1; 342 return (flags_ & DOWNLOAD_TO_BUFFER) == 1;
342 } 343 }
343 344
344 } // namespace plugin 345 } // namespace plugin
OLDNEW
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/file_downloader.h ('k') | ppapi/native_client/src/trusted/plugin/json_manifest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698