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

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

Issue 387353004: Create only a single LegacyRenderWidgetHostHWND per WebContentsViewAura. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@render_frame_ax_3
Patch Set: Fix Win 8 Created 6 years, 3 months 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
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/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 #include "ui/base/dragdrop/os_exchange_data.h" 59 #include "ui/base/dragdrop/os_exchange_data.h"
60 #include "ui/base/hit_test.h" 60 #include "ui/base/hit_test.h"
61 #include "ui/compositor/layer.h" 61 #include "ui/compositor/layer.h"
62 #include "ui/compositor/scoped_layer_animation_settings.h" 62 #include "ui/compositor/scoped_layer_animation_settings.h"
63 #include "ui/events/event.h" 63 #include "ui/events/event.h"
64 #include "ui/events/event_utils.h" 64 #include "ui/events/event_utils.h"
65 #include "ui/gfx/canvas.h" 65 #include "ui/gfx/canvas.h"
66 #include "ui/gfx/image/image.h" 66 #include "ui/gfx/image/image.h"
67 #include "ui/gfx/image/image_png_rep.h" 67 #include "ui/gfx/image/image_png_rep.h"
68 #include "ui/gfx/image/image_skia.h" 68 #include "ui/gfx/image/image_skia.h"
69 #include "ui/gfx/native_widget_types.h"
69 #include "ui/gfx/screen.h" 70 #include "ui/gfx/screen.h"
70 #include "ui/wm/public/drag_drop_client.h" 71 #include "ui/wm/public/drag_drop_client.h"
71 #include "ui/wm/public/drag_drop_delegate.h" 72 #include "ui/wm/public/drag_drop_delegate.h"
72 73
74 #if defined(OS_WIN)
75 #include "content/browser/accessibility/browser_accessibility_manager.h"
76 #include "content/browser/accessibility/browser_accessibility_win.h"
77 #include "ui/base/win/hidden_window.h"
78 #endif
79
73 namespace content { 80 namespace content {
74 WebContentsView* CreateWebContentsView( 81 WebContentsView* CreateWebContentsView(
75 WebContentsImpl* web_contents, 82 WebContentsImpl* web_contents,
76 WebContentsViewDelegate* delegate, 83 WebContentsViewDelegate* delegate,
77 RenderViewHostDelegateView** render_view_host_delegate_view) { 84 RenderViewHostDelegateView** render_view_host_delegate_view) {
78 WebContentsViewAura* rv = new WebContentsViewAura(web_contents, delegate); 85 WebContentsViewAura* rv = new WebContentsViewAura(web_contents, delegate);
79 *render_view_host_delegate_view = rv; 86 *render_view_host_delegate_view = rv;
80 return rv; 87 return rv;
81 } 88 }
82 89
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 host_window_ = NULL; 641 host_window_ = NULL;
635 } 642 }
636 } 643 }
637 644
638 virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE { 645 virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE {
639 if (window == view_->window_) { 646 if (window == view_->window_) {
640 window->GetHost()->AddObserver(this); 647 window->GetHost()->AddObserver(this);
641 #if defined(OS_WIN) 648 #if defined(OS_WIN)
642 if (!window->GetRootWindow()->HasObserver(this)) 649 if (!window->GetRootWindow()->HasObserver(this))
643 window->GetRootWindow()->AddObserver(this); 650 window->GetRootWindow()->AddObserver(this);
651 if (view_->legacy_hwnd_) {
652 view_->legacy_hwnd_->UpdateParent(
653 window->GetHost()->GetAcceleratedWidget());
654 }
644 #endif 655 #endif
645 } 656 }
646 } 657 }
647 658
648 virtual void OnWindowRemovingFromRootWindow(aura::Window* window, 659 virtual void OnWindowRemovingFromRootWindow(aura::Window* window,
649 aura::Window* new_root) OVERRIDE { 660 aura::Window* new_root) OVERRIDE {
650 if (window == view_->window_) { 661 if (window == view_->window_) {
651 window->GetHost()->RemoveObserver(this); 662 window->GetHost()->RemoveObserver(this);
652 #if defined(OS_WIN) 663 #if defined(OS_WIN)
653 window->GetRootWindow()->RemoveObserver(this); 664 window->GetRootWindow()->RemoveObserver(this);
654 665
655 const aura::Window::Windows& root_children = 666 const aura::Window::Windows& root_children =
656 window->GetRootWindow()->children(); 667 window->GetRootWindow()->children();
657 for (size_t i = 0; i < root_children.size(); ++i) { 668 for (size_t i = 0; i < root_children.size(); ++i) {
658 if (root_children[i] != view_->window_ && 669 if (root_children[i] != view_->window_ &&
659 root_children[i] != host_window_) { 670 root_children[i] != host_window_) {
660 root_children[i]->RemoveObserver(this); 671 root_children[i]->RemoveObserver(this);
661 } 672 }
662 } 673 }
674
675 // Update the legacy window's parent temporarily to the desktop window.
676 // It will eventually get reparented to the right root.
677 if (view_->legacy_hwnd_)
678 view_->legacy_hwnd_->UpdateParent(::GetDesktopWindow());
ananta 2014/09/23 20:14:06 I know that this is a copy of the existing code in
dmazzoni 2014/09/24 22:57:52 Makes sense, done.
663 #endif 679 #endif
664 } 680 }
665 } 681 }
666 682
667 // Overridden WindowTreeHostObserver: 683 // Overridden WindowTreeHostObserver:
668 virtual void OnHostMoved(const aura::WindowTreeHost* host, 684 virtual void OnHostMoved(const aura::WindowTreeHost* host,
669 const gfx::Point& new_origin) OVERRIDE { 685 const gfx::Point& new_origin) OVERRIDE {
670 TRACE_EVENT1("ui", 686 TRACE_EVENT1("ui",
671 "WebContentsViewAura::WindowObserver::OnHostMoved", 687 "WebContentsViewAura::WindowObserver::OnHostMoved",
672 "new_origin", new_origin.ToString()); 688 "new_origin", new_origin.ToString());
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 1022
1007 void WebContentsViewAura::GetContainerBounds(gfx::Rect *out) const { 1023 void WebContentsViewAura::GetContainerBounds(gfx::Rect *out) const {
1008 *out = window_->GetBoundsInScreen(); 1024 *out = window_->GetBoundsInScreen();
1009 } 1025 }
1010 1026
1011 void WebContentsViewAura::SizeContents(const gfx::Size& size) { 1027 void WebContentsViewAura::SizeContents(const gfx::Size& size) {
1012 gfx::Rect bounds = window_->bounds(); 1028 gfx::Rect bounds = window_->bounds();
1013 if (bounds.size() != size) { 1029 if (bounds.size() != size) {
1014 bounds.set_size(size); 1030 bounds.set_size(size);
1015 window_->SetBounds(bounds); 1031 window_->SetBounds(bounds);
1032 if (legacy_hwnd_)
1033 legacy_hwnd_->SetBounds(window_->GetBoundsInRootWindow());
1016 } else { 1034 } else {
1017 // Our size matches what we want but the renderers size may not match. 1035 // Our size matches what we want but the renderers size may not match.
1018 // Pretend we were resized so that the renderers size is updated too. 1036 // Pretend we were resized so that the renderers size is updated too.
1019 SizeChangedCommon(size); 1037 SizeChangedCommon(size);
1020 } 1038 }
1021 } 1039 }
1022 1040
1023 void WebContentsViewAura::Focus() { 1041 void WebContentsViewAura::Focus() {
1024 if (web_contents_->GetInterstitialPage()) { 1042 if (web_contents_->GetInterstitialPage()) {
1025 web_contents_->GetInterstitialPage()->Focus(); 1043 web_contents_->GetInterstitialPage()->Focus();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 // 1) guests do not support NPAPI plugins. 1117 // 1) guests do not support NPAPI plugins.
1100 // 2) guests' window bounds are supposed to come from its embedder. 1118 // 2) guests' window bounds are supposed to come from its embedder.
1101 if (!BrowserPluginGuest::IsGuest(web_contents_)) 1119 if (!BrowserPluginGuest::IsGuest(web_contents_))
1102 window_observer_.reset(new WindowObserver(this)); 1120 window_observer_.reset(new WindowObserver(this));
1103 1121
1104 // delegate_->GetDragDestDelegate() creates a new delegate on every call. 1122 // delegate_->GetDragDestDelegate() creates a new delegate on every call.
1105 // Hence, we save a reference to it locally. Similar model is used on other 1123 // Hence, we save a reference to it locally. Similar model is used on other
1106 // platforms as well. 1124 // platforms as well.
1107 if (delegate_) 1125 if (delegate_)
1108 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); 1126 drag_dest_delegate_ = delegate_->GetDragDestDelegate();
1127
1128 #if defined(OS_WIN)
1129 HWND parent_hwnd;
1130 if (context && context->GetHost())
1131 parent_hwnd = context->GetHost()->GetAcceleratedWidget();
1132 else
1133 parent_hwnd = ::GetDesktopWindow();
ananta 2014/09/23 20:14:06 It would be good to know when context is going to
dmazzoni 2014/09/24 22:57:52 The comment above says that sometimes object hiera
1134 legacy_hwnd_.reset(LegacyRenderWidgetHostHWND::Create(parent_hwnd, this));
1135 #endif
1109 } 1136 }
1110 1137
1111 RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForWidget( 1138 RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForWidget(
1112 RenderWidgetHost* render_widget_host) { 1139 RenderWidgetHost* render_widget_host) {
1113 if (render_widget_host->GetView()) { 1140 if (render_widget_host->GetView()) {
1114 // During testing, the view will already be set up in most cases to the 1141 // During testing, the view will already be set up in most cases to the
1115 // test view, so we don't want to clobber it with a real one. To verify that 1142 // test view, so we don't want to clobber it with a real one. To verify that
1116 // this actually is happening (and somebody isn't accidentally creating the 1143 // this actually is happening (and somebody isn't accidentally creating the
1117 // view twice), we check for the RVH Factory, which will be set when we're 1144 // view twice), we check for the RVH Factory, which will be set when we're
1118 // making special ones (which go along with the special views). 1145 // making special ones (which go along with the special views).
(...skipping 20 matching lines...) Expand all
1139 // We listen to drag drop events in the newly created view's window. 1166 // We listen to drag drop events in the newly created view's window.
1140 aura::client::SetDragDropDelegate(view->GetNativeView(), this); 1167 aura::client::SetDragDropDelegate(view->GetNativeView(), this);
1141 1168
1142 if (view->overscroll_controller() && 1169 if (view->overscroll_controller() &&
1143 (!web_contents_->GetDelegate() || 1170 (!web_contents_->GetDelegate() ||
1144 web_contents_->GetDelegate()->CanOverscrollContent())) { 1171 web_contents_->GetDelegate()->CanOverscrollContent())) {
1145 InstallOverscrollControllerDelegate(view); 1172 InstallOverscrollControllerDelegate(view);
1146 } 1173 }
1147 1174
1148 AttachTouchEditableToRenderView(); 1175 AttachTouchEditableToRenderView();
1176
1177 #if defined(OS_WIN)
1178 view->SetLegacyRenderWidgetHostHWND(legacy_hwnd_.get());
1179 #endif
1180
1149 return view; 1181 return view;
1150 } 1182 }
1151 1183
1152 RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForPopupWidget( 1184 RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForPopupWidget(
1153 RenderWidgetHost* render_widget_host) { 1185 RenderWidgetHost* render_widget_host) {
1154 return new RenderWidgetHostViewAura(render_widget_host); 1186 RenderWidgetHostViewAura* view =
1187 new RenderWidgetHostViewAura(render_widget_host);
1188 #if defined(OS_WIN)
1189 view->SetLegacyRenderWidgetHostHWND(legacy_hwnd_.get());
1190 #endif
1191 return view;
1155 } 1192 }
1156 1193
1157 void WebContentsViewAura::SetPageTitle(const base::string16& title) { 1194 void WebContentsViewAura::SetPageTitle(const base::string16& title) {
1158 window_->SetTitle(title); 1195 window_->SetTitle(title);
1159 } 1196 }
1160 1197
1161 void WebContentsViewAura::RenderViewCreated(RenderViewHost* host) { 1198 void WebContentsViewAura::RenderViewCreated(RenderViewHost* host) {
1162 } 1199 }
1163 1200
1164 void WebContentsViewAura::RenderViewSwappedIn(RenderViewHost* host) { 1201 void WebContentsViewAura::RenderViewSwappedIn(RenderViewHost* host) {
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
1614 } 1651 }
1615 return; 1652 return;
1616 } 1653 }
1617 if (visible) { 1654 if (visible) {
1618 if (!web_contents_->should_normally_be_visible()) 1655 if (!web_contents_->should_normally_be_visible())
1619 web_contents_->WasShown(); 1656 web_contents_->WasShown();
1620 } else { 1657 } else {
1621 if (web_contents_->should_normally_be_visible()) 1658 if (web_contents_->should_normally_be_visible())
1622 web_contents_->WasHidden(); 1659 web_contents_->WasHidden();
1623 } 1660 }
1661
1662 #if defined(OS_WIN)
1663 if (!legacy_hwnd_)
1664 return;
1665
1666 if (visible) {
1667 legacy_hwnd_->UpdateParent(
1668 GetNativeView()->GetHost()->GetAcceleratedWidget());
1669 legacy_hwnd_->SetBounds(window_->GetBoundsInRootWindow());
1670 legacy_hwnd_->Show();
1671 } else {
1672 // We reparent the legacy Chrome_RenderWidgetHostHWND window to the global
1673 // hidden window on the same lines as Windowed plugin windows.
1674 legacy_hwnd_->UpdateParent(ui::GetHiddenWindow());
1675 legacy_hwnd_->Hide();
1676 }
1677 #endif
1624 } 1678 }
1625 1679
1680 #if defined(OS_WIN)
1681 gfx::NativeViewAccessible
1682 WebContentsViewAura::GetNativeViewAccessible() {
1683 BrowserAccessibilityManager* manager =
1684 web_contents_->GetRootBrowserAccessibilityManager();
1685 if (!manager)
1686 return NULL;
1687
1688 return manager->GetRoot()->ToBrowserAccessibilityWin();
1689 }
1690 #endif
1691
1626 } // namespace content 1692 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698