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/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility) | 192 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility) |
193 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UnlockMouse_ACK, OnUnlockMouseAck) | 193 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UnlockMouse_ACK, OnUnlockMouseAck) |
194 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateGeometry, OnUpdateGeometry) | 194 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateGeometry, OnUpdateGeometry) |
195 IPC_MESSAGE_UNHANDLED(handled = false) | 195 IPC_MESSAGE_UNHANDLED(handled = false) |
196 IPC_END_MESSAGE_MAP() | 196 IPC_END_MESSAGE_MAP() |
197 return handled; | 197 return handled; |
198 } | 198 } |
199 | 199 |
200 void BrowserPluginGuest::Initialize( | 200 void BrowserPluginGuest::Initialize( |
201 const BrowserPluginHostMsg_Attach_Params& params, | 201 const BrowserPluginHostMsg_Attach_Params& params, |
202 WebContentsImpl* embedder_web_contents) { | 202 WebContentsImpl* embedder_web_contents, |
203 const base::DictionaryValue& extra_params) { | |
204 printf("BPG::Initialize()\n"); | |
203 focused_ = params.focused; | 205 focused_ = params.focused; |
204 guest_visible_ = params.visible; | 206 guest_visible_ = params.visible; |
205 guest_opaque_ = params.opaque; | 207 guest_opaque_ = params.opaque; |
206 guest_window_rect_ = params.resize_guest_params.view_rect; | 208 guest_window_rect_ = params.resize_guest_params.view_rect; |
207 | 209 |
208 auto_size_enabled_ = params.auto_size_params.enable; | 210 auto_size_enabled_ = params.auto_size_params.enable; |
209 max_auto_size_ = params.auto_size_params.max_size; | 211 max_auto_size_ = params.auto_size_params.max_size; |
210 min_auto_size_ = params.auto_size_params.min_size; | 212 min_auto_size_ = params.auto_size_params.min_size; |
211 | 213 |
212 // Once a BrowserPluginGuest has an embedder WebContents, it's considered to | 214 // Once a BrowserPluginGuest has an embedder WebContents, it's considered to |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 | 247 |
246 // Create a swapped out RenderView for the guest in the embedder render | 248 // Create a swapped out RenderView for the guest in the embedder render |
247 // process, so that the embedder can access the guest's window object. | 249 // process, so that the embedder can access the guest's window object. |
248 int guest_routing_id = | 250 int guest_routing_id = |
249 GetWebContents()->CreateSwappedOutRenderView( | 251 GetWebContents()->CreateSwappedOutRenderView( |
250 embedder_web_contents_->GetSiteInstance()); | 252 embedder_web_contents_->GetSiteInstance()); |
251 SendMessageToEmbedder( | 253 SendMessageToEmbedder( |
252 new BrowserPluginMsg_GuestContentWindowReady(instance_id_, | 254 new BrowserPluginMsg_GuestContentWindowReady(instance_id_, |
253 guest_routing_id)); | 255 guest_routing_id)); |
254 | 256 |
255 if (!params.src.empty()) { | |
256 // params.src will be validated in BrowserPluginGuest::OnNavigateGuest. | |
257 OnNavigateGuest(instance_id_, params.src); | |
258 has_render_view_ = true; | |
259 } | |
260 | |
261 WebPreferences prefs = GetWebContents()->GetWebkitPrefs(); | 257 WebPreferences prefs = GetWebContents()->GetWebkitPrefs(); |
262 prefs.navigate_on_drag_drop = false; | 258 prefs.navigate_on_drag_drop = false; |
263 GetWebContents()->GetRenderViewHost()->UpdateWebkitPreferences(prefs); | 259 GetWebContents()->GetRenderViewHost()->UpdateWebkitPreferences(prefs); |
264 | 260 |
265 // Enable input method for guest if it's enabled for the embedder. | 261 // Enable input method for guest if it's enabled for the embedder. |
266 if (static_cast<RenderViewHostImpl*>( | 262 if (static_cast<RenderViewHostImpl*>( |
267 embedder_web_contents_->GetRenderViewHost())->input_method_active()) { | 263 embedder_web_contents_->GetRenderViewHost())->input_method_active()) { |
268 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( | 264 RenderViewHostImpl* guest_rvh = static_cast<RenderViewHostImpl*>( |
269 GetWebContents()->GetRenderViewHost()); | 265 GetWebContents()->GetRenderViewHost()); |
270 guest_rvh->SetInputMethodActive(true); | 266 guest_rvh->SetInputMethodActive(true); |
271 } | 267 } |
272 | 268 |
273 // Inform the embedder of the guest's information. | 269 // Inform the embedder of the guest's information. |
274 // We pull the partition information from the site's URL, which is of the form | 270 // We pull the partition information from the site's URL, which is of the form |
275 // guest://site/{persist}?{partition_name}. | 271 // guest://site/{persist}?{partition_name}. |
276 const GURL& site_url = GetWebContents()->GetSiteInstance()->GetSiteURL(); | 272 const GURL& site_url = GetWebContents()->GetSiteInstance()->GetSiteURL(); |
277 BrowserPluginMsg_Attach_ACK_Params ack_params; | 273 BrowserPluginMsg_Attach_ACK_Params ack_params; |
278 ack_params.storage_partition_id = site_url.query(); | 274 ack_params.storage_partition_id = site_url.query(); |
279 ack_params.persist_storage = | 275 ack_params.persist_storage = |
280 site_url.path().find("persist") != std::string::npos; | 276 site_url.path().find("persist") != std::string::npos; |
281 SendMessageToEmbedder( | 277 SendMessageToEmbedder( |
282 new BrowserPluginMsg_Attach_ACK(instance_id_, ack_params)); | 278 new BrowserPluginMsg_Attach_ACK(instance_id_, ack_params)); |
283 | 279 |
284 if (delegate_) | 280 if (delegate_) { |
285 delegate_->DidAttach(); | 281 delegate_->DidAttach(extra_params); |
282 // TODO(lazyboy): Should not set this if src is empty. | |
283 has_render_view_ = true; | |
Fady Samuel
2014/05/27 14:19:06
This flag only makes sense for a new window with a
lazyboy
2014/05/27 20:43:00
So what change is required to get that info here t
| |
284 } | |
286 } | 285 } |
287 | 286 |
288 BrowserPluginGuest::~BrowserPluginGuest() { | 287 BrowserPluginGuest::~BrowserPluginGuest() { |
289 while (!pending_messages_.empty()) { | 288 while (!pending_messages_.empty()) { |
290 delete pending_messages_.front(); | 289 delete pending_messages_.front(); |
291 pending_messages_.pop(); | 290 pending_messages_.pop(); |
292 } | 291 } |
293 } | 292 } |
294 | 293 |
295 // static | 294 // static |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
416 ColorChooser* BrowserPluginGuest::OpenColorChooser( | 415 ColorChooser* BrowserPluginGuest::OpenColorChooser( |
417 WebContents* web_contents, | 416 WebContents* web_contents, |
418 SkColor color, | 417 SkColor color, |
419 const std::vector<ColorSuggestion>& suggestions) { | 418 const std::vector<ColorSuggestion>& suggestions) { |
420 if (!delegate_) | 419 if (!delegate_) |
421 return NULL; | 420 return NULL; |
422 return delegate_->OpenColorChooser(web_contents, color, suggestions); | 421 return delegate_->OpenColorChooser(web_contents, color, suggestions); |
423 } | 422 } |
424 | 423 |
425 bool BrowserPluginGuest::HandleContextMenu(const ContextMenuParams& params) { | 424 bool BrowserPluginGuest::HandleContextMenu(const ContextMenuParams& params) { |
425 printf("+++ %s\n", __PRETTY_FUNCTION__); | |
426 if (delegate_) { | 426 if (delegate_) { |
427 WebContentsViewGuest* view_guest = | 427 WebContentsViewGuest* view_guest = |
428 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); | 428 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); |
429 ContextMenuParams context_menu_params = | 429 ContextMenuParams context_menu_params = |
430 view_guest->ConvertContextMenuParams(params); | 430 view_guest->ConvertContextMenuParams(params); |
431 | 431 |
432 printf("To delegate_\n"); | |
432 return delegate_->HandleContextMenu(context_menu_params); | 433 return delegate_->HandleContextMenu(context_menu_params); |
433 } | 434 } |
435 printf("To WebContentsViewGuest\n"); | |
434 | 436 |
435 // Will be handled by WebContentsViewGuest. | 437 // Will be handled by WebContentsViewGuest. |
436 return false; | 438 return false; |
437 } | 439 } |
438 | 440 |
439 void BrowserPluginGuest::HandleKeyboardEvent( | 441 void BrowserPluginGuest::HandleKeyboardEvent( |
440 WebContents* source, | 442 WebContents* source, |
441 const NativeWebKeyboardEvent& event) { | 443 const NativeWebKeyboardEvent& event) { |
442 if (!delegate_) | 444 if (!delegate_) |
443 return; | 445 return; |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
700 return handled; | 702 return handled; |
701 } | 703 } |
702 | 704 |
703 void BrowserPluginGuest::Attach( | 705 void BrowserPluginGuest::Attach( |
704 WebContentsImpl* embedder_web_contents, | 706 WebContentsImpl* embedder_web_contents, |
705 BrowserPluginHostMsg_Attach_Params params, | 707 BrowserPluginHostMsg_Attach_Params params, |
706 const base::DictionaryValue& extra_params) { | 708 const base::DictionaryValue& extra_params) { |
707 if (attached()) | 709 if (attached()) |
708 return; | 710 return; |
709 | 711 |
710 // Clear parameters that get inherited from the opener. | |
711 params.storage_partition_id.clear(); | |
712 params.persist_storage = false; | |
713 params.src.clear(); | |
714 | |
715 // If a RenderView has already been created for this new window, then we need | 712 // If a RenderView has already been created for this new window, then we need |
716 // to initialize the browser-side state now so that the RenderFrameHostManager | 713 // to initialize the browser-side state now so that the RenderFrameHostManager |
717 // does not create a new RenderView on navigation. | 714 // does not create a new RenderView on navigation. |
718 if (has_render_view_) { | 715 if (has_render_view_) { |
719 static_cast<RenderViewHostImpl*>( | 716 static_cast<RenderViewHostImpl*>( |
720 GetWebContents()->GetRenderViewHost())->Init(); | 717 GetWebContents()->GetRenderViewHost())->Init(); |
721 WebContentsViewGuest* new_view = | 718 WebContentsViewGuest* new_view = |
722 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); | 719 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); |
723 new_view->CreateViewForWidget(web_contents()->GetRenderViewHost()); | 720 new_view->CreateViewForWidget(web_contents()->GetRenderViewHost()); |
724 } | 721 } |
725 | 722 |
726 Initialize(params, embedder_web_contents); | 723 Initialize(params, embedder_web_contents, extra_params); |
727 | 724 |
728 SendQueuedMessages(); | 725 SendQueuedMessages(); |
729 | 726 |
730 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Attached")); | 727 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Attached")); |
731 } | 728 } |
732 | 729 |
733 void BrowserPluginGuest::OnCompositorFrameSwappedACK( | 730 void BrowserPluginGuest::OnCompositorFrameSwappedACK( |
734 int instance_id, | 731 int instance_id, |
735 const FrameHostMsg_CompositorFrameSwappedACK_Params& params) { | 732 const FrameHostMsg_CompositorFrameSwappedACK_Params& params) { |
736 RenderWidgetHostImpl::SendSwapCompositorFrameAck(params.producing_route_id, | 733 RenderWidgetHostImpl::SendSwapCompositorFrameAck(params.producing_route_id, |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1147 void BrowserPluginGuest::OnImeCompositionRangeChanged( | 1144 void BrowserPluginGuest::OnImeCompositionRangeChanged( |
1148 const gfx::Range& range, | 1145 const gfx::Range& range, |
1149 const std::vector<gfx::Rect>& character_bounds) { | 1146 const std::vector<gfx::Rect>& character_bounds) { |
1150 static_cast<RenderWidgetHostViewBase*>( | 1147 static_cast<RenderWidgetHostViewBase*>( |
1151 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( | 1148 web_contents()->GetRenderWidgetHostView())->ImeCompositionRangeChanged( |
1152 range, character_bounds); | 1149 range, character_bounds); |
1153 } | 1150 } |
1154 #endif | 1151 #endif |
1155 | 1152 |
1156 } // namespace content | 1153 } // namespace content |
OLD | NEW |