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

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: Oops, forgot to upload delegate in new file Created 6 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
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 #include "ui/base/dragdrop/os_exchange_data.h" 60 #include "ui/base/dragdrop/os_exchange_data.h"
61 #include "ui/base/hit_test.h" 61 #include "ui/base/hit_test.h"
62 #include "ui/compositor/layer.h" 62 #include "ui/compositor/layer.h"
63 #include "ui/compositor/scoped_layer_animation_settings.h" 63 #include "ui/compositor/scoped_layer_animation_settings.h"
64 #include "ui/events/event.h" 64 #include "ui/events/event.h"
65 #include "ui/events/event_utils.h" 65 #include "ui/events/event_utils.h"
66 #include "ui/gfx/canvas.h" 66 #include "ui/gfx/canvas.h"
67 #include "ui/gfx/image/image.h" 67 #include "ui/gfx/image/image.h"
68 #include "ui/gfx/image/image_png_rep.h" 68 #include "ui/gfx/image/image_png_rep.h"
69 #include "ui/gfx/image/image_skia.h" 69 #include "ui/gfx/image/image_skia.h"
70 #include "ui/gfx/native_widget_types.h"
70 #include "ui/gfx/screen.h" 71 #include "ui/gfx/screen.h"
71 #include "ui/wm/public/drag_drop_client.h" 72 #include "ui/wm/public/drag_drop_client.h"
72 #include "ui/wm/public/drag_drop_delegate.h" 73 #include "ui/wm/public/drag_drop_delegate.h"
73 74
75 #if defined(OS_WIN)
76 #include "content/browser/accessibility/browser_accessibility_manager.h"
77 #include "content/browser/accessibility/browser_accessibility_win.h"
78 #include "ui/base/win/hidden_window.h"
79 #endif
80
74 namespace content { 81 namespace content {
75 WebContentsView* CreateWebContentsView( 82 WebContentsView* CreateWebContentsView(
76 WebContentsImpl* web_contents, 83 WebContentsImpl* web_contents,
77 WebContentsViewDelegate* delegate, 84 WebContentsViewDelegate* delegate,
78 RenderViewHostDelegateView** render_view_host_delegate_view) { 85 RenderViewHostDelegateView** render_view_host_delegate_view) {
79 WebContentsViewAura* rv = new WebContentsViewAura(web_contents, delegate); 86 WebContentsViewAura* rv = new WebContentsViewAura(web_contents, delegate);
80 *render_view_host_delegate_view = rv; 87 *render_view_host_delegate_view = rv;
81 return rv; 88 return rv;
82 } 89 }
83 90
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 host_window_ = NULL; 642 host_window_ = NULL;
636 } 643 }
637 } 644 }
638 645
639 virtual void OnWindowAddedToRootWindow(aura::Window* window) override { 646 virtual void OnWindowAddedToRootWindow(aura::Window* window) override {
640 if (window == view_->window_) { 647 if (window == view_->window_) {
641 window->GetHost()->AddObserver(this); 648 window->GetHost()->AddObserver(this);
642 #if defined(OS_WIN) 649 #if defined(OS_WIN)
643 if (!window->GetRootWindow()->HasObserver(this)) 650 if (!window->GetRootWindow()->HasObserver(this))
644 window->GetRootWindow()->AddObserver(this); 651 window->GetRootWindow()->AddObserver(this);
652 if (view_->legacy_hwnd_) {
653 view_->legacy_hwnd_->UpdateParent(
654 window->GetHost()->GetAcceleratedWidget());
655 }
645 #endif 656 #endif
646 } 657 }
647 } 658 }
648 659
649 virtual void OnWindowRemovingFromRootWindow(aura::Window* window, 660 virtual void OnWindowRemovingFromRootWindow(aura::Window* window,
650 aura::Window* new_root) override { 661 aura::Window* new_root) override {
651 if (window == view_->window_) { 662 if (window == view_->window_) {
652 window->GetHost()->RemoveObserver(this); 663 window->GetHost()->RemoveObserver(this);
653 #if defined(OS_WIN) 664 #if defined(OS_WIN)
654 window->GetRootWindow()->RemoveObserver(this); 665 window->GetRootWindow()->RemoveObserver(this);
655 666
656 const aura::Window::Windows& root_children = 667 const aura::Window::Windows& root_children =
657 window->GetRootWindow()->children(); 668 window->GetRootWindow()->children();
658 for (size_t i = 0; i < root_children.size(); ++i) { 669 for (size_t i = 0; i < root_children.size(); ++i) {
659 if (root_children[i] != view_->window_ && 670 if (root_children[i] != view_->window_ &&
660 root_children[i] != host_window_) { 671 root_children[i] != host_window_) {
661 root_children[i]->RemoveObserver(this); 672 root_children[i]->RemoveObserver(this);
662 } 673 }
663 } 674 }
675
676 if (view_->legacy_hwnd_)
677 view_->legacy_hwnd_->UpdateParent(ui::GetHiddenWindow());
664 #endif 678 #endif
665 } 679 }
666 } 680 }
667 681
668 // Overridden WindowTreeHostObserver: 682 // Overridden WindowTreeHostObserver:
669 virtual void OnHostMoved(const aura::WindowTreeHost* host, 683 virtual void OnHostMoved(const aura::WindowTreeHost* host,
670 const gfx::Point& new_origin) override { 684 const gfx::Point& new_origin) override {
671 TRACE_EVENT1("ui", 685 TRACE_EVENT1("ui",
672 "WebContentsViewAura::WindowObserver::OnHostMoved", 686 "WebContentsViewAura::WindowObserver::OnHostMoved",
673 "new_origin", new_origin.ToString()); 687 "new_origin", new_origin.ToString());
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 1024
1011 void WebContentsViewAura::GetContainerBounds(gfx::Rect *out) const { 1025 void WebContentsViewAura::GetContainerBounds(gfx::Rect *out) const {
1012 *out = window_->GetBoundsInScreen(); 1026 *out = window_->GetBoundsInScreen();
1013 } 1027 }
1014 1028
1015 void WebContentsViewAura::SizeContents(const gfx::Size& size) { 1029 void WebContentsViewAura::SizeContents(const gfx::Size& size) {
1016 gfx::Rect bounds = window_->bounds(); 1030 gfx::Rect bounds = window_->bounds();
1017 if (bounds.size() != size) { 1031 if (bounds.size() != size) {
1018 bounds.set_size(size); 1032 bounds.set_size(size);
1019 window_->SetBounds(bounds); 1033 window_->SetBounds(bounds);
1034 #if defined(OS_WIN)
1035 if (legacy_hwnd_)
1036 legacy_hwnd_->SetBounds(window_->GetBoundsInRootWindow());
1037 #endif
1020 } else { 1038 } else {
1021 // Our size matches what we want but the renderers size may not match. 1039 // Our size matches what we want but the renderers size may not match.
1022 // Pretend we were resized so that the renderers size is updated too. 1040 // Pretend we were resized so that the renderers size is updated too.
1023 SizeChangedCommon(size); 1041 SizeChangedCommon(size);
1024 } 1042 }
1025 } 1043 }
1026 1044
1027 void WebContentsViewAura::Focus() { 1045 void WebContentsViewAura::Focus() {
1028 if (web_contents_->GetInterstitialPage()) { 1046 if (web_contents_->GetInterstitialPage()) {
1029 web_contents_->GetInterstitialPage()->Focus(); 1047 web_contents_->GetInterstitialPage()->Focus();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 // 1) guests do not support NPAPI plugins. 1124 // 1) guests do not support NPAPI plugins.
1107 // 2) guests' window bounds are supposed to come from its embedder. 1125 // 2) guests' window bounds are supposed to come from its embedder.
1108 if (!BrowserPluginGuest::IsGuest(web_contents_)) 1126 if (!BrowserPluginGuest::IsGuest(web_contents_))
1109 window_observer_.reset(new WindowObserver(this)); 1127 window_observer_.reset(new WindowObserver(this));
1110 1128
1111 // delegate_->GetDragDestDelegate() creates a new delegate on every call. 1129 // delegate_->GetDragDestDelegate() creates a new delegate on every call.
1112 // Hence, we save a reference to it locally. Similar model is used on other 1130 // Hence, we save a reference to it locally. Similar model is used on other
1113 // platforms as well. 1131 // platforms as well.
1114 if (delegate_) 1132 if (delegate_)
1115 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); 1133 drag_dest_delegate_ = delegate_->GetDragDestDelegate();
1134
1135 #if defined(OS_WIN)
1136 if (context && context->GetHost()) {
1137 HWND parent_hwnd = context->GetHost()->GetAcceleratedWidget();
1138 CHECK(parent_hwnd);
1139 legacy_hwnd_.reset(LegacyRenderWidgetHostHWND::Create(parent_hwnd, this));
1140 }
1141 #endif
1116 } 1142 }
1117 1143
1118 RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForWidget( 1144 RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForWidget(
1119 RenderWidgetHost* render_widget_host, bool is_guest_view_hack) { 1145 RenderWidgetHost* render_widget_host, bool is_guest_view_hack) {
1120 if (render_widget_host->GetView()) { 1146 if (render_widget_host->GetView()) {
1121 // During testing, the view will already be set up in most cases to the 1147 // During testing, the view will already be set up in most cases to the
1122 // test view, so we don't want to clobber it with a real one. To verify that 1148 // test view, so we don't want to clobber it with a real one. To verify that
1123 // this actually is happening (and somebody isn't accidentally creating the 1149 // this actually is happening (and somebody isn't accidentally creating the
1124 // view twice), we check for the RVH Factory, which will be set when we're 1150 // view twice), we check for the RVH Factory, which will be set when we're
1125 // making special ones (which go along with the special views). 1151 // making special ones (which go along with the special views).
(...skipping 20 matching lines...) Expand all
1146 // We listen to drag drop events in the newly created view's window. 1172 // We listen to drag drop events in the newly created view's window.
1147 aura::client::SetDragDropDelegate(view->GetNativeView(), this); 1173 aura::client::SetDragDropDelegate(view->GetNativeView(), this);
1148 1174
1149 if (view->overscroll_controller() && 1175 if (view->overscroll_controller() &&
1150 (!web_contents_->GetDelegate() || 1176 (!web_contents_->GetDelegate() ||
1151 web_contents_->GetDelegate()->CanOverscrollContent())) { 1177 web_contents_->GetDelegate()->CanOverscrollContent())) {
1152 InstallOverscrollControllerDelegate(view); 1178 InstallOverscrollControllerDelegate(view);
1153 } 1179 }
1154 1180
1155 AttachTouchEditableToRenderView(); 1181 AttachTouchEditableToRenderView();
1182
1183 #if defined(OS_WIN)
1184 if (legacy_hwnd_)
1185 view->SetLegacyRenderWidgetHostHWND(legacy_hwnd_.get());
1186 #endif
1187
1156 return view; 1188 return view;
1157 } 1189 }
1158 1190
1159 RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForPopupWidget( 1191 RenderWidgetHostViewBase* WebContentsViewAura::CreateViewForPopupWidget(
1160 RenderWidgetHost* render_widget_host) { 1192 RenderWidgetHost* render_widget_host) {
1161 return new RenderWidgetHostViewAura(render_widget_host, false); 1193 RenderWidgetHostViewAura* view =
1194 new RenderWidgetHostViewAura(render_widget_host, false);
1195 #if defined(OS_WIN)
1196 if (legacy_hwnd_)
1197 view->SetLegacyRenderWidgetHostHWND(legacy_hwnd_.get());
1198 #endif
1199 return view;
1162 } 1200 }
1163 1201
1164 void WebContentsViewAura::SetPageTitle(const base::string16& title) { 1202 void WebContentsViewAura::SetPageTitle(const base::string16& title) {
1165 window_->SetTitle(title); 1203 window_->SetTitle(title);
1166 } 1204 }
1167 1205
1168 void WebContentsViewAura::RenderViewCreated(RenderViewHost* host) { 1206 void WebContentsViewAura::RenderViewCreated(RenderViewHost* host) {
1169 } 1207 }
1170 1208
1171 void WebContentsViewAura::RenderViewSwappedIn(RenderViewHost* host) { 1209 void WebContentsViewAura::RenderViewSwappedIn(RenderViewHost* host) {
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
1631 } 1669 }
1632 return; 1670 return;
1633 } 1671 }
1634 if (visible) { 1672 if (visible) {
1635 if (!web_contents_->should_normally_be_visible()) 1673 if (!web_contents_->should_normally_be_visible())
1636 web_contents_->WasShown(); 1674 web_contents_->WasShown();
1637 } else { 1675 } else {
1638 if (web_contents_->should_normally_be_visible()) 1676 if (web_contents_->should_normally_be_visible())
1639 web_contents_->WasHidden(); 1677 web_contents_->WasHidden();
1640 } 1678 }
1679
1680 #if defined(OS_WIN)
1681 if (!legacy_hwnd_)
1682 return;
1683
1684 if (visible && GetNativeView() && GetNativeView()->GetHost()) {
1685 legacy_hwnd_->UpdateParent(
1686 GetNativeView()->GetHost()->GetAcceleratedWidget());
1687 legacy_hwnd_->SetBounds(window_->GetBoundsInRootWindow());
1688 legacy_hwnd_->Show();
1689 } else {
1690 // We reparent the legacy Chrome_RenderWidgetHostHWND window to the global
1691 // hidden window on the same lines as Windowed plugin windows.
1692 legacy_hwnd_->UpdateParent(ui::GetHiddenWindow());
1693 legacy_hwnd_->Hide();
1694 }
1695 #endif
1641 } 1696 }
1642 1697
1698 #if defined(OS_WIN)
1699 gfx::NativeViewAccessible
1700 WebContentsViewAura::GetNativeViewAccessible() {
1701 BrowserAccessibilityManager* manager =
1702 web_contents_->GetRootBrowserAccessibilityManager();
1703 if (!manager)
1704 return nullptr;
1705
1706 return manager->GetRoot()->ToBrowserAccessibilityWin();
1707 }
1708 #endif
1709
1643 } // namespace content 1710 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_view_aura.h ('k') | ui/views/controls/webview/webview_interactive_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698