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 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 5 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 virtual void WasHidden() OVERRIDE { | 58 virtual void WasHidden() OVERRIDE { |
59 browser_plugin_guest_->EmbedderVisibilityChanged(false); | 59 browser_plugin_guest_->EmbedderVisibilityChanged(false); |
60 } | 60 } |
61 | 61 |
62 private: | 62 private: |
63 BrowserPluginGuest* browser_plugin_guest_; | 63 BrowserPluginGuest* browser_plugin_guest_; |
64 | 64 |
65 DISALLOW_COPY_AND_ASSIGN(EmbedderWebContentsObserver); | 65 DISALLOW_COPY_AND_ASSIGN(EmbedderWebContentsObserver); |
66 }; | 66 }; |
67 | 67 |
68 BrowserPluginGuest::BrowserPluginGuest( | 68 BrowserPluginGuest::BrowserPluginGuest(int guest_instance_id, |
69 int instance_id, | 69 bool has_render_view, |
70 bool has_render_view, | 70 WebContentsImpl* web_contents, |
71 WebContentsImpl* web_contents, | 71 BrowserPluginGuestDelegate* delegate) |
72 BrowserPluginGuestDelegate* delegate) | |
73 : WebContentsObserver(web_contents), | 72 : WebContentsObserver(web_contents), |
74 embedder_web_contents_(NULL), | 73 embedder_web_contents_(NULL), |
75 instance_id_(instance_id), | 74 guest_instance_id_(guest_instance_id), |
76 guest_device_scale_factor_(1.0f), | 75 guest_device_scale_factor_(1.0f), |
77 focused_(false), | 76 focused_(false), |
78 mouse_locked_(false), | 77 mouse_locked_(false), |
79 pending_lock_request_(false), | 78 pending_lock_request_(false), |
80 guest_visible_(false), | 79 guest_visible_(false), |
81 guest_opaque_(true), | 80 guest_opaque_(true), |
82 embedder_visible_(true), | 81 embedder_visible_(true), |
83 copy_request_id_(0), | 82 copy_request_id_(0), |
84 has_render_view_(has_render_view), | 83 has_render_view_(has_render_view), |
85 is_in_destruction_(false), | 84 is_in_destruction_(false), |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 OnSetContentsOpaque) | 155 OnSetContentsOpaque) |
157 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility) | 156 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility) |
158 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UnlockMouse_ACK, OnUnlockMouseAck) | 157 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UnlockMouse_ACK, OnUnlockMouseAck) |
159 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateGeometry, OnUpdateGeometry) | 158 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateGeometry, OnUpdateGeometry) |
160 IPC_MESSAGE_UNHANDLED(handled = false) | 159 IPC_MESSAGE_UNHANDLED(handled = false) |
161 IPC_END_MESSAGE_MAP() | 160 IPC_END_MESSAGE_MAP() |
162 return handled; | 161 return handled; |
163 } | 162 } |
164 | 163 |
165 void BrowserPluginGuest::Initialize( | 164 void BrowserPluginGuest::Initialize( |
| 165 int browser_plugin_instance_id, |
166 const BrowserPluginHostMsg_Attach_Params& params, | 166 const BrowserPluginHostMsg_Attach_Params& params, |
167 WebContentsImpl* embedder_web_contents, | 167 WebContentsImpl* embedder_web_contents) { |
168 const base::DictionaryValue& extra_params) { | |
169 focused_ = params.focused; | 168 focused_ = params.focused; |
170 guest_visible_ = params.visible; | 169 guest_visible_ = params.visible; |
171 guest_opaque_ = params.opaque; | 170 guest_opaque_ = params.opaque; |
172 guest_window_rect_ = gfx::Rect(params.origin, | 171 guest_window_rect_ = gfx::Rect(params.origin, |
173 params.resize_guest_params.view_size); | 172 params.resize_guest_params.view_size); |
174 | 173 |
175 // Once a BrowserPluginGuest has an embedder WebContents, it's considered to | 174 // Once a BrowserPluginGuest has an embedder WebContents, it's considered to |
176 // be attached. | 175 // be attached. |
177 embedder_web_contents_ = embedder_web_contents; | 176 embedder_web_contents_ = embedder_web_contents; |
178 | 177 |
(...skipping 18 matching lines...) Expand all Loading... |
197 // TODO(fsamuel): Remove this once http://crbug.com/169110 is addressed. | 196 // TODO(fsamuel): Remove this once http://crbug.com/169110 is addressed. |
198 renderer_prefs->report_frame_name_changes = true; | 197 renderer_prefs->report_frame_name_changes = true; |
199 // Navigation is disabled in Chrome Apps. We want to make sure guest-initiated | 198 // Navigation is disabled in Chrome Apps. We want to make sure guest-initiated |
200 // navigations still continue to function inside the app. | 199 // navigations still continue to function inside the app. |
201 renderer_prefs->browser_handles_all_top_level_requests = false; | 200 renderer_prefs->browser_handles_all_top_level_requests = false; |
202 // Disable "client blocked" error page for browser plugin. | 201 // Disable "client blocked" error page for browser plugin. |
203 renderer_prefs->disable_client_blocked_error_page = true; | 202 renderer_prefs->disable_client_blocked_error_page = true; |
204 | 203 |
205 embedder_web_contents_observer_.reset(new EmbedderWebContentsObserver(this)); | 204 embedder_web_contents_observer_.reset(new EmbedderWebContentsObserver(this)); |
206 | 205 |
207 OnResizeGuest(instance_id_, params.resize_guest_params); | 206 OnResizeGuest(guest_instance_id_, params.resize_guest_params); |
208 | 207 |
209 // Create a swapped out RenderView for the guest in the embedder render | 208 // Create a swapped out RenderView for the guest in the embedder render |
210 // process, so that the embedder can access the guest's window object. | 209 // process, so that the embedder can access the guest's window object. |
211 int guest_routing_id = | 210 int guest_routing_id = |
212 GetWebContents()->CreateSwappedOutRenderView( | 211 GetWebContents()->CreateSwappedOutRenderView( |
213 embedder_web_contents_->GetSiteInstance()); | 212 embedder_web_contents_->GetSiteInstance()); |
214 SendMessageToEmbedder( | |
215 new BrowserPluginMsg_GuestContentWindowReady(instance_id_, | |
216 guest_routing_id)); | |
217 | 213 |
218 // TODO(chrishtr): this code is wrong. The navigate_on_drag_drop field will | 214 // TODO(chrishtr): this code is wrong. The navigate_on_drag_drop field will |
219 // be reset again the next time preferences are updated. | 215 // be reset again the next time preferences are updated. |
220 WebPreferences prefs = | 216 WebPreferences prefs = |
221 GetWebContents()->GetRenderViewHost()->GetWebkitPreferences(); | 217 GetWebContents()->GetRenderViewHost()->GetWebkitPreferences(); |
222 prefs.navigate_on_drag_drop = false; | 218 prefs.navigate_on_drag_drop = false; |
223 GetWebContents()->GetRenderViewHost()->UpdateWebkitPreferences(prefs); | 219 GetWebContents()->GetRenderViewHost()->UpdateWebkitPreferences(prefs); |
224 | 220 |
225 // Enable input method for guest if it's enabled for the embedder. | 221 // Enable input method for guest if it's enabled for the embedder. |
226 if (static_cast<RenderViewHostImpl*>( | 222 if (static_cast<RenderViewHostImpl*>( |
227 embedder_web_contents_->GetRenderViewHost())->input_method_active()) { | 223 embedder_web_contents_->GetRenderViewHost())->input_method_active()) { |
228 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( | 224 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( |
229 GetWebContents()->GetRenderViewHost()); | 225 GetWebContents()->GetRenderViewHost()); |
230 guest_rvh->SetInputMethodActive(true); | 226 guest_rvh->SetInputMethodActive(true); |
231 } | 227 } |
232 | 228 |
233 // Inform the embedder of the guest's attachment. | 229 // Inform the embedder of the guest's attachment. |
234 SendMessageToEmbedder(new BrowserPluginMsg_Attach_ACK(instance_id_)); | 230 SendMessageToEmbedder(new BrowserPluginMsg_Attach_ACK(guest_instance_id_)); |
| 231 |
| 232 SendMessageToEmbedder(new BrowserPluginMsg_GuestContentWindowReady( |
| 233 guest_instance_id_, guest_routing_id)); |
235 } | 234 } |
236 | 235 |
237 BrowserPluginGuest::~BrowserPluginGuest() { | 236 BrowserPluginGuest::~BrowserPluginGuest() { |
238 } | 237 } |
239 | 238 |
240 // static | 239 // static |
241 BrowserPluginGuest* BrowserPluginGuest::Create( | 240 BrowserPluginGuest* BrowserPluginGuest::Create( |
242 int instance_id, | 241 int instance_id, |
243 WebContentsImpl* web_contents, | 242 WebContentsImpl* web_contents, |
244 BrowserPluginGuestDelegate* delegate) { | 243 BrowserPluginGuestDelegate* delegate) { |
(...skipping 13 matching lines...) Expand all Loading... |
258 render_view_host))); | 257 render_view_host))); |
259 } | 258 } |
260 | 259 |
261 RenderWidgetHostView* BrowserPluginGuest::GetEmbedderRenderWidgetHostView() { | 260 RenderWidgetHostView* BrowserPluginGuest::GetEmbedderRenderWidgetHostView() { |
262 if (!attached()) | 261 if (!attached()) |
263 return NULL; | 262 return NULL; |
264 return embedder_web_contents_->GetRenderWidgetHostView(); | 263 return embedder_web_contents_->GetRenderWidgetHostView(); |
265 } | 264 } |
266 | 265 |
267 void BrowserPluginGuest::UpdateVisibility() { | 266 void BrowserPluginGuest::UpdateVisibility() { |
268 OnSetVisibility(instance_id_, visible()); | 267 OnSetVisibility(guest_instance_id_, visible()); |
269 } | 268 } |
270 | 269 |
271 void BrowserPluginGuest::CopyFromCompositingSurface( | 270 void BrowserPluginGuest::CopyFromCompositingSurface( |
272 gfx::Rect src_subrect, | 271 gfx::Rect src_subrect, |
273 gfx::Size dst_size, | 272 gfx::Size dst_size, |
274 const base::Callback<void(bool, const SkBitmap&)>& callback) { | 273 const base::Callback<void(bool, const SkBitmap&)>& callback) { |
275 copy_request_callbacks_.insert(std::make_pair(++copy_request_id_, callback)); | 274 copy_request_callbacks_.insert(std::make_pair(++copy_request_id_, callback)); |
276 SendMessageToEmbedder( | 275 SendMessageToEmbedder( |
277 new BrowserPluginMsg_CopyFromCompositingSurface(instance_id(), | 276 new BrowserPluginMsg_CopyFromCompositingSurface(instance_id(), |
278 copy_request_id_, src_subrect, dst_size)); | 277 copy_request_id_, src_subrect, dst_size)); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.DidNavigate")); | 367 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.DidNavigate")); |
369 } | 368 } |
370 | 369 |
371 void BrowserPluginGuest::RenderViewReady() { | 370 void BrowserPluginGuest::RenderViewReady() { |
372 RenderViewHost* rvh = GetWebContents()->GetRenderViewHost(); | 371 RenderViewHost* rvh = GetWebContents()->GetRenderViewHost(); |
373 // TODO(fsamuel): Investigate whether it's possible to update state earlier | 372 // TODO(fsamuel): Investigate whether it's possible to update state earlier |
374 // here (see http://crbug.com/158151). | 373 // here (see http://crbug.com/158151). |
375 Send(new InputMsg_SetFocus(routing_id(), focused_)); | 374 Send(new InputMsg_SetFocus(routing_id(), focused_)); |
376 UpdateVisibility(); | 375 UpdateVisibility(); |
377 | 376 |
378 OnSetContentsOpaque(instance_id_, guest_opaque_); | 377 OnSetContentsOpaque(guest_instance_id_, guest_opaque_); |
379 | 378 |
380 RenderWidgetHostImpl::From(rvh)->set_hung_renderer_delay_ms( | 379 RenderWidgetHostImpl::From(rvh)->set_hung_renderer_delay_ms( |
381 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)); | 380 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)); |
382 } | 381 } |
383 | 382 |
384 void BrowserPluginGuest::RenderProcessGone(base::TerminationStatus status) { | 383 void BrowserPluginGuest::RenderProcessGone(base::TerminationStatus status) { |
385 SendMessageToEmbedder(new BrowserPluginMsg_GuestGone(instance_id())); | 384 SendMessageToEmbedder(new BrowserPluginMsg_GuestGone(instance_id())); |
386 switch (status) { | 385 switch (status) { |
387 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: | 386 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: |
388 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Killed")); | 387 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Killed")); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 IPC_MESSAGE_HANDLER(ViewHostMsg_TextInputStateChanged, | 450 IPC_MESSAGE_HANDLER(ViewHostMsg_TextInputStateChanged, |
452 OnTextInputStateChanged) | 451 OnTextInputStateChanged) |
453 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse) | 452 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse) |
454 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) | 453 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnUpdateRect) |
455 IPC_MESSAGE_UNHANDLED(handled = false) | 454 IPC_MESSAGE_UNHANDLED(handled = false) |
456 IPC_END_MESSAGE_MAP() | 455 IPC_END_MESSAGE_MAP() |
457 return handled; | 456 return handled; |
458 } | 457 } |
459 | 458 |
460 void BrowserPluginGuest::Attach( | 459 void BrowserPluginGuest::Attach( |
| 460 int browser_plugin_instance_id, |
461 WebContentsImpl* embedder_web_contents, | 461 WebContentsImpl* embedder_web_contents, |
462 const BrowserPluginHostMsg_Attach_Params& params, | 462 const BrowserPluginHostMsg_Attach_Params& params) { |
463 const base::DictionaryValue& extra_params) { | |
464 if (attached()) | 463 if (attached()) |
465 return; | 464 return; |
466 | 465 |
467 if (delegate_) | 466 if (delegate_) |
468 delegate_->WillAttach(embedder_web_contents, extra_params); | 467 delegate_->WillAttach(embedder_web_contents); |
469 | 468 |
470 // If a RenderView has already been created for this new window, then we need | 469 // If a RenderView has already been created for this new window, then we need |
471 // to initialize the browser-side state now so that the RenderFrameHostManager | 470 // to initialize the browser-side state now so that the RenderFrameHostManager |
472 // does not create a new RenderView on navigation. | 471 // does not create a new RenderView on navigation. |
473 if (has_render_view_) { | 472 if (has_render_view_) { |
474 static_cast<RenderViewHostImpl*>( | 473 static_cast<RenderViewHostImpl*>( |
475 GetWebContents()->GetRenderViewHost())->Init(); | 474 GetWebContents()->GetRenderViewHost())->Init(); |
476 WebContentsViewGuest* new_view = | 475 WebContentsViewGuest* new_view = |
477 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); | 476 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); |
478 new_view->CreateViewForWidget(web_contents()->GetRenderViewHost()); | 477 new_view->CreateViewForWidget(web_contents()->GetRenderViewHost()); |
479 } | 478 } |
480 | 479 |
481 Initialize(params, embedder_web_contents, extra_params); | 480 Initialize(browser_plugin_instance_id, params, embedder_web_contents); |
482 | 481 |
483 SendQueuedMessages(); | 482 SendQueuedMessages(); |
484 | 483 |
485 if (delegate_) | 484 if (delegate_) |
486 delegate_->DidAttach(); | 485 delegate_->DidAttach(); |
487 | 486 |
488 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Attached")); | 487 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Attached")); |
489 } | 488 } |
490 | 489 |
491 void BrowserPluginGuest::OnCompositorFrameSwappedACK( | 490 void BrowserPluginGuest::OnCompositorFrameSwappedACK( |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 void BrowserPluginGuest::OnImeCompositionRangeChanged( | 836 void BrowserPluginGuest::OnImeCompositionRangeChanged( |
838 const gfx::Range& range, | 837 const gfx::Range& range, |
839 const std::vector<gfx::Rect>& character_bounds) { | 838 const std::vector<gfx::Rect>& character_bounds) { |
840 static_cast<RenderWidgetHostViewBase*>( | 839 static_cast<RenderWidgetHostViewBase*>( |
841 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( | 840 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( |
842 range, character_bounds); | 841 range, character_bounds); |
843 } | 842 } |
844 #endif | 843 #endif |
845 | 844 |
846 } // namespace content | 845 } // namespace content |
OLD | NEW |