Update V8 to version 4.7.20.
[chromium-blink-merge.git] / content / ppapi_plugin / ppapi_thread.h
blobed09b1f548b005627faaddc07beccbbd05b839b3
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_
8 #include <map>
9 #include <string>
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_impl.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"
26 #if defined(OS_WIN)
27 #include "base/win/scoped_handle.h"
28 #endif
30 namespace base {
31 class CommandLine;
32 class FilePath;
35 namespace IPC {
36 struct ChannelHandle;
39 namespace content {
41 class PpapiBlinkPlatformImpl;
43 #if defined(COMPILER_MSVC)
44 // See explanation for other RenderViewHostImpl which is the same issue.
45 #pragma warning(push)
46 #pragma warning(disable: 4250)
47 #endif
49 class PpapiThread : public ChildThreadImpl,
50 public ppapi::proxy::PluginDispatcher::PluginDelegate,
51 public ppapi::proxy::PluginProxyDelegate {
52 public:
53 PpapiThread(const base::CommandLine& command_line, bool is_broker);
54 ~PpapiThread() override;
55 void Shutdown() override;
57 private:
58 // Make sure the enum list in tools/histogram/histograms.xml is updated with
59 // any change in this list.
60 enum LoadResult {
61 LOAD_SUCCESS,
62 LOAD_FAILED,
63 ENTRY_POINT_MISSING,
64 INIT_FAILED,
65 FILE_MISSING,
66 // NOTE: Add new values only immediately above this line.
67 LOAD_RESULT_MAX // Boundary value for UMA_HISTOGRAM_ENUMERATION.
70 // ChildThread overrides.
71 bool Send(IPC::Message* msg) override;
72 bool OnControlMessageReceived(const IPC::Message& msg) override;
73 void OnChannelConnected(int32 peer_pid) override;
75 // PluginDispatcher::PluginDelegate implementation.
76 std::set<PP_Instance>* GetGloballySeenInstanceIDSet() override;
77 base::SingleThreadTaskRunner* GetIPCTaskRunner() override;
78 base::WaitableEvent* GetShutdownEvent() override;
79 IPC::PlatformFileForTransit ShareHandleWithRemote(
80 base::PlatformFile handle,
81 base::ProcessId peer_pid,
82 bool should_close_source) override;
83 base::SharedMemoryHandle ShareSharedMemoryHandleWithRemote(
84 const base::SharedMemoryHandle& handle,
85 base::ProcessId remote_pid) override;
86 uint32 Register(ppapi::proxy::PluginDispatcher* plugin_dispatcher) override;
87 void Unregister(uint32 plugin_dispatcher_id) override;
89 // PluginProxyDelegate.
90 // SendToBrowser() is intended to be safe to use on another thread so
91 // long as the main PpapiThread outlives it.
92 IPC::Sender* GetBrowserSender() override;
93 std::string GetUILanguage() override;
94 void PreCacheFontForFlash(const void* logfontw) override;
95 void SetActiveURL(const std::string& url) override;
96 PP_Resource CreateBrowserFont(ppapi::proxy::Connection connection,
97 PP_Instance instance,
98 const PP_BrowserFont_Trusted_Description& desc,
99 const ppapi::Preferences& prefs) override;
101 // Message handlers.
102 void OnLoadPlugin(const base::FilePath& path,
103 const ppapi::PpapiPermissions& permissions);
104 void OnCreateChannel(base::ProcessId renderer_pid,
105 int renderer_child_id,
106 bool incognito);
107 void OnSetNetworkState(bool online);
108 void OnCrash();
109 void OnHang();
111 // Sets up the channel to the given renderer. On success, returns true and
112 // fills the given ChannelHandle with the information from the new channel.
113 bool SetupRendererChannel(base::ProcessId renderer_pid,
114 int renderer_child_id,
115 bool incognito,
116 IPC::ChannelHandle* handle);
118 // Sets up the name of the plugin for logging using the given path.
119 void SavePluginName(const base::FilePath& path);
121 void ReportLoadResult(const base::FilePath& path, LoadResult result);
123 // Reports |error| to UMA when plugin load fails.
124 void ReportLoadErrorCode(const base::FilePath& path,
125 const base::NativeLibraryLoadError& error);
127 // Reports time to load the plugin.
128 void ReportLoadTime(const base::FilePath& path,
129 const base::TimeDelta load_time);
131 // True if running in a broker process rather than a normal plugin process.
132 bool is_broker_;
134 base::ScopedNativeLibrary library_;
136 ppapi::PpapiPermissions permissions_;
138 // Global state tracking for the proxy.
139 ppapi::proxy::PluginGlobals plugin_globals_;
141 // Storage for plugin entry points.
142 PepperPluginInfo::EntryPoints plugin_entry_points_;
144 // Callback to call when a new instance connects to the broker.
145 // Used only when is_broker_.
146 PP_ConnectInstance_Func connect_instance_func_;
148 // Local concept of the module ID. Some functions take this. It's necessary
149 // for the in-process PPAPI to handle this properly, but for proxied it's
150 // unnecessary. The proxy talking to multiple renderers means that each
151 // renderer has a different idea of what the module ID is for this plugin.
152 // To force people to "do the right thing" we generate a random module ID
153 // and pass it around as necessary.
154 PP_Module local_pp_module_;
156 // See Dispatcher::Delegate::GetGloballySeenInstanceIDSet.
157 std::set<PP_Instance> globally_seen_instance_ids_;
159 // The PluginDispatcher instances contained in the map are not owned by it.
160 std::map<uint32, ppapi::proxy::PluginDispatcher*> plugin_dispatchers_;
161 uint32 next_plugin_dispatcher_id_;
163 // The BlinkPlatformImpl implementation.
164 scoped_ptr<PpapiBlinkPlatformImpl> blink_platform_impl_;
166 #if defined(OS_WIN)
167 // Caches the handle to the peer process if this is a broker.
168 base::win::ScopedHandle peer_handle_;
169 #endif
171 DISALLOW_IMPLICIT_CONSTRUCTORS(PpapiThread);
174 #if defined(COMPILER_MSVC)
175 #pragma warning(pop)
176 #endif
178 } // namespace content
180 #endif // CONTENT_PPAPI_PLUGIN_PPAPI_THREAD_H_