OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 // A BrowserPluginGuest represents the browser side of browser <--> renderer | 5 // A BrowserPluginGuest represents the browser side of browser <--> renderer |
6 // communication. A BrowserPlugin (a WebPlugin) is on the renderer side of | 6 // communication. A BrowserPlugin (a WebPlugin) is on the renderer side of |
7 // browser <--> guest renderer communication. The 'guest' renderer is a | 7 // browser <--> guest renderer communication. The 'guest' renderer is a |
8 // <browser> tag. | 8 // <browser> tag. |
9 // | 9 // |
10 // BrowserPluginGuest lives on the UI thread of the browser process. It has a | 10 // BrowserPluginGuest lives on the UI thread of the browser process. It has a |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 // Overrides factory for testing. Default (NULL) value indicates regular | 69 // Overrides factory for testing. Default (NULL) value indicates regular |
70 // (non-test) environment. | 70 // (non-test) environment. |
71 static void set_factory_for_testing(BrowserPluginHostFactory* factory) { | 71 static void set_factory_for_testing(BrowserPluginHostFactory* factory) { |
72 content::BrowserPluginGuest::factory_ = factory; | 72 content::BrowserPluginGuest::factory_ = factory; |
73 } | 73 } |
74 | 74 |
75 void set_guest_hang_timeout_for_testing(const base::TimeDelta& timeout) { | 75 void set_guest_hang_timeout_for_testing(const base::TimeDelta& timeout) { |
76 guest_hang_timeout_ = timeout; | 76 guest_hang_timeout_ = timeout; |
77 } | 77 } |
78 | 78 |
79 void set_embedder_render_process_host( | |
80 RenderProcessHost* render_process_host) { | |
81 embedder_render_process_host_ = render_process_host; | |
82 } | |
83 | |
79 // WebContentsObserver implementation. | 84 // WebContentsObserver implementation. |
80 virtual void DidCommitProvisionalLoadForFrame( | 85 virtual void DidCommitProvisionalLoadForFrame( |
81 int64 frame_id, | 86 int64 frame_id, |
82 bool is_main_frame, | 87 bool is_main_frame, |
83 const GURL& url, | 88 const GURL& url, |
84 PageTransition transition_type, | 89 PageTransition transition_type, |
85 RenderViewHost* render_view_host) OVERRIDE; | 90 RenderViewHost* render_view_host) OVERRIDE; |
86 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; | 91 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; |
87 | 92 |
88 // WebContentsDelegate implementation. | 93 // WebContentsDelegate implementation. |
89 virtual void RendererUnresponsive(WebContents* source) OVERRIDE; | 94 virtual void RendererUnresponsive(WebContents* source) OVERRIDE; |
90 | 95 |
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, | 96 void SetDamageBuffer(TransportDIB* damage_buffer, |
116 #if defined(OS_WIN) | 97 #if defined(OS_WIN) |
117 int damage_buffer_size, | 98 int damage_buffer_size, |
118 #endif | 99 #endif |
119 const gfx::Size& damage_view_size, | 100 const gfx::Size& damage_view_size, |
120 float scale_factor); | 101 float scale_factor); |
121 | 102 |
122 void UpdateRect(RenderViewHost* render_view_host, | 103 void UpdateRect(RenderViewHost* render_view_host, |
123 const ViewHostMsg_UpdateRect_Params& params); | 104 const ViewHostMsg_UpdateRect_Params& params); |
124 void UpdateRectACK(int message_id, const gfx::Size& size); | 105 void UpdateRectACK(int message_id, const gfx::Size& size); |
125 // Handles input event routed through the embedder (which is initiated in the | 106 // Handles input event routed through the embedder (which is initiated in the |
126 // browser plugin (renderer side of the embedder)). | 107 // browser plugin (renderer side of the embedder)). |
127 void HandleInputEvent(RenderViewHost* render_view_host, | 108 void HandleInputEvent(RenderViewHost* render_view_host, |
128 const gfx::Rect& guest_rect, | 109 const gfx::Rect& guest_rect, |
129 const WebKit::WebInputEvent& event, | 110 const WebKit::WebInputEvent& event, |
130 IPC::Message* reply_message); | 111 IPC::Message* reply_message); |
131 // Overrides default ShowWidget message so we show them on the correct | 112 // Overrides default ShowWidget message so we show them on the correct |
132 // coordinates. | 113 // coordinates. |
133 void ShowWidget(RenderViewHost* render_view_host, | 114 void ShowWidget(RenderViewHost* render_view_host, |
134 int route_id, | 115 int route_id, |
135 const gfx::Rect& initial_pos); | 116 const gfx::Rect& initial_pos); |
136 void SetCursor(const WebCursor& cursor); | 117 void SetCursor(const WebCursor& cursor); |
137 // Handles input event acks so they are sent to browser plugin host (via | 118 // Handles input event acks so they are sent to browser plugin host (via |
138 // embedder) instead of default view/widget host. | 119 // embedder) instead of default view/widget host. |
139 void HandleInputEventAck(RenderViewHost* render_view_host, bool handled); | 120 void HandleInputEventAck(RenderViewHost* render_view_host, bool handled); |
140 | 121 |
122 WebContents* GetWebContents(); | |
Charlie Reis
2012/09/20 18:24:04
It's not immediately obvious why you need this. M
lazyboy
2012/09/20 20:29:43
Done.
| |
123 | |
124 // Overridden in tests. | |
125 virtual bool ViewTakeFocus(bool reverse); | |
126 // Overridden in tests. | |
127 virtual void SetFocus(bool focused); | |
128 | |
129 private: | |
130 friend class TestBrowserPluginGuest; | |
131 | |
132 BrowserPluginGuest(int instance_id, | |
133 WebContentsImpl* web_contents, | |
134 RenderViewHost* render_view_host); | |
135 | |
136 RenderProcessHost* embedder_render_process_host() { | |
137 return embedder_render_process_host_; | |
138 } | |
139 // Returns the identifier that uniquely identifies a browser plugin guest | |
140 // within an embedder. | |
141 int instance_id() const { return instance_id_; } | |
142 TransportDIB* damage_buffer() const { return damage_buffer_.get(); } | |
143 const gfx::Size& damage_view_size() const { return damage_view_size_; } | |
144 float damage_buffer_scale_factor() const { | |
145 return damage_buffer_scale_factor_; | |
146 } | |
147 | |
141 // Helper to send messages to embedder. Overridden in test implementation | 148 // Helper to send messages to embedder. Overridden in test implementation |
142 // since we want to intercept certain messages for testing. | 149 // since we want to intercept certain messages for testing. |
143 virtual void SendMessageToEmbedder(IPC::Message* msg); | 150 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 | 151 |
149 // Static factory instance (always NULL for non-test). | 152 // Static factory instance (always NULL for non-test). |
150 static content::BrowserPluginHostFactory* factory_; | 153 static content::BrowserPluginHostFactory* factory_; |
151 | 154 |
152 RenderProcessHost* embedder_render_process_host_; | 155 RenderProcessHost* embedder_render_process_host_; |
153 // An identifier that uniquely identifies a browser plugin guest within an | 156 // An identifier that uniquely identifies a browser plugin guest within an |
154 // embedder. | 157 // embedder. |
155 int instance_id_; | 158 int instance_id_; |
156 scoped_ptr<TransportDIB> damage_buffer_; | 159 scoped_ptr<TransportDIB> damage_buffer_; |
157 #if defined(OS_WIN) | 160 #if defined(OS_WIN) |
158 size_t damage_buffer_size_; | 161 size_t damage_buffer_size_; |
159 #endif | 162 #endif |
160 gfx::Size damage_view_size_; | 163 gfx::Size damage_view_size_; |
161 float damage_buffer_scale_factor_; | 164 float damage_buffer_scale_factor_; |
162 scoped_ptr<IPC::Message> pending_input_event_reply_; | 165 scoped_ptr<IPC::Message> pending_input_event_reply_; |
163 gfx::Rect guest_rect_; | 166 gfx::Rect guest_rect_; |
164 WebCursor cursor_; | 167 WebCursor cursor_; |
165 IDMap<RenderViewHost> pending_updates_; | 168 IDMap<RenderViewHost> pending_updates_; |
166 int pending_update_counter_; | 169 int pending_update_counter_; |
167 base::TimeDelta guest_hang_timeout_; | 170 base::TimeDelta guest_hang_timeout_; |
168 | 171 |
169 DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuest); | 172 DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuest); |
170 }; | 173 }; |
171 | 174 |
172 } // namespace content | 175 } // namespace content |
173 | 176 |
174 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ | 177 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ |
OLD | NEW |