[content shell] hook up testRunner.dumpEditingCallbacks
[chromium-blink-merge.git] / content / ppapi_plugin / ppapi_thread.h
blob6d5bb16a575ddc8feb8ef153f3d2ffb9bf7195a4
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.h"
15 #include "base/scoped_native_library.h"
16 #include "build/build_config.h"
17 #include "content/common/child_thread.h"
18 #include "ppapi/c/pp_module.h"
19 #include "ppapi/c/trusted/ppp_broker.h"
20 #include "ppapi/proxy/plugin_dispatcher.h"
21 #include "ppapi/proxy/plugin_globals.h"
22 #include "ppapi/proxy/plugin_proxy_delegate.h"
23 #include "webkit/plugins/ppapi/plugin_module.h"
25 #if defined(OS_WIN)
26 #include "base/win/scoped_handle.h"
27 #endif
29 class CommandLine;
30 class FilePath;
32 namespace IPC {
33 struct ChannelHandle;
36 namespace content {
38 class PpapiWebKitPlatformSupportImpl;
40 class PpapiThread : public ChildThread,
41 public ppapi::proxy::PluginDispatcher::PluginDelegate,
42 public ppapi::proxy::PluginProxyDelegate {
43 public:
44 PpapiThread(const CommandLine& command_line, bool is_broker);
45 virtual ~PpapiThread();
47 private:
48 // ChildThread overrides.
49 virtual bool Send(IPC::Message* msg) OVERRIDE;
50 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
51 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
53 // PluginDispatcher::PluginDelegate implementation.
54 virtual std::set<PP_Instance>* GetGloballySeenInstanceIDSet() OVERRIDE;
55 virtual base::MessageLoopProxy* GetIPCMessageLoop() OVERRIDE;
56 virtual base::WaitableEvent* GetShutdownEvent() OVERRIDE;
57 virtual IPC::PlatformFileForTransit ShareHandleWithRemote(
58 base::PlatformFile handle,
59 const IPC::SyncChannel& channel,
60 bool should_close_source) OVERRIDE;
61 virtual uint32 Register(
62 ppapi::proxy::PluginDispatcher* plugin_dispatcher) OVERRIDE;
63 virtual void Unregister(uint32 plugin_dispatcher_id) OVERRIDE;
65 // PluginProxyDelegate.
66 // SendToBrowser() is intended to be safe to use on another thread so
67 // long as the main PpapiThread outlives it.
68 virtual IPC::Sender* GetBrowserSender() OVERRIDE;
69 virtual std::string GetUILanguage() OVERRIDE;
70 virtual void PreCacheFont(const void* logfontw) OVERRIDE;
71 virtual void SetActiveURL(const std::string& url) OVERRIDE;
73 // Message handlers.
74 void OnMsgLoadPlugin(const FilePath& path,
75 const ppapi::PpapiPermissions& permissions);
76 void OnMsgCreateChannel(int renderer_id,
77 bool incognito);
78 void OnMsgResourceReply(
79 const ppapi::proxy::ResourceMessageReplyParams& reply_params,
80 const IPC::Message& nested_msg);
81 void OnMsgSetNetworkState(bool online);
82 void OnPluginDispatcherMessageReceived(const IPC::Message& msg);
84 // Sets up the channel to the given renderer. On success, returns true and
85 // fills the given ChannelHandle with the information from the new channel.
86 bool SetupRendererChannel(int renderer_id,
87 bool incognito,
88 IPC::ChannelHandle* handle);
90 // Sets up the name of the plugin for logging using the given path.
91 void SavePluginName(const FilePath& path);
93 // True if running in a broker process rather than a normal plugin process.
94 bool is_broker_;
96 base::ScopedNativeLibrary library_;
98 ppapi::PpapiPermissions permissions_;
100 // Global state tracking for the proxy.
101 ppapi::proxy::PluginGlobals plugin_globals_;
103 // Storage for plugin entry points.
104 webkit::ppapi::PluginModule::EntryPoints plugin_entry_points_;
106 // Callback to call when a new instance connects to the broker.
107 // Used only when is_broker_.
108 PP_ConnectInstance_Func connect_instance_func_;
110 // Local concept of the module ID. Some functions take this. It's necessary
111 // for the in-process PPAPI to handle this properly, but for proxied it's
112 // unnecessary. The proxy talking to multiple renderers means that each
113 // renderer has a different idea of what the module ID is for this plugin.
114 // To force people to "do the right thing" we generate a random module ID
115 // and pass it around as necessary.
116 PP_Module local_pp_module_;
118 // See Dispatcher::Delegate::GetGloballySeenInstanceIDSet.
119 std::set<PP_Instance> globally_seen_instance_ids_;
121 // The PluginDispatcher instances contained in the map are not owned by it.
122 std::map<uint32, ppapi::proxy::PluginDispatcher*> plugin_dispatchers_;
123 uint32 next_plugin_dispatcher_id_;
125 // The WebKitPlatformSupport implementation.
126 scoped_ptr<PpapiWebKitPlatformSupportImpl> webkit_platform_support_;
128 #if defined(OS_WIN)
129 // Caches the handle to the peer process if this is a broker.
130 base::win::ScopedHandle peer_handle_;
131 #endif
133 DISALLOW_IMPLICIT_CONSTRUCTORS(PpapiThread);
136 } // namespace content
138 #endif // CONTENT_PPAPI_PLUGIN_PPAPI_THREAD_H_