OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/guest_view/browser/guest_view_base.h" | 5 #include "components/guest_view/browser/guest_view_base.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 void GuestViewBase::DidDetach() { | 438 void GuestViewBase::DidDetach() { |
439 GuestViewManager::FromBrowserContext(browser_context_)->DetachGuest(this); | 439 GuestViewManager::FromBrowserContext(browser_context_)->DetachGuest(this); |
440 StopTrackingEmbedderZoomLevel(); | 440 StopTrackingEmbedderZoomLevel(); |
441 owner_web_contents()->Send(new GuestViewMsg_GuestDetached( | 441 owner_web_contents()->Send(new GuestViewMsg_GuestDetached( |
442 element_instance_id_)); | 442 element_instance_id_)); |
443 element_instance_id_ = kInstanceIDNone; | 443 element_instance_id_ = kInstanceIDNone; |
444 if (!CanRunInDetachedState()) | 444 if (!CanRunInDetachedState()) |
445 Destroy(true); | 445 Destroy(true); |
446 } | 446 } |
447 | 447 |
| 448 bool GuestViewBase::HandleFindForEmbedder( |
| 449 int request_id, |
| 450 const base::string16& search_text, |
| 451 const blink::WebFindOptions& options) { |
| 452 if (ShouldHandleFindRequestsForEmbedder()) { |
| 453 web_contents()->Find(request_id, search_text, options); |
| 454 return true; |
| 455 } |
| 456 return false; |
| 457 } |
| 458 |
| 459 bool GuestViewBase::HandleStopFindingForEmbedder( |
| 460 content::StopFindAction action) { |
| 461 if (ShouldHandleFindRequestsForEmbedder()) { |
| 462 web_contents()->StopFinding(action); |
| 463 return true; |
| 464 } |
| 465 return false; |
| 466 } |
| 467 |
448 WebContents* GuestViewBase::GetOwnerWebContents() const { | 468 WebContents* GuestViewBase::GetOwnerWebContents() const { |
449 return owner_web_contents_; | 469 return owner_web_contents_; |
450 } | 470 } |
451 | 471 |
452 void GuestViewBase::GuestSizeChanged(const gfx::Size& new_size) { | 472 void GuestViewBase::GuestSizeChanged(const gfx::Size& new_size) { |
453 UpdateGuestSize(new_size, auto_size_enabled_); | 473 UpdateGuestSize(new_size, auto_size_enabled_); |
454 } | 474 } |
455 | 475 |
456 const GURL& GuestViewBase::GetOwnerSiteURL() const { | 476 const GURL& GuestViewBase::GetOwnerSiteURL() const { |
457 return owner_web_contents()->GetLastCommittedURL(); | 477 return owner_web_contents()->GetLastCommittedURL(); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 // queued events. | 563 // queued events. |
544 SignalWhenReady(callback); | 564 SignalWhenReady(callback); |
545 } | 565 } |
546 | 566 |
547 void GuestViewBase::SignalWhenReady(const base::Closure& callback) { | 567 void GuestViewBase::SignalWhenReady(const base::Closure& callback) { |
548 // The default behavior is to call the |callback| immediately. Derived classes | 568 // The default behavior is to call the |callback| immediately. Derived classes |
549 // can implement an alternative signal for readiness. | 569 // can implement an alternative signal for readiness. |
550 callback.Run(); | 570 callback.Run(); |
551 } | 571 } |
552 | 572 |
| 573 bool GuestViewBase::ShouldHandleFindRequestsForEmbedder() const { |
| 574 return false; |
| 575 } |
| 576 |
553 int GuestViewBase::LogicalPixelsToPhysicalPixels(double logical_pixels) const { | 577 int GuestViewBase::LogicalPixelsToPhysicalPixels(double logical_pixels) const { |
554 DCHECK(logical_pixels >= 0); | 578 DCHECK(logical_pixels >= 0); |
555 double zoom_factor = GetEmbedderZoomFactor(); | 579 double zoom_factor = GetEmbedderZoomFactor(); |
556 return lround(logical_pixels * zoom_factor); | 580 return lround(logical_pixels * zoom_factor); |
557 } | 581 } |
558 | 582 |
559 double GuestViewBase::PhysicalPixelsToLogicalPixels(int physical_pixels) const { | 583 double GuestViewBase::PhysicalPixelsToLogicalPixels(int physical_pixels) const { |
560 DCHECK(physical_pixels >= 0); | 584 DCHECK(physical_pixels >= 0); |
561 double zoom_factor = GetEmbedderZoomFactor(); | 585 double zoom_factor = GetEmbedderZoomFactor(); |
562 return physical_pixels / zoom_factor; | 586 return physical_pixels / zoom_factor; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 return; | 719 return; |
696 | 720 |
697 embedder_web_contents()->GetDelegate()->UpdateTargetURL( | 721 embedder_web_contents()->GetDelegate()->UpdateTargetURL( |
698 embedder_web_contents(), url); | 722 embedder_web_contents(), url); |
699 } | 723 } |
700 | 724 |
701 bool GuestViewBase::ShouldResumeRequestsForCreatedWindow() { | 725 bool GuestViewBase::ShouldResumeRequestsForCreatedWindow() { |
702 return false; | 726 return false; |
703 } | 727 } |
704 | 728 |
| 729 void GuestViewBase::FindReply(WebContents* source, |
| 730 int request_id, |
| 731 int number_of_matches, |
| 732 const gfx::Rect& selection_rect, |
| 733 int active_match_ordinal, |
| 734 bool final_update) { |
| 735 if (ShouldHandleFindRequestsForEmbedder() && |
| 736 attached() && embedder_web_contents()->GetDelegate()) { |
| 737 embedder_web_contents()->GetDelegate()->FindReply(embedder_web_contents(), |
| 738 request_id, |
| 739 number_of_matches, |
| 740 selection_rect, |
| 741 active_match_ordinal, |
| 742 final_update); |
| 743 } |
| 744 } |
| 745 |
705 content::RenderWidgetHost* GuestViewBase::GetOwnerRenderWidgetHost() { | 746 content::RenderWidgetHost* GuestViewBase::GetOwnerRenderWidgetHost() { |
706 // We assume guests live inside an owner RenderFrame but the RenderFrame may | 747 // We assume guests live inside an owner RenderFrame but the RenderFrame may |
707 // not be cross-process. In case a type of guest should be allowed to be | 748 // not be cross-process. In case a type of guest should be allowed to be |
708 // embedded in a cross-process frame, this method should be overrode for that | 749 // embedded in a cross-process frame, this method should be overrode for that |
709 // specific guest type. For all other guests, the owner RenderWidgetHost is | 750 // specific guest type. For all other guests, the owner RenderWidgetHost is |
710 // that of the owner WebContents. | 751 // that of the owner WebContents. |
711 if (GetOwnerWebContents() && | 752 if (GetOwnerWebContents() && |
712 GetOwnerWebContents()->GetRenderWidgetHostView()) { | 753 GetOwnerWebContents()->GetRenderWidgetHostView()) { |
713 return GetOwnerWebContents() | 754 return GetOwnerWebContents() |
714 ->GetRenderWidgetHostView() | 755 ->GetRenderWidgetHostView() |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 | 929 |
889 void GuestViewBase::UpdateGuestSize(const gfx::Size& new_size, | 930 void GuestViewBase::UpdateGuestSize(const gfx::Size& new_size, |
890 bool due_to_auto_resize) { | 931 bool due_to_auto_resize) { |
891 if (due_to_auto_resize) | 932 if (due_to_auto_resize) |
892 GuestSizeChangedDueToAutoSize(guest_size_, new_size); | 933 GuestSizeChangedDueToAutoSize(guest_size_, new_size); |
893 DispatchOnResizeEvent(guest_size_, new_size); | 934 DispatchOnResizeEvent(guest_size_, new_size); |
894 guest_size_ = new_size; | 935 guest_size_ = new_size; |
895 } | 936 } |
896 | 937 |
897 } // namespace guest_view | 938 } // namespace guest_view |
OLD | NEW |