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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_aura.cc

Issue 1815593002: Remove windowed NPAPI code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@make_test_plugin_windowless
Patch Set: fix compile Created 4 years, 9 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/renderer_host/render_widget_host_view_aura.h" 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 // of the border area, in percentage of the corresponding dimension. 134 // of the border area, in percentage of the corresponding dimension.
135 const int kMouseLockBorderPercentage = 15; 135 const int kMouseLockBorderPercentage = 15;
136 136
137 // When accelerated compositing is enabled and a widget resize is pending, 137 // When accelerated compositing is enabled and a widget resize is pending,
138 // we delay further resizes of the UI. The following constant is the maximum 138 // we delay further resizes of the UI. The following constant is the maximum
139 // length of time that we should delay further UI resizes while waiting for a 139 // length of time that we should delay further UI resizes while waiting for a
140 // resized frame from a renderer. 140 // resized frame from a renderer.
141 const int kResizeLockTimeoutMs = 67; 141 const int kResizeLockTimeoutMs = 67;
142 142
143 #if defined(OS_WIN) 143 #if defined(OS_WIN)
144 // Used to associate a plugin HWND with its RenderWidgetHostViewAura instance.
145 const wchar_t kWidgetOwnerProperty[] = L"RenderWidgetHostViewAuraOwner";
146
147 BOOL CALLBACK WindowDestroyingCallback(HWND window, LPARAM param) {
148 RenderWidgetHostViewAura* widget =
149 reinterpret_cast<RenderWidgetHostViewAura*>(param);
150 if (GetProp(window, kWidgetOwnerProperty) == widget) {
151 // Properties set on HWNDs must be removed to avoid leaks.
152 RemoveProp(window, kWidgetOwnerProperty);
153 RenderWidgetHostViewBase::DetachPluginWindowsCallback(window);
154 }
155 return TRUE;
156 }
157
158 BOOL CALLBACK HideWindowsCallback(HWND window, LPARAM param) {
159 RenderWidgetHostViewAura* widget =
160 reinterpret_cast<RenderWidgetHostViewAura*>(param);
161 if (GetProp(window, kWidgetOwnerProperty) == widget)
162 SetParent(window, ui::GetHiddenWindow());
163 return TRUE;
164 }
165
166 BOOL CALLBACK ShowWindowsCallback(HWND window, LPARAM param) {
167 RenderWidgetHostViewAura* widget =
168 reinterpret_cast<RenderWidgetHostViewAura*>(param);
169
170 if (GetProp(window, kWidgetOwnerProperty) == widget &&
171 widget->GetNativeView()->GetHost()) {
172 HWND parent = widget->GetNativeView()->GetHost()->GetAcceleratedWidget();
173 SetParent(window, parent);
174 }
175 return TRUE;
176 }
177
178 struct CutoutRectsParams {
179 RenderWidgetHostViewAura* widget;
180 std::vector<gfx::Rect> cutout_rects;
181 std::map<HWND, WebPluginGeometry>* geometry;
182 };
183
184 // Used to update the region for the windowed plugin to draw in. We start with
185 // the clip rect from the renderer, then remove the cutout rects from the
186 // renderer, and then remove the transient windows from the root window and the
187 // constrained windows from the parent window.
188 BOOL CALLBACK SetCutoutRectsCallback(HWND window, LPARAM param) {
189 CutoutRectsParams* params = reinterpret_cast<CutoutRectsParams*>(param);
190
191 if (GetProp(window, kWidgetOwnerProperty) == params->widget) {
192 // First calculate the offset of this plugin from the root window, since
193 // the cutouts are relative to the root window.
194 HWND parent =
195 params->widget->GetNativeView()->GetHost()->GetAcceleratedWidget();
196 POINT offset;
197 offset.x = offset.y = 0;
198 MapWindowPoints(window, parent, &offset, 1);
199
200 // Now get the cached clip rect and cutouts for this plugin window that came
201 // from the renderer.
202 std::map<HWND, WebPluginGeometry>::iterator i = params->geometry->begin();
203 while (i != params->geometry->end() &&
204 i->second.window != window &&
205 GetParent(i->second.window) != window) {
206 ++i;
207 }
208
209 if (i == params->geometry->end()) {
210 NOTREACHED();
211 return TRUE;
212 }
213
214 HRGN hrgn = CreateRectRgn(i->second.clip_rect.x(),
215 i->second.clip_rect.y(),
216 i->second.clip_rect.right(),
217 i->second.clip_rect.bottom());
218 // We start with the cutout rects that came from the renderer, then add the
219 // ones that came from transient and constrained windows.
220 std::vector<gfx::Rect> cutout_rects = i->second.cutout_rects;
221 for (size_t i = 0; i < params->cutout_rects.size(); ++i) {
222 gfx::Rect offset_cutout = params->cutout_rects[i];
223 offset_cutout.Offset(-offset.x, -offset.y);
224 cutout_rects.push_back(offset_cutout);
225 }
226 gfx::SubtractRectanglesFromRegion(hrgn, cutout_rects);
227 // If we don't have any cutout rects then no point in messing with the
228 // window region.
229 if (cutout_rects.size())
230 SetWindowRgn(window, hrgn, TRUE);
231 }
232 return TRUE;
233 }
234
235 // A callback function for EnumThreadWindows to enumerate and dismiss 144 // A callback function for EnumThreadWindows to enumerate and dismiss
236 // any owned popup windows. 145 // any owned popup windows.
237 BOOL CALLBACK DismissOwnedPopups(HWND window, LPARAM arg) { 146 BOOL CALLBACK DismissOwnedPopups(HWND window, LPARAM arg) {
238 const HWND toplevel_hwnd = reinterpret_cast<HWND>(arg); 147 const HWND toplevel_hwnd = reinterpret_cast<HWND>(arg);
239 148
240 if (::IsWindowVisible(window)) { 149 if (::IsWindowVisible(window)) {
241 const HWND owner = ::GetWindow(window, GW_OWNER); 150 const HWND owner = ::GetWindow(window, GW_OWNER);
242 if (toplevel_hwnd == owner) { 151 if (toplevel_hwnd == owner) {
243 ::PostMessage(window, WM_CANCELMODE, 0, 0); 152 ::PostMessage(window, WM_CANCELMODE, 0, 0);
244 } 153 }
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 #if defined(OS_WIN) 561 #if defined(OS_WIN)
653 if (legacy_render_widget_host_HWND_) { 562 if (legacy_render_widget_host_HWND_) {
654 // Reparent the legacy Chrome_RenderWidgetHostHWND window to the parent 563 // Reparent the legacy Chrome_RenderWidgetHostHWND window to the parent
655 // window before reparenting any plugins. This ensures that the plugin 564 // window before reparenting any plugins. This ensures that the plugin
656 // windows stay on top of the child Zorder in the parent and receive 565 // windows stay on top of the child Zorder in the parent and receive
657 // mouse events, etc. 566 // mouse events, etc.
658 legacy_render_widget_host_HWND_->UpdateParent( 567 legacy_render_widget_host_HWND_->UpdateParent(
659 GetNativeView()->GetHost()->GetAcceleratedWidget()); 568 GetNativeView()->GetHost()->GetAcceleratedWidget());
660 legacy_render_widget_host_HWND_->SetBounds( 569 legacy_render_widget_host_HWND_->SetBounds(
661 window_->GetBoundsInRootWindow()); 570 window_->GetBoundsInRootWindow());
571 legacy_render_widget_host_HWND_->Show();
662 } 572 }
663 LPARAM lparam = reinterpret_cast<LPARAM>(this);
664 EnumChildWindows(ui::GetHiddenWindow(), ShowWindowsCallback, lparam);
665
666 if (legacy_render_widget_host_HWND_)
667 legacy_render_widget_host_HWND_->Show();
668 #endif 573 #endif
669 } 574 }
670 575
671 void RenderWidgetHostViewAura::Hide() { 576 void RenderWidgetHostViewAura::Hide() {
672 window_->Hide(); 577 window_->Hide();
673 578
674 // TODO(wjmaclean): can host_ ever be null? 579 // TODO(wjmaclean): can host_ ever be null?
675 if (host_ && !host_->is_hidden()) { 580 if (host_ && !host_->is_hidden()) {
676 host_->WasHidden(); 581 host_->WasHidden();
677 delegated_frame_host_->WasHidden(); 582 delegated_frame_host_->WasHidden();
678 583
679 #if defined(OS_WIN) 584 #if defined(OS_WIN)
680 constrained_rects_.clear();
681 aura::WindowTreeHost* host = window_->GetHost(); 585 aura::WindowTreeHost* host = window_->GetHost();
682 if (host) { 586 if (host) {
683 HWND parent = host->GetAcceleratedWidget();
684 LPARAM lparam = reinterpret_cast<LPARAM>(this);
685 EnumChildWindows(parent, HideWindowsCallback, lparam);
686 // We reparent the legacy Chrome_RenderWidgetHostHWND window to the global 587 // We reparent the legacy Chrome_RenderWidgetHostHWND window to the global
687 // hidden window on the same lines as Windowed plugin windows. 588 // hidden window on the same lines as Windowed plugin windows.
688 if (legacy_render_widget_host_HWND_) 589 if (legacy_render_widget_host_HWND_)
689 legacy_render_widget_host_HWND_->UpdateParent(ui::GetHiddenWindow()); 590 legacy_render_widget_host_HWND_->UpdateParent(ui::GetHiddenWindow());
690 } 591 }
691 #endif 592 #endif
692 } 593 }
693 594
694 #if defined(OS_WIN) 595 #if defined(OS_WIN)
695 if (legacy_render_widget_host_HWND_) 596 if (legacy_render_widget_host_HWND_)
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 host_->SendScreenRects(); 795 host_->SendScreenRects();
895 } 796 }
896 } 797 }
897 798
898 void RenderWidgetHostViewAura::ParentHierarchyChanged() { 799 void RenderWidgetHostViewAura::ParentHierarchyChanged() {
899 ancestor_window_observer_.reset(new WindowAncestorObserver(this)); 800 ancestor_window_observer_.reset(new WindowAncestorObserver(this));
900 // Snap when we receive a hierarchy changed. http://crbug.com/388908. 801 // Snap when we receive a hierarchy changed. http://crbug.com/388908.
901 HandleParentBoundsChanged(); 802 HandleParentBoundsChanged();
902 } 803 }
903 804
904 void RenderWidgetHostViewAura::MovePluginWindows(
905 const std::vector<WebPluginGeometry>& plugin_window_moves) {
906 #if defined(OS_WIN)
907 // We need to clip the rectangle to the tab's viewport, otherwise we will draw
908 // over the browser UI.
909 if (!window_->GetRootWindow()) {
910 DCHECK(plugin_window_moves.empty());
911 return;
912 }
913 HWND parent = window_->GetHost()->GetAcceleratedWidget();
914 gfx::Rect view_bounds = window_->GetBoundsInRootWindow();
915 std::vector<WebPluginGeometry> moves = plugin_window_moves;
916
917 gfx::Rect view_port(view_bounds.size());
918
919 for (size_t i = 0; i < moves.size(); ++i) {
920 gfx::Rect clip(moves[i].clip_rect);
921 gfx::Vector2d view_port_offset(
922 moves[i].window_rect.OffsetFromOrigin());
923 clip.Offset(view_port_offset);
924 clip.Intersect(view_port);
925 clip.Offset(-view_port_offset);
926 moves[i].clip_rect = clip;
927
928 moves[i].window_rect.Offset(view_bounds.OffsetFromOrigin());
929
930 plugin_window_moves_[moves[i].window] = moves[i];
931
932 // constrained_rects_ are relative to the root window. We want to convert
933 // them to be relative to the plugin window.
934 for (size_t j = 0; j < constrained_rects_.size(); ++j) {
935 gfx::Rect offset_cutout = constrained_rects_[j];
936 offset_cutout -= moves[i].window_rect.OffsetFromOrigin();
937 moves[i].cutout_rects.push_back(offset_cutout);
938 }
939 }
940
941 MovePluginWindowsHelper(parent, moves);
942
943 // Make sure each plugin window (or its wrapper if it exists) has a pointer to
944 // |this|.
945 for (size_t i = 0; i < moves.size(); ++i) {
946 HWND window = moves[i].window;
947 if (GetParent(window) != parent) {
948 window = GetParent(window);
949 }
950 if (!GetProp(window, kWidgetOwnerProperty))
951 SetProp(window, kWidgetOwnerProperty, this);
952 }
953 #endif // defined(OS_WIN)
954 }
955
956 void RenderWidgetHostViewAura::Focus() { 805 void RenderWidgetHostViewAura::Focus() {
957 // Make sure we have a FocusClient before attempting to Focus(). In some 806 // Make sure we have a FocusClient before attempting to Focus(). In some
958 // situations we may not yet be in a valid Window hierarchy (such as reloading 807 // situations we may not yet be in a valid Window hierarchy (such as reloading
959 // after out of memory discarded the tab). 808 // after out of memory discarded the tab).
960 aura::client::FocusClient* client = aura::client::GetFocusClient(window_); 809 aura::client::FocusClient* client = aura::client::GetFocusClient(window_);
961 if (client) 810 if (client)
962 window_->Focus(); 811 window_->Focus();
963 } 812 }
964 813
965 bool RenderWidgetHostViewAura::HasFocus() const { 814 bool RenderWidgetHostViewAura::HasFocus() const {
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 1019
1171 void RenderWidgetHostViewAura::EndFrameSubscription() { 1020 void RenderWidgetHostViewAura::EndFrameSubscription() {
1172 delegated_frame_host_->EndFrameSubscription(); 1021 delegated_frame_host_->EndFrameSubscription();
1173 } 1022 }
1174 1023
1175 #if defined(OS_WIN) 1024 #if defined(OS_WIN)
1176 bool RenderWidgetHostViewAura::UsesNativeWindowFrame() const { 1025 bool RenderWidgetHostViewAura::UsesNativeWindowFrame() const {
1177 return (legacy_render_widget_host_HWND_ != NULL); 1026 return (legacy_render_widget_host_HWND_ != NULL);
1178 } 1027 }
1179 1028
1180 void RenderWidgetHostViewAura::UpdateConstrainedWindowRects(
1181 const std::vector<gfx::Rect>& rects) {
1182 // Check this before setting constrained_rects_, so that next time they're set
1183 // and we have a root window we don't early return.
1184 if (!window_->GetHost())
1185 return;
1186
1187 if (rects == constrained_rects_)
1188 return;
1189
1190 constrained_rects_ = rects;
1191
1192 HWND parent = window_->GetHost()->GetAcceleratedWidget();
1193 CutoutRectsParams params;
1194 params.widget = this;
1195 params.cutout_rects = constrained_rects_;
1196 params.geometry = &plugin_window_moves_;
1197 LPARAM lparam = reinterpret_cast<LPARAM>(&params);
1198 EnumChildWindows(parent, SetCutoutRectsCallback, lparam);
1199 }
1200
1201 void RenderWidgetHostViewAura::UpdateMouseLockRegion() { 1029 void RenderWidgetHostViewAura::UpdateMouseLockRegion() {
1202 RECT window_rect = 1030 RECT window_rect =
1203 gfx::win::DIPToScreenRect(window_->GetBoundsInScreen()).ToRECT(); 1031 gfx::win::DIPToScreenRect(window_->GetBoundsInScreen()).ToRECT();
1204 ::ClipCursor(&window_rect); 1032 ::ClipCursor(&window_rect);
1205 } 1033 }
1206 1034
1207 void RenderWidgetHostViewAura::OnLegacyWindowDestroyed() { 1035 void RenderWidgetHostViewAura::OnLegacyWindowDestroyed() {
1208 legacy_render_widget_host_HWND_ = NULL; 1036 legacy_render_widget_host_HWND_ = NULL;
1209 legacy_window_destroyed_ = true; 1037 legacy_window_destroyed_ = true;
1210 } 1038 }
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after
1944 device_scale_factor_ = device_scale_factor; 1772 device_scale_factor_ = device_scale_factor;
1945 const gfx::Display display = gfx::Screen::GetScreen()-> 1773 const gfx::Display display = gfx::Screen::GetScreen()->
1946 GetDisplayNearestWindow(window_); 1774 GetDisplayNearestWindow(window_);
1947 DCHECK_EQ(device_scale_factor, display.device_scale_factor()); 1775 DCHECK_EQ(device_scale_factor, display.device_scale_factor());
1948 current_cursor_.SetDisplayInfo(display); 1776 current_cursor_.SetDisplayInfo(display);
1949 SnapToPhysicalPixelBoundary(); 1777 SnapToPhysicalPixelBoundary();
1950 } 1778 }
1951 1779
1952 void RenderWidgetHostViewAura::OnWindowDestroying(aura::Window* window) { 1780 void RenderWidgetHostViewAura::OnWindowDestroying(aura::Window* window) {
1953 #if defined(OS_WIN) 1781 #if defined(OS_WIN)
1954 HWND parent = NULL;
1955 // If the tab was hidden and it's closed, host_->is_hidden would have been
1956 // reset to false in RenderWidgetHostImpl::RendererExited.
1957 if (!window_->GetRootWindow() || host_->is_hidden()) {
1958 parent = ui::GetHiddenWindow();
1959 } else {
1960 parent = window_->GetHost()->GetAcceleratedWidget();
1961 }
1962 LPARAM lparam = reinterpret_cast<LPARAM>(this);
1963 EnumChildWindows(parent, WindowDestroyingCallback, lparam);
1964
1965 // The LegacyRenderWidgetHostHWND instance is destroyed when its window is 1782 // The LegacyRenderWidgetHostHWND instance is destroyed when its window is
1966 // destroyed. Normally we control when that happens via the Destroy call 1783 // destroyed. Normally we control when that happens via the Destroy call
1967 // in the dtor. However there may be cases where the window is destroyed 1784 // in the dtor. However there may be cases where the window is destroyed
1968 // by Windows, i.e. the parent window is destroyed before the 1785 // by Windows, i.e. the parent window is destroyed before the
1969 // RenderWidgetHostViewAura instance goes away etc. To avoid that we 1786 // RenderWidgetHostViewAura instance goes away etc. To avoid that we
1970 // destroy the LegacyRenderWidgetHostHWND instance here. 1787 // destroy the LegacyRenderWidgetHostHWND instance here.
1971 if (legacy_render_widget_host_HWND_) { 1788 if (legacy_render_widget_host_HWND_) {
1972 legacy_render_widget_host_HWND_->set_host(NULL); 1789 legacy_render_widget_host_HWND_->set_host(NULL);
1973 legacy_render_widget_host_HWND_->Destroy(); 1790 legacy_render_widget_host_HWND_->Destroy();
1974 // The Destroy call above will delete the LegacyRenderWidgetHostHWND 1791 // The Destroy call above will delete the LegacyRenderWidgetHostHWND
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after
2764 // Don't recursively call SetBounds if this bounds update is the result of 2581 // Don't recursively call SetBounds if this bounds update is the result of
2765 // a Window::SetBoundsInternal call. 2582 // a Window::SetBoundsInternal call.
2766 if (!in_bounds_changed_) 2583 if (!in_bounds_changed_)
2767 window_->SetBounds(rect); 2584 window_->SetBounds(rect);
2768 host_->WasResized(); 2585 host_->WasResized();
2769 delegated_frame_host_->WasResized(); 2586 delegated_frame_host_->WasResized();
2770 #if defined(OS_WIN) 2587 #if defined(OS_WIN)
2771 // Create the legacy dummy window which corresponds to the bounds of the 2588 // Create the legacy dummy window which corresponds to the bounds of the
2772 // webcontents. This will be passed as the container window for windowless 2589 // webcontents. This will be passed as the container window for windowless
2773 // plugins. 2590 // plugins.
2774 // Plugins like Flash assume the container window which is returned via the
2775 // NPNVnetscapeWindow property corresponds to the bounds of the webpage.
2776 // This is not true in Aura where we have only HWND which is the main Aura
2777 // window. If we return this window to plugins like Flash then it causes the
2778 // coordinate translations done by these plugins to break.
2779 // Additonally the legacy dummy window is needed for accessibility and for 2591 // Additonally the legacy dummy window is needed for accessibility and for
jam 2016/03/18 17:00:19 nit: this second part of the comment doesn't make
piman 2016/03/18 18:49:17 I thought we still needed that for legacy mouse/tr
jam 2016/03/18 21:56:16 to be clear, I meant specifically that the comment
piman 2016/03/18 22:22:00 Oh... I kept it because "... This will be passed a
2780 // scrolling to work in legacy drivers for trackpoints/trackpads, etc. 2592 // scrolling to work in legacy drivers for trackpoints/trackpads, etc.
2781 if (!legacy_window_destroyed_ && GetNativeViewId()) { 2593 if (!legacy_window_destroyed_ && GetNativeViewId()) {
2782 if (!legacy_render_widget_host_HWND_) { 2594 if (!legacy_render_widget_host_HWND_) {
2783 legacy_render_widget_host_HWND_ = LegacyRenderWidgetHostHWND::Create( 2595 legacy_render_widget_host_HWND_ = LegacyRenderWidgetHostHWND::Create(
2784 reinterpret_cast<HWND>(GetNativeViewId())); 2596 reinterpret_cast<HWND>(GetNativeViewId()));
2785 } 2597 }
2786 if (legacy_render_widget_host_HWND_) { 2598 if (legacy_render_widget_host_HWND_) {
2787 legacy_render_widget_host_HWND_->set_host(this); 2599 legacy_render_widget_host_HWND_->set_host(this);
2788 legacy_render_widget_host_HWND_->SetBounds( 2600 legacy_render_widget_host_HWND_->SetBounds(
2789 window_->GetBoundsInRootWindow()); 2601 window_->GetBoundsInRootWindow());
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
3129 2941
3130 //////////////////////////////////////////////////////////////////////////////// 2942 ////////////////////////////////////////////////////////////////////////////////
3131 // RenderWidgetHostViewBase, public: 2943 // RenderWidgetHostViewBase, public:
3132 2944
3133 // static 2945 // static
3134 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { 2946 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) {
3135 GetScreenInfoForWindow(results, NULL); 2947 GetScreenInfoForWindow(results, NULL);
3136 } 2948 }
3137 2949
3138 } // namespace content 2950 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698