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
3 // found in the LICENSE file.
5 #ifndef CONTENT_PPAPI_PLUGIN_PPAPI_THREAD_H_
6 #define CONTENT_PPAPI_PLUGIN_PPAPI_THREAD_H_
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/process/process.h"
15 #include "base/scoped_native_library.h"
16 #include "build/build_config.h"
17 #include "content/child/child_thread.h"
18 #include "content/public/common/pepper_plugin_info.h"
19 #include "ppapi/c/pp_module.h"
20 #include "ppapi/c/trusted/ppp_broker.h"
21 #include "ppapi/proxy/connection.h"
22 #include "ppapi/proxy/plugin_dispatcher.h"
23 #include "ppapi/proxy/plugin_globals.h"
24 #include "ppapi/proxy/plugin_proxy_delegate.h"
27 #include "base/win/scoped_handle.h"
41 class PpapiBlinkPlatformImpl
;
43 class PpapiThread
: public ChildThread
,
44 public ppapi::proxy::PluginDispatcher::PluginDelegate
,
45 public ppapi::proxy::PluginProxyDelegate
{
47 PpapiThread(const base::CommandLine
& command_line
, bool is_broker
);
48 ~PpapiThread() override
;
49 void Shutdown() override
;
52 // Make sure the enum list in tools/histogram/histograms.xml is updated with
53 // any change in this list.
60 // NOTE: Add new values only immediately above this line.
61 LOAD_RESULT_MAX
// Boundary value for UMA_HISTOGRAM_ENUMERATION.
64 // ChildThread overrides.
65 bool Send(IPC::Message
* msg
) override
;
66 bool OnControlMessageReceived(const IPC::Message
& msg
) override
;
67 void OnChannelConnected(int32 peer_pid
) override
;
69 // PluginDispatcher::PluginDelegate implementation.
70 std::set
<PP_Instance
>* GetGloballySeenInstanceIDSet() override
;
71 base::MessageLoopProxy
* GetIPCMessageLoop() override
;
72 base::WaitableEvent
* GetShutdownEvent() override
;
73 IPC::PlatformFileForTransit
ShareHandleWithRemote(
74 base::PlatformFile handle
,
75 base::ProcessId peer_pid
,
76 bool should_close_source
) override
;
77 uint32
Register(ppapi::proxy::PluginDispatcher
* plugin_dispatcher
) override
;
78 void Unregister(uint32 plugin_dispatcher_id
) override
;
80 // PluginProxyDelegate.
81 // SendToBrowser() is intended to be safe to use on another thread so
82 // long as the main PpapiThread outlives it.
83 IPC::Sender
* GetBrowserSender() override
;
84 std::string
GetUILanguage() override
;
85 void PreCacheFont(const void* logfontw
) override
;
86 void SetActiveURL(const std::string
& url
) override
;
87 PP_Resource
CreateBrowserFont(ppapi::proxy::Connection connection
,
89 const PP_BrowserFont_Trusted_Description
& desc
,
90 const ppapi::Preferences
& prefs
) override
;
93 void OnLoadPlugin(const base::FilePath
& path
,
94 const ppapi::PpapiPermissions
& permissions
);
95 void OnCreateChannel(base::ProcessId renderer_pid
,
96 int renderer_child_id
,
98 void OnSetNetworkState(bool online
);
102 // Sets up the channel to the given renderer. On success, returns true and
103 // fills the given ChannelHandle with the information from the new channel.
104 bool SetupRendererChannel(base::ProcessId renderer_pid
,
105 int renderer_child_id
,
107 IPC::ChannelHandle
* handle
);
109 // Sets up the name of the plugin for logging using the given path.
110 void SavePluginName(const base::FilePath
& path
);
112 void ReportLoadResult(const base::FilePath
& path
, LoadResult result
);
114 // Reports |error| to UMA when plugin load fails.
115 void ReportLoadErrorCode(const base::FilePath
& path
,
116 const base::NativeLibraryLoadError
& error
);
118 // True if running in a broker process rather than a normal plugin process.
121 base::ScopedNativeLibrary library_
;
123 ppapi::PpapiPermissions permissions_
;
125 // Global state tracking for the proxy.
126 ppapi::proxy::PluginGlobals plugin_globals_
;
128 // Storage for plugin entry points.
129 PepperPluginInfo::EntryPoints plugin_entry_points_
;
131 // Callback to call when a new instance connects to the broker.
132 // Used only when is_broker_.
133 PP_ConnectInstance_Func connect_instance_func_
;
135 // Local concept of the module ID. Some functions take this. It's necessary
136 // for the in-process PPAPI to handle this properly, but for proxied it's
137 // unnecessary. The proxy talking to multiple renderers means that each
138 // renderer has a different idea of what the module ID is for this plugin.
139 // To force people to "do the right thing" we generate a random module ID
140 // and pass it around as necessary.
141 PP_Module local_pp_module_
;
143 // See Dispatcher::Delegate::GetGloballySeenInstanceIDSet.
144 std::set
<PP_Instance
> globally_seen_instance_ids_
;
146 // The PluginDispatcher instances contained in the map are not owned by it.
147 std::map
<uint32
, ppapi::proxy::PluginDispatcher
*> plugin_dispatchers_
;
148 uint32 next_plugin_dispatcher_id_
;
150 // The BlinkPlatformImpl implementation.
151 scoped_ptr
<PpapiBlinkPlatformImpl
> blink_platform_impl_
;
154 // Caches the handle to the peer process if this is a broker.
155 base::win::ScopedHandle peer_handle_
;
158 DISALLOW_IMPLICIT_CONSTRUCTORS(PpapiThread
);
161 } // namespace content
163 #endif // CONTENT_PPAPI_PLUGIN_PPAPI_THREAD_H_