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(pp_instance(), | |
631 reinterpret_cast<void*>(ipc_channel_handle_ptr.release()))) { | |
Mark Seaborn
2012/06/21 19:49:49
Nit: indent this by 4 more spaces so it looks like
bbudge
2012/06/21 21:20:01
Done.
| |
632 using_ipc_proxy_ = true; | |
633 // We need to explicitly schedule this here. It is normally called in | |
634 // response to starting the SRPC proxy. | |
635 CHECK(init_done_cb.pp_completion_callback().func != NULL); | |
636 PLUGIN_PRINTF(("Plugin::LoadNaClModuleCommon, started ipc proxy.\n")); | |
637 pp::Module::Get()->core()->CallOnMainThread(0, init_done_cb, PP_OK); | |
638 } | |
612 return true; | 639 return true; |
613 } | 640 } |
614 | 641 |
615 bool Plugin::LoadNaClModule(nacl::DescWrapper* wrapper, | 642 bool Plugin::LoadNaClModule(nacl::DescWrapper* wrapper, |
616 ErrorInfo* error_info, | 643 ErrorInfo* error_info, |
617 pp::CompletionCallback init_done_cb, | 644 pp::CompletionCallback init_done_cb, |
618 pp::CompletionCallback crash_cb) { | 645 pp::CompletionCallback crash_cb) { |
619 // Before forking a new sel_ldr process, ensure that we do not leak | 646 // Before forking a new sel_ldr process, ensure that we do not leak |
620 // the ServiceRuntime object for an existing subprocess, and that any | 647 // the ServiceRuntime object for an existing subprocess, and that any |
621 // associated listener threads do not go unjoined because if they | 648 // associated listener threads do not go unjoined because if they |
622 // outlive the Plugin object, they will not be memory safe. | 649 // outlive the Plugin object, they will not be memory safe. |
623 ShutDownSubprocesses(); | 650 ShutDownSubprocesses(); |
624 if (!LoadNaClModuleCommon(wrapper, &main_subprocess_, manifest_.get(), | 651 if (!LoadNaClModuleCommon(wrapper, &main_subprocess_, manifest_.get(), |
625 true, error_info, init_done_cb, crash_cb)) { | 652 true, error_info, init_done_cb, crash_cb)) { |
626 return false; | 653 return false; |
627 } | 654 } |
628 PLUGIN_PRINTF(("Plugin::LoadNaClModule (%s)\n", | 655 PLUGIN_PRINTF(("Plugin::LoadNaClModule (%s)\n", |
629 main_subprocess_.detailed_description().c_str())); | 656 main_subprocess_.detailed_description().c_str())); |
630 return true; | 657 return true; |
631 } | 658 } |
632 | 659 |
633 bool Plugin::LoadNaClModuleContinuationIntern(ErrorInfo* error_info) { | 660 bool Plugin::LoadNaClModuleContinuationIntern(ErrorInfo* error_info) { |
661 // If we are using the IPC proxy, StartSrpcServices and StartJSObjectProxy | |
662 // don't makes sense. Return 'true' so that the plugin continues loading. | |
663 if (using_ipc_proxy_) | |
664 return true; | |
665 | |
634 if (!main_subprocess_.StartSrpcServices()) { | 666 if (!main_subprocess_.StartSrpcServices()) { |
635 error_info->SetReport(ERROR_SRPC_CONNECTION_FAIL, | 667 error_info->SetReport(ERROR_SRPC_CONNECTION_FAIL, |
636 "SRPC connection failure for " + | 668 "SRPC connection failure for " + |
637 main_subprocess_.description()); | 669 main_subprocess_.description()); |
638 return false; | 670 return false; |
639 } | 671 } |
640 if (!main_subprocess_.StartJSObjectProxy(this, error_info)) { | 672 if (!main_subprocess_.StartJSObjectProxy(this, error_info)) { |
641 return false; | 673 return false; |
642 } | 674 } |
643 PLUGIN_PRINTF(("Plugin::LoadNaClModule (%s)\n", | 675 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), | 887 main_subprocess_("main subprocess", NULL, NULL), |
856 nacl_ready_state_(UNSENT), | 888 nacl_ready_state_(UNSENT), |
857 nexe_error_reported_(false), | 889 nexe_error_reported_(false), |
858 wrapper_factory_(NULL), | 890 wrapper_factory_(NULL), |
859 last_error_string_(""), | 891 last_error_string_(""), |
860 ppapi_proxy_(NULL), | 892 ppapi_proxy_(NULL), |
861 enable_dev_interfaces_(false), | 893 enable_dev_interfaces_(false), |
862 init_time_(0), | 894 init_time_(0), |
863 ready_time_(0), | 895 ready_time_(0), |
864 nexe_size_(0), | 896 nexe_size_(0), |
865 time_of_last_progress_event_(0) { | 897 time_of_last_progress_event_(0), |
898 using_ipc_proxy_(false) { | |
866 PLUGIN_PRINTF(("Plugin::Plugin (this=%p, pp_instance=%" | 899 PLUGIN_PRINTF(("Plugin::Plugin (this=%p, pp_instance=%" |
867 NACL_PRId32")\n", static_cast<void*>(this), pp_instance)); | 900 NACL_PRId32")\n", static_cast<void*>(this), pp_instance)); |
868 callback_factory_.Initialize(this); | 901 callback_factory_.Initialize(this); |
869 nexe_downloader_.Initialize(this); | 902 nexe_downloader_.Initialize(this); |
870 } | 903 } |
871 | 904 |
872 | 905 |
873 Plugin::~Plugin() { | 906 Plugin::~Plugin() { |
874 int64_t shutdown_start = NaClGetTimeOfDayMicroseconds(); | 907 int64_t shutdown_start = NaClGetTimeOfDayMicroseconds(); |
875 | 908 |
(...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1887 static_cast<uint32_t>(text.size())); | 1920 static_cast<uint32_t>(text.size())); |
1888 const PPB_Console_Dev* console_interface = | 1921 const PPB_Console_Dev* console_interface = |
1889 static_cast<const PPB_Console_Dev*>( | 1922 static_cast<const PPB_Console_Dev*>( |
1890 module->GetBrowserInterface(PPB_CONSOLE_DEV_INTERFACE)); | 1923 module->GetBrowserInterface(PPB_CONSOLE_DEV_INTERFACE)); |
1891 console_interface->LogWithSource(pp_instance(), PP_LOGLEVEL_LOG, prefix, str); | 1924 console_interface->LogWithSource(pp_instance(), PP_LOGLEVEL_LOG, prefix, str); |
1892 var_interface->Release(prefix); | 1925 var_interface->Release(prefix); |
1893 var_interface->Release(str); | 1926 var_interface->Release(str); |
1894 } | 1927 } |
1895 | 1928 |
1896 } // namespace plugin | 1929 } // namespace plugin |
OLD | NEW |