diff options
Diffstat (limited to 'ppapi')
-rw-r--r-- | ppapi/api/private/ppb_nacl_private.idl | 20 | ||||
-rw-r--r-- | ppapi/c/private/ppb_nacl_private.h | 20 | ||||
-rw-r--r-- | ppapi/native_client/src/trusted/plugin/plugin.cc | 111 | ||||
-rw-r--r-- | ppapi/native_client/src/trusted/plugin/plugin.h | 15 | ||||
-rw-r--r-- | ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c | 14 |
5 files changed, 73 insertions, 107 deletions
diff --git a/ppapi/api/private/ppb_nacl_private.idl b/ppapi/api/private/ppb_nacl_private.idl index ce4719f..aefc6dc 100644 --- a/ppapi/api/private/ppb_nacl_private.idl +++ b/ppapi/api/private/ppb_nacl_private.idl @@ -301,19 +301,6 @@ interface PPB_NaCl_Private { [in] uint64_t loaded_bytes, [in] uint64_t total_bytes); - /* Report that the attempt to open the nexe has finished. Opening the file - * may have failed, as indicated by a pp_error value that is not PP_OK or an - * fd of -1. Failure to stat the file to determine its length results in - * nexe_bytes_read being -1. - */ - void NexeFileDidOpen([in] PP_Instance instance, - [in] int32_t pp_error, - [in] int32_t fd, - [in] int32_t http_status, - [in] int64_t nexe_bytes_read, - [in] str_t url, - [in] int64_t time_since_open); - /* Report that the nexe loaded successfully. */ void ReportLoadSuccess([in] PP_Instance instance, [in] str_t url, @@ -440,4 +427,11 @@ interface PPB_NaCl_Private { */ void PostMessageToJavaScript([in] PP_Instance instance, [in] str_t message); + + /* Downloads the .nexe file at the given URL to a file, and sets |handle| + * to a handle to a file containing its contents. */ + void DownloadNexe([in] PP_Instance instance, + [in] str_t url, + [out] PP_FileHandle handle, + [in] PP_CompletionCallback callback); }; diff --git a/ppapi/c/private/ppb_nacl_private.h b/ppapi/c/private/ppb_nacl_private.h index 34c125f..67df0ff 100644 --- a/ppapi/c/private/ppb_nacl_private.h +++ b/ppapi/c/private/ppb_nacl_private.h @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -/* From private/ppb_nacl_private.idl modified Wed May 14 11:49:42 2014. */ +/* From private/ppb_nacl_private.idl modified Fri May 16 11:43:13 2014. */ #ifndef PPAPI_C_PRIVATE_PPB_NACL_PRIVATE_H_ #define PPAPI_C_PRIVATE_PPB_NACL_PRIVATE_H_ @@ -326,18 +326,6 @@ struct PPB_NaCl_Private_1_0 { PP_Bool length_is_computable, uint64_t loaded_bytes, uint64_t total_bytes); - /* Report that the attempt to open the nexe has finished. Opening the file - * may have failed, as indicated by a pp_error value that is not PP_OK or an - * fd of -1. Failure to stat the file to determine its length results in - * nexe_bytes_read being -1. - */ - void (*NexeFileDidOpen)(PP_Instance instance, - int32_t pp_error, - int32_t fd, - int32_t http_status, - int64_t nexe_bytes_read, - const char* url, - int64_t time_since_open); /* Report that the nexe loaded successfully. */ void (*ReportLoadSuccess)(PP_Instance instance, const char* url, @@ -430,6 +418,12 @@ struct PPB_NaCl_Private_1_0 { * This method may be called on any thread. */ void (*PostMessageToJavaScript)(PP_Instance instance, const char* message); + /* Downloads the .nexe file at the given URL to a file, and sets |handle| + * to a handle to a file containing its contents. */ + void (*DownloadNexe)(PP_Instance instance, + const char* url, + PP_FileHandle* handle, + struct PP_CompletionCallback callback); }; typedef struct PPB_NaCl_Private_1_0 PPB_NaCl_Private; diff --git a/ppapi/native_client/src/trusted/plugin/plugin.cc b/ppapi/native_client/src/trusted/plugin/plugin.cc index 226cb59..b516879 100644 --- a/ppapi/native_client/src/trusted/plugin/plugin.cc +++ b/ppapi/native_client/src/trusted/plugin/plugin.cc @@ -53,6 +53,27 @@ const int64_t kSizeKBMin = 1; const int64_t kSizeKBMax = 512*1024; // very large .nexe const uint32_t kSizeKBBuckets = 100; +// Converts a PP_FileHandle to a POSIX file descriptor. +int32_t ConvertFileDescriptor(PP_FileHandle handle) { + PLUGIN_PRINTF(("ConvertFileDescriptor, handle=%d\n", handle)); +#if NACL_WINDOWS + int32_t file_desc = NACL_NO_FILE_DESC; + // On Windows, valid handles are 32 bit unsigned integers so this is safe. + file_desc = reinterpret_cast<intptr_t>(handle); + // Convert the Windows HANDLE from Pepper to a POSIX file descriptor. + int32_t posix_desc = _open_osfhandle(file_desc, _O_RDWR | _O_BINARY); + if (posix_desc == -1) { + // Close the Windows HANDLE if it can't be converted. + CloseHandle(reinterpret_cast<HANDLE>(file_desc)); + return -1; + } + return posix_desc; +#else + return handle; +#endif +} + + } // namespace void Plugin::ShutDownSubprocesses() { @@ -338,14 +359,13 @@ Plugin::Plugin(PP_Instance pp_instance) uses_nonsfi_mode_(false), wrapper_factory_(NULL), time_of_last_progress_event_(0), - nexe_open_time_(-1), manifest_id_(-1), + nexe_handle_(PP_kInvalidFileHandle), nacl_interface_(NULL), uma_interface_(this) { PLUGIN_PRINTF(("Plugin::Plugin (this=%p, pp_instance=%" NACL_PRId32 ")\n", static_cast<void*>(this), pp_instance)); callback_factory_.Initialize(this); - nexe_downloader_.Initialize(this); nacl_interface_ = GetNaClInterface(); CHECK(nacl_interface_ != NULL); @@ -423,37 +443,14 @@ bool Plugin::HandleDocumentLoad(const pp::URLLoader& url_loader) { } void Plugin::NexeFileDidOpen(int32_t pp_error) { - NaClFileInfo tmp_info(nexe_downloader_.GetFileInfo()); - NaClFileInfoAutoCloser info(&tmp_info); - - int64_t nexe_bytes_read = -1; - if (pp_error == PP_OK && info.get_desc() != NACL_NO_FILE_DESC) { - struct stat stat_buf; - if (0 == fstat(info.get_desc(), &stat_buf)) - nexe_bytes_read = stat_buf.st_size; - } - - int64_t now = NaClGetTimeOfDayMicroseconds(); - int64_t download_time; - if (now < nexe_open_time_) - download_time = 0; - else - download_time = now - nexe_open_time_; - - nacl_interface_->NexeFileDidOpen( - pp_instance(), - pp_error, - info.get_desc(), - nexe_downloader_.status_code(), - nexe_bytes_read, - nexe_downloader_.url().c_str(), - download_time / 1000); - - if (nexe_bytes_read == -1) + if (pp_error != PP_OK) return; + int32_t desc = ConvertFileDescriptor(nexe_handle_); + nexe_handle_ = PP_kInvalidFileHandle; // Clear out nexe handle. + nacl::scoped_ptr<nacl::DescWrapper> - wrapper(wrapper_factory()->MakeFileDesc(info.Release().desc, O_RDONLY)); + wrapper(wrapper_factory()->MakeFileDesc(desc, O_RDONLY)); NaClLog(4, "NexeFileDidOpen: invoking LoadNaClModule\n"); LoadNaClModule( wrapper.release(), @@ -556,36 +553,28 @@ void Plugin::ProcessNaClManifest(const nacl::string& manifest_json) { PP_Bool uses_nonsfi_mode; if (nacl_interface_->GetManifestProgramURL(pp_instance(), manifest_id_, &pp_program_url, &pnacl_options, &uses_nonsfi_mode)) { - std::string program_url = pp::Var(pp::PASS_REF, pp_program_url).AsString(); + program_url_ = pp::Var(pp::PASS_REF, pp_program_url).AsString(); // TODO(teravest): Make ProcessNaClManifest take responsibility for more of // this function. - nacl_interface_->ProcessNaClManifest(pp_instance(), program_url.c_str()); + nacl_interface_->ProcessNaClManifest(pp_instance(), program_url_.c_str()); uses_nonsfi_mode_ = PP_ToBool(uses_nonsfi_mode); if (pnacl_options.translate) { pp::CompletionCallback translate_callback = callback_factory_.NewCallback(&Plugin::BitcodeDidTranslate); pnacl_coordinator_.reset( PnaclCoordinator::BitcodeToNative(this, - program_url, + program_url_, pnacl_options, translate_callback)); return; } else { - nexe_open_time_ = NaClGetTimeOfDayMicroseconds(); - // Try the fast path first. This will only block if the file is installed. - if (OpenURLFast(program_url, &nexe_downloader_)) { - NexeFileDidOpen(PP_OK); - } else { - pp::CompletionCallback open_callback = - callback_factory_.NewCallback(&Plugin::NexeFileDidOpen); - // Will always call the callback on success or failure. - CHECK( - nexe_downloader_.Open(program_url, - DOWNLOAD_TO_FILE, - open_callback, - true, - &UpdateDownloadProgress)); - } + pp::CompletionCallback open_callback = + callback_factory_.NewCallback(&Plugin::NexeFileDidOpen); + // Will always call the callback on success or failure. + nacl_interface_->DownloadNexe(pp_instance(), + program_url_.c_str(), + &nexe_handle_, + open_callback.pp_completion_callback()); return; } } @@ -693,9 +682,8 @@ bool Plugin::StreamAsFile(const nacl::string& url, void Plugin::ReportLoadSuccess(uint64_t loaded_bytes, uint64_t total_bytes) { - const nacl::string& url = nexe_downloader_.url(); nacl_interface_->ReportLoadSuccess( - pp_instance(), url.c_str(), loaded_bytes, total_bytes); + pp_instance(), program_url_.c_str(), loaded_bytes, total_bytes); } @@ -731,10 +719,9 @@ void Plugin::UpdateDownloadProgress( // Find the URL loader that sent this notification. const FileDownloader* file_downloader = plugin->FindFileDownloader(pp_resource); - // If not a streamed file, it must be the .nexe loader. - if (file_downloader == NULL) - file_downloader = &plugin->nexe_downloader_; - nacl::string url = file_downloader->url(); + nacl::string url; + if (file_downloader) + url = file_downloader->url(); LengthComputable length_computable = (total_bytes_to_be_received >= 0) ? LENGTH_IS_COMPUTABLE : LENGTH_IS_NOT_COMPUTABLE; @@ -750,17 +737,13 @@ void Plugin::UpdateDownloadProgress( const FileDownloader* Plugin::FindFileDownloader( PP_Resource url_loader) const { const FileDownloader* file_downloader = NULL; - if (url_loader == nexe_downloader_.url_loader()) { - file_downloader = &nexe_downloader_; - } else { - std::set<FileDownloader*>::const_iterator it = url_downloaders_.begin(); - while (it != url_downloaders_.end()) { - if (url_loader == (*it)->url_loader()) { - file_downloader = (*it); - break; - } - ++it; + std::set<FileDownloader*>::const_iterator it = url_downloaders_.begin(); + while (it != url_downloaders_.end()) { + if (url_loader == (*it)->url_loader()) { + file_downloader = (*it); + break; } + ++it; } return file_downloader; } diff --git a/ppapi/native_client/src/trusted/plugin/plugin.h b/ppapi/native_client/src/trusted/plugin/plugin.h index 3a14470..cb958bc 100644 --- a/ppapi/native_client/src/trusted/plugin/plugin.h +++ b/ppapi/native_client/src/trusted/plugin/plugin.h @@ -281,13 +281,9 @@ class Plugin : public pp::Instance { nacl::DescWrapperFactory* wrapper_factory_; - // File download support. |nexe_downloader_| can be opened with a specific - // callback to run when the file has been downloaded and is opened for - // reading. We use one downloader for all URL downloads to prevent issuing - // multiple GETs that might arrive out of order. For example, this will - // prevent a GET of a NaCl manifest while a .nexe GET is pending. Note that - // this will also prevent simultaneous handling of multiple .nexes on a page. - FileDownloader nexe_downloader_; + // Original, unresolved URL for the .nexe program to load. + std::string program_url_; + pp::CompletionCallbackFactory<Plugin> callback_factory_; nacl::scoped_ptr<PnaclCoordinator> pnacl_coordinator_; @@ -315,12 +311,11 @@ class Plugin : public pp::Instance { int64_t time_of_last_progress_event_; int exit_status_; - // Open times are in microseconds. - int64_t nexe_open_time_; - PP_Var manifest_data_var_; int32_t manifest_id_; + PP_FileHandle nexe_handle_; + const PPB_NaCl_Private* nacl_interface_; pp::UMAPrivate uma_interface_; }; diff --git a/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c b/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c index 29d56f3..5dd9635 100644 --- a/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c +++ b/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c @@ -3257,11 +3257,6 @@ static void Pnacl_M25_PPB_NaCl_Private_DispatchEvent(PP_Instance instance, PP_Na iface->DispatchEvent(instance, event_type, resource_url, length_is_computable, loaded_bytes, total_bytes); } -static void Pnacl_M25_PPB_NaCl_Private_NexeFileDidOpen(PP_Instance instance, int32_t pp_error, int32_t fd, int32_t http_status, int64_t nexe_bytes_read, const char* url, int64_t time_since_open) { - const struct PPB_NaCl_Private_1_0 *iface = Pnacl_WrapperInfo_PPB_NaCl_Private_1_0.real_iface; - iface->NexeFileDidOpen(instance, pp_error, fd, http_status, nexe_bytes_read, url, time_since_open); -} - static void Pnacl_M25_PPB_NaCl_Private_ReportLoadSuccess(PP_Instance instance, const char* url, uint64_t loaded_bytes, uint64_t total_bytes) { const struct PPB_NaCl_Private_1_0 *iface = Pnacl_WrapperInfo_PPB_NaCl_Private_1_0.real_iface; iface->ReportLoadSuccess(instance, url, loaded_bytes, total_bytes); @@ -3412,6 +3407,11 @@ static void Pnacl_M25_PPB_NaCl_Private_PostMessageToJavaScript(PP_Instance insta iface->PostMessageToJavaScript(instance, message); } +static void Pnacl_M25_PPB_NaCl_Private_DownloadNexe(PP_Instance instance, const char* url, PP_FileHandle* handle, struct PP_CompletionCallback* callback) { + const struct PPB_NaCl_Private_1_0 *iface = Pnacl_WrapperInfo_PPB_NaCl_Private_1_0.real_iface; + iface->DownloadNexe(instance, url, handle, *callback); +} + /* End wrapper methods for PPB_NaCl_Private_1_0 */ /* Begin wrapper methods for PPB_NetAddress_Private_0_1 */ @@ -5143,7 +5143,6 @@ static const struct PPB_NaCl_Private_1_0 Pnacl_Wrappers_PPB_NaCl_Private_1_0 = { .ReportTranslationFinished = (void (*)(PP_Instance instance, PP_Bool success))&Pnacl_M25_PPB_NaCl_Private_ReportTranslationFinished, .OpenNaClExecutable = (PP_FileHandle (*)(PP_Instance instance, const char* file_url, uint64_t* file_token_lo, uint64_t* file_token_hi))&Pnacl_M25_PPB_NaCl_Private_OpenNaClExecutable, .DispatchEvent = (void (*)(PP_Instance instance, PP_NaClEventType event_type, const char* resource_url, PP_Bool length_is_computable, uint64_t loaded_bytes, uint64_t total_bytes))&Pnacl_M25_PPB_NaCl_Private_DispatchEvent, - .NexeFileDidOpen = (void (*)(PP_Instance instance, int32_t pp_error, int32_t fd, int32_t http_status, int64_t nexe_bytes_read, const char* url, int64_t time_since_open))&Pnacl_M25_PPB_NaCl_Private_NexeFileDidOpen, .ReportLoadSuccess = (void (*)(PP_Instance instance, const char* url, uint64_t loaded_bytes, uint64_t total_bytes))&Pnacl_M25_PPB_NaCl_Private_ReportLoadSuccess, .ReportLoadError = (void (*)(PP_Instance instance, PP_NaClError error, const char* error_message, const char* console_message))&Pnacl_M25_PPB_NaCl_Private_ReportLoadError, .ReportLoadAbort = (void (*)(PP_Instance instance))&Pnacl_M25_PPB_NaCl_Private_ReportLoadAbort, @@ -5173,7 +5172,8 @@ static const struct PPB_NaCl_Private_1_0 Pnacl_Wrappers_PPB_NaCl_Private_1_0 = { .ManifestResolveKey = (PP_Bool (*)(PP_Instance instance, int32_t manifest_id, const char* key, struct PP_Var* full_url, struct PP_PNaClOptions* pnacl_options))&Pnacl_M25_PPB_NaCl_Private_ManifestResolveKey, .GetPnaclResourceInfo = (PP_Bool (*)(PP_Instance instance, const char* filename, struct PP_Var* llc_tool_name, struct PP_Var* ld_tool_name))&Pnacl_M25_PPB_NaCl_Private_GetPnaclResourceInfo, .GetCpuFeatureAttrs = (struct PP_Var (*)(void))&Pnacl_M25_PPB_NaCl_Private_GetCpuFeatureAttrs, - .PostMessageToJavaScript = (void (*)(PP_Instance instance, const char* message))&Pnacl_M25_PPB_NaCl_Private_PostMessageToJavaScript + .PostMessageToJavaScript = (void (*)(PP_Instance instance, const char* message))&Pnacl_M25_PPB_NaCl_Private_PostMessageToJavaScript, + .DownloadNexe = (void (*)(PP_Instance instance, const char* url, PP_FileHandle* handle, struct PP_CompletionCallback callback))&Pnacl_M25_PPB_NaCl_Private_DownloadNexe }; static const struct PPB_NetAddress_Private_0_1 Pnacl_Wrappers_PPB_NetAddress_Private_0_1 = { |