#ifndef CONTENT_BROWSER_PLUGIN_PROCESS_HOST_H_
#define CONTENT_BROWSER_PLUGIN_PROCESS_HOST_H_
#include "build/build_config.h"
#include <list>
#include <set>
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "content/common/content_export.h"
#include "content/public/browser/browser_child_process_host_delegate.h"
#include "content/public/browser/browser_child_process_host_iterator.h"
#include "ipc/ipc_channel_proxy.h"
#include "webkit/plugins/webplugininfo.h"
#include "ui/gfx/native_widget_types.h"
class BrowserChildProcessHostImpl;
namespace content {
class ResourceContext;
}
namespace gfx {
class Rect;
}
namespace IPC {
struct ChannelHandle;
}
class CONTENT_EXPORT PluginProcessHost
: public content::BrowserChildProcessHostDelegate,
public IPC::Sender {
public:
class Client {
public:
virtual int ID() = 0;
virtual content::ResourceContext* GetResourceContext() = 0;
virtual bool OffTheRecord() = 0;
virtual void SetPluginInfo(const webkit::WebPluginInfo& info) = 0;
virtual void OnFoundPluginProcessHost(PluginProcessHost* host) = 0;
virtual void OnSentPluginChannelRequest() = 0;
virtual void OnChannelOpened(const IPC::ChannelHandle& handle) = 0;
virtual void OnError() = 0;
protected:
virtual ~Client() {}
};
PluginProcessHost();
virtual ~PluginProcessHost();
virtual bool Send(IPC::Message* message) OVERRIDE;
bool Init(const webkit::WebPluginInfo& info);
void ForceShutdown();
virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
virtual void OnChannelError() OVERRIDE;
void OpenChannelToPlugin(Client* client);
static void CancelPendingRequestsForResourceContext(
content::ResourceContext* context);
void CancelPendingRequest(Client* client);
void CancelSentRequest(Client* client);
void OnModalDialogResponse(const std::string& json_retval,
IPC::Message* sync_result);
#if defined(OS_MACOSX)
void OnAppActivation();
#endif
const webkit::WebPluginInfo& info() const { return info_; }
#if defined(OS_WIN)
void AddWindow(HWND window);
#endif
void AddFilter(IPC::ChannelProxy::MessageFilter* filter);
private:
void RequestPluginChannel(Client* client);
void OnChannelCreated(const IPC::ChannelHandle& channel_handle);
#if defined(OS_WIN)
void OnPluginWindowDestroyed(HWND window, HWND parent);
void OnReparentPluginWindow(HWND window, HWND parent);
void OnReportExecutableMemory(size_t size);
#endif
#if defined(USE_X11)
void OnMapNativeViewId(gfx::NativeViewId id, gfx::PluginWindowHandle* output);
#endif
#if defined(OS_MACOSX)
void OnPluginSelectWindow(uint32 window_id, gfx::Rect window_rect,
bool modal);
void OnPluginShowWindow(uint32 window_id, gfx::Rect window_rect,
bool modal);
void OnPluginHideWindow(uint32 window_id, gfx::Rect window_rect);
void OnPluginSetCursorVisibility(bool visible);
#endif
virtual bool CanShutdown() OVERRIDE;
virtual void OnProcessCrashed(int exit_code) OVERRIDE;
void CancelRequests();
std::vector<Client*> pending_requests_;
std::list<Client*> sent_requests_;
webkit::WebPluginInfo info_;
#if defined(OS_WIN)
std::set<HWND> plugin_parent_windows_set_;
#endif
#if defined(OS_MACOSX)
std::set<uint32> plugin_visible_windows_set_;
std::set<uint32> plugin_fullscreen_windows_set_;
std::set<uint32> plugin_modal_windows_set_;
bool plugin_cursor_visible_;
#endif
scoped_ptr<BrowserChildProcessHostImpl> process_;
DISALLOW_COPY_AND_ASSIGN(PluginProcessHost);
};
class PluginProcessHostIterator
: public content::BrowserChildProcessHostTypeIterator<PluginProcessHost> {
public:
PluginProcessHostIterator()
: content::BrowserChildProcessHostTypeIterator<PluginProcessHost>(
content::PROCESS_TYPE_PLUGIN) {}
};
#endif