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 | |
468 WebContents* GuestViewBase::GetOwnerWebContents() const { | 448 WebContents* GuestViewBase::GetOwnerWebContents() const { |
469 return owner_web_contents_; | 449 return owner_web_contents_; |
470 } | 450 } |
471 | 451 |
472 void GuestViewBase::GuestSizeChanged(const gfx::Size& new_size) { | 452 void GuestViewBase::GuestSizeChanged(const gfx::Size& new_size) { |
473 UpdateGuestSize(new_size, auto_size_enabled_); | 453 UpdateGuestSize(new_size, auto_size_enabled_); |
474 } | 454 } |
475 | 455 |
476 const GURL& GuestViewBase::GetOwnerSiteURL() const { | 456 const GURL& GuestViewBase::GetOwnerSiteURL() const { |
477 return owner_web_contents()->GetLastCommittedURL(); | 457 return owner_web_contents()->GetLastCommittedURL(); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 // queued events. | 543 // queued events. |
564 SignalWhenReady(callback); | 544 SignalWhenReady(callback); |
565 } | 545 } |
566 | 546 |
567 void GuestViewBase::SignalWhenReady(const base::Closure& callback) { | 547 void GuestViewBase::SignalWhenReady(const base::Closure& callback) { |
568 // The default behavior is to call the |callback| immediately. Derived classes | 548 // The default behavior is to call the |callback| immediately. Derived classes |
569 // can implement an alternative signal for readiness. | 549 // can implement an alternative signal for readiness. |
570 callback.Run(); | 550 callback.Run(); |
571 } | 551 } |
572 | 552 |
573 bool GuestViewBase::ShouldHandleFindRequestsForEmbedder() const { | |
574 return false; | |
575 } | |
576 | |
577 int GuestViewBase::LogicalPixelsToPhysicalPixels(double logical_pixels) const { | 553 int GuestViewBase::LogicalPixelsToPhysicalPixels(double logical_pixels) const { |
578 DCHECK(logical_pixels >= 0); | 554 DCHECK(logical_pixels >= 0); |
579 double zoom_factor = GetEmbedderZoomFactor(); | 555 double zoom_factor = GetEmbedderZoomFactor(); |
580 return lround(logical_pixels * zoom_factor); | 556 return lround(logical_pixels * zoom_factor); |
581 } | 557 } |
582 | 558 |
583 double GuestViewBase::PhysicalPixelsToLogicalPixels(int physical_pixels) const { | 559 double GuestViewBase::PhysicalPixelsToLogicalPixels(int physical_pixels) const { |
584 DCHECK(physical_pixels >= 0); | 560 DCHECK(physical_pixels >= 0); |
585 double zoom_factor = GetEmbedderZoomFactor(); | 561 double zoom_factor = GetEmbedderZoomFactor(); |
586 return physical_pixels / zoom_factor; | 562 return physical_pixels / zoom_factor; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 return; | 695 return; |
720 | 696 |
721 embedder_web_contents()->GetDelegate()->UpdateTargetURL( | 697 embedder_web_contents()->GetDelegate()->UpdateTargetURL( |
722 embedder_web_contents(), url); | 698 embedder_web_contents(), url); |
723 } | 699 } |
724 | 700 |
725 bool GuestViewBase::ShouldResumeRequestsForCreatedWindow() { | 701 bool GuestViewBase::ShouldResumeRequestsForCreatedWindow() { |
726 return false; | 702 return false; |
727 } | 703 } |
728 | 704 |
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 | |
746 content::RenderWidgetHost* GuestViewBase::GetOwnerRenderWidgetHost() { | 705 content::RenderWidgetHost* GuestViewBase::GetOwnerRenderWidgetHost() { |
747 // We assume guests live inside an owner RenderFrame but the RenderFrame may | 706 // We assume guests live inside an owner RenderFrame but the RenderFrame may |
748 // not be cross-process. In case a type of guest should be allowed to be | 707 // not be cross-process. In case a type of guest should be allowed to be |
749 // embedded in a cross-process frame, this method should be overrode for that | 708 // embedded in a cross-process frame, this method should be overrode for that |
750 // specific guest type. For all other guests, the owner RenderWidgetHost is | 709 // specific guest type. For all other guests, the owner RenderWidgetHost is |
751 // that of the owner WebContents. | 710 // that of the owner WebContents. |
752 if (GetOwnerWebContents() && | 711 if (GetOwnerWebContents() && |
753 GetOwnerWebContents()->GetRenderWidgetHostView()) { | 712 GetOwnerWebContents()->GetRenderWidgetHostView()) { |
754 return GetOwnerWebContents() | 713 return GetOwnerWebContents() |
755 ->GetRenderWidgetHostView() | 714 ->GetRenderWidgetHostView() |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 | 888 |
930 void GuestViewBase::UpdateGuestSize(const gfx::Size& new_size, | 889 void GuestViewBase::UpdateGuestSize(const gfx::Size& new_size, |
931 bool due_to_auto_resize) { | 890 bool due_to_auto_resize) { |
932 if (due_to_auto_resize) | 891 if (due_to_auto_resize) |
933 GuestSizeChangedDueToAutoSize(guest_size_, new_size); | 892 GuestSizeChangedDueToAutoSize(guest_size_, new_size); |
934 DispatchOnResizeEvent(guest_size_, new_size); | 893 DispatchOnResizeEvent(guest_size_, new_size); |
935 guest_size_ = new_size; | 894 guest_size_ = new_size; |
936 } | 895 } |
937 | 896 |
938 } // namespace guest_view | 897 } // namespace guest_view |
OLD | NEW |