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

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

Issue 260053008: Trusted plugin: Miscellaneous cleanup. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months 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
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/plugin.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifdef _MSC_VER 5 #ifdef _MSC_VER
6 // Do not warn about use of std::copy with raw pointers. 6 // Do not warn about use of std::copy with raw pointers.
7 #pragma warning(disable : 4996) 7 #pragma warning(disable : 4996)
8 #endif 8 #endif
9 9
10 #include "ppapi/native_client/src/trusted/plugin/plugin.h" 10 #include "ppapi/native_client/src/trusted/plugin/plugin.h"
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 return NULL; 347 return NULL;
348 } 348 }
349 349
350 PLUGIN_PRINTF(("Plugin::LoadHelperNaClModule (%s, %s)\n", 350 PLUGIN_PRINTF(("Plugin::LoadHelperNaClModule (%s, %s)\n",
351 helper_url.c_str(), 351 helper_url.c_str(),
352 nacl_subprocess.get()->detailed_description().c_str())); 352 nacl_subprocess.get()->detailed_description().c_str()));
353 353
354 return nacl_subprocess.release(); 354 return nacl_subprocess.release();
355 } 355 }
356 356
357 Plugin* Plugin::New(PP_Instance pp_instance) {
358 PLUGIN_PRINTF(("Plugin::New (pp_instance=%" NACL_PRId32 ")\n", pp_instance));
359 Plugin* plugin = new Plugin(pp_instance);
360 PLUGIN_PRINTF(("Plugin::New (plugin=%p)\n", static_cast<void*>(plugin)));
361 return plugin;
362 }
363
364 // All failures of this function will show up as "Missing Plugin-in", so 357 // All failures of this function will show up as "Missing Plugin-in", so
365 // there is no need to log to JS console that there was an initialization 358 // there is no need to log to JS console that there was an initialization
366 // failure. Note that module loading functions will log their own errors. 359 // failure. Note that module loading functions will log their own errors.
367 bool Plugin::Init(uint32_t argc, const char* argn[], const char* argv[]) { 360 bool Plugin::Init(uint32_t argc, const char* argn[], const char* argv[]) {
368 PLUGIN_PRINTF(("Plugin::Init (argc=%" NACL_PRIu32 ")\n", argc)); 361 PLUGIN_PRINTF(("Plugin::Init (argc=%" NACL_PRIu32 ")\n", argc));
369 nacl_interface_->InitializePlugin(pp_instance(), argc, argn, argv); 362 nacl_interface_->InitializePlugin(pp_instance(), argc, argn, argv);
370 url_util_ = pp::URLUtil_Dev::Get();
371 if (url_util_ == NULL)
372 return false;
373
374 wrapper_factory_ = new nacl::DescWrapperFactory(); 363 wrapper_factory_ = new nacl::DescWrapperFactory();
375 pp::Var manifest_url(pp::PASS_REF, nacl_interface_->GetManifestURLArgument( 364 pp::Var manifest_url(pp::PASS_REF, nacl_interface_->GetManifestURLArgument(
376 pp_instance())); 365 pp_instance()));
377 if (manifest_url.is_string() && !manifest_url.AsString().empty()) 366 if (manifest_url.is_string() && !manifest_url.AsString().empty())
378 RequestNaClManifest(manifest_url.AsString()); 367 RequestNaClManifest(manifest_url.AsString());
379 return true; 368 return true;
380 } 369 }
381 370
382 Plugin::Plugin(PP_Instance pp_instance) 371 Plugin::Plugin(PP_Instance pp_instance)
383 : pp::Instance(pp_instance), 372 : pp::Instance(pp_instance),
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 ReportLoadError(error_info); 636 ReportLoadError(error_info);
648 return; 637 return;
649 } 638 }
650 639
651 ProcessNaClManifest(json_buffer); 640 ProcessNaClManifest(json_buffer);
652 } 641 }
653 642
654 void Plugin::ProcessNaClManifest(const nacl::string& manifest_json) { 643 void Plugin::ProcessNaClManifest(const nacl::string& manifest_json) {
655 HistogramSizeKB("NaCl.Perf.Size.Manifest", 644 HistogramSizeKB("NaCl.Perf.Size.Manifest",
656 static_cast<int32_t>(manifest_json.length() / 1024)); 645 static_cast<int32_t>(manifest_json.length() / 1024));
657 ErrorInfo error_info; 646 if (!SetManifestObject(manifest_json))
658 if (!SetManifestObject(manifest_json, &error_info)) {
659 ReportLoadError(error_info);
660 return; 647 return;
661 }
662 648
663 nacl::string program_url; 649 nacl::string program_url;
664 PP_PNaClOptions pnacl_options = {PP_FALSE, PP_FALSE, 2}; 650 PP_PNaClOptions pnacl_options = {PP_FALSE, PP_FALSE, 2};
665 bool uses_nonsfi_mode; 651 bool uses_nonsfi_mode;
652 ErrorInfo error_info;
666 if (manifest_->GetProgramURL( 653 if (manifest_->GetProgramURL(
667 &program_url, &pnacl_options, &uses_nonsfi_mode, &error_info)) { 654 &program_url, &pnacl_options, &uses_nonsfi_mode, &error_info)) {
668 // TODO(teravest): Make ProcessNaClManifest take responsibility for more of 655 // TODO(teravest): Make ProcessNaClManifest take responsibility for more of
669 // this function. 656 // this function.
670 nacl_interface_->ProcessNaClManifest(pp_instance(), program_url.c_str()); 657 nacl_interface_->ProcessNaClManifest(pp_instance(), program_url.c_str());
671 uses_nonsfi_mode_ = uses_nonsfi_mode; 658 uses_nonsfi_mode_ = uses_nonsfi_mode;
672 if (pnacl_options.translate) { 659 if (pnacl_options.translate) {
673 pp::CompletionCallback translate_callback = 660 pp::CompletionCallback translate_callback =
674 callback_factory_.NewCallback(&Plugin::BitcodeDidTranslate); 661 callback_factory_.NewCallback(&Plugin::BitcodeDidTranslate);
675 // Will always call the callback on success or failure. 662 // Will always call the callback on success or failure.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 // Will always call the callback on success or failure. 722 // Will always call the callback on success or failure.
736 CHECK(nexe_downloader_.Open(nmf_resolved_url.AsString(), 723 CHECK(nexe_downloader_.Open(nmf_resolved_url.AsString(),
737 DOWNLOAD_TO_FILE, 724 DOWNLOAD_TO_FILE,
738 open_callback, 725 open_callback,
739 false, 726 false,
740 NULL)); 727 NULL));
741 } 728 }
742 } 729 }
743 730
744 731
745 bool Plugin::SetManifestObject(const nacl::string& manifest_json, 732 bool Plugin::SetManifestObject(const nacl::string& manifest_json) {
746 ErrorInfo* error_info) {
747 PLUGIN_PRINTF(("Plugin::SetManifestObject(): manifest_json='%s'.\n", 733 PLUGIN_PRINTF(("Plugin::SetManifestObject(): manifest_json='%s'.\n",
748 manifest_json.c_str())); 734 manifest_json.c_str()));
749 if (error_info == NULL) 735 ErrorInfo error_info;
750 return false; 736
751 // Determine whether lookups should use portable (i.e., pnacl versions) 737 // Determine whether lookups should use portable (i.e., pnacl versions)
752 // rather than platform-specific files. 738 // rather than platform-specific files.
753 bool is_pnacl = nacl_interface_->IsPNaCl(pp_instance()); 739 bool is_pnacl = nacl_interface_->IsPNaCl(pp_instance());
754 bool nonsfi_mode_enabled = 740 bool nonsfi_mode_enabled =
755 PP_ToBool(nacl_interface_->IsNonSFIModeEnabled()); 741 PP_ToBool(nacl_interface_->IsNonSFIModeEnabled());
756 pp::Var manifest_base_url = 742 pp::Var manifest_base_url =
757 pp::Var(pp::PASS_REF, nacl_interface_->GetManifestBaseURL(pp_instance())); 743 pp::Var(pp::PASS_REF, nacl_interface_->GetManifestBaseURL(pp_instance()));
758 std::string manifest_base_url_str = manifest_base_url.AsString(); 744 std::string manifest_base_url_str = manifest_base_url.AsString();
759 bool pnacl_debug = GetNaClInterface()->NaClDebugEnabledForURL( 745 bool pnacl_debug = GetNaClInterface()->NaClDebugEnabledForURL(
760 manifest_base_url_str.c_str()); 746 manifest_base_url_str.c_str());
761 const char* sandbox_isa = nacl_interface_->GetSandboxArch(); 747 const char* sandbox_isa = nacl_interface_->GetSandboxArch();
762 nacl::scoped_ptr<JsonManifest> json_manifest( 748 nacl::scoped_ptr<JsonManifest> json_manifest(
763 new JsonManifest(url_util_, 749 new JsonManifest(pp::URLUtil_Dev::Get(),
764 manifest_base_url_str, 750 manifest_base_url_str,
765 (is_pnacl ? kPortableArch : sandbox_isa), 751 (is_pnacl ? kPortableArch : sandbox_isa),
766 nonsfi_mode_enabled, 752 nonsfi_mode_enabled,
767 pnacl_debug)); 753 pnacl_debug));
768 if (!json_manifest->Init(manifest_json, error_info)) { 754 if (!json_manifest->Init(manifest_json, &error_info)) {
755 ReportLoadError(error_info);
769 return false; 756 return false;
770 } 757 }
771 manifest_.reset(json_manifest.release()); 758 manifest_.reset(json_manifest.release());
772 return true; 759 return true;
773 } 760 }
774 761
775 void Plugin::UrlDidOpenForStreamAsFile( 762 void Plugin::UrlDidOpenForStreamAsFile(
776 int32_t pp_error, 763 int32_t pp_error,
777 FileDownloader* url_downloader, 764 FileDownloader* url_downloader,
778 pp::CompletionCallback callback) { 765 pp::CompletionCallback callback) {
779 PLUGIN_PRINTF(("Plugin::UrlDidOpen (pp_error=%" NACL_PRId32 766 PLUGIN_PRINTF(("Plugin::UrlDidOpen (pp_error=%" NACL_PRId32
780 ", url_downloader=%p)\n", pp_error, 767 ", url_downloader=%p)\n", pp_error,
781 static_cast<void*>(url_downloader))); 768 static_cast<void*>(url_downloader)));
782 url_downloaders_.erase(url_downloader); 769 url_downloaders_.erase(url_downloader);
783 nacl::scoped_ptr<FileDownloader> scoped_url_downloader(url_downloader); 770 nacl::scoped_ptr<FileDownloader> scoped_url_downloader(url_downloader);
784 NaClFileInfo tmp_info(scoped_url_downloader->GetFileInfo()); 771 NaClFileInfo tmp_info(scoped_url_downloader->GetFileInfo());
785 NaClFileInfoAutoCloser *info = new NaClFileInfoAutoCloser(&tmp_info); 772 NaClFileInfoAutoCloser *info = new NaClFileInfoAutoCloser(&tmp_info);
786 773
787 if (pp_error != PP_OK) { 774 if (pp_error != PP_OK) {
788 callback.Run(pp_error); 775 callback.Run(pp_error);
789 delete info; 776 delete info;
790 } else if (info->get_desc() > NACL_NO_FILE_DESC) { 777 } else if (info->get_desc() > NACL_NO_FILE_DESC) {
791 std::map<nacl::string, NaClFileInfoAutoCloser*>::iterator it = 778 std::map<nacl::string, NaClFileInfoAutoCloser*>::iterator it =
792 url_file_info_map_.find(url_downloader->url()); 779 url_file_info_map_.find(url_downloader->url());
793 if (it != url_file_info_map_.end()) { 780 if (it != url_file_info_map_.end())
794 delete it->second; 781 delete it->second;
795 }
796 url_file_info_map_[url_downloader->url()] = info; 782 url_file_info_map_[url_downloader->url()] = info;
797 callback.Run(PP_OK); 783 callback.Run(PP_OK);
798 } else { 784 } else {
799 callback.Run(PP_ERROR_FAILED); 785 callback.Run(PP_ERROR_FAILED);
800 delete info; 786 delete info;
801 } 787 }
802 } 788 }
803 789
804 struct NaClFileInfo Plugin::GetFileInfo(const nacl::string& url) { 790 struct NaClFileInfo Plugin::GetFileInfo(const nacl::string& url) {
805 struct NaClFileInfo info; 791 struct NaClFileInfo info;
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 // We shouldn't hit this if the file URL is in an installed app. 953 // We shouldn't hit this if the file URL is in an installed app.
968 if (file_handle == PP_kInvalidFileHandle) 954 if (file_handle == PP_kInvalidFileHandle)
969 return false; 955 return false;
970 956
971 // FileDownloader takes ownership of the file handle. 957 // FileDownloader takes ownership of the file handle.
972 downloader->OpenFast(url, file_handle, file_token_lo, file_token_hi); 958 downloader->OpenFast(url, file_handle, file_token_lo, file_token_hi);
973 return true; 959 return true;
974 } 960 }
975 961
976 bool Plugin::DocumentCanRequest(const std::string& url) { 962 bool Plugin::DocumentCanRequest(const std::string& url) {
977 CHECK(url_util_ != NULL); 963 CHECK(pp::URLUtil_Dev::Get() != NULL);
978 return url_util_->DocumentCanRequest(this, pp::Var(url)); 964 return pp::URLUtil_Dev::Get()->DocumentCanRequest(this, pp::Var(url));
dmichael (off chromium) 2014/04/28 23:01:44 Hopefully this doesn't matter, but *if* this ever
979 } 965 }
980 966
981 void Plugin::set_exit_status(int exit_status) { 967 void Plugin::set_exit_status(int exit_status) {
982 pp::Core* core = pp::Module::Get()->core(); 968 pp::Core* core = pp::Module::Get()->core();
983 if (core->IsMainThread()) { 969 if (core->IsMainThread()) {
984 SetExitStatusOnMainThread(PP_OK, exit_status); 970 SetExitStatusOnMainThread(PP_OK, exit_status);
985 } else { 971 } else {
986 pp::CompletionCallback callback = 972 pp::CompletionCallback callback =
987 callback_factory_.NewCallback(&Plugin::SetExitStatusOnMainThread, 973 callback_factory_.NewCallback(&Plugin::SetExitStatusOnMainThread,
988 exit_status); 974 exit_status);
989 core->CallOnMainThread(0, callback, 0); 975 core->CallOnMainThread(0, callback, 0);
990 } 976 }
991 } 977 }
992 978
993 void Plugin::SetExitStatusOnMainThread(int32_t pp_error, 979 void Plugin::SetExitStatusOnMainThread(int32_t pp_error,
994 int exit_status) { 980 int exit_status) {
995 DCHECK(pp::Module::Get()->core()->IsMainThread()); 981 DCHECK(pp::Module::Get()->core()->IsMainThread());
996 DCHECK(nacl_interface_); 982 DCHECK(nacl_interface_);
997 nacl_interface_->SetExitStatus(pp_instance(), exit_status); 983 nacl_interface_->SetExitStatus(pp_instance(), exit_status);
998 } 984 }
999 985
1000 986
1001 } // namespace plugin 987 } // namespace plugin
OLDNEW
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/plugin.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698