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