OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CONTENT_BROWSER_PLUGIN_PROCESS_HOST_H_ | |
6 #define CONTENT_BROWSER_PLUGIN_PROCESS_HOST_H_ | |
7 | |
8 #include "build/build_config.h" | |
9 | |
10 #include <stdint.h> | |
11 | |
12 #include <list> | |
13 #include <map> | |
14 #include <set> | |
15 #include <string> | |
16 #include <vector> | |
17 | |
18 #include "base/compiler_specific.h" | |
19 #include "base/macros.h" | |
20 #include "base/memory/ref_counted.h" | |
21 #include "base/process/process_handle.h" | |
22 #include "content/common/content_export.h" | |
23 #include "content/public/browser/browser_child_process_host_delegate.h" | |
24 #include "content/public/browser/browser_child_process_host_iterator.h" | |
25 #include "content/public/common/process_type.h" | |
26 #include "content/public/common/resource_type.h" | |
27 #include "content/public/common/webplugininfo.h" | |
28 #include "ipc/ipc_channel_proxy.h" | |
29 #include "ui/gfx/native_widget_types.h" | |
30 | |
31 struct ResourceHostMsg_Request; | |
32 | |
33 namespace gfx { | |
34 class Rect; | |
35 } | |
36 | |
37 namespace IPC { | |
38 struct ChannelHandle; | |
39 } | |
40 | |
41 namespace net { | |
42 class URLRequestContext; | |
43 } | |
44 | |
45 namespace content { | |
46 class BrowserChildProcessHostImpl; | |
47 class ResourceContext; | |
48 | |
49 // Represents the browser side of the browser <--> plugin communication | |
50 // channel. Different plugins run in their own process, but multiple instances | |
51 // of the same plugin run in the same process. There will be one | |
52 // PluginProcessHost per plugin process, matched with a corresponding | |
53 // PluginProcess running in the plugin process. The browser is responsible for | |
54 // starting the plugin process when a plugin is created that doesn't already | |
55 // have a process. After that, most of the communication is directly between | |
56 // the renderer and plugin processes. | |
57 class CONTENT_EXPORT PluginProcessHost : public BrowserChildProcessHostDelegate, | |
58 public IPC::Sender { | |
59 public: | |
60 class Client { | |
61 public: | |
62 // Returns an opaque unique identifier for the process requesting | |
63 // the channel. | |
64 virtual int ID() = 0; | |
65 // Returns the resource context for the renderer requesting the channel. | |
66 virtual ResourceContext* GetResourceContext() = 0; | |
67 virtual bool OffTheRecord() = 0; | |
68 virtual void SetPluginInfo(const WebPluginInfo& info) = 0; | |
69 virtual void OnFoundPluginProcessHost(PluginProcessHost* host) = 0; | |
70 virtual void OnSentPluginChannelRequest() = 0; | |
71 // The client should delete itself when one of these methods is called. | |
72 virtual void OnChannelOpened(const IPC::ChannelHandle& handle) = 0; | |
73 virtual void OnError() = 0; | |
74 | |
75 protected: | |
76 virtual ~Client() {} | |
77 }; | |
78 | |
79 PluginProcessHost(); | |
80 ~PluginProcessHost() override; | |
81 | |
82 // IPC::Sender implementation: | |
83 bool Send(IPC::Message* message) override; | |
84 | |
85 // Initialize the new plugin process, returning true on success. This must | |
86 // be called before the object can be used. | |
87 bool Init(const WebPluginInfo& info); | |
88 | |
89 // Force the plugin process to shutdown (cleanly). | |
90 void ForceShutdown(); | |
91 | |
92 bool OnMessageReceived(const IPC::Message& msg) override; | |
93 void OnChannelConnected(int32_t peer_pid) override; | |
94 void OnChannelError() override; | |
95 | |
96 // Tells the plugin process to create a new channel for communication with a | |
97 // renderer. When the plugin process responds with the channel name, | |
98 // OnChannelOpened in the client is called. | |
99 void OpenChannelToPlugin(Client* client); | |
100 | |
101 // This function is called to cancel pending requests to open new channels. | |
102 void CancelPendingRequest(Client* client); | |
103 | |
104 // This function is called to cancel sent requests to open new channels. | |
105 void CancelSentRequest(Client* client); | |
106 | |
107 // This function is called on the IO thread once we receive a reply from the | |
108 // modal HTML dialog (in the form of a JSON string). This function forwards | |
109 // that reply back to the plugin that requested the dialog. | |
110 void OnModalDialogResponse(const std::string& json_retval, | |
111 IPC::Message* sync_result); | |
112 | |
113 #if defined(OS_MACOSX) | |
114 // This function is called on the IO thread when the browser becomes the | |
115 // active application. | |
116 void OnAppActivation(); | |
117 #endif | |
118 | |
119 const WebPluginInfo& info() const { return info_; } | |
120 | |
121 #if defined(OS_WIN) | |
122 // Tracks plugin parent windows created on the browser UI thread. | |
123 void AddWindow(HWND window); | |
124 #endif | |
125 | |
126 // Given a pid of a plugin process, returns the plugin information in |info| | |
127 // if we know about that process. Otherwise returns false. | |
128 // This method can be called on any thread. | |
129 static bool GetWebPluginInfoFromPluginPid(base::ProcessId pid, | |
130 WebPluginInfo* info); | |
131 | |
132 private: | |
133 // Sends a message to the plugin process to request creation of a new channel | |
134 // for the given mime type. | |
135 void RequestPluginChannel(Client* client); | |
136 | |
137 // Message handlers. | |
138 void OnChannelCreated(const IPC::ChannelHandle& channel_handle); | |
139 void OnChannelDestroyed(int renderer_id); | |
140 | |
141 #if defined(OS_MACOSX) | |
142 void OnPluginShowWindow(uint32_t window_id, | |
143 gfx::Rect window_rect, | |
144 bool modal); | |
145 void OnPluginHideWindow(uint32_t window_id, gfx::Rect window_rect); | |
146 void OnPluginSetCursorVisibility(bool visible); | |
147 #endif | |
148 | |
149 bool CanShutdown() override; | |
150 void OnProcessCrashed(int exit_code) override; | |
151 | |
152 void CancelRequests(); | |
153 | |
154 // Callback for ResourceMessageFilter. | |
155 void GetContexts(ResourceType resource_type, | |
156 int origin_pid, | |
157 ResourceContext** resource_context, | |
158 net::URLRequestContext** request_context); | |
159 | |
160 // These are channel requests that we are waiting to send to the | |
161 // plugin process once the channel is opened. | |
162 std::vector<Client*> pending_requests_; | |
163 | |
164 // These are the channel requests that we have already sent to | |
165 // the plugin process, but haven't heard back about yet. | |
166 std::list<Client*> sent_requests_; | |
167 | |
168 // Information about the plugin. | |
169 WebPluginInfo info_; | |
170 | |
171 // The pid of the plugin process. | |
172 int pid_; | |
173 | |
174 #if defined(OS_MACOSX) | |
175 // Tracks plugin windows currently visible. | |
176 std::set<uint32_t> plugin_visible_windows_set_; | |
177 // Tracks full screen windows currently visible. | |
178 std::set<uint32_t> plugin_fullscreen_windows_set_; | |
179 // Tracks modal windows currently visible. | |
180 std::set<uint32_t> plugin_modal_windows_set_; | |
181 // Tracks the current visibility of the cursor. | |
182 bool plugin_cursor_visible_; | |
183 #endif | |
184 | |
185 // Map from render_process_id to its ResourceContext. Instead of storing the | |
186 // raw pointer, we store the struct below. This is needed because a renderer | |
187 // process can actually have multiple IPC channels to the same plugin process, | |
188 // depending on timing conditions with plugin instance creation and shutdown. | |
189 struct ResourceContextEntry { | |
190 ResourceContext* resource_context; | |
191 int ref_count; | |
192 }; | |
193 typedef std::map<int, ResourceContextEntry> ResourceContextMap; | |
194 ResourceContextMap resource_context_map_; | |
195 | |
196 scoped_ptr<BrowserChildProcessHostImpl> process_; | |
197 | |
198 DISALLOW_COPY_AND_ASSIGN(PluginProcessHost); | |
199 }; | |
200 | |
201 class PluginProcessHostIterator | |
202 : public BrowserChildProcessHostTypeIterator<PluginProcessHost> { | |
203 public: | |
204 PluginProcessHostIterator() | |
205 : BrowserChildProcessHostTypeIterator<PluginProcessHost>( | |
206 PROCESS_TYPE_PLUGIN) {} | |
207 }; | |
208 | |
209 } // namespace content | |
210 | |
211 #endif // CONTENT_BROWSER_PLUGIN_PROCESS_HOST_H_ | |
OLD | NEW |