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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 : PermissionRequest(guest), | 91 : PermissionRequest(guest), |
92 instance_id_(instance_id) { | 92 instance_id_(instance_id) { |
93 RecordAction( | 93 RecordAction( |
94 base::UserMetricsAction("BrowserPlugin.Guest.PermissionRequest.NewWindow
")); | 94 base::UserMetricsAction("BrowserPlugin.Guest.PermissionRequest.NewWindow
")); |
95 } | 95 } |
96 | 96 |
97 virtual void RespondImpl(bool should_allow, | 97 virtual void RespondImpl(bool should_allow, |
98 const std::string& user_input) OVERRIDE { | 98 const std::string& user_input) OVERRIDE { |
99 int embedder_render_process_id = | 99 int embedder_render_process_id = |
100 guest_->embedder_web_contents()->GetRenderProcessHost()->GetID(); | 100 guest_->embedder_web_contents()->GetRenderProcessHost()->GetID(); |
101 BrowserPluginGuest* guest = | 101 BrowserPluginGuest* guest = guest_->GetBrowserPluginGuestManager()-> |
102 guest_->GetWebContents()->GetBrowserPluginGuestManager()-> | 102 GetGuestByInstanceID(instance_id_, embedder_render_process_id); |
103 GetGuestByInstanceID(instance_id_, embedder_render_process_id); | |
104 if (!guest) { | 103 if (!guest) { |
105 VLOG(0) << "Guest not found. Instance ID: " << instance_id_; | 104 VLOG(0) << "Guest not found. Instance ID: " << instance_id_; |
106 return; | 105 return; |
107 } | 106 } |
108 | 107 |
109 // If we do not destroy the guest then we allow the new window. | 108 // If we do not destroy the guest then we allow the new window. |
110 if (!should_allow) | 109 if (!should_allow) |
111 guest->Destroy(); | 110 guest->Destroy(); |
112 } | 111 } |
113 | 112 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 181 |
183 private: | 182 private: |
184 BrowserPluginGuest* browser_plugin_guest_; | 183 BrowserPluginGuest* browser_plugin_guest_; |
185 | 184 |
186 DISALLOW_COPY_AND_ASSIGN(EmbedderWebContentsObserver); | 185 DISALLOW_COPY_AND_ASSIGN(EmbedderWebContentsObserver); |
187 }; | 186 }; |
188 | 187 |
189 BrowserPluginGuest::BrowserPluginGuest( | 188 BrowserPluginGuest::BrowserPluginGuest( |
190 int instance_id, | 189 int instance_id, |
191 bool has_render_view, | 190 bool has_render_view, |
192 WebContentsImpl* web_contents, | 191 WebContentsImpl* web_contents) |
193 BrowserPluginGuest* opener) | |
194 : WebContentsObserver(web_contents), | 192 : WebContentsObserver(web_contents), |
195 embedder_web_contents_(NULL), | 193 embedder_web_contents_(NULL), |
196 instance_id_(instance_id), | 194 instance_id_(instance_id), |
197 guest_device_scale_factor_(1.0f), | 195 guest_device_scale_factor_(1.0f), |
198 guest_hang_timeout_( | 196 guest_hang_timeout_( |
199 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)), | 197 base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)), |
200 focused_(false), | 198 focused_(false), |
201 mouse_locked_(false), | 199 mouse_locked_(false), |
202 pending_lock_request_(false), | 200 pending_lock_request_(false), |
203 embedder_visible_(true), | 201 embedder_visible_(true), |
204 auto_size_enabled_(false), | 202 auto_size_enabled_(false), |
205 copy_request_id_(0), | 203 copy_request_id_(0), |
206 next_permission_request_id_(browser_plugin::kInvalidPermissionRequestID), | 204 next_permission_request_id_(browser_plugin::kInvalidPermissionRequestID), |
207 has_render_view_(has_render_view), | 205 has_render_view_(has_render_view), |
208 last_seen_auto_size_enabled_(false), | 206 last_seen_auto_size_enabled_(false), |
209 is_in_destruction_(false), | 207 is_in_destruction_(false), |
210 last_text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 208 last_text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
211 last_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), | 209 last_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), |
212 last_can_compose_inline_(true), | 210 last_can_compose_inline_(true), |
213 weak_ptr_factory_(this) { | 211 weak_ptr_factory_(this) { |
214 DCHECK(web_contents); | 212 DCHECK(web_contents); |
215 web_contents->SetDelegate(this); | 213 web_contents->SetDelegate(this); |
216 if (opener) | 214 GetBrowserPluginGuestManager()->AddGuest(instance_id_, GetWebContents()); |
217 opener_ = opener->AsWeakPtr(); | |
218 GetWebContents()->GetBrowserPluginGuestManager()->AddGuest(instance_id_, | |
219 GetWebContents()); | |
220 } | 215 } |
221 | 216 |
222 bool BrowserPluginGuest::AddMessageToConsole(WebContents* source, | 217 bool BrowserPluginGuest::AddMessageToConsole(WebContents* source, |
223 int32 level, | 218 int32 level, |
224 const base::string16& message, | 219 const base::string16& message, |
225 int32 line_no, | 220 int32 line_no, |
226 const base::string16& source_id) { | 221 const base::string16& source_id) { |
227 if (!delegate_) | 222 if (!delegate_) |
228 return false; | 223 return false; |
229 | 224 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 BrowserPluginGuestDelegate::PermissionResponseCallback callback = | 290 BrowserPluginGuestDelegate::PermissionResponseCallback callback = |
296 base::Bind(&BrowserPluginGuest::RespondToPermissionRequest, | 291 base::Bind(&BrowserPluginGuest::RespondToPermissionRequest, |
297 AsWeakPtr(), | 292 AsWeakPtr(), |
298 request_id); | 293 request_id); |
299 delegate_->RequestPermission( | 294 delegate_->RequestPermission( |
300 permission_type, request_info, callback, request->AllowedByDefault()); | 295 permission_type, request_info, callback, request->AllowedByDefault()); |
301 } | 296 } |
302 | 297 |
303 BrowserPluginGuest* BrowserPluginGuest::CreateNewGuestWindow( | 298 BrowserPluginGuest* BrowserPluginGuest::CreateNewGuestWindow( |
304 const OpenURLParams& params) { | 299 const OpenURLParams& params) { |
305 BrowserPluginGuestManager* guest_manager = | 300 BrowserPluginGuestManager* guest_manager = GetBrowserPluginGuestManager(); |
306 GetWebContents()->GetBrowserPluginGuestManager(); | |
307 | 301 |
308 // Allocate a new instance ID for the new guest. | 302 // Allocate a new instance ID for the new guest. |
309 int instance_id = guest_manager->get_next_instance_id(); | 303 int instance_id = guest_manager->GetNextInstanceID(); |
310 | 304 |
311 // Set the attach params to use the same partition as the opener. | 305 // Set the attach params to use the same partition as the opener. |
312 // We pull the partition information from the site's URL, which is of the form | 306 // We pull the partition information from the site's URL, which is of the form |
313 // guest://site/{persist}?{partition_name}. | 307 // guest://site/{persist}?{partition_name}. |
314 const GURL& site_url = GetWebContents()->GetSiteInstance()->GetSiteURL(); | 308 const GURL& site_url = GetWebContents()->GetSiteInstance()->GetSiteURL(); |
315 BrowserPluginHostMsg_Attach_Params attach_params; | 309 BrowserPluginHostMsg_Attach_Params attach_params; |
316 attach_params.storage_partition_id = site_url.query(); | 310 attach_params.storage_partition_id = site_url.query(); |
317 attach_params.persist_storage = | 311 attach_params.persist_storage = |
318 site_url.path().find("persist") != std::string::npos; | 312 site_url.path().find("persist") != std::string::npos; |
319 | 313 |
320 // The new guest gets a copy of this guest's extra params so that the content | 314 // The new guest gets a copy of this guest's extra params so that the content |
321 // embedder exposes the same API for this guest as its opener. | 315 // embedder exposes the same API for this guest as its opener. |
322 scoped_ptr<base::DictionaryValue> extra_params( | 316 scoped_ptr<base::DictionaryValue> extra_params( |
323 extra_attach_params_->DeepCopy()); | 317 extra_attach_params_->DeepCopy()); |
324 BrowserPluginGuest* new_guest = | 318 BrowserPluginGuest* new_guest = |
325 GetWebContents()->GetBrowserPluginGuestManager()->CreateGuest( | 319 guest_manager->CreateGuest(GetWebContents()->GetSiteInstance(), |
326 GetWebContents()->GetSiteInstance(), instance_id, | 320 instance_id, |
327 attach_params, extra_params.Pass()); | 321 attach_params, |
328 new_guest->opener_ = AsWeakPtr(); | 322 extra_params.Pass()); |
| 323 if (new_guest->delegate_) |
| 324 new_guest->delegate_->SetOpener(GetWebContents()); |
329 | 325 |
330 // Take ownership of |new_guest|. | 326 // Take ownership of |new_guest|. |
331 pending_new_windows_.insert( | 327 pending_new_windows_.insert( |
332 std::make_pair(new_guest, NewWindowInfo(params.url, std::string()))); | 328 std::make_pair(new_guest, NewWindowInfo(params.url, std::string()))); |
333 | 329 |
334 // Request permission to show the new window. | 330 // Request permission to show the new window. |
335 RequestNewWindowPermission(params.disposition, gfx::Rect(), | 331 RequestNewWindowPermission(params.disposition, gfx::Rect(), |
336 params.user_gesture, new_guest->GetWebContents()); | 332 params.user_gesture, new_guest->GetWebContents()); |
337 | 333 |
338 return new_guest; | 334 return new_guest; |
339 } | 335 } |
340 | 336 |
341 base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() { | 337 base::WeakPtr<BrowserPluginGuest> BrowserPluginGuest::AsWeakPtr() { |
342 return weak_ptr_factory_.GetWeakPtr(); | 338 return weak_ptr_factory_.GetWeakPtr(); |
343 } | 339 } |
344 | 340 |
345 void BrowserPluginGuest::EmbedderDestroyed() { | 341 void BrowserPluginGuest::EmbedderDestroyed() { |
346 embedder_web_contents_ = NULL; | 342 embedder_web_contents_ = NULL; |
347 if (delegate_) | 343 if (delegate_) |
348 delegate_->EmbedderDestroyed(); | 344 delegate_->EmbedderDestroyed(); |
349 Destroy(); | 345 Destroy(); |
350 } | 346 } |
351 | 347 |
352 void BrowserPluginGuest::Destroy() { | 348 void BrowserPluginGuest::Destroy() { |
353 is_in_destruction_ = true; | 349 is_in_destruction_ = true; |
354 if (!attached() && opener()) | 350 if (!attached() && GetOpener()) |
355 opener()->pending_new_windows_.erase(this); | 351 GetOpener()->pending_new_windows_.erase(this); |
356 DestroyUnattachedWindows(); | 352 DestroyUnattachedWindows(); |
357 GetWebContents()->GetBrowserPluginGuestManager()->RemoveGuest(instance_id_); | 353 GetBrowserPluginGuestManager()->RemoveGuest(instance_id_); |
358 delete GetWebContents(); | 354 delete GetWebContents(); |
359 } | 355 } |
360 | 356 |
361 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( | 357 bool BrowserPluginGuest::OnMessageReceivedFromEmbedder( |
362 const IPC::Message& message) { | 358 const IPC::Message& message) { |
363 bool handled = true; | 359 bool handled = true; |
364 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) | 360 IPC_BEGIN_MESSAGE_MAP(BrowserPluginGuest, message) |
365 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_CompositorFrameSwappedACK, | 361 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_CompositorFrameSwappedACK, |
366 OnCompositorFrameSwappedACK) | 362 OnCompositorFrameSwappedACK) |
367 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_CopyFromCompositingSurfaceAck, | 363 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_CopyFromCompositingSurfaceAck, |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 BrowserPluginGuest* BrowserPluginGuest::Create( | 498 BrowserPluginGuest* BrowserPluginGuest::Create( |
503 int instance_id, | 499 int instance_id, |
504 SiteInstance* guest_site_instance, | 500 SiteInstance* guest_site_instance, |
505 WebContentsImpl* web_contents, | 501 WebContentsImpl* web_contents, |
506 scoped_ptr<base::DictionaryValue> extra_params) { | 502 scoped_ptr<base::DictionaryValue> extra_params) { |
507 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create")); | 503 RecordAction(base::UserMetricsAction("BrowserPlugin.Guest.Create")); |
508 BrowserPluginGuest* guest = NULL; | 504 BrowserPluginGuest* guest = NULL; |
509 if (factory_) { | 505 if (factory_) { |
510 guest = factory_->CreateBrowserPluginGuest(instance_id, web_contents); | 506 guest = factory_->CreateBrowserPluginGuest(instance_id, web_contents); |
511 } else { | 507 } else { |
512 guest = new BrowserPluginGuest(instance_id, false, web_contents, NULL); | 508 guest = new BrowserPluginGuest(instance_id, false, web_contents); |
513 } | 509 } |
514 guest->extra_attach_params_.reset(extra_params->DeepCopy()); | 510 guest->extra_attach_params_.reset(extra_params->DeepCopy()); |
515 web_contents->SetBrowserPluginGuest(guest); | 511 web_contents->SetBrowserPluginGuest(guest); |
516 BrowserPluginGuestDelegate* delegate = NULL; | 512 BrowserPluginGuestDelegate* delegate = NULL; |
517 GetContentClient()->browser()->GuestWebContentsCreated( | 513 GetContentClient()->browser()->GuestWebContentsCreated( |
518 guest_site_instance, web_contents, NULL, &delegate, extra_params.Pass()); | 514 guest_site_instance, web_contents, NULL, &delegate, extra_params.Pass()); |
519 guest->SetDelegate(delegate); | 515 guest->SetDelegate(delegate); |
520 return guest; | 516 return guest; |
521 } | 517 } |
522 | 518 |
523 // static | 519 // static |
524 BrowserPluginGuest* BrowserPluginGuest::CreateWithOpener( | 520 BrowserPluginGuest* BrowserPluginGuest::CreateWithOpener( |
525 int instance_id, | 521 int instance_id, |
526 bool has_render_view, | 522 bool has_render_view, |
527 WebContentsImpl* web_contents, | 523 WebContentsImpl* web_contents, |
528 BrowserPluginGuest* opener) { | 524 BrowserPluginGuest* opener) { |
529 BrowserPluginGuest* guest = | 525 BrowserPluginGuest* guest = |
530 new BrowserPluginGuest( | 526 new BrowserPluginGuest( |
531 instance_id, has_render_view, web_contents, opener); | 527 instance_id, has_render_view, web_contents); |
532 web_contents->SetBrowserPluginGuest(guest); | 528 web_contents->SetBrowserPluginGuest(guest); |
533 BrowserPluginGuestDelegate* delegate = NULL; | 529 BrowserPluginGuestDelegate* delegate = NULL; |
534 GetContentClient()->browser()->GuestWebContentsCreated( | 530 GetContentClient()->browser()->GuestWebContentsCreated( |
535 opener->GetWebContents()->GetSiteInstance(), | 531 opener->GetWebContents()->GetSiteInstance(), |
536 web_contents, opener->GetWebContents(), &delegate, | 532 web_contents, opener->GetWebContents(), &delegate, |
537 scoped_ptr<base::DictionaryValue>()); | 533 scoped_ptr<base::DictionaryValue>()); |
538 guest->SetDelegate(delegate); | 534 guest->SetDelegate(delegate); |
539 return guest; | 535 return guest; |
540 } | 536 } |
541 | 537 |
542 RenderWidgetHostView* BrowserPluginGuest::GetEmbedderRenderWidgetHostView() { | 538 RenderWidgetHostView* BrowserPluginGuest::GetEmbedderRenderWidgetHostView() { |
543 if (!attached()) | 539 if (!attached()) |
544 return NULL; | 540 return NULL; |
545 return embedder_web_contents_->GetRenderWidgetHostView(); | 541 return embedder_web_contents_->GetRenderWidgetHostView(); |
546 } | 542 } |
547 | 543 |
| 544 BrowserPluginGuest* BrowserPluginGuest::GetOpener() const { |
| 545 if (!delegate_) |
| 546 return NULL; |
| 547 |
| 548 WebContents* opener = delegate_->GetOpener(); |
| 549 if (!opener) |
| 550 return NULL; |
| 551 |
| 552 return static_cast<WebContentsImpl*>(opener)->GetBrowserPluginGuest(); |
| 553 } |
| 554 |
548 void BrowserPluginGuest::UpdateVisibility() { | 555 void BrowserPluginGuest::UpdateVisibility() { |
549 OnSetVisibility(instance_id_, visible()); | 556 OnSetVisibility(instance_id_, visible()); |
550 } | 557 } |
551 | 558 |
552 void BrowserPluginGuest::CopyFromCompositingSurface( | 559 void BrowserPluginGuest::CopyFromCompositingSurface( |
553 gfx::Rect src_subrect, | 560 gfx::Rect src_subrect, |
554 gfx::Size dst_size, | 561 gfx::Size dst_size, |
555 const base::Callback<void(bool, const SkBitmap&)>& callback) { | 562 const base::Callback<void(bool, const SkBitmap&)>& callback) { |
556 copy_request_callbacks_.insert(std::make_pair(++copy_request_id_, callback)); | 563 copy_request_callbacks_.insert(std::make_pair(++copy_request_id_, callback)); |
557 SendMessageToEmbedder( | 564 SendMessageToEmbedder( |
558 new BrowserPluginMsg_CopyFromCompositingSurface(instance_id(), | 565 new BrowserPluginMsg_CopyFromCompositingSurface(instance_id(), |
559 copy_request_id_, src_subrect, dst_size)); | 566 copy_request_id_, src_subrect, dst_size)); |
560 } | 567 } |
561 | 568 |
| 569 BrowserPluginGuestManager* |
| 570 BrowserPluginGuest::GetBrowserPluginGuestManager() const { |
| 571 return BrowserPluginGuestManager::FromBrowserContext( |
| 572 GetWebContents()->GetBrowserContext()); |
| 573 } |
| 574 |
562 // screen. | 575 // screen. |
563 gfx::Rect BrowserPluginGuest::ToGuestRect(const gfx::Rect& bounds) { | 576 gfx::Rect BrowserPluginGuest::ToGuestRect(const gfx::Rect& bounds) { |
564 gfx::Rect guest_rect(bounds); | 577 gfx::Rect guest_rect(bounds); |
565 guest_rect.Offset(guest_window_rect_.OffsetFromOrigin()); | 578 guest_rect.Offset(guest_window_rect_.OffsetFromOrigin()); |
566 return guest_rect; | 579 return guest_rect; |
567 } | 580 } |
568 | 581 |
569 void BrowserPluginGuest::EmbedderVisibilityChanged(bool visible) { | 582 void BrowserPluginGuest::EmbedderVisibilityChanged(bool visible) { |
570 embedder_visible_ = visible; | 583 embedder_visible_ = visible; |
571 UpdateVisibility(); | 584 UpdateVisibility(); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 } | 710 } |
698 | 711 |
699 WebContents* BrowserPluginGuest::OpenURLFromTab(WebContents* source, | 712 WebContents* BrowserPluginGuest::OpenURLFromTab(WebContents* source, |
700 const OpenURLParams& params) { | 713 const OpenURLParams& params) { |
701 // If the guest wishes to navigate away prior to attachment then we save the | 714 // If the guest wishes to navigate away prior to attachment then we save the |
702 // navigation to perform upon attachment. Navigation initializes a lot of | 715 // navigation to perform upon attachment. Navigation initializes a lot of |
703 // state that assumes an embedder exists, such as RenderWidgetHostViewGuest. | 716 // state that assumes an embedder exists, such as RenderWidgetHostViewGuest. |
704 // Navigation also resumes resource loading which we don't want to allow | 717 // Navigation also resumes resource loading which we don't want to allow |
705 // until attachment. | 718 // until attachment. |
706 if (!attached()) { | 719 if (!attached()) { |
707 PendingWindowMap::iterator it = opener()->pending_new_windows_.find(this); | 720 PendingWindowMap::iterator it = |
708 if (it == opener()->pending_new_windows_.end()) | 721 GetOpener()->pending_new_windows_.find(this); |
| 722 if (it == GetOpener()->pending_new_windows_.end()) |
709 return NULL; | 723 return NULL; |
710 const NewWindowInfo& old_target_url = it->second; | 724 const NewWindowInfo& old_target_url = it->second; |
711 NewWindowInfo new_window_info(params.url, old_target_url.name); | 725 NewWindowInfo new_window_info(params.url, old_target_url.name); |
712 new_window_info.changed = new_window_info.url != old_target_url.url; | 726 new_window_info.changed = new_window_info.url != old_target_url.url; |
713 it->second = new_window_info; | 727 it->second = new_window_info; |
714 return NULL; | 728 return NULL; |
715 } | 729 } |
716 if (params.disposition == CURRENT_TAB) { | 730 if (params.disposition == CURRENT_TAB) { |
717 // This can happen for cross-site redirects. | 731 // This can happen for cross-site redirects. |
718 LoadURLWithParams(params.url, params.referrer, params.transition, source); | 732 LoadURLWithParams(params.url, params.referrer, params.transition, source); |
719 return source; | 733 return source; |
720 } | 734 } |
721 | 735 |
722 return CreateNewGuestWindow(params)->GetWebContents(); | 736 return CreateNewGuestWindow(params)->GetWebContents(); |
723 } | 737 } |
724 | 738 |
725 void BrowserPluginGuest::WebContentsCreated(WebContents* source_contents, | 739 void BrowserPluginGuest::WebContentsCreated(WebContents* source_contents, |
726 int opener_render_frame_id, | 740 int opener_render_frame_id, |
727 const base::string16& frame_name, | 741 const base::string16& frame_name, |
728 const GURL& target_url, | 742 const GURL& target_url, |
729 WebContents* new_contents) { | 743 WebContents* new_contents) { |
730 WebContentsImpl* new_contents_impl = | 744 WebContentsImpl* new_contents_impl = |
731 static_cast<WebContentsImpl*>(new_contents); | 745 static_cast<WebContentsImpl*>(new_contents); |
732 BrowserPluginGuest* guest = new_contents_impl->GetBrowserPluginGuest(); | 746 BrowserPluginGuest* guest = new_contents_impl->GetBrowserPluginGuest(); |
733 guest->opener_ = AsWeakPtr(); | 747 if (guest->delegate_) |
| 748 guest->delegate_->SetOpener(GetWebContents()); |
734 std::string guest_name = base::UTF16ToUTF8(frame_name); | 749 std::string guest_name = base::UTF16ToUTF8(frame_name); |
735 guest->name_ = guest_name; | 750 guest->name_ = guest_name; |
736 // Take ownership of the new guest until it is attached to the embedder's DOM | 751 // Take ownership of the new guest until it is attached to the embedder's DOM |
737 // tree to avoid leaking a guest if this guest is destroyed before attaching | 752 // tree to avoid leaking a guest if this guest is destroyed before attaching |
738 // the new guest. | 753 // the new guest. |
739 pending_new_windows_.insert( | 754 pending_new_windows_.insert( |
740 std::make_pair(guest, NewWindowInfo(target_url, guest_name))); | 755 std::make_pair(guest, NewWindowInfo(target_url, guest_name))); |
741 } | 756 } |
742 | 757 |
743 void BrowserPluginGuest::RendererUnresponsive(WebContents* source) { | 758 void BrowserPluginGuest::RendererUnresponsive(WebContents* source) { |
(...skipping 20 matching lines...) Expand all Loading... |
764 | 779 |
765 embedder_web_contents_->GetDelegate()->RunFileChooser(web_contents, params); | 780 embedder_web_contents_->GetDelegate()->RunFileChooser(web_contents, params); |
766 } | 781 } |
767 | 782 |
768 bool BrowserPluginGuest::ShouldFocusPageAfterCrash() { | 783 bool BrowserPluginGuest::ShouldFocusPageAfterCrash() { |
769 // Rather than managing focus in WebContentsImpl::RenderViewReady, we will | 784 // Rather than managing focus in WebContentsImpl::RenderViewReady, we will |
770 // manage the focus ourselves. | 785 // manage the focus ourselves. |
771 return false; | 786 return false; |
772 } | 787 } |
773 | 788 |
774 WebContentsImpl* BrowserPluginGuest::GetWebContents() { | 789 WebContentsImpl* BrowserPluginGuest::GetWebContents() const { |
775 return static_cast<WebContentsImpl*>(web_contents()); | 790 return static_cast<WebContentsImpl*>(web_contents()); |
776 } | 791 } |
777 | 792 |
778 gfx::Point BrowserPluginGuest::GetScreenCoordinates( | 793 gfx::Point BrowserPluginGuest::GetScreenCoordinates( |
779 const gfx::Point& relative_position) const { | 794 const gfx::Point& relative_position) const { |
780 gfx::Point screen_pos(relative_position); | 795 gfx::Point screen_pos(relative_position); |
781 screen_pos += guest_window_rect_.OffsetFromOrigin(); | 796 screen_pos += guest_window_rect_.OffsetFromOrigin(); |
782 return screen_pos; | 797 return screen_pos; |
783 } | 798 } |
784 | 799 |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1020 GetWebContents()->GetRenderViewHost())->Init(); | 1035 GetWebContents()->GetRenderViewHost())->Init(); |
1021 WebContentsViewGuest* new_view = | 1036 WebContentsViewGuest* new_view = |
1022 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); | 1037 static_cast<WebContentsViewGuest*>(GetWebContents()->GetView()); |
1023 new_view->CreateViewForWidget(web_contents()->GetRenderViewHost()); | 1038 new_view->CreateViewForWidget(web_contents()->GetRenderViewHost()); |
1024 } | 1039 } |
1025 | 1040 |
1026 // We need to do a navigation here if the target URL has changed between | 1041 // We need to do a navigation here if the target URL has changed between |
1027 // the time the WebContents was created and the time it was attached. | 1042 // the time the WebContents was created and the time it was attached. |
1028 // We also need to do an initial navigation if a RenderView was never | 1043 // We also need to do an initial navigation if a RenderView was never |
1029 // created for the new window in cases where there is no referrer. | 1044 // created for the new window in cases where there is no referrer. |
1030 PendingWindowMap::iterator it = opener()->pending_new_windows_.find(this); | 1045 PendingWindowMap::iterator it = GetOpener()->pending_new_windows_.find(this); |
1031 if (it != opener()->pending_new_windows_.end()) { | 1046 if (it != GetOpener()->pending_new_windows_.end()) { |
1032 const NewWindowInfo& new_window_info = it->second; | 1047 const NewWindowInfo& new_window_info = it->second; |
1033 if (new_window_info.changed || !has_render_view_) | 1048 if (new_window_info.changed || !has_render_view_) |
1034 params.src = it->second.url.spec(); | 1049 params.src = it->second.url.spec(); |
1035 } else { | 1050 } else { |
1036 NOTREACHED(); | 1051 NOTREACHED(); |
1037 } | 1052 } |
1038 | 1053 |
1039 // Once a new guest is attached to the DOM of the embedder page, then the | 1054 // Once a new guest is attached to the DOM of the embedder page, then the |
1040 // lifetime of the new guest is no longer managed by the opener guest. | 1055 // lifetime of the new guest is no longer managed by the opener guest. |
1041 opener()->pending_new_windows_.erase(this); | 1056 GetOpener()->pending_new_windows_.erase(this); |
1042 | 1057 |
1043 // The guest's frame name takes precedence over the BrowserPlugin's name. | 1058 // The guest's frame name takes precedence over the BrowserPlugin's name. |
1044 // The guest's frame name is assigned in | 1059 // The guest's frame name is assigned in |
1045 // BrowserPluginGuest::WebContentsCreated. | 1060 // BrowserPluginGuest::WebContentsCreated. |
1046 if (!name_.empty()) | 1061 if (!name_.empty()) |
1047 params.name.clear(); | 1062 params.name.clear(); |
1048 | 1063 |
1049 Initialize(params, embedder_web_contents); | 1064 Initialize(params, embedder_web_contents); |
1050 | 1065 |
1051 SendQueuedMessages(); | 1066 SendQueuedMessages(); |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1532 const GURL& url) { | 1547 const GURL& url) { |
1533 if (!url.is_valid()) { | 1548 if (!url.is_valid()) { |
1534 callback.Run(false); | 1549 callback.Run(false); |
1535 return; | 1550 return; |
1536 } | 1551 } |
1537 | 1552 |
1538 delegate_->CanDownload(request_method, url, callback); | 1553 delegate_->CanDownload(request_method, url, callback); |
1539 } | 1554 } |
1540 | 1555 |
1541 } // namespace content | 1556 } // namespace content |
OLD | NEW |