Commit d0b8c43a authored by Christopher Cameron's avatar Christopher Cameron Committed by Commit Bot

Break native parenting of NativeWidgetMac

In theory, views::Widget::ReparentNativeView and
views::Widget::InitParams allow specifying any NSView* as the parent of
a views::Widget.

The only parent ever actually specified in production is the NSView*
corresponding to the root views::View of another views::Widget.

Add a CHECK to verify that this is the case. If the CHECK is not hit,
then we remove this functionality. Continue to allow testing of this
path (for now) by disabling this CHECK via a static method.

Bug: 859152
Change-Id: I70a9a22352e22b1949d37c86c36388ed5380316b
Reviewed-on: https://chromium-review.googlesource.com/1255863
Commit-Queue: ccameron <ccameron@chromium.org>
Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595752}
parent ed40bff2
......@@ -42,6 +42,7 @@
#import "ui/views_bridge_mac/bridged_content_view.h"
#import "ui/views_bridge_mac/bridged_native_widget_impl.h"
#import "ui/views_bridge_mac/native_widget_mac_nswindow.h"
#include "ui/views_bridge_mac/widget_owner_nswindow_adapter.h"
// Donates an implementation of -[NSAnimation stopAnimation] which calls the
// original implementation, then quits a nested run loop.
......@@ -159,6 +160,7 @@ class NativeWidgetMacTest : public WidgetTest {
// Make a native NSWindow with the given |style_mask| to use as a parent.
TestNativeParentWindow* MakeNativeParentWithStyle(int style_mask) {
WidgetOwnerNSWindowAdapter::AllowForTesting();
native_parent_.reset([[TestNativeParentWindow alloc]
initWithContentRect:ParentRect()
styleMask:style_mask
......
......@@ -7,6 +7,7 @@
#import "base/mac/scoped_nsobject.h"
#include "base/macros.h"
#import "ui/views/views_export.h"
#import "ui/views_bridge_mac/bridged_native_widget_owner.h"
@class NSView;
......@@ -19,6 +20,12 @@ namespace views {
// backed by another BridgedNativeWidgetImpl.
class WidgetOwnerNSWindowAdapter : public BridgedNativeWidgetOwner {
public:
// This class appears to be unused outside of NativeWidgetMacTest. This class
// will crash on instantiation unless AllowForTesting is called. If no crashes
// are reported in the wild, then this class may be removed.
// https://832676
static VIEWS_EXPORT void AllowForTesting();
// Create an adapter that will own |child|, tying its lifetime with the
// NSWindow containing |anchor_view|. The object is self-deleting, via a call
// to RemoveChildWindow() made in child->OnWindowWillClose().
......
......@@ -44,6 +44,15 @@
namespace views {
namespace {
bool g_allow_widget_owner_ns_window_adapter = false;
}
// static
void WidgetOwnerNSWindowAdapter::AllowForTesting() {
g_allow_widget_owner_ns_window_adapter = true;
}
WidgetOwnerNSWindowAdapter::WidgetOwnerNSWindowAdapter(
BridgedNativeWidgetImpl* child,
NSView* anchor_view)
......@@ -51,6 +60,7 @@ WidgetOwnerNSWindowAdapter::WidgetOwnerNSWindowAdapter(
anchor_view_([anchor_view retain]),
observer_bridge_(
[[WidgetOwnerNSWindowAdapterBridge alloc] initWithAdapter:this]) {
CHECK(g_allow_widget_owner_ns_window_adapter);
// Although the |anchor_view| must be in an NSWindow when the child dialog is
// created, it's permitted for the |anchor_view| to be removed from its view
// hierarchy before the child dialog window is fully removed from screen. When
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment