blob: aee437a5b96d8aee330e95d0f2e1524e8d722be3 [file] [log] [blame]
[email protected]35135512009-07-23 20:36:491// Copyright (c) 2009 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]aa2da5a2008-08-08 07:56:395#ifndef CHROME_BROWSER_PLUGIN_PROCESS_HOST_H_
6#define CHROME_BROWSER_PLUGIN_PROCESS_HOST_H_
initial.commit09911bf2008-07-26 23:55:297
[email protected]6eaddcc2009-02-23 21:03:048#include "build/build_config.h"
9
[email protected]4566f132009-03-12 01:55:1310#include <queue>
[email protected]2456c572009-11-09 04:21:5111#include <set>
12#include <string>
initial.commit09911bf2008-07-26 23:55:2913#include <vector>
14
[email protected]010ea08a2009-10-11 20:21:3215#include "app/gfx/native_widget_types.h"
initial.commit09911bf2008-07-26 23:55:2916#include "base/basictypes.h"
initial.commit09911bf2008-07-26 23:55:2917#include "base/scoped_ptr.h"
18#include "base/task.h"
[email protected]41b2780f2009-01-31 01:34:2019#include "chrome/browser/net/resolve_proxy_msg_helper.h"
[email protected]b5bb35f2009-02-05 20:17:0720#include "chrome/browser/renderer_host/resource_message_filter.h"
[email protected]6dffde322009-02-18 03:47:4821#include "chrome/common/child_process_host.h"
[email protected]946d1b22009-07-22 23:57:2122#include "ipc/ipc_channel_handle.h"
[email protected]706f2dc2009-04-24 17:17:4523#include "webkit/glue/webplugininfo.h"
initial.commit09911bf2008-07-26 23:55:2924
initial.commit09911bf2008-07-26 23:55:2925class URLRequestContext;
26struct ViewHostMsg_Resource_Request;
27class 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]6dffde322009-02-18 03:47:4837class PluginProcessHost : public ChildProcessHost,
[email protected]41b2780f2009-01-31 01:34:2038 public ResolveProxyMsgHelper::Delegate {
initial.commit09911bf2008-07-26 23:55:2939 public:
[email protected]dabe6072009-03-17 00:52:3540 PluginProcessHost();
initial.commit09911bf2008-07-26 23:55:2941 ~PluginProcessHost();
42
43 // Initialize the new plugin process, returning true on success. This must
[email protected]610c0892009-09-08 19:46:1844 // be called before the object can be used.
45 bool Init(const WebPluginInfo& info, const std::wstring& locale);
initial.commit09911bf2008-07-26 23:55:2946
initial.commit09911bf2008-07-26 23:55:2947 virtual void OnMessageReceived(const IPC::Message& msg);
48 virtual void OnChannelConnected(int32 peer_pid);
49 virtual void OnChannelError();
50
[email protected]41b2780f2009-01-31 01:34:2051 // ResolveProxyMsgHelper::Delegate implementation:
52 virtual void OnResolveProxyCompleted(IPC::Message* reply_msg,
53 int result,
54 const std::string& proxy_list);
55
initial.commit09911bf2008-07-26 23:55:2956 // 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.commit09911bf2008-07-26 23:55:2963 // 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]d2e884d2009-06-22 20:37:5266 const IPC::ChannelHandle& channel,
[email protected]8a3b7962009-09-04 05:53:2367 const WebPluginInfo& info,
initial.commit09911bf2008-07-26 23:55:2968 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]a96ec6a2009-11-04 17:27:0876#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]a436d922009-02-13 23:16:4282 const WebPluginInfo& info() const { return info_; }
83
[email protected]20b64d32009-03-05 02:07:1884#if defined(OS_WIN)
85 // Tracks plugin parent windows created on the browser UI thread.
86 void AddWindow(HWND window);
87#endif
88
initial.commit09911bf2008-07-26 23:55:2989 private:
[email protected]63de95b2008-12-10 04:11:2790 friend class PluginResolveProxyHelper;
91
[email protected]dabe6072009-03-17 00:52:3592 // ResourceDispatcherHost::Receiver implementation:
93 virtual URLRequestContext* GetRequestContext(
94 uint32 request_id,
95 const ViewHostMsg_Resource_Request& request_data);
96
initial.commit09911bf2008-07-26 23:55:2997 // 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]fb1277e82009-11-21 20:32:30102
103 virtual void OnProcessLaunched();
104
initial.commit09911bf2008-07-26 23:55:29105 // Message handlers.
[email protected]3dfc7a42009-06-27 01:43:51106 void OnChannelCreated(const IPC::ChannelHandle& channel_handle);
initial.commit09911bf2008-07-26 23:55:29107 void OnGetPluginFinderUrl(std::string* plugin_finder_url);
initial.commit09911bf2008-07-26 23:55:29108 void OnGetCookies(uint32 request_context, const GURL& url,
109 std::string* cookies);
[email protected]c84a7852009-09-16 21:36:44110 void OnAccessFiles(int renderer_id, const std::vector<std::string>& files,
[email protected]35135512009-07-23 20:36:49111 bool* allowed);
[email protected]63de95b2008-12-10 04:11:27112 void OnResolveProxy(const GURL& url, IPC::Message* reply_msg);
initial.commit09911bf2008-07-26 23:55:29113 void OnPluginMessage(const std::vector<uint8>& data);
[email protected]6eaddcc2009-02-23 21:03:04114
115#if defined(OS_WIN)
[email protected]875d4892009-04-21 21:48:36116 void OnPluginWindowDestroyed(HWND window, HWND parent);
[email protected]76543b92009-08-31 17:27:45117 void OnDownloadUrl(const std::string& url, int source_child_unique_id,
[email protected]829c2842009-04-01 01:48:52118 gfx::NativeWindow caller_window);
[email protected]6eaddcc2009-02-23 21:03:04119#endif
initial.commit09911bf2008-07-26 23:55:29120
[email protected]700d3d52009-07-07 17:40:46121#if defined(OS_LINUX)
122 void OnMapNativeViewId(gfx::NativeViewId id, gfx::PluginWindowHandle* output);
123#endif
124
[email protected]1d5ac662009-10-01 19:41:56125#if defined(OS_MACOSX)
[email protected]a96ec6a2009-11-04 17:27:08126 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]1d5ac662009-10-01 19:41:56130 void OnPluginHideWindow(uint32 window_id, gfx::Rect window_rect);
[email protected]27f5a6c82009-11-20 18:26:16131 void OnPluginReceivedFocus(int process_id, int instance_id);
[email protected]1d5ac662009-10-01 19:41:56132#endif
133
[email protected]51d70e02009-03-27 20:45:59134 virtual bool CanShutdown() { return sent_requests_.empty(); }
135
initial.commit09911bf2008-07-26 23:55:29136 struct ChannelRequest {
137 ChannelRequest(ResourceMessageFilter* renderer_message_filter,
[email protected]3dfc7a42009-06-27 01:43:51138 const std::string& m, IPC::Message* r) :
[email protected]6eaddcc2009-02-23 21:03:04139 mime_type(m), reply_msg(r),
[email protected]3dfc7a42009-06-27 01:43:51140 renderer_message_filter_(renderer_message_filter) { }
initial.commit09911bf2008-07-26 23:55:29141 std::string mime_type;
142 IPC::Message* reply_msg;
143 scoped_refptr<ResourceMessageFilter> renderer_message_filter_;
initial.commit09911bf2008-07-26 23:55:29144 };
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]4566f132009-03-12 01:55:13152 std::queue<ChannelRequest> sent_requests_;
initial.commit09911bf2008-07-26 23:55:29153
[email protected]a27a9382009-02-11 23:55:10154 // Information about the plugin.
155 WebPluginInfo info_;
initial.commit09911bf2008-07-26 23:55:29156
[email protected]41b2780f2009-01-31 01:34:20157 // Helper class for handling PluginProcessHost_ResolveProxy messages (manages
158 // the requests to the proxy service).
159 ResolveProxyMsgHelper resolve_proxy_msg_helper_;
[email protected]63de95b2008-12-10 04:11:27160
[email protected]20b64d32009-03-05 02:07:18161#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]1d5ac662009-10-01 19:41:56165#if defined(OS_MACOSX)
166 // Tracks plugin windows currently visible
167 std::set<uint32> plugin_visible_windows_set_;
[email protected]b44dbd12009-10-11 19:02:15168 // Tracks full screen windows currently visible
169 std::set<uint32> plugin_fullscreen_windows_set_;
[email protected]a96ec6a2009-11-04 17:27:08170 // Tracks modal windows currently visible
171 std::set<uint32> plugin_modal_windows_set_;
[email protected]1d5ac662009-10-01 19:41:56172#endif
[email protected]20b64d32009-03-05 02:07:18173
[email protected]2735e3692009-09-25 18:19:39174 DISALLOW_COPY_AND_ASSIGN(PluginProcessHost);
initial.commit09911bf2008-07-26 23:55:29175};
176
[email protected]aa2da5a2008-08-08 07:56:39177#endif // CHROME_BROWSER_PLUGIN_PROCESS_HOST_H_