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

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

Issue 63013002: Revert 233297 "Fix windowed NPAPI plugins covering up dialogs on..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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
674 } 666 }
675 667
676 // Overridden from aura::WindowObserver: 668 // 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
706 virtual void OnWindowParentChanged(aura::Window* window, 669 virtual void OnWindowParentChanged(aura::Window* window,
707 aura::Window* parent) OVERRIDE { 670 aura::Window* parent) OVERRIDE {
708 if (window != view_->window_) 671 if (window == parent_)
709 return; 672 return;
710 if (parent_) 673 if (parent_)
711 parent_->RemoveObserver(this); 674 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
726 parent_ = parent; 675 parent_ = parent;
727 if (parent) 676 if (parent)
728 parent->AddObserver(this); 677 parent->AddObserver(this);
729 } 678 }
730 679
731 virtual void OnWindowBoundsChanged(aura::Window* window, 680 virtual void OnWindowBoundsChanged(aura::Window* window,
732 const gfx::Rect& old_bounds, 681 const gfx::Rect& old_bounds,
733 const gfx::Rect& new_bounds) OVERRIDE { 682 const gfx::Rect& new_bounds) OVERRIDE {
734 if (window == parent_ || window == view_->window_) { 683 SendScreenRects();
735 SendScreenRects(); 684 if (view_->touch_editable_)
736 if (view_->touch_editable_) 685 view_->touch_editable_->UpdateEditingController();
737 view_->touch_editable_->UpdateEditingController();
738 #if defined(OS_WIN)
739 } else {
740 UpdateConstrainedWindows(NULL);
741 #endif
742 }
743 } 686 }
744 687
745 virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE { 688 virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE {
746 if (window == view_->window_) 689 if (window != parent_)
747 window->GetDispatcher()->AddRootWindowObserver(this); 690 window->GetDispatcher()->AddRootWindowObserver(this);
748 } 691 }
749 692
750 virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE { 693 virtual void OnWindowRemovingFromRootWindow(aura::Window* window) OVERRIDE {
751 if (window == view_->window_) 694 if (window != parent_)
752 window->GetDispatcher()->RemoveRootWindowObserver(this); 695 window->GetDispatcher()->RemoveRootWindowObserver(this);
753 } 696 }
754 697
755 // Overridden RootWindowObserver: 698 // Overridden RootWindowObserver:
756 virtual void OnRootWindowHostMoved(const aura::RootWindow* root, 699 virtual void OnRootWindowHostMoved(const aura::RootWindow* root,
757 const gfx::Point& new_origin) OVERRIDE { 700 const gfx::Point& new_origin) OVERRIDE {
758 TRACE_EVENT1("ui", 701 TRACE_EVENT1("ui",
759 "WebContentsViewAura::WindowObserver::OnRootWindowHostMoved", 702 "WebContentsViewAura::WindowObserver::OnRootWindowHostMoved",
760 "new_origin", new_origin.ToString()); 703 "new_origin", new_origin.ToString());
761 704
762 // This is for the desktop case (i.e. Aura desktop). 705 // This is for the desktop case (i.e. Aura desktop).
763 SendScreenRects(); 706 SendScreenRects();
764 } 707 }
765 708
766 private: 709 private:
767 void SendScreenRects() { 710 void SendScreenRects() {
768 RenderWidgetHostImpl::From(view_->web_contents_->GetRenderViewHost())-> 711 RenderWidgetHostImpl::From(view_->web_contents_->GetRenderViewHost())->
769 SendScreenRects(); 712 SendScreenRects();
770 } 713 }
771 714
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
793 WebContentsViewAura* view_; 715 WebContentsViewAura* view_;
794 716
795 // We cache the old parent so that we can unregister when it's not the parent 717 // We cache the old parent so that we can unregister when it's not the parent
796 // anymore. 718 // anymore.
797 aura::Window* parent_; 719 aura::Window* parent_;
798 720
799 DISALLOW_COPY_AND_ASSIGN(WindowObserver); 721 DISALLOW_COPY_AND_ASSIGN(WindowObserver);
800 }; 722 };
801 723
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
802 //////////////////////////////////////////////////////////////////////////////// 814 ////////////////////////////////////////////////////////////////////////////////
803 // WebContentsViewAura, public: 815 // WebContentsViewAura, public:
804 816
805 WebContentsViewAura::WebContentsViewAura( 817 WebContentsViewAura::WebContentsViewAura(
806 WebContentsImpl* web_contents, 818 WebContentsImpl* web_contents,
807 WebContentsViewDelegate* delegate) 819 WebContentsViewDelegate* delegate)
808 : web_contents_(web_contents), 820 : web_contents_(web_contents),
809 delegate_(delegate), 821 delegate_(delegate),
810 current_drag_op_(WebKit::WebDragOperationNone), 822 current_drag_op_(WebKit::WebDragOperationNone),
811 drag_dest_delegate_(NULL), 823 drag_dest_delegate_(NULL),
812 current_rvh_for_drag_(NULL), 824 current_rvh_for_drag_(NULL),
813 overscroll_change_brightness_(false), 825 overscroll_change_brightness_(false),
814 current_overscroll_gesture_(OVERSCROLL_NONE), 826 current_overscroll_gesture_(OVERSCROLL_NONE),
815 completed_overscroll_gesture_(OVERSCROLL_NONE), 827 completed_overscroll_gesture_(OVERSCROLL_NONE),
816 touch_editable_(TouchEditableImplAura::Create()) { 828 touch_editable_(TouchEditableImplAura::Create()) {
817 } 829 }
818 830
819 //////////////////////////////////////////////////////////////////////////////// 831 ////////////////////////////////////////////////////////////////////////////////
820 // WebContentsViewAura, private: 832 // WebContentsViewAura, private:
821 833
822 WebContentsViewAura::~WebContentsViewAura() { 834 WebContentsViewAura::~WebContentsViewAura() {
823 if (!window_) 835 if (!window_)
824 return; 836 return;
825 837
826 window_observer_.reset(); 838 window_observer_.reset();
827 839 #if defined(OS_WIN)
840 child_window_observer_.reset();
841 #endif
828 // Window needs a valid delegate during its destructor, so we explicitly 842 // Window needs a valid delegate during its destructor, so we explicitly
829 // delete it here. 843 // delete it here.
830 window_.reset(); 844 window_.reset();
831 } 845 }
832 846
833 void WebContentsViewAura::SetupOverlayWindowForTesting() { 847 void WebContentsViewAura::SetupOverlayWindowForTesting() {
834 if (navigation_overlay_) 848 if (navigation_overlay_)
835 navigation_overlay_->SetupForTesting(); 849 navigation_overlay_->SetupForTesting();
836 } 850 }
837 851
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 // us. 1162 // us.
1149 if (root_window) { 1163 if (root_window) {
1150 aura::client::ParentWindowWithContext( 1164 aura::client::ParentWindowWithContext(
1151 window_.get(), root_window, root_window->GetBoundsInScreen()); 1165 window_.get(), root_window, root_window->GetBoundsInScreen());
1152 } 1166 }
1153 } 1167 }
1154 window_->layer()->SetMasksToBounds(true); 1168 window_->layer()->SetMasksToBounds(true);
1155 window_->SetName("WebContentsViewAura"); 1169 window_->SetName("WebContentsViewAura");
1156 1170
1157 window_observer_.reset(new WindowObserver(this)); 1171 window_observer_.reset(new WindowObserver(this));
1172 #if defined(OS_WIN)
1173 child_window_observer_.reset(new ChildWindowObserver(this));
1174 #endif
1158 1175
1159 // delegate_->GetDragDestDelegate() creates a new delegate on every call. 1176 // delegate_->GetDragDestDelegate() creates a new delegate on every call.
1160 // Hence, we save a reference to it locally. Similar model is used on other 1177 // Hence, we save a reference to it locally. Similar model is used on other
1161 // platforms as well. 1178 // platforms as well.
1162 if (delegate_) 1179 if (delegate_)
1163 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); 1180 drag_dest_delegate_ = delegate_->GetDragDestDelegate();
1164 } 1181 }
1165 1182
1166 RenderWidgetHostView* WebContentsViewAura::CreateViewForWidget( 1183 RenderWidgetHostView* WebContentsViewAura::CreateViewForWidget(
1167 RenderWidgetHost* render_widget_host) { 1184 RenderWidgetHost* render_widget_host) {
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
1633 event.location(), 1650 event.location(),
1634 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), 1651 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(),
1635 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); 1652 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags()));
1636 if (drag_dest_delegate_) 1653 if (drag_dest_delegate_)
1637 drag_dest_delegate_->OnDrop(); 1654 drag_dest_delegate_->OnDrop();
1638 current_drop_data_.reset(); 1655 current_drop_data_.reset();
1639 return current_drag_op_; 1656 return current_drag_op_;
1640 } 1657 }
1641 1658
1642 } // namespace content 1659 } // namespace content
OLDNEW
« no previous file with comments | « trunk/src/content/browser/web_contents/web_contents_view_aura.h ('k') | trunk/src/content/test/plugin/plugin_test_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698