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_BROWSER_PLUGIN_PROCESS_HOST_H_
6 #define CONTENT_BROWSER_PLUGIN_PROCESS_HOST_H_
8 #include "build/build_config.h"
15 #include "base/basictypes.h"
16 #include "base/compiler_specific.h"
17 #include "base/memory/ref_counted.h"
18 #include "content/common/content_export.h"
19 #include "content/public/browser/browser_child_process_host_delegate.h"
20 #include "content/public/browser/browser_child_process_host_iterator.h"
21 #include "ipc/ipc_channel_proxy.h"
22 #include "webkit/plugins/webplugininfo.h"
23 #include "ui/gfx/native_widget_types.h"
34 class BrowserChildProcessHostImpl
;
35 class ResourceContext
;
37 // Represents the browser side of the browser <--> plugin communication
38 // channel. Different plugins run in their own process, but multiple instances
39 // of the same plugin run in the same process. There will be one
40 // PluginProcessHost per plugin process, matched with a corresponding
41 // PluginProcess running in the plugin process. The browser is responsible for
42 // starting the plugin process when a plugin is created that doesn't already
43 // have a process. After that, most of the communication is directly between
44 // the renderer and plugin processes.
45 class CONTENT_EXPORT PluginProcessHost
: public BrowserChildProcessHostDelegate
,
50 // Returns an opaque unique identifier for the process requesting
53 // Returns the resource context for the renderer requesting the channel.
54 virtual ResourceContext
* GetResourceContext() = 0;
55 virtual bool OffTheRecord() = 0;
56 virtual void SetPluginInfo(const webkit::WebPluginInfo
& info
) = 0;
57 virtual void OnFoundPluginProcessHost(PluginProcessHost
* host
) = 0;
58 virtual void OnSentPluginChannelRequest() = 0;
59 // The client should delete itself when one of these methods is called.
60 virtual void OnChannelOpened(const IPC::ChannelHandle
& handle
) = 0;
61 virtual void OnError() = 0;
68 virtual ~PluginProcessHost();
70 // IPC::Sender implementation:
71 virtual bool Send(IPC::Message
* message
) OVERRIDE
;
73 // Initialize the new plugin process, returning true on success. This must
74 // be called before the object can be used.
75 bool Init(const webkit::WebPluginInfo
& info
);
77 // Force the plugin process to shutdown (cleanly).
80 virtual bool OnMessageReceived(const IPC::Message
& msg
) OVERRIDE
;
81 virtual void OnChannelConnected(int32 peer_pid
) OVERRIDE
;
82 virtual void OnChannelError() OVERRIDE
;
84 // Tells the plugin process to create a new channel for communication with a
85 // renderer. When the plugin process responds with the channel name,
86 // OnChannelOpened in the client is called.
87 void OpenChannelToPlugin(Client
* client
);
89 // Cancels all pending channel requests for the given resource context.
90 static void CancelPendingRequestsForResourceContext(ResourceContext
* context
);
92 // This function is called to cancel pending requests to open new channels.
93 void CancelPendingRequest(Client
* client
);
95 // This function is called to cancel sent requests to open new channels.
96 void CancelSentRequest(Client
* client
);
98 // This function is called on the IO thread once we receive a reply from the
99 // modal HTML dialog (in the form of a JSON string). This function forwards
100 // that reply back to the plugin that requested the dialog.
101 void OnModalDialogResponse(const std::string
& json_retval
,
102 IPC::Message
* sync_result
);
104 #if defined(OS_MACOSX)
105 // This function is called on the IO thread when the browser becomes the
106 // active application.
107 void OnAppActivation();
110 const webkit::WebPluginInfo
& info() const { return info_
; }
113 // Tracks plugin parent windows created on the browser UI thread.
114 void AddWindow(HWND window
);
117 // Adds an IPC message filter. A reference will be kept to the filter.
118 void AddFilter(IPC::ChannelProxy::MessageFilter
* filter
);
121 // Sends a message to the plugin process to request creation of a new channel
122 // for the given mime type.
123 void RequestPluginChannel(Client
* client
);
126 void OnChannelCreated(const IPC::ChannelHandle
& channel_handle
);
129 void OnPluginWindowDestroyed(HWND window
, HWND parent
);
133 void OnMapNativeViewId(gfx::NativeViewId id
, gfx::PluginWindowHandle
* output
);
136 #if defined(OS_MACOSX)
137 void OnPluginSelectWindow(uint32 window_id
, gfx::Rect window_rect
,
139 void OnPluginShowWindow(uint32 window_id
, gfx::Rect window_rect
,
141 void OnPluginHideWindow(uint32 window_id
, gfx::Rect window_rect
);
142 void OnPluginSetCursorVisibility(bool visible
);
145 virtual bool CanShutdown() OVERRIDE
;
146 virtual void OnProcessCrashed(int exit_code
) OVERRIDE
;
148 void CancelRequests();
150 // These are channel requests that we are waiting to send to the
151 // plugin process once the channel is opened.
152 std::vector
<Client
*> pending_requests_
;
154 // These are the channel requests that we have already sent to
155 // the plugin process, but haven't heard back about yet.
156 std::list
<Client
*> sent_requests_
;
158 // Information about the plugin.
159 webkit::WebPluginInfo info_
;
162 // Tracks plugin parent windows created on the UI thread.
163 std::set
<HWND
> plugin_parent_windows_set_
;
165 #if defined(OS_MACOSX)
166 // Tracks plugin windows currently visible.
167 std::set
<uint32
> plugin_visible_windows_set_
;
168 // Tracks full screen windows currently visible.
169 std::set
<uint32
> plugin_fullscreen_windows_set_
;
170 // Tracks modal windows currently visible.
171 std::set
<uint32
> plugin_modal_windows_set_
;
172 // Tracks the current visibility of the cursor.
173 bool plugin_cursor_visible_
;
176 scoped_ptr
<BrowserChildProcessHostImpl
> process_
;
178 DISALLOW_COPY_AND_ASSIGN(PluginProcessHost
);
181 class PluginProcessHostIterator
182 : public BrowserChildProcessHostTypeIterator
<PluginProcessHost
> {
184 PluginProcessHostIterator()
185 : BrowserChildProcessHostTypeIterator
<PluginProcessHost
>(
186 PROCESS_TYPE_PLUGIN
) {}
189 } // namespace content
191 #endif // CONTENT_BROWSER_PLUGIN_PROCESS_HOST_H_