OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_PLUGIN_PROCESS_HOST_H_ | 5 #ifndef CONTENT_BROWSER_PLUGIN_PROCESS_HOST_H_ |
6 #define CONTENT_BROWSER_PLUGIN_PROCESS_HOST_H_ | 6 #define CONTENT_BROWSER_PLUGIN_PROCESS_HOST_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 | 10 |
11 #include <queue> | 11 #include <queue> |
12 #include <set> | 12 #include <set> |
13 #include <string> | 13 #include <string> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
18 #include "content/browser/browser_child_process_host.h" | 18 #include "content/browser/browser_child_process_host.h" |
19 #include "webkit/plugins/npapi/webplugininfo.h" | 19 #include "webkit/plugins/webplugininfo.h" |
20 #include "ui/gfx/native_widget_types.h" | 20 #include "ui/gfx/native_widget_types.h" |
21 | 21 |
22 namespace gfx { | 22 namespace gfx { |
23 class Rect; | 23 class Rect; |
24 } | 24 } |
25 | 25 |
26 namespace IPC { | 26 namespace IPC { |
27 struct ChannelHandle; | 27 struct ChannelHandle; |
28 } | 28 } |
29 | 29 |
30 class GURL; | 30 class GURL; |
31 | 31 |
32 // Represents the browser side of the browser <--> plugin communication | 32 // Represents the browser side of the browser <--> plugin communication |
33 // channel. Different plugins run in their own process, but multiple instances | 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 | 34 // of the same plugin run in the same process. There will be one |
35 // PluginProcessHost per plugin process, matched with a corresponding | 35 // PluginProcessHost per plugin process, matched with a corresponding |
36 // PluginProcess running in the plugin process. The browser is responsible for | 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 | 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 | 38 // have a process. After that, most of the communication is directly between |
39 // the renderer and plugin processes. | 39 // the renderer and plugin processes. |
40 class PluginProcessHost : public BrowserChildProcessHost { | 40 class PluginProcessHost : public BrowserChildProcessHost { |
41 public: | 41 public: |
42 class Client { | 42 class Client { |
43 public: | 43 public: |
44 // Returns a opaque unique identifier for the process requesting | 44 // Returns a opaque unique identifier for the process requesting |
45 // the channel. | 45 // the channel. |
46 virtual int ID() = 0; | 46 virtual int ID() = 0; |
47 virtual bool OffTheRecord() = 0; | 47 virtual bool OffTheRecord() = 0; |
48 virtual void SetPluginInfo(const webkit::npapi::WebPluginInfo& info) = 0; | 48 virtual void SetPluginInfo(const webkit::WebPluginInfo& info) = 0; |
49 // The client should delete itself when one of these methods is called. | 49 // The client should delete itself when one of these methods is called. |
50 virtual void OnChannelOpened(const IPC::ChannelHandle& handle) = 0; | 50 virtual void OnChannelOpened(const IPC::ChannelHandle& handle) = 0; |
51 virtual void OnError() = 0; | 51 virtual void OnError() = 0; |
52 | 52 |
53 protected: | 53 protected: |
54 virtual ~Client() {} | 54 virtual ~Client() {} |
55 }; | 55 }; |
56 | 56 |
57 PluginProcessHost(); | 57 PluginProcessHost(); |
58 virtual ~PluginProcessHost(); | 58 virtual ~PluginProcessHost(); |
59 | 59 |
60 // Initialize the new plugin process, returning true on success. This must | 60 // Initialize the new plugin process, returning true on success. This must |
61 // be called before the object can be used. | 61 // be called before the object can be used. |
62 bool Init(const webkit::npapi::WebPluginInfo& info, const std::string& locale)
; | 62 bool Init(const webkit::WebPluginInfo& info, const std::string& locale); |
63 | 63 |
64 // Force the plugin process to shutdown (cleanly). | 64 // Force the plugin process to shutdown (cleanly). |
65 virtual void ForceShutdown(); | 65 virtual void ForceShutdown(); |
66 | 66 |
67 virtual bool OnMessageReceived(const IPC::Message& msg); | 67 virtual bool OnMessageReceived(const IPC::Message& msg); |
68 virtual void OnChannelConnected(int32 peer_pid); | 68 virtual void OnChannelConnected(int32 peer_pid); |
69 virtual void OnChannelError(); | 69 virtual void OnChannelError(); |
70 | 70 |
71 // Tells the plugin process to create a new channel for communication with a | 71 // Tells the plugin process to create a new channel for communication with a |
72 // renderer. When the plugin process responds with the channel name, | 72 // renderer. When the plugin process responds with the channel name, |
73 // OnChannelOpened in the client is called. | 73 // OnChannelOpened in the client is called. |
74 void OpenChannelToPlugin(Client* client); | 74 void OpenChannelToPlugin(Client* client); |
75 | 75 |
76 // This function is called on the IO thread once we receive a reply from the | 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 | 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. | 78 // that reply back to the plugin that requested the dialog. |
79 void OnModalDialogResponse(const std::string& json_retval, | 79 void OnModalDialogResponse(const std::string& json_retval, |
80 IPC::Message* sync_result); | 80 IPC::Message* sync_result); |
81 | 81 |
82 #if defined(OS_MACOSX) | 82 #if defined(OS_MACOSX) |
83 // This function is called on the IO thread when the browser becomes the | 83 // This function is called on the IO thread when the browser becomes the |
84 // active application. | 84 // active application. |
85 void OnAppActivation(); | 85 void OnAppActivation(); |
86 #endif | 86 #endif |
87 | 87 |
88 const webkit::npapi::WebPluginInfo& info() const { return info_; } | 88 const webkit::WebPluginInfo& info() const { return info_; } |
89 | 89 |
90 #if defined(OS_WIN) | 90 #if defined(OS_WIN) |
91 // Tracks plugin parent windows created on the browser UI thread. | 91 // Tracks plugin parent windows created on the browser UI thread. |
92 void AddWindow(HWND window); | 92 void AddWindow(HWND window); |
93 #endif | 93 #endif |
94 | 94 |
95 private: | 95 private: |
96 // Sends a message to the plugin process to request creation of a new channel | 96 // Sends a message to the plugin process to request creation of a new channel |
97 // for the given mime type. | 97 // for the given mime type. |
98 void RequestPluginChannel(Client* client); | 98 void RequestPluginChannel(Client* client); |
(...skipping 25 matching lines...) Expand all Loading... |
124 | 124 |
125 // These are channel requests that we are waiting to send to the | 125 // These are channel requests that we are waiting to send to the |
126 // plugin process once the channel is opened. | 126 // plugin process once the channel is opened. |
127 std::vector<Client*> pending_requests_; | 127 std::vector<Client*> pending_requests_; |
128 | 128 |
129 // These are the channel requests that we have already sent to | 129 // These are the channel requests that we have already sent to |
130 // the plugin process, but haven't heard back about yet. | 130 // the plugin process, but haven't heard back about yet. |
131 std::queue<Client*> sent_requests_; | 131 std::queue<Client*> sent_requests_; |
132 | 132 |
133 // Information about the plugin. | 133 // Information about the plugin. |
134 webkit::npapi::WebPluginInfo info_; | 134 webkit::WebPluginInfo info_; |
135 | 135 |
136 #if defined(OS_WIN) | 136 #if defined(OS_WIN) |
137 // Tracks plugin parent windows created on the UI thread. | 137 // Tracks plugin parent windows created on the UI thread. |
138 std::set<HWND> plugin_parent_windows_set_; | 138 std::set<HWND> plugin_parent_windows_set_; |
139 #endif | 139 #endif |
140 #if defined(OS_MACOSX) | 140 #if defined(OS_MACOSX) |
141 // Tracks plugin windows currently visible. | 141 // Tracks plugin windows currently visible. |
142 std::set<uint32> plugin_visible_windows_set_; | 142 std::set<uint32> plugin_visible_windows_set_; |
143 // Tracks full screen windows currently visible. | 143 // Tracks full screen windows currently visible. |
144 std::set<uint32> plugin_fullscreen_windows_set_; | 144 std::set<uint32> plugin_fullscreen_windows_set_; |
145 // Tracks modal windows currently visible. | 145 // Tracks modal windows currently visible. |
146 std::set<uint32> plugin_modal_windows_set_; | 146 std::set<uint32> plugin_modal_windows_set_; |
147 // Tracks the current visibility of the cursor. | 147 // Tracks the current visibility of the cursor. |
148 bool plugin_cursor_visible_; | 148 bool plugin_cursor_visible_; |
149 #endif | 149 #endif |
150 | 150 |
151 DISALLOW_COPY_AND_ASSIGN(PluginProcessHost); | 151 DISALLOW_COPY_AND_ASSIGN(PluginProcessHost); |
152 }; | 152 }; |
153 | 153 |
154 #endif // CONTENT_BROWSER_PLUGIN_PROCESS_HOST_H_ | 154 #endif // CONTENT_BROWSER_PLUGIN_PROCESS_HOST_H_ |
OLD | NEW |