| OLD | NEW |
| 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 "native_client/src/trusted/plugin/plugin.h" | 10 #include "native_client/src/trusted/plugin/plugin.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "native_client/src/include/nacl_scoped_ptr.h" | 27 #include "native_client/src/include/nacl_scoped_ptr.h" |
| 28 #include "native_client/src/include/nacl_string.h" | 28 #include "native_client/src/include/nacl_string.h" |
| 29 #include "native_client/src/include/portability.h" | 29 #include "native_client/src/include/portability.h" |
| 30 #include "native_client/src/include/portability_io.h" | 30 #include "native_client/src/include/portability_io.h" |
| 31 #include "native_client/src/include/portability_string.h" | 31 #include "native_client/src/include/portability_string.h" |
| 32 #include "native_client/src/shared/platform/nacl_check.h" | 32 #include "native_client/src/shared/platform/nacl_check.h" |
| 33 #include "native_client/src/shared/ppapi_proxy/browser_ppp.h" | 33 #include "native_client/src/shared/ppapi_proxy/browser_ppp.h" |
| 34 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" | 34 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" |
| 35 #include "native_client/src/trusted/nonnacl_util/sel_ldr_launcher.h" | 35 #include "native_client/src/trusted/nonnacl_util/sel_ldr_launcher.h" |
| 36 #include "native_client/src/trusted/plugin/json_manifest.h" | 36 #include "native_client/src/trusted/plugin/json_manifest.h" |
| 37 #include "native_client/src/trusted/plugin/nacl_entry_points.h" | |
| 38 #include "native_client/src/trusted/plugin/nacl_subprocess.h" | 37 #include "native_client/src/trusted/plugin/nacl_subprocess.h" |
| 39 #include "native_client/src/trusted/plugin/nexe_arch.h" | 38 #include "native_client/src/trusted/plugin/nexe_arch.h" |
| 40 #include "native_client/src/trusted/plugin/plugin_error.h" | 39 #include "native_client/src/trusted/plugin/plugin_error.h" |
| 41 #include "native_client/src/trusted/plugin/scriptable_plugin.h" | 40 #include "native_client/src/trusted/plugin/scriptable_plugin.h" |
| 42 #include "native_client/src/trusted/plugin/service_runtime.h" | 41 #include "native_client/src/trusted/plugin/service_runtime.h" |
| 43 #include "native_client/src/trusted/plugin/utility.h" | 42 #include "native_client/src/trusted/plugin/utility.h" |
| 44 #include "native_client/src/trusted/service_runtime/nacl_error_code.h" | 43 #include "native_client/src/trusted/service_runtime/nacl_error_code.h" |
| 45 | 44 |
| 46 #include "ppapi/c/dev/ppb_console_dev.h" | 45 #include "ppapi/c/dev/ppb_console_dev.h" |
| 47 #include "ppapi/c/dev/ppp_find_dev.h" | 46 #include "ppapi/c/dev/ppp_find_dev.h" |
| 48 #include "ppapi/c/dev/ppp_printing_dev.h" | 47 #include "ppapi/c/dev/ppp_printing_dev.h" |
| 49 #include "ppapi/c/dev/ppp_scrollbar_dev.h" | 48 #include "ppapi/c/dev/ppp_scrollbar_dev.h" |
| 50 #include "ppapi/c/dev/ppp_selection_dev.h" | 49 #include "ppapi/c/dev/ppp_selection_dev.h" |
| 51 #include "ppapi/c/dev/ppp_widget_dev.h" | 50 #include "ppapi/c/dev/ppp_widget_dev.h" |
| 52 #include "ppapi/c/dev/ppp_zoom_dev.h" | 51 #include "ppapi/c/dev/ppp_zoom_dev.h" |
| 53 #include "ppapi/c/pp_errors.h" | 52 #include "ppapi/c/pp_errors.h" |
| 54 #include "ppapi/c/ppb_var.h" | 53 #include "ppapi/c/ppb_var.h" |
| 55 #include "ppapi/c/ppp_input_event.h" | 54 #include "ppapi/c/ppp_input_event.h" |
| 56 #include "ppapi/c/ppp_instance.h" | 55 #include "ppapi/c/ppp_instance.h" |
| 57 #include "ppapi/c/ppp_mouse_lock.h" | 56 #include "ppapi/c/ppp_mouse_lock.h" |
| 58 #include "ppapi/c/private/ppb_nacl_private.h" | |
| 59 #include "ppapi/c/private/ppb_uma_private.h" | 57 #include "ppapi/c/private/ppb_uma_private.h" |
| 60 #include "ppapi/cpp/dev/find_dev.h" | 58 #include "ppapi/cpp/dev/find_dev.h" |
| 61 #include "ppapi/cpp/dev/printing_dev.h" | 59 #include "ppapi/cpp/dev/printing_dev.h" |
| 62 #include "ppapi/cpp/dev/scrollbar_dev.h" | 60 #include "ppapi/cpp/dev/scrollbar_dev.h" |
| 63 #include "ppapi/cpp/dev/selection_dev.h" | 61 #include "ppapi/cpp/dev/selection_dev.h" |
| 64 #include "ppapi/cpp/dev/text_input_dev.h" | 62 #include "ppapi/cpp/dev/text_input_dev.h" |
| 65 #include "ppapi/cpp/dev/url_util_dev.h" | 63 #include "ppapi/cpp/dev/url_util_dev.h" |
| 66 #include "ppapi/cpp/dev/widget_client_dev.h" | 64 #include "ppapi/cpp/dev/widget_client_dev.h" |
| 67 #include "ppapi/cpp/dev/zoom_dev.h" | 65 #include "ppapi/cpp/dev/zoom_dev.h" |
| 68 #include "ppapi/cpp/image_data.h" | 66 #include "ppapi/cpp/image_data.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 113 |
| 116 // Up to 33 minutes. | 114 // Up to 33 minutes. |
| 117 const int64_t kTimeLargeMin = 100; // in ms | 115 const int64_t kTimeLargeMin = 100; // in ms |
| 118 const int64_t kTimeLargeMax = 2000000; // in ms | 116 const int64_t kTimeLargeMax = 2000000; // in ms |
| 119 const uint32_t kTimeLargeBuckets = 100; | 117 const uint32_t kTimeLargeBuckets = 100; |
| 120 | 118 |
| 121 const int64_t kSizeKBMin = 1; | 119 const int64_t kSizeKBMin = 1; |
| 122 const int64_t kSizeKBMax = 512*1024; // very large .nexe | 120 const int64_t kSizeKBMax = 512*1024; // very large .nexe |
| 123 const uint32_t kSizeKBBuckets = 100; | 121 const uint32_t kSizeKBBuckets = 100; |
| 124 | 122 |
| 125 const PPB_NaCl_Private* GetNaclInterface() { | |
| 126 pp::Module *module = pp::Module::Get(); | |
| 127 CHECK(module); | |
| 128 return static_cast<const PPB_NaCl_Private*>( | |
| 129 module->GetBrowserInterface(PPB_NACL_PRIVATE_INTERFACE)); | |
| 130 } | |
| 131 | |
| 132 const PPB_UMA_Private* GetUMAInterface() { | 123 const PPB_UMA_Private* GetUMAInterface() { |
| 133 pp::Module *module = pp::Module::Get(); | 124 pp::Module *module = pp::Module::Get(); |
| 134 CHECK(module); | 125 CHECK(module); |
| 135 return static_cast<const PPB_UMA_Private*>( | 126 return static_cast<const PPB_UMA_Private*>( |
| 136 module->GetBrowserInterface(PPB_UMA_PRIVATE_INTERFACE)); | 127 module->GetBrowserInterface(PPB_UMA_PRIVATE_INTERFACE)); |
| 137 } | 128 } |
| 138 | 129 |
| 139 void HistogramTimeSmall(const std::string& name, int64_t ms) { | 130 void HistogramTimeSmall(const std::string& name, int64_t ms) { |
| 140 if (ms < 0) return; | 131 if (ms < 0) return; |
| 141 | 132 |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 subprocess->set_service_runtime(new_service_runtime); | 596 subprocess->set_service_runtime(new_service_runtime); |
| 606 PLUGIN_PRINTF(("Plugin::LoadNaClModuleCommon (service_runtime=%p)\n", | 597 PLUGIN_PRINTF(("Plugin::LoadNaClModuleCommon (service_runtime=%p)\n", |
| 607 static_cast<void*>(new_service_runtime))); | 598 static_cast<void*>(new_service_runtime))); |
| 608 if (NULL == new_service_runtime) { | 599 if (NULL == new_service_runtime) { |
| 609 error_info->SetReport(ERROR_SEL_LDR_INIT, | 600 error_info->SetReport(ERROR_SEL_LDR_INIT, |
| 610 "sel_ldr init failure " + subprocess->description()); | 601 "sel_ldr init failure " + subprocess->description()); |
| 611 return false; | 602 return false; |
| 612 } | 603 } |
| 613 | 604 |
| 614 bool service_runtime_started = | 605 bool service_runtime_started = |
| 615 new_service_runtime->Start(wrapper, | 606 new_service_runtime->Start(wrapper, error_info, manifest_base_url()); |
| 616 error_info, | |
| 617 manifest_base_url()); | |
| 618 PLUGIN_PRINTF(("Plugin::LoadNaClModuleCommon (service_runtime_started=%d)\n", | 607 PLUGIN_PRINTF(("Plugin::LoadNaClModuleCommon (service_runtime_started=%d)\n", |
| 619 service_runtime_started)); | 608 service_runtime_started)); |
| 620 if (!service_runtime_started) { | 609 if (!service_runtime_started) { |
| 621 return false; | 610 return false; |
| 622 } | 611 } |
| 623 | |
| 624 // Try to start the Chrome IPC-based proxy. | |
| 625 const PPB_NaCl_Private* ppb_nacl = GetNaclInterface(); | |
| 626 if (ppb_nacl->StartPpapiProxy(pp_instance())) { | |
| 627 using_ipc_proxy_ = true; | |
| 628 // We need to explicitly schedule this here. It is normally called in | |
| 629 // response to starting the SRPC proxy. | |
| 630 CHECK(init_done_cb.pp_completion_callback().func != NULL); | |
| 631 PLUGIN_PRINTF(("Plugin::LoadNaClModuleCommon, started ipc proxy.\n")); | |
| 632 pp::Module::Get()->core()->CallOnMainThread(0, init_done_cb, PP_OK); | |
| 633 } | |
| 634 return true; | 612 return true; |
| 635 } | 613 } |
| 636 | 614 |
| 637 bool Plugin::LoadNaClModule(nacl::DescWrapper* wrapper, | 615 bool Plugin::LoadNaClModule(nacl::DescWrapper* wrapper, |
| 638 ErrorInfo* error_info, | 616 ErrorInfo* error_info, |
| 639 pp::CompletionCallback init_done_cb, | 617 pp::CompletionCallback init_done_cb, |
| 640 pp::CompletionCallback crash_cb) { | 618 pp::CompletionCallback crash_cb) { |
| 641 // Before forking a new sel_ldr process, ensure that we do not leak | 619 // Before forking a new sel_ldr process, ensure that we do not leak |
| 642 // the ServiceRuntime object for an existing subprocess, and that any | 620 // the ServiceRuntime object for an existing subprocess, and that any |
| 643 // associated listener threads do not go unjoined because if they | 621 // associated listener threads do not go unjoined because if they |
| 644 // outlive the Plugin object, they will not be memory safe. | 622 // outlive the Plugin object, they will not be memory safe. |
| 645 ShutDownSubprocesses(); | 623 ShutDownSubprocesses(); |
| 646 if (!LoadNaClModuleCommon(wrapper, &main_subprocess_, manifest_.get(), | 624 if (!LoadNaClModuleCommon(wrapper, &main_subprocess_, manifest_.get(), |
| 647 true, error_info, init_done_cb, crash_cb)) { | 625 true, error_info, init_done_cb, crash_cb)) { |
| 648 return false; | 626 return false; |
| 649 } | 627 } |
| 650 PLUGIN_PRINTF(("Plugin::LoadNaClModule (%s)\n", | 628 PLUGIN_PRINTF(("Plugin::LoadNaClModule (%s)\n", |
| 651 main_subprocess_.detailed_description().c_str())); | 629 main_subprocess_.detailed_description().c_str())); |
| 652 return true; | 630 return true; |
| 653 } | 631 } |
| 654 | 632 |
| 655 bool Plugin::LoadNaClModuleContinuationIntern(ErrorInfo* error_info) { | 633 bool Plugin::LoadNaClModuleContinuationIntern(ErrorInfo* error_info) { |
| 656 // If we are using the IPC proxy, StartSrpcServices and StartJSObjectProxy | |
| 657 // don't makes sense. Return 'true' so that the plugin continues loading. | |
| 658 if (using_ipc_proxy_) | |
| 659 return true; | |
| 660 | |
| 661 if (!main_subprocess_.StartSrpcServices()) { | 634 if (!main_subprocess_.StartSrpcServices()) { |
| 662 error_info->SetReport(ERROR_SRPC_CONNECTION_FAIL, | 635 error_info->SetReport(ERROR_SRPC_CONNECTION_FAIL, |
| 663 "SRPC connection failure for " + | 636 "SRPC connection failure for " + |
| 664 main_subprocess_.description()); | 637 main_subprocess_.description()); |
| 665 return false; | 638 return false; |
| 666 } | 639 } |
| 667 if (!main_subprocess_.StartJSObjectProxy(this, error_info)) { | 640 if (!main_subprocess_.StartJSObjectProxy(this, error_info)) { |
| 668 return false; | 641 return false; |
| 669 } | 642 } |
| 670 PLUGIN_PRINTF(("Plugin::LoadNaClModule (%s)\n", | 643 PLUGIN_PRINTF(("Plugin::LoadNaClModule (%s)\n", |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 main_subprocess_("main subprocess", NULL, NULL), | 855 main_subprocess_("main subprocess", NULL, NULL), |
| 883 nacl_ready_state_(UNSENT), | 856 nacl_ready_state_(UNSENT), |
| 884 nexe_error_reported_(false), | 857 nexe_error_reported_(false), |
| 885 wrapper_factory_(NULL), | 858 wrapper_factory_(NULL), |
| 886 last_error_string_(""), | 859 last_error_string_(""), |
| 887 ppapi_proxy_(NULL), | 860 ppapi_proxy_(NULL), |
| 888 enable_dev_interfaces_(false), | 861 enable_dev_interfaces_(false), |
| 889 init_time_(0), | 862 init_time_(0), |
| 890 ready_time_(0), | 863 ready_time_(0), |
| 891 nexe_size_(0), | 864 nexe_size_(0), |
| 892 time_of_last_progress_event_(0), | 865 time_of_last_progress_event_(0) { |
| 893 using_ipc_proxy_(false) { | |
| 894 PLUGIN_PRINTF(("Plugin::Plugin (this=%p, pp_instance=%" | 866 PLUGIN_PRINTF(("Plugin::Plugin (this=%p, pp_instance=%" |
| 895 NACL_PRId32")\n", static_cast<void*>(this), pp_instance)); | 867 NACL_PRId32")\n", static_cast<void*>(this), pp_instance)); |
| 896 callback_factory_.Initialize(this); | 868 callback_factory_.Initialize(this); |
| 897 nexe_downloader_.Initialize(this); | 869 nexe_downloader_.Initialize(this); |
| 898 } | 870 } |
| 899 | 871 |
| 900 | 872 |
| 901 Plugin::~Plugin() { | 873 Plugin::~Plugin() { |
| 902 int64_t shutdown_start = NaClGetTimeOfDayMicroseconds(); | 874 int64_t shutdown_start = NaClGetTimeOfDayMicroseconds(); |
| 903 | 875 |
| (...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1915 static_cast<uint32_t>(text.size())); | 1887 static_cast<uint32_t>(text.size())); |
| 1916 const PPB_Console_Dev* console_interface = | 1888 const PPB_Console_Dev* console_interface = |
| 1917 static_cast<const PPB_Console_Dev*>( | 1889 static_cast<const PPB_Console_Dev*>( |
| 1918 module->GetBrowserInterface(PPB_CONSOLE_DEV_INTERFACE)); | 1890 module->GetBrowserInterface(PPB_CONSOLE_DEV_INTERFACE)); |
| 1919 console_interface->LogWithSource(pp_instance(), PP_LOGLEVEL_LOG, prefix, str); | 1891 console_interface->LogWithSource(pp_instance(), PP_LOGLEVEL_LOG, prefix, str); |
| 1920 var_interface->Release(prefix); | 1892 var_interface->Release(prefix); |
| 1921 var_interface->Release(str); | 1893 var_interface->Release(str); |
| 1922 } | 1894 } |
| 1923 | 1895 |
| 1924 } // namespace plugin | 1896 } // namespace plugin |
| OLD | NEW |