[email protected] | 3513551 | 2009-07-23 20:36:49 | [diff] [blame] | 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | aa2da5a | 2008-08-08 07:56:39 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_PLUGIN_PROCESS_HOST_H_ |
| 6 | #define CHROME_BROWSER_PLUGIN_PROCESS_HOST_H_ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 7 | |
[email protected] | 6eaddcc | 2009-02-23 21:03:04 | [diff] [blame] | 8 | #include "build/build_config.h" |
| 9 | |
[email protected] | 4566f13 | 2009-03-12 01:55:13 | [diff] [blame] | 10 | #include <queue> |
[email protected] | 2456c57 | 2009-11-09 04:21:51 | [diff] [blame] | 11 | #include <set> |
| 12 | #include <string> |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 13 | #include <vector> |
| 14 | |
[email protected] | 010ea08a | 2009-10-11 20:21:32 | [diff] [blame] | 15 | #include "app/gfx/native_widget_types.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 16 | #include "base/basictypes.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 17 | #include "base/scoped_ptr.h" |
| 18 | #include "base/task.h" |
[email protected] | 41b2780f | 2009-01-31 01:34:20 | [diff] [blame] | 19 | #include "chrome/browser/net/resolve_proxy_msg_helper.h" |
[email protected] | b5bb35f | 2009-02-05 20:17:07 | [diff] [blame] | 20 | #include "chrome/browser/renderer_host/resource_message_filter.h" |
[email protected] | 6dffde32 | 2009-02-18 03:47:48 | [diff] [blame] | 21 | #include "chrome/common/child_process_host.h" |
[email protected] | 946d1b2 | 2009-07-22 23:57:21 | [diff] [blame] | 22 | #include "ipc/ipc_channel_handle.h" |
[email protected] | 706f2dc | 2009-04-24 17:17:45 | [diff] [blame] | 23 | #include "webkit/glue/webplugininfo.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 24 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 25 | class URLRequestContext; |
| 26 | struct ViewHostMsg_Resource_Request; |
| 27 | class GURL; |
| 28 | |
| 29 | // Represents the browser side of the browser <--> plugin communication |
| 30 | // channel. Different plugins run in their own process, but multiple instances |
| 31 | // of the same plugin run in the same process. There will be one |
| 32 | // PluginProcessHost per plugin process, matched with a corresponding |
| 33 | // PluginProcess running in the plugin process. The browser is responsible for |
| 34 | // starting the plugin process when a plugin is created that doesn't already |
| 35 | // have a process. After that, most of the communication is directly between |
| 36 | // the renderer and plugin processes. |
[email protected] | 6dffde32 | 2009-02-18 03:47:48 | [diff] [blame] | 37 | class PluginProcessHost : public ChildProcessHost, |
[email protected] | 41b2780f | 2009-01-31 01:34:20 | [diff] [blame] | 38 | public ResolveProxyMsgHelper::Delegate { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 39 | public: |
[email protected] | dabe607 | 2009-03-17 00:52:35 | [diff] [blame] | 40 | PluginProcessHost(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 41 | ~PluginProcessHost(); |
| 42 | |
| 43 | // Initialize the new plugin process, returning true on success. This must |
[email protected] | 610c089 | 2009-09-08 19:46:18 | [diff] [blame] | 44 | // be called before the object can be used. |
| 45 | bool Init(const WebPluginInfo& info, const std::wstring& locale); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 46 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 47 | virtual void OnMessageReceived(const IPC::Message& msg); |
| 48 | virtual void OnChannelConnected(int32 peer_pid); |
| 49 | virtual void OnChannelError(); |
| 50 | |
[email protected] | 41b2780f | 2009-01-31 01:34:20 | [diff] [blame] | 51 | // ResolveProxyMsgHelper::Delegate implementation: |
| 52 | virtual void OnResolveProxyCompleted(IPC::Message* reply_msg, |
| 53 | int result, |
| 54 | const std::string& proxy_list); |
| 55 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 56 | // Tells the plugin process to create a new channel for communication with a |
| 57 | // renderer. When the plugin process responds with the channel name, |
| 58 | // reply_msg is used to send the name to the renderer. |
| 59 | void OpenChannelToPlugin(ResourceMessageFilter* renderer_message_filter, |
| 60 | const std::string& mime_type, |
| 61 | IPC::Message* reply_msg); |
| 62 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 63 | // Sends the reply to an open channel request to the renderer with the given |
| 64 | // channel name. |
| 65 | static void ReplyToRenderer(ResourceMessageFilter* renderer_message_filter, |
[email protected] | d2e884d | 2009-06-22 20:37:52 | [diff] [blame] | 66 | const IPC::ChannelHandle& channel, |
[email protected] | 8a3b796 | 2009-09-04 05:53:23 | [diff] [blame] | 67 | const WebPluginInfo& info, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 68 | IPC::Message* reply_msg); |
| 69 | |
| 70 | // This function is called on the IO thread once we receive a reply from the |
| 71 | // modal HTML dialog (in the form of a JSON string). This function forwards |
| 72 | // that reply back to the plugin that requested the dialog. |
| 73 | void OnModalDialogResponse(const std::string& json_retval, |
| 74 | IPC::Message* sync_result); |
| 75 | |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 76 | #if defined(OS_MACOSX) |
| 77 | // This function is called on the IO thread when the browser becomes the |
| 78 | // active application. |
| 79 | void OnAppActivation(); |
| 80 | #endif |
| 81 | |
[email protected] | a436d92 | 2009-02-13 23:16:42 | [diff] [blame] | 82 | const WebPluginInfo& info() const { return info_; } |
| 83 | |
[email protected] | 20b64d3 | 2009-03-05 02:07:18 | [diff] [blame] | 84 | #if defined(OS_WIN) |
| 85 | // Tracks plugin parent windows created on the browser UI thread. |
| 86 | void AddWindow(HWND window); |
| 87 | #endif |
| 88 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 89 | private: |
[email protected] | 63de95b | 2008-12-10 04:11:27 | [diff] [blame] | 90 | friend class PluginResolveProxyHelper; |
| 91 | |
[email protected] | dabe607 | 2009-03-17 00:52:35 | [diff] [blame] | 92 | // ResourceDispatcherHost::Receiver implementation: |
| 93 | virtual URLRequestContext* GetRequestContext( |
| 94 | uint32 request_id, |
| 95 | const ViewHostMsg_Resource_Request& request_data); |
| 96 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 97 | // Sends a message to the plugin process to request creation of a new channel |
| 98 | // for the given mime type. |
| 99 | void RequestPluginChannel(ResourceMessageFilter* renderer_message_filter, |
| 100 | const std::string& mime_type, |
| 101 | IPC::Message* reply_msg); |
[email protected] | fb1277e8 | 2009-11-21 20:32:30 | [diff] [blame] | 102 | |
| 103 | virtual void OnProcessLaunched(); |
| 104 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 105 | // Message handlers. |
[email protected] | 3dfc7a4 | 2009-06-27 01:43:51 | [diff] [blame] | 106 | void OnChannelCreated(const IPC::ChannelHandle& channel_handle); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 107 | void OnGetPluginFinderUrl(std::string* plugin_finder_url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 108 | void OnGetCookies(uint32 request_context, const GURL& url, |
| 109 | std::string* cookies); |
[email protected] | c84a785 | 2009-09-16 21:36:44 | [diff] [blame] | 110 | void OnAccessFiles(int renderer_id, const std::vector<std::string>& files, |
[email protected] | 3513551 | 2009-07-23 20:36:49 | [diff] [blame] | 111 | bool* allowed); |
[email protected] | 63de95b | 2008-12-10 04:11:27 | [diff] [blame] | 112 | void OnResolveProxy(const GURL& url, IPC::Message* reply_msg); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 113 | void OnPluginMessage(const std::vector<uint8>& data); |
[email protected] | 6eaddcc | 2009-02-23 21:03:04 | [diff] [blame] | 114 | |
| 115 | #if defined(OS_WIN) |
[email protected] | 875d489 | 2009-04-21 21:48:36 | [diff] [blame] | 116 | void OnPluginWindowDestroyed(HWND window, HWND parent); |
[email protected] | 76543b9 | 2009-08-31 17:27:45 | [diff] [blame] | 117 | void OnDownloadUrl(const std::string& url, int source_child_unique_id, |
[email protected] | 829c284 | 2009-04-01 01:48:52 | [diff] [blame] | 118 | gfx::NativeWindow caller_window); |
[email protected] | 6eaddcc | 2009-02-23 21:03:04 | [diff] [blame] | 119 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 120 | |
[email protected] | 700d3d5 | 2009-07-07 17:40:46 | [diff] [blame] | 121 | #if defined(OS_LINUX) |
| 122 | void OnMapNativeViewId(gfx::NativeViewId id, gfx::PluginWindowHandle* output); |
| 123 | #endif |
| 124 | |
[email protected] | 1d5ac66 | 2009-10-01 19:41:56 | [diff] [blame] | 125 | #if defined(OS_MACOSX) |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 126 | void OnPluginSelectWindow(uint32 window_id, gfx::Rect window_rect, |
| 127 | bool modal); |
| 128 | void OnPluginShowWindow(uint32 window_id, gfx::Rect window_rect, |
| 129 | bool modal); |
[email protected] | 1d5ac66 | 2009-10-01 19:41:56 | [diff] [blame] | 130 | void OnPluginHideWindow(uint32 window_id, gfx::Rect window_rect); |
[email protected] | 27f5a6c8 | 2009-11-20 18:26:16 | [diff] [blame] | 131 | void OnPluginReceivedFocus(int process_id, int instance_id); |
[email protected] | 1d5ac66 | 2009-10-01 19:41:56 | [diff] [blame] | 132 | #endif |
| 133 | |
[email protected] | 51d70e0 | 2009-03-27 20:45:59 | [diff] [blame] | 134 | virtual bool CanShutdown() { return sent_requests_.empty(); } |
| 135 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 136 | struct ChannelRequest { |
| 137 | ChannelRequest(ResourceMessageFilter* renderer_message_filter, |
[email protected] | 3dfc7a4 | 2009-06-27 01:43:51 | [diff] [blame] | 138 | const std::string& m, IPC::Message* r) : |
[email protected] | 6eaddcc | 2009-02-23 21:03:04 | [diff] [blame] | 139 | mime_type(m), reply_msg(r), |
[email protected] | 3dfc7a4 | 2009-06-27 01:43:51 | [diff] [blame] | 140 | renderer_message_filter_(renderer_message_filter) { } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 141 | std::string mime_type; |
| 142 | IPC::Message* reply_msg; |
| 143 | scoped_refptr<ResourceMessageFilter> renderer_message_filter_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | // These are channel requests that we are waiting to send to the |
| 147 | // plugin process once the channel is opened. |
| 148 | std::vector<ChannelRequest> pending_requests_; |
| 149 | |
| 150 | // These are the channel requests that we have already sent to |
| 151 | // the plugin process, but haven't heard back about yet. |
[email protected] | 4566f13 | 2009-03-12 01:55:13 | [diff] [blame] | 152 | std::queue<ChannelRequest> sent_requests_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 153 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 154 | // Information about the plugin. |
| 155 | WebPluginInfo info_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 156 | |
[email protected] | 41b2780f | 2009-01-31 01:34:20 | [diff] [blame] | 157 | // Helper class for handling PluginProcessHost_ResolveProxy messages (manages |
| 158 | // the requests to the proxy service). |
| 159 | ResolveProxyMsgHelper resolve_proxy_msg_helper_; |
[email protected] | 63de95b | 2008-12-10 04:11:27 | [diff] [blame] | 160 | |
[email protected] | 20b64d3 | 2009-03-05 02:07:18 | [diff] [blame] | 161 | #if defined(OS_WIN) |
| 162 | // Tracks plugin parent windows created on the UI thread. |
| 163 | std::set<HWND> plugin_parent_windows_set_; |
| 164 | #endif |
[email protected] | 1d5ac66 | 2009-10-01 19:41:56 | [diff] [blame] | 165 | #if defined(OS_MACOSX) |
| 166 | // Tracks plugin windows currently visible |
| 167 | std::set<uint32> plugin_visible_windows_set_; |
[email protected] | b44dbd1 | 2009-10-11 19:02:15 | [diff] [blame] | 168 | // Tracks full screen windows currently visible |
| 169 | std::set<uint32> plugin_fullscreen_windows_set_; |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 170 | // Tracks modal windows currently visible |
| 171 | std::set<uint32> plugin_modal_windows_set_; |
[email protected] | 1d5ac66 | 2009-10-01 19:41:56 | [diff] [blame] | 172 | #endif |
[email protected] | 20b64d3 | 2009-03-05 02:07:18 | [diff] [blame] | 173 | |
[email protected] | 2735e369 | 2009-09-25 18:19:39 | [diff] [blame] | 174 | DISALLOW_COPY_AND_ASSIGN(PluginProcessHost); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 175 | }; |
| 176 | |
[email protected] | aa2da5a | 2008-08-08 07:56:39 | [diff] [blame] | 177 | #endif // CHROME_BROWSER_PLUGIN_PROCESS_HOST_H_ |