OLD | NEW |
| (Empty) |
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. | |
4 | |
5 // A BrowserPluginGuest represents the browser side of browser <--> renderer | |
6 // communication. A BrowserPlugin (a WebPlugin) is on the renderer side of | |
7 // browser <--> guest renderer communication. The 'guest' renderer is a | |
8 // <browser> tag. | |
9 // | |
10 // BrowserPluginGuest lives on the UI thread of the browser process. It has a | |
11 // helper, BrowserPluginGuestHelper, which is a RenderViewHostObserver. The | |
12 // helper object receives messages (ViewHostMsg_*) directed at the browser | |
13 // plugin and redirects them to this class. Any messages the embedder might be | |
14 // interested in knowing or modifying about the guest should be listened for | |
15 // here. | |
16 // | |
17 // Since BrowserPlugin is a WebPlugin, we need to provide overridden behaviors | |
18 // for messages like handleInputEvent, updateGeometry. Such messages get | |
19 // routed into BrowserPluginGuest via its embedder (BrowserPluginEmbedder). | |
20 // These are BrowserPluginHost_* messages sent from the BrowserPlugin. | |
21 // | |
22 // BrowserPluginGuest knows about its embedder process. Communication to | |
23 // renderer happens through the embedder process. | |
24 // | |
25 // A BrowserPluginGuest is also associated directly with the WebContents related | |
26 // to the BrowserPlugin. BrowserPluginGuest is a WebContentsDelegate and | |
27 // WebContentsObserver for the WebContents. | |
28 | |
29 #ifndef CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ | |
30 #define CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ | |
31 | |
32 #include <map> | |
33 | |
34 #include "base/compiler_specific.h" | |
35 #include "base/id_map.h" | |
36 #include "base/time.h" | |
37 #include "content/public/browser/web_contents_delegate.h" | |
38 #include "content/public/browser/web_contents_observer.h" | |
39 #include "ui/gfx/rect.h" | |
40 #include "webkit/glue/webcursor.h" | |
41 | |
42 class TransportDIB; | |
43 struct ViewHostMsg_UpdateRect_Params; | |
44 | |
45 namespace WebKit { | |
46 class WebInputEvent; | |
47 } | |
48 | |
49 namespace content { | |
50 | |
51 class BrowserPluginHostFactory; | |
52 class BrowserPluginEmbedder; | |
53 class RenderProcessHost; | |
54 | |
55 // A browser plugin guest provides functionality for WebContents to operate in | |
56 // the guest role and implements guest specific overrides for ViewHostMsg_* | |
57 // messages. | |
58 // | |
59 // BrowserPluginEmbedder is responsible for creating and destroying a guest. | |
60 class CONTENT_EXPORT BrowserPluginGuest : public WebContentsDelegate, | |
61 public WebContentsObserver { | |
62 public: | |
63 virtual ~BrowserPluginGuest(); | |
64 | |
65 static BrowserPluginGuest* Create(int instance_id, | |
66 WebContentsImpl* web_contents, | |
67 content::RenderViewHost* render_view_host); | |
68 | |
69 // Overrides factory for testing. Default (NULL) value indicates regular | |
70 // (non-test) environment. | |
71 static void set_factory_for_testing(BrowserPluginHostFactory* factory) { | |
72 content::BrowserPluginGuest::factory_ = factory; | |
73 } | |
74 | |
75 void set_guest_hang_timeout_for_testing(const base::TimeDelta& timeout) { | |
76 guest_hang_timeout_ = timeout; | |
77 } | |
78 | |
79 // WebContentsObserver implementation. | |
80 virtual void DidCommitProvisionalLoadForFrame( | |
81 int64 frame_id, | |
82 bool is_main_frame, | |
83 const GURL& url, | |
84 PageTransition transition_type, | |
85 RenderViewHost* render_view_host) OVERRIDE; | |
86 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; | |
87 | |
88 // WebContentsDelegate implementation. | |
89 virtual void RendererUnresponsive(WebContents* source) OVERRIDE; | |
90 | |
91 private: | |
92 friend class BrowserPluginEmbedder; | |
93 friend class BrowserPluginGuestHelper; | |
94 friend class TestBrowserPluginGuest; | |
95 | |
96 BrowserPluginGuest(int instance_id, | |
97 WebContentsImpl* web_contents, | |
98 RenderViewHost* render_view_host); | |
99 | |
100 void set_embedder_render_process_host( | |
101 RenderProcessHost* render_process_host) { | |
102 embedder_render_process_host_ = render_process_host; | |
103 } | |
104 RenderProcessHost* embedder_render_process_host() { | |
105 return embedder_render_process_host_; | |
106 } | |
107 // Returns the identifier that uniquely identifies a browser plugin guest | |
108 // within an embedder. | |
109 int instance_id() const { return instance_id_; } | |
110 TransportDIB* damage_buffer() const { return damage_buffer_.get(); } | |
111 const gfx::Size& damage_view_size() const { return damage_view_size_; } | |
112 float damage_buffer_scale_factor() const { | |
113 return damage_buffer_scale_factor_; | |
114 } | |
115 void SetDamageBuffer(TransportDIB* damage_buffer, | |
116 #if defined(OS_WIN) | |
117 int damage_buffer_size, | |
118 #endif | |
119 const gfx::Size& damage_view_size, | |
120 float scale_factor); | |
121 | |
122 void UpdateRect(RenderViewHost* render_view_host, | |
123 const ViewHostMsg_UpdateRect_Params& params); | |
124 void UpdateRectACK(int message_id, const gfx::Size& size); | |
125 // Handles input event routed through the embedder (which is initiated in the | |
126 // browser plugin (renderer side of the embedder)). | |
127 void HandleInputEvent(RenderViewHost* render_view_host, | |
128 const gfx::Rect& guest_rect, | |
129 const WebKit::WebInputEvent& event, | |
130 IPC::Message* reply_message); | |
131 // Overrides default ShowWidget message so we show them on the correct | |
132 // coordinates. | |
133 void ShowWidget(RenderViewHost* render_view_host, | |
134 int route_id, | |
135 const gfx::Rect& initial_pos); | |
136 void SetCursor(const WebCursor& cursor); | |
137 // Handles input event acks so they are sent to browser plugin host (via | |
138 // embedder) instead of default view/widget host. | |
139 void HandleInputEventAck(RenderViewHost* render_view_host, bool handled); | |
140 | |
141 // Helper to send messages to embedder. Overridden in test implementation | |
142 // since we want to intercept certain messages for testing. | |
143 virtual void SendMessageToEmbedder(IPC::Message* msg); | |
144 // Overridden in tests. | |
145 virtual void SetFocus(bool focused); | |
146 // Overridden in tests. | |
147 virtual bool ViewTakeFocus(bool reverse); | |
148 | |
149 // Static factory instance (always NULL for non-test). | |
150 static content::BrowserPluginHostFactory* factory_; | |
151 | |
152 RenderProcessHost* embedder_render_process_host_; | |
153 // An identifier that uniquely identifies a browser plugin guest within an | |
154 // embedder. | |
155 int instance_id_; | |
156 scoped_ptr<TransportDIB> damage_buffer_; | |
157 #if defined(OS_WIN) | |
158 size_t damage_buffer_size_; | |
159 #endif | |
160 gfx::Size damage_view_size_; | |
161 float damage_buffer_scale_factor_; | |
162 scoped_ptr<IPC::Message> pending_input_event_reply_; | |
163 gfx::Rect guest_rect_; | |
164 WebCursor cursor_; | |
165 IDMap<RenderViewHost> pending_updates_; | |
166 int pending_update_counter_; | |
167 base::TimeDelta guest_hang_timeout_; | |
168 | |
169 DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuest); | |
170 }; | |
171 | |
172 } // namespace content | |
173 | |
174 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ | |
OLD | NEW |