Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: content/browser/web_contents/web_contents_view_aura.cc

Issue 53153003: Fix windowed NPAPI plugins covering up dialogs on Win Aura. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix test with small browser size Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/web_contents/web_contents_view_aura.h" 5 #include "content/browser/web_contents/web_contents_view_aura.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 parent_(NULL) { 656 parent_(NULL) {
657 view_->window_->AddObserver(this); 657 view_->window_->AddObserver(this);
658 } 658 }
659 659
660 virtual ~WindowObserver() { 660 virtual ~WindowObserver() {
661 view_->window_->RemoveObserver(this); 661 view_->window_->RemoveObserver(this);
662 if (view_->window_->GetDispatcher()) 662 if (view_->window_->GetDispatcher())
663 view_->window_->GetDispatcher()->RemoveRootWindowObserver(this); 663 view_->window_->GetDispatcher()->RemoveRootWindowObserver(this);
664 if (parent_) 664 if (parent_)
665 parent_->RemoveObserver(this); 665 parent_->RemoveObserver(this);
666
667 #if defined(OS_WIN)
668 if (parent_) {
669 const aura::Window::Windows& children = parent_->children();
670 for (size_t i = 0; i < children.size(); ++i)
671 children[i]->RemoveObserver(this);
672 }
673 #endif
666 } 674 }
667 675
668 // Overridden from aura::WindowObserver: 676 // Overridden from aura::WindowObserver:
677 #if defined(OS_WIN)
678 // Constrained windows are added as children of the parent's parent's view
679 // which may overlap with windowed NPAPI plugins. In that case, tell the RWHV
680 // so that it can update the plugins' cutout rects accordingly.
681 // Note: this is hard coding how Chrome layer adds its dialogs. Since NPAPI is
682 // going to be deprecated in a year, this is ok for now. The test for this is
683 // PrintPreviewTest.WindowedNPAPIPluginHidden.
684 virtual void OnWindowAdded(aura::Window* new_window) OVERRIDE {
685 if (new_window->parent() != parent_)
686 return;
687
688 new_window->AddObserver(this);
689 UpdateConstrainedWindows(NULL);
690 }
691
692 virtual void OnWillRemoveWindow(aura::Window* window) OVERRIDE {
693 if (window->parent() == parent_ && window != view_->window_) {
694 window->RemoveObserver(this);
695 UpdateConstrainedWindows(window);
696 }
697 }
698
699 virtual void OnWindowVisibilityChanged(aura::Window* window,
700 bool visible) OVERRIDE {
701 if (window->parent() == parent_ && window != view_->window_)
702 UpdateConstrainedWindows(NULL);
703 }
704 #endif
705
669 virtual void OnWindowParentChanged(aura::Window* window, 706 virtual void OnWindowParentChanged(aura::Window* window,
670 aura::Window* parent) OVERRIDE { 707 aura::Window* parent) OVERRIDE {
671 if (window == parent_) 708 if (window != view_->window_)
672 return; 709 return;
673 if (parent_) 710 if (parent_)
674 parent_->RemoveObserver(this); 711 parent_->RemoveObserver(this);
712
713 #if defined(OS_WIN)
714 if (parent_) {
715 const aura::Window::Windows& children = parent_->children();
716 for (size_t i = 0; i < children.size(); ++i)
717 children[i]->RemoveObserver(this);
718
719 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura(
720 view_->web_contents_->GetRenderWidgetHostView());
721 if (view)
722 view->UpdateConstrainedWindowRects(std::vector<gfx::Rect>());
723 }
724 #endif
725
675 parent_ = parent; 726 parent_ = parent;
676 if (parent) 727 if (parent)
677 parent->AddObserver(this); 728 parent->AddObserver(this);
678 } 729 }
679 730
680 virtual void OnWindowBoundsChanged(aura::Window* window, 731 virtual void OnWindowBoundsChanged(aura::Window* window,
681 const gfx::Rect& old_bounds, 732 const gfx::Rect& old_bounds,
682 const gfx::Rect& new_bounds) OVERRIDE { 733 const gfx::Rect& new_bounds) OVERRIDE {
683 SendScreenRects(); 734 if (window == parent_ || window == view_->window_) {
684 if (view_->touch_editable_) 735 SendScreenRects();
685 view_->touch_editable_->UpdateEditingController(); 736 if (view_->touch_editable_)
737 view_->touch_editable_->UpdateEditingController();
738 #if defined(OS_WIN)
739 } else {
740 UpdateConstrainedWindows(NULL);
741 #endif
742 }
686 } 743 }
687 744
688 virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE { 745 virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE {
689 if (window != parent_) 746 if (window == view_->window_)
690 window->GetDispatcher()->AddRootWindowObserver(this); 747 window->GetDispatcher()->AddRootWindowObserver(this);
691 } 748 }
692 749
693 virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE { 750 virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE {
694 if (window != parent_) 751 if (window == view_->window_)
695 window->GetDispatcher()->RemoveRootWindowObserver(this); 752 window->GetDispatcher()->RemoveRootWindowObserver(this);
696 } 753 }
697 754
698 // Overridden RootWindowObserver: 755 // Overridden RootWindowObserver:
699 virtual void OnRootWindowHostMoved(const aura::RootWindow* root, 756 virtual void OnRootWindowHostMoved(const aura::RootWindow* root,
700 const gfx::Point& new_origin) OVERRIDE { 757 const gfx::Point& new_origin) OVERRIDE {
701 TRACE_EVENT1("ui", 758 TRACE_EVENT1("ui",
702 "WebContentsViewAura::WindowObserver::OnRootWindowHostMoved", 759 "WebContentsViewAura::WindowObserver::OnRootWindowHostMoved",
703 "new_origin", new_origin.ToString()); 760 "new_origin", new_origin.ToString());
704 761
705 // This is for the desktop case (i.e. Aura desktop). 762 // This is for the desktop case (i.e. Aura desktop).
706 SendScreenRects(); 763 SendScreenRects();
707 } 764 }
708 765
709 private: 766 private:
710 void SendScreenRects() { 767 void SendScreenRects() {
711 RenderWidgetHostImpl::From(view_->web_contents_->GetRenderViewHost())-> 768 RenderWidgetHostImpl::From(view_->web_contents_->GetRenderViewHost())->
712 SendScreenRects(); 769 SendScreenRects();
713 } 770 }
714 771
772 #if defined(OS_WIN)
773 void UpdateConstrainedWindows(aura::Window* exclude) {
774 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura(
775 view_->web_contents_->GetRenderWidgetHostView());
776 if (!view)
777 return;
778
779 std::vector<gfx::Rect> constrained_windows;
780 const aura::Window::Windows& children = parent_->children();
781 for (size_t i = 0; i < children.size(); ++i) {
782 if (children[i] != view_->window_ &&
783 children[i] != exclude &&
784 children[i]->IsVisible()) {
785 constrained_windows.push_back(children[i]->GetBoundsInRootWindow());
786 }
787 }
788
789 view->UpdateConstrainedWindowRects(constrained_windows);
790 }
791 #endif
792
715 WebContentsViewAura* view_; 793 WebContentsViewAura* view_;
716 794
717 // We cache the old parent so that we can unregister when it's not the parent 795 // We cache the old parent so that we can unregister when it's not the parent
718 // anymore. 796 // anymore.
719 aura::Window* parent_; 797 aura::Window* parent_;
720 798
721 DISALLOW_COPY_AND_ASSIGN(WindowObserver); 799 DISALLOW_COPY_AND_ASSIGN(WindowObserver);
722 }; 800 };
723 801
724 #if defined(OS_WIN)
725 // Constrained windows are added as children of the WebContent's view which may
726 // overlap with windowed NPAPI plugins. In that case, tell the RWHV so that it
727 // can update the plugins' cutout rects accordingly.
728 class WebContentsViewAura::ChildWindowObserver : public aura::WindowObserver,
729 public WebContentsObserver {
730 public:
731 explicit ChildWindowObserver(WebContentsViewAura* view)
732 : WebContentsObserver(view->web_contents_),
733 view_(view),
734 web_contents_destroyed_(false) {
735 view_->window_->AddObserver(this);
736 }
737
738 virtual ~ChildWindowObserver() {
739 view_->window_->RemoveObserver(this);
740 const aura::Window::Windows& children = view_->window_->children();
741 for (size_t i = 0; i < children.size(); ++i)
742 children[i]->RemoveObserver(this);
743 }
744
745 // Overridden from aura::WindowObserver:
746 virtual void OnWindowAdded(aura::Window* new_window) OVERRIDE {
747 // If new child windows are added to the WebContent's view, tell the RWHV.
748 // We also start watching them to know when their size is updated. Of
749 // course, ignore the shadow window that contains the RWHV and child windows
750 // of the child windows that we are watching.
751 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura(
752 view_->web_contents_->GetRenderWidgetHostView());
753 aura::Window* content_window = view ? view->GetNativeView() : NULL;
754 if (new_window->parent() == view_->window_ &&
755 new_window != content_window) {
756 new_window->AddObserver(this);
757 UpdateConstrainedWindows(NULL);
758 }
759 }
760
761 virtual void OnWillRemoveWindow(aura::Window* window) OVERRIDE {
762 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura(
763 view_->web_contents_->GetRenderWidgetHostView());
764 aura::Window* content_window = view ? view->GetNativeView() : NULL;
765 if (window->parent() == view_->window_ &&
766 window != content_window) {
767 window->RemoveObserver(this);
768 UpdateConstrainedWindows(window);
769 }
770 }
771
772 virtual void OnWindowBoundsChanged(aura::Window* window,
773 const gfx::Rect& old_bounds,
774 const gfx::Rect& new_bounds) OVERRIDE {
775 if (window->parent() == view_->window_ &&
776 window != view_->GetContentNativeView()) {
777 UpdateConstrainedWindows(NULL);
778 }
779 }
780
781 // Overridden from WebContentsObserver:
782 virtual void WebContentsDestroyed(WebContents* web_contents) OVERRIDE {
783 web_contents_destroyed_ = true;
784 }
785
786 private:
787 void UpdateConstrainedWindows(aura::Window* exclude) {
788 if (web_contents_destroyed_)
789 return;
790
791 RenderWidgetHostViewAura* view = ToRenderWidgetHostViewAura(
792 view_->web_contents_->GetRenderWidgetHostView());
793 if (!view)
794 return;
795
796 std::vector<gfx::Rect> constrained_windows;
797 const aura::Window::Windows& children = view_->window_->children();
798 aura::Window* content = view_->GetContentNativeView();
799 for (size_t i = 0; i < children.size(); ++i) {
800 if (children[i] != content && children[i] != exclude)
801 constrained_windows.push_back(children[i]->GetBoundsInRootWindow());
802 }
803
804 view->UpdateConstrainedWindowRects(constrained_windows);
805 }
806
807 WebContentsViewAura* view_;
808 bool web_contents_destroyed_;
809
810 DISALLOW_COPY_AND_ASSIGN(ChildWindowObserver);
811 };
812 #endif
813
814 //////////////////////////////////////////////////////////////////////////////// 802 ////////////////////////////////////////////////////////////////////////////////
815 // WebContentsViewAura, public: 803 // WebContentsViewAura, public:
816 804
817 WebContentsViewAura::WebContentsViewAura( 805 WebContentsViewAura::WebContentsViewAura(
818 WebContentsImpl* web_contents, 806 WebContentsImpl* web_contents,
819 WebContentsViewDelegate* delegate) 807 WebContentsViewDelegate* delegate)
820 : web_contents_(web_contents), 808 : web_contents_(web_contents),
821 delegate_(delegate), 809 delegate_(delegate),
822 current_drag_op_(WebKit::WebDragOperationNone), 810 current_drag_op_(WebKit::WebDragOperationNone),
823 drag_dest_delegate_(NULL), 811 drag_dest_delegate_(NULL),
824 current_rvh_for_drag_(NULL), 812 current_rvh_for_drag_(NULL),
825 overscroll_change_brightness_(false), 813 overscroll_change_brightness_(false),
826 current_overscroll_gesture_(OVERSCROLL_NONE), 814 current_overscroll_gesture_(OVERSCROLL_NONE),
827 completed_overscroll_gesture_(OVERSCROLL_NONE), 815 completed_overscroll_gesture_(OVERSCROLL_NONE),
828 touch_editable_(TouchEditableImplAura::Create()) { 816 touch_editable_(TouchEditableImplAura::Create()) {
829 } 817 }
830 818
831 //////////////////////////////////////////////////////////////////////////////// 819 ////////////////////////////////////////////////////////////////////////////////
832 // WebContentsViewAura, private: 820 // WebContentsViewAura, private:
833 821
834 WebContentsViewAura::~WebContentsViewAura() { 822 WebContentsViewAura::~WebContentsViewAura() {
835 if (!window_) 823 if (!window_)
836 return; 824 return;
837 825
838 window_observer_.reset(); 826 window_observer_.reset();
839 #if defined(OS_WIN) 827
840 child_window_observer_.reset();
841 #endif
842 // Window needs a valid delegate during its destructor, so we explicitly 828 // Window needs a valid delegate during its destructor, so we explicitly
843 // delete it here. 829 // delete it here.
844 window_.reset(); 830 window_.reset();
845 } 831 }
846 832
847 void WebContentsViewAura::SetupOverlayWindowForTesting() { 833 void WebContentsViewAura::SetupOverlayWindowForTesting() {
848 if (navigation_overlay_) 834 if (navigation_overlay_)
849 navigation_overlay_->SetupForTesting(); 835 navigation_overlay_->SetupForTesting();
850 } 836 }
851 837
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
1162 // us. 1148 // us.
1163 if (root_window) { 1149 if (root_window) {
1164 aura::client::ParentWindowWithContext( 1150 aura::client::ParentWindowWithContext(
1165 window_.get(), root_window, root_window->GetBoundsInScreen()); 1151 window_.get(), root_window, root_window->GetBoundsInScreen());
1166 } 1152 }
1167 } 1153 }
1168 window_->layer()->SetMasksToBounds(true); 1154 window_->layer()->SetMasksToBounds(true);
1169 window_->SetName("WebContentsViewAura"); 1155 window_->SetName("WebContentsViewAura");
1170 1156
1171 window_observer_.reset(new WindowObserver(this)); 1157 window_observer_.reset(new WindowObserver(this));
1172 #if defined(OS_WIN)
1173 child_window_observer_.reset(new ChildWindowObserver(this));
1174 #endif
1175 1158
1176 // delegate_->GetDragDestDelegate() creates a new delegate on every call. 1159 // delegate_->GetDragDestDelegate() creates a new delegate on every call.
1177 // Hence, we save a reference to it locally. Similar model is used on other 1160 // Hence, we save a reference to it locally. Similar model is used on other
1178 // platforms as well. 1161 // platforms as well.
1179 if (delegate_) 1162 if (delegate_)
1180 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); 1163 drag_dest_delegate_ = delegate_->GetDragDestDelegate();
1181 } 1164 }
1182 1165
1183 RenderWidgetHostView* WebContentsViewAura::CreateViewForWidget( 1166 RenderWidgetHostView* WebContentsViewAura::CreateViewForWidget(
1184 RenderWidgetHost* render_widget_host) { 1167 RenderWidgetHost* render_widget_host) {
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
1650 event.location(), 1633 event.location(),
1651 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), 1634 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(),
1652 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); 1635 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags()));
1653 if (drag_dest_delegate_) 1636 if (drag_dest_delegate_)
1654 drag_dest_delegate_->OnDrop(); 1637 drag_dest_delegate_->OnDrop();
1655 current_drop_data_.reset(); 1638 current_drop_data_.reset();
1656 return current_drag_op_; 1639 return current_drag_op_;
1657 } 1640 }
1658 1641
1659 } // namespace content 1642 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_view_aura.h ('k') | content/test/plugin/plugin_test_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698