diff options
-rw-r--r-- | content/ppapi_plugin/ppapi_broker_main.cc | 5 | ||||
-rw-r--r-- | content/ppapi_plugin/ppapi_plugin_main.cc | 2 | ||||
-rw-r--r-- | content/ppapi_plugin/ppapi_thread.cc | 102 | ||||
-rw-r--r-- | content/ppapi_plugin/ppapi_thread.h | 12 | ||||
-rw-r--r-- | ppapi/c/pp_completion_callback.h | 2 | ||||
-rw-r--r-- | ppapi/c/ppp.h | 4 | ||||
-rw-r--r-- | ppapi/c/trusted/ppp_broker.h | 90 | ||||
-rw-r--r-- | ppapi/ppapi_cpp.gypi | 1 |
8 files changed, 174 insertions, 44 deletions
diff --git a/content/ppapi_plugin/ppapi_broker_main.cc b/content/ppapi_plugin/ppapi_broker_main.cc index edaaa10..7b63f56 100644 --- a/content/ppapi_plugin/ppapi_broker_main.cc +++ b/content/ppapi_plugin/ppapi_broker_main.cc @@ -14,15 +14,14 @@ int PpapiBrokerMain(const MainFunctionParams& parameters) { const CommandLine& command_line = parameters.command_line_; if (command_line.HasSwitch(switches::kPpapiStartupDialog)) { - ChildProcess::WaitForDebugger("Ppapi"); + ChildProcess::WaitForDebugger("PpapiBroker"); } MessageLoop main_message_loop(MessageLoop::TYPE_DEFAULT); base::PlatformThread::SetName("CrPPAPIBrokerMain"); ChildProcess ppapi_broker_process; - //TODO:(ddorwin): Parameterize PpapiThread so the broker can reuse it. - ppapi_broker_process.set_main_thread(new PpapiThread()); + ppapi_broker_process.set_main_thread(new PpapiThread(true)); // Broker. main_message_loop.Run(); return 0; diff --git a/content/ppapi_plugin/ppapi_plugin_main.cc b/content/ppapi_plugin/ppapi_plugin_main.cc index e18051a..655e18a 100644 --- a/content/ppapi_plugin/ppapi_plugin_main.cc +++ b/content/ppapi_plugin/ppapi_plugin_main.cc @@ -21,7 +21,7 @@ int PpapiPluginMain(const MainFunctionParams& parameters) { base::PlatformThread::SetName("CrPPAPIMain"); ChildProcess ppapi_process; - ppapi_process.set_main_thread(new PpapiThread()); + ppapi_process.set_main_thread(new PpapiThread(false)); // Not a broker. main_message_loop.Run(); return 0; diff --git a/content/ppapi_plugin/ppapi_thread.cc b/content/ppapi_plugin/ppapi_thread.cc index ecec2dd..cab4d93 100644 --- a/content/ppapi_plugin/ppapi_thread.cc +++ b/content/ppapi_plugin/ppapi_thread.cc @@ -16,21 +16,30 @@ #include "ppapi/c/ppp.h" #include "ppapi/proxy/ppapi_messages.h" -PpapiThread::PpapiThread() - : get_plugin_interface_(NULL), +typedef int32_t (*InitializeBrokerFunc) + (PP_ConnectInstance_Func* connect_instance_func); + +PpapiThread::PpapiThread(bool is_broker) + : is_broker_(is_broker), + get_plugin_interface_(NULL), + connect_instance_func_(NULL), local_pp_module_( base::RandInt(0, std::numeric_limits<PP_Module>::max())) { } PpapiThread::~PpapiThread() { - if (library_.is_valid()) { - // The ShutdownModule function is optional. - pp::proxy::Dispatcher::ShutdownModuleFunc shutdown_module = - reinterpret_cast<pp::proxy::Dispatcher::ShutdownModuleFunc>( - library_.GetFunctionPointer("PPP_ShutdownModule")); - if (shutdown_module) - shutdown_module(); - } + if (!library_.is_valid()) + return; + + // The ShutdownModule/ShutdownBroker function is optional. + pp::proxy::Dispatcher::ShutdownModuleFunc shutdown_function = + is_broker_ ? + reinterpret_cast<pp::proxy::Dispatcher::ShutdownModuleFunc>( + library_.GetFunctionPointer("PPP_ShutdownBroker")) : + reinterpret_cast<pp::proxy::Dispatcher::ShutdownModuleFunc>( + library_.GetFunctionPointer("PPP_ShutdownModule")); + if (shutdown_function) + shutdown_function(); } // The "regular" ChildThread implements this function and does some standard @@ -65,29 +74,50 @@ void PpapiThread::OnMsgLoadPlugin(const FilePath& path) { if (!library.is_valid()) return; - // Get the GetInterface function (required). - get_plugin_interface_ = - reinterpret_cast<pp::proxy::Dispatcher::GetInterfaceFunc>( - library.GetFunctionPointer("PPP_GetInterface")); - if (!get_plugin_interface_) { - LOG(WARNING) << "No PPP_GetInterface in plugin library"; - return; - } - - // Get the InitializeModule function (required). - pp::proxy::Dispatcher::InitModuleFunc init_module = - reinterpret_cast<pp::proxy::Dispatcher::InitModuleFunc>( - library.GetFunctionPointer("PPP_InitializeModule")); - if (!init_module) { - LOG(WARNING) << "No PPP_InitializeModule in plugin library"; - return; - } - int32_t init_error = init_module( - local_pp_module_, - &pp::proxy::PluginDispatcher::GetInterfaceFromDispatcher); - if (init_error != PP_OK) { - LOG(WARNING) << "InitModule failed with error " << init_error; - return; + if (is_broker_) { + // Get the InitializeBroker function (required). + InitializeBrokerFunc init_broker = + reinterpret_cast<InitializeBrokerFunc>( + library.GetFunctionPointer("PPP_InitializeBroker")); + if (!init_broker) { + LOG(WARNING) << "No PPP_InitializeBroker in plugin library"; + return; + } + + int32_t init_error = init_broker(&connect_instance_func_); + if (init_error != PP_OK) { + LOG(WARNING) << "InitBroker failed with error " << init_error; + return; + } + if (!connect_instance_func_) { + LOG(WARNING) << "InitBroker did not provide PP_ConnectInstance_Func"; + return; + } + } else { + // Get the GetInterface function (required). + get_plugin_interface_ = + reinterpret_cast<pp::proxy::Dispatcher::GetInterfaceFunc>( + library.GetFunctionPointer("PPP_GetInterface")); + if (!get_plugin_interface_) { + LOG(WARNING) << "No PPP_GetInterface in plugin library"; + return; + } + + // Get the InitializeModule function (required). + pp::proxy::Dispatcher::InitModuleFunc init_module = + reinterpret_cast<pp::proxy::Dispatcher::InitModuleFunc>( + library.GetFunctionPointer("PPP_InitializeModule")); + if (!init_module) { + LOG(WARNING) << "No PPP_InitializeModule in plugin library"; + return; + } + int32_t init_error = init_module( + local_pp_module_, + &pp::proxy::PluginDispatcher::GetInterfaceFromDispatcher); + if (init_error != PP_OK) { + LOG(WARNING) << "InitModule failed with error " << init_error; + return; + } } library_.Reset(library.Release()); @@ -109,6 +139,11 @@ void PpapiThread::OnMsgCreateChannel(base::ProcessHandle host_process_handle, bool PpapiThread::SetupRendererChannel(base::ProcessHandle host_process_handle, int renderer_id, IPC::ChannelHandle* handle) { + // TODO(ddorwin): PluginProcessDispatcher is overkill for the broker. TBD + // whether to create separate dispatcher classes for the broker. + // TODO(ddorwin): Provide connect_instance_func_ when is_broker_. + DCHECK(is_broker_ == (connect_instance_func_ != NULL)); + DCHECK(is_broker_ == (get_plugin_interface_ == NULL)); PluginProcessDispatcher* dispatcher(new PluginProcessDispatcher( host_process_handle, get_plugin_interface_)); @@ -131,4 +166,3 @@ bool PpapiThread::SetupRendererChannel(base::ProcessHandle host_process_handle, // lifetime of the attached channel. return true; } - diff --git a/content/ppapi_plugin/ppapi_thread.h b/content/ppapi_plugin/ppapi_thread.h index b1cd3bf..95cd7dc 100644 --- a/content/ppapi_plugin/ppapi_thread.h +++ b/content/ppapi_plugin/ppapi_thread.h @@ -14,6 +14,7 @@ #include "content/common/child_thread.h" #include "ppapi/c/pp_module.h" #include "ppapi/proxy/dispatcher.h" +#include "ppapi/c/trusted/ppp_broker.h" class FilePath; @@ -30,7 +31,7 @@ class PluginDispatcher; class PpapiThread : public ChildThread, public pp::proxy::Dispatcher::Delegate { public: - PpapiThread(); + explicit PpapiThread(bool is_broker); ~PpapiThread(); private: @@ -53,10 +54,17 @@ class PpapiThread : public ChildThread, int renderer_id, IPC::ChannelHandle* handle); + // True if running in a broker process rather than a normal plugin process. + bool is_broker_; + base::ScopedNativeLibrary library_; pp::proxy::Dispatcher::GetInterfaceFunc get_plugin_interface_; + // Callback to call when a new instance connects to the broker. + // Used only when is_broker_. + PP_ConnectInstance_Func connect_instance_func_; + // Local concept of the module ID. Some functions take this. It's necessary // for the in-process PPAPI to handle this properly, but for proxied it's // unnecessary. The proxy talking to multiple renderers means that each @@ -68,7 +76,7 @@ class PpapiThread : public ChildThread, // See Dispatcher::Delegate::GetGloballySeenInstanceIDSet. std::set<PP_Instance> globally_seen_instance_ids_; - DISALLOW_COPY_AND_ASSIGN(PpapiThread); + DISALLOW_IMPLICIT_CONSTRUCTORS(PpapiThread); }; #endif // CONTENT_PPAPI_PLUGIN_PPAPI_THREAD_H_ diff --git a/ppapi/c/pp_completion_callback.h b/ppapi/c/pp_completion_callback.h index 96edf6f..5778beb1 100644 --- a/ppapi/c/pp_completion_callback.h +++ b/ppapi/c/pp_completion_callback.h @@ -21,7 +21,7 @@ */ /** - * PP_CompletionCallback_Funct defines the signature that you implmeent to + * PP_CompletionCallback_Func defines the signature that you implement to * receive callbacks on asynchronous completion. */ typedef void (*PP_CompletionCallback_Func)(void* user_data, int32_t result); diff --git a/ppapi/c/ppp.h b/ppapi/c/ppp.h index 2a8f182..d901dc5 100644 --- a/ppapi/c/ppp.h +++ b/ppapi/c/ppp.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 The Chromium Authors. All rights reserved. +/* Copyright (c) 2011 The Chromium Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ @@ -60,7 +60,6 @@ PP_EXPORT int32_t PPP_InitializeModule(PP_Module module, */ /** PPP_ShutdownModule() is called before the Native Client module is unloaded. - * Your code must implement this function. */ PP_EXPORT void PPP_ShutdownModule(); /** @@ -97,4 +96,3 @@ PP_EXPORT const void* PPP_GetInterface(const char* interface_name); #endif #endif /* PPAPI_C_PPP_H_ */ - diff --git a/ppapi/c/trusted/ppp_broker.h b/ppapi/c/trusted/ppp_broker.h new file mode 100644 index 0000000..09cd570 --- /dev/null +++ b/ppapi/c/trusted/ppp_broker.h @@ -0,0 +1,90 @@ +/* Copyright (c) 2011 The Chromium Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#ifndef PPAPI_C_TRUSTED_PPP_BROKER_H_ +#define PPAPI_C_TRUSTED_PPP_BROKER_H_ + +#include "ppapi/c/pp_instance.h" +#include "ppapi/c/pp_stdint.h" + +#if __GNUC__ >= 4 +#define PP_EXPORT __attribute__ ((visibility("default"))) +#elif defined(_MSC_VER) +#define PP_EXPORT __declspec(dllexport) +#endif + +/** + * @file + * This file defines functions that your module must implement to support a + * broker. + */ + +// {PENDING: undefine PP_EXPORT?} + + +/* We don't want name mangling for these external functions. We only need + * 'extern "C"' if we're compiling with a C++ compiler. + */ +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup Typedefs + * @{ + */ + +/** + * PP_ConnectInstance_Func defines the signature that you implement to + * receive notifications when a new instance connects to the broker. + * + * @param[in] instance The plugin instance connecting to the broker. + * @param[in] socket Handle to a socket the broker can use to communicate with + * the instance. + * @return PP_OK on success. Any other value on failure. + */ +typedef int32_t (*PP_ConnectInstance_Func)(PP_Instance instance, int socket); +/** + * @} + */ + +/** + * @addtogroup Functions + * @{ + */ + +/** + * PPP_InitializeBroker() is the entry point for a broker and is + * called by the browser when your module loads. Your code must implement this + * function. + * + * Failure indicates to the browser that this broker can not be used. In this + * case, the broker will be unloaded. + * + * @param[out] connect_instance_func A pointer to a connect instance function. + * @return PP_OK on success. Any other value on failure. +*/ +PP_EXPORT int32_t PPP_InitializeBroker( + PP_ConnectInstance_Func* connect_instance_func); +/** + * @} + */ + +/** + * @addtogroup Functions + * @{ + */ + +/** PPP_ShutdownBroker() is called before the broker is unloaded. + */ +PP_EXPORT void PPP_ShutdownBroker(); +/** + * @} + */ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* PPAPI_C_TRUSTED_PPP_BROKER_H_ */ diff --git a/ppapi/ppapi_cpp.gypi b/ppapi/ppapi_cpp.gypi index 959d606..23dccbb 100644 --- a/ppapi/ppapi_cpp.gypi +++ b/ppapi/ppapi_cpp.gypi @@ -104,6 +104,7 @@ 'c/trusted/ppb_image_data_trusted.h', 'c/trusted/ppb_broker_trusted.h', 'c/trusted/ppb_url_loader_trusted.h', + 'c/trusted/ppp_broker.h', ], }, { |