blob: 68cd7387c042b16330efe00aed5982d1e69c0a00 [file] [log] [blame]
[email protected]3b63f8f42011-03-28 01:54:151// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]a0421732011-02-23 03:55:402// 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#pragma once
8
9#include "build/build_config.h"
10
11#include <queue>
12#include <set>
13#include <string>
14#include <vector>
15
16#include "base/basictypes.h"
[email protected]3b63f8f42011-03-28 01:54:1517#include "base/memory/ref_counted.h"
[email protected]a0421732011-02-23 03:55:4018#include "content/browser/browser_child_process_host.h"
19#include "ui/gfx/native_widget_types.h"
20#include "webkit/plugins/npapi/webplugininfo.h"
21
22namespace gfx {
23class Rect;
24}
25
26namespace IPC {
27struct ChannelHandle;
28}
29
30class GURL;
31
32// Represents the browser side of the browser <--> plugin communication
33// channel. Different plugins run in their own process, but multiple instances
34// of the same plugin run in the same process. There will be one
35// PluginProcessHost per plugin process, matched with a corresponding
36// PluginProcess running in the plugin process. The browser is responsible for
37// starting the plugin process when a plugin is created that doesn't already
38// have a process. After that, most of the communication is directly between
39// the renderer and plugin processes.
[email protected]f6b224d2011-03-15 17:16:5540class PluginProcessHost : public BrowserChildProcessHost {
[email protected]a0421732011-02-23 03:55:4041 public:
42 class Client {
43 public:
44 // Returns a opaque unique identifier for the process requesting
45 // the channel.
46 virtual int ID() = 0;
47 virtual bool OffTheRecord() = 0;
48 virtual void SetPluginInfo(const webkit::npapi::WebPluginInfo& info) = 0;
49 // The client should delete itself when one of these methods is called.
50 virtual void OnChannelOpened(const IPC::ChannelHandle& handle) = 0;
51 virtual void OnError() = 0;
52
53 protected:
54 virtual ~Client() {}
55 };
56
57 PluginProcessHost();
58 virtual ~PluginProcessHost();
59
60 // Initialize the new plugin process, returning true on success. This must
61 // be called before the object can be used.
62 bool Init(const webkit::npapi::WebPluginInfo& info, const std::string& locale);
63
64 // Force the plugin process to shutdown (cleanly).
65 virtual void ForceShutdown();
66
67 virtual bool OnMessageReceived(const IPC::Message& msg);
68 virtual void OnChannelConnected(int32 peer_pid);
69 virtual void OnChannelError();
70
[email protected]a0421732011-02-23 03:55:4071 // Tells the plugin process to create a new channel for communication with a
72 // renderer. When the plugin process responds with the channel name,
73 // OnChannelOpened in the client is called.
74 void OpenChannelToPlugin(Client* client);
75
76 // This function is called on the IO thread once we receive a reply from the
77 // modal HTML dialog (in the form of a JSON string). This function forwards
78 // that reply back to the plugin that requested the dialog.
79 void OnModalDialogResponse(const std::string& json_retval,
80 IPC::Message* sync_result);
81
82#if defined(OS_MACOSX)
83 // This function is called on the IO thread when the browser becomes the
84 // active application.
85 void OnAppActivation();
86#endif
87
88 const webkit::npapi::WebPluginInfo& info() const { return info_; }
89
90#if defined(OS_WIN)
91 // Tracks plugin parent windows created on the browser UI thread.
92 void AddWindow(HWND window);
93#endif
94
95 private:
[email protected]a0421732011-02-23 03:55:4096 // Sends a message to the plugin process to request creation of a new channel
97 // for the given mime type.
98 void RequestPluginChannel(Client* client);
99
[email protected]a0421732011-02-23 03:55:40100 // Message handlers.
101 void OnChannelCreated(const IPC::ChannelHandle& channel_handle);
102 void OnGetPluginFinderUrl(std::string* plugin_finder_url);
[email protected]a0421732011-02-23 03:55:40103
104#if defined(OS_WIN)
105 void OnPluginWindowDestroyed(HWND window, HWND parent);
106 void OnDownloadUrl(const std::string& url, int source_child_unique_id,
107 gfx::NativeWindow caller_window);
108#endif
109
110#if defined(USE_X11)
111 void OnMapNativeViewId(gfx::NativeViewId id, gfx::PluginWindowHandle* output);
112#endif
113
114#if defined(OS_MACOSX)
115 void OnPluginSelectWindow(uint32 window_id, gfx::Rect window_rect,
116 bool modal);
117 void OnPluginShowWindow(uint32 window_id, gfx::Rect window_rect,
118 bool modal);
119 void OnPluginHideWindow(uint32 window_id, gfx::Rect window_rect);
120 void OnPluginSetCursorVisibility(bool visible);
121#endif
122
123 virtual bool CanShutdown();
124
125 void CancelRequests();
126
127 // These are channel requests that we are waiting to send to the
128 // plugin process once the channel is opened.
129 std::vector<Client*> pending_requests_;
130
131 // These are the channel requests that we have already sent to
132 // the plugin process, but haven't heard back about yet.
133 std::queue<Client*> sent_requests_;
134
135 // Information about the plugin.
136 webkit::npapi::WebPluginInfo info_;
137
[email protected]a0421732011-02-23 03:55:40138#if defined(OS_WIN)
139 // Tracks plugin parent windows created on the UI thread.
140 std::set<HWND> plugin_parent_windows_set_;
141#endif
142#if defined(OS_MACOSX)
143 // Tracks plugin windows currently visible.
144 std::set<uint32> plugin_visible_windows_set_;
145 // Tracks full screen windows currently visible.
146 std::set<uint32> plugin_fullscreen_windows_set_;
147 // Tracks modal windows currently visible.
148 std::set<uint32> plugin_modal_windows_set_;
149 // Tracks the current visibility of the cursor.
150 bool plugin_cursor_visible_;
151#endif
152
153 DISALLOW_COPY_AND_ASSIGN(PluginProcessHost);
154};
155
156#endif // CONTENT_BROWSER_PLUGIN_PROCESS_HOST_H_