Skip to content

Commit f8a42a3

Browse files
committedOct 7, 2024
Bug 1921903 - Ensure we don't create hidden widgets in non-macOS platforms. r=rkraesig,geckoview-reviewers,win-reviewers,m_kato
Pretty sure that we can't hit that case right now, and try with MOZ_ASSERT agrees with me at least. Popups don't get there. For puppet widgets, mParentWidget is provided explicitly. This code is all super messy and can be cleaned-up significantly. See following patch. Differential Revision: https://phabricator.services.mozilla.com/D224612
1 parent 3c4ccf3 commit f8a42a3

File tree

8 files changed

+56
-103
lines changed

8 files changed

+56
-103
lines changed
 

‎layout/base/PresShell.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -10590,7 +10590,7 @@ bool PresShell::VerifyIncrementalReflow() {
1059010590
NS_ENSURE_TRUE(view, false);
1059110591

1059210592
// now create the widget for the view
10593-
rv = view->CreateWidgetForParent(parentWidget, nullptr, true);
10593+
rv = view->CreateWidgetForParent(parentWidget, true);
1059410594
NS_ENSURE_SUCCESS(rv, false);
1059510595

1059610596
// Setup hierarchical relationship in view manager

‎layout/base/nsDocumentViewer.cpp

+5-19
Original file line numberDiff line numberDiff line change
@@ -2216,8 +2216,7 @@ nsresult nsDocumentViewer::MakeWindow(const nsSize& aSize,
22162216
return NS_OK;
22172217
}
22182218

2219-
bool shouldAttach = ShouldAttachToTopLevel();
2220-
2219+
const bool shouldAttach = ShouldAttachToTopLevel();
22212220
if (shouldAttach) {
22222221
// If the old view is already attached to our parent, detach
22232222
DetachFromTopLevelWidget();
@@ -2242,27 +2241,14 @@ nsresult nsDocumentViewer::MakeWindow(const nsSize& aSize,
22422241
// because when they're displayed, they're painted into *another* document's
22432242
// widget.
22442243
if (!mDocument->IsResourceDoc() && (mParentWidget || !aContainerView)) {
2245-
// pass in a native widget to be the parent widget ONLY if the view
2246-
// hierarchy will stand alone. otherwise the view will find its own parent
2247-
// widget and "do the right thing" to establish a parent/child widget
2248-
// relationship
2249-
widget::InitData initData;
2250-
widget::InitData* initDataPtr;
2251-
if (!mParentWidget) {
2252-
initDataPtr = &initData;
2253-
initData.mWindowType = widget::WindowType::Invisible;
2254-
} else {
2255-
initDataPtr = nullptr;
2256-
}
2257-
22582244
if (shouldAttach) {
22592245
// Reuse the top level parent widget.
22602246
rv = view->AttachToTopLevelWidget(mParentWidget);
22612247
mAttachedToParent = true;
2262-
} else if (!aContainerView && mParentWidget) {
2263-
rv = view->CreateWidgetForParent(mParentWidget, initDataPtr, true, false);
2248+
} else if (!mParentWidget || aContainerView) {
2249+
rv = view->CreateWidget(true, false);
22642250
} else {
2265-
rv = view->CreateWidget(initDataPtr, true, false);
2251+
rv = view->CreateWidgetForParent(mParentWidget, true, false);
22662252
}
22672253
if (NS_FAILED(rv)) return rv;
22682254
}
@@ -3252,7 +3238,7 @@ bool nsDocumentViewer::ShouldAttachToTopLevel() {
32523238
return true;
32533239
}
32543240

3255-
// FIXME(emilio): Can we unify this between macOS and aother platforms?
3241+
// TODO(emilio, bug 1919165): Unify this between macOS and other platforms?
32563242
#ifdef XP_MACOSX
32573243
return false;
32583244
#else

‎view/nsView.cpp

+10-21
Original file line numberDiff line numberDiff line change
@@ -502,17 +502,12 @@ struct DefaultWidgetInitData : public widget::InitData {
502502
}
503503
};
504504

505-
nsresult nsView::CreateWidget(widget::InitData* aWidgetInitData,
506-
bool aEnableDragDrop, bool aResetVisibility) {
505+
nsresult nsView::CreateWidget(bool aEnableDragDrop, bool aResetVisibility) {
507506
AssertNoWindow();
508-
MOZ_ASSERT(
509-
!aWidgetInitData || aWidgetInitData->mWindowType != WindowType::Popup,
510-
"Use CreateWidgetForPopup");
511507

512-
DefaultWidgetInitData defaultInitData;
513-
aWidgetInitData = aWidgetInitData ? aWidgetInitData : &defaultInitData;
514-
LayoutDeviceIntRect trect = CalcWidgetBounds(
515-
aWidgetInitData->mWindowType, aWidgetInitData->mTransparencyMode);
508+
DefaultWidgetInitData initData;
509+
LayoutDeviceIntRect trect =
510+
CalcWidgetBounds(initData.mWindowType, initData.mTransparencyMode);
516511

517512
nsIWidget* parentWidget =
518513
GetParent() ? GetParent()->GetNearestWidget(nullptr) : nullptr;
@@ -523,7 +518,7 @@ nsresult nsView::CreateWidget(widget::InitData* aWidgetInitData,
523518

524519
// XXX: using aForceUseIWidgetParent=true to preserve previous
525520
// semantics. It's not clear that it's actually needed.
526-
mWindow = parentWidget->CreateChild(trect, aWidgetInitData, true);
521+
mWindow = parentWidget->CreateChild(trect, &initData, true);
527522
if (!mWindow) {
528523
return NS_ERROR_FAILURE;
529524
}
@@ -534,22 +529,16 @@ nsresult nsView::CreateWidget(widget::InitData* aWidgetInitData,
534529
}
535530

536531
nsresult nsView::CreateWidgetForParent(nsIWidget* aParentWidget,
537-
widget::InitData* aWidgetInitData,
538532
bool aEnableDragDrop,
539533
bool aResetVisibility) {
540534
AssertNoWindow();
541-
MOZ_ASSERT(
542-
!aWidgetInitData || aWidgetInitData->mWindowType != WindowType::Popup,
543-
"Use CreateWidgetForPopup");
544535
MOZ_ASSERT(aParentWidget, "Parent widget required");
545536

546-
DefaultWidgetInitData defaultInitData;
547-
aWidgetInitData = aWidgetInitData ? aWidgetInitData : &defaultInitData;
548-
549-
LayoutDeviceIntRect trect = CalcWidgetBounds(
550-
aWidgetInitData->mWindowType, aWidgetInitData->mTransparencyMode);
537+
DefaultWidgetInitData initData;
538+
LayoutDeviceIntRect trect =
539+
CalcWidgetBounds(initData.mWindowType, initData.mTransparencyMode);
551540

552-
mWindow = aParentWidget->CreateChild(trect, aWidgetInitData);
541+
mWindow = aParentWidget->CreateChild(trect, &initData);
553542
if (!mWindow) {
554543
return NS_ERROR_FAILURE;
555544
}
@@ -622,7 +611,7 @@ void nsView::SetNeedsWindowPropertiesSync() {
622611

623612
// Attach to a top level widget and start receiving mirrored events.
624613
nsresult nsView::AttachToTopLevelWidget(nsIWidget* aWidget) {
625-
MOZ_ASSERT(nullptr != aWidget, "null widget ptr");
614+
MOZ_ASSERT(aWidget, "null widget ptr");
626615

627616
/// XXXjimm This is a temporary workaround to an issue w/document
628617
// viewer (bug 513162).

‎view/nsView.h

+1-5
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,9 @@ class nsView final : public nsIWidgetListener {
280280
* CreateWidget*() will look around in the view hierarchy for an
281281
* appropriate parent widget for the view.
282282
*
283-
* @param aWidgetInitData data used to initialize this view's widget before
284-
* its create is called.
285283
* @return error status
286284
*/
287-
nsresult CreateWidget(mozilla::widget::InitData* aWidgetInitData = nullptr,
288-
bool aEnableDragDrop = true,
285+
nsresult CreateWidget(bool aEnableDragDrop = true,
289286
bool aResetVisibility = true);
290287

291288
/**
@@ -294,7 +291,6 @@ class nsView final : public nsIWidgetListener {
294291
* as for |CreateWidget()|.
295292
*/
296293
nsresult CreateWidgetForParent(nsIWidget* aParentWidget,
297-
mozilla::widget::InitData* = nullptr,
298294
bool aEnableDragDrop = true,
299295
bool aResetVisibility = true);
300296

‎widget/android/nsWindow.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -2241,6 +2241,9 @@ nsresult nsWindow::Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
22412241
mBounds = rect;
22422242
SetSizeConstraints(SizeConstraints());
22432243

2244+
MOZ_DIAGNOSTIC_ASSERT(!aInitData ||
2245+
aInitData->mWindowType != WindowType::Invisible);
2246+
22442247
BaseCreate(nullptr, aInitData);
22452248

22462249
NS_ASSERTION(IsTopLevel() || parent,

‎widget/gtk/nsWindow.cpp

+9-12
Original file line numberDiff line numberDiff line change
@@ -755,10 +755,6 @@ void nsWindow::SetParent(nsIWidget* aNewParent) {
755755
}
756756

757757
bool nsWindow::WidgetTypeSupportsAcceleration() {
758-
if (mWindowType == WindowType::Invisible) {
759-
return false;
760-
}
761-
762758
if (IsSmallPopup()) {
763759
return false;
764760
}
@@ -2969,7 +2965,7 @@ void nsWindow::MoveToWorkspace(const nsAString& workspaceIDStr) {
29692965

29702966
void nsWindow::SetUserTimeAndStartupTokenForActivatedWindow() {
29712967
nsGTKToolkit* toolkit = nsGTKToolkit::GetToolkit();
2972-
if (!toolkit || MOZ_UNLIKELY(mWindowType == WindowType::Invisible)) {
2968+
if (!toolkit) {
29732969
return;
29742970
}
29752971

@@ -5876,12 +5872,14 @@ nsresult nsWindow::Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
58765872
widget::InitData* aInitData) {
58775873
LOG("nsWindow::Create\n");
58785874

5875+
MOZ_DIAGNOSTIC_ASSERT(!aInitData ||
5876+
aInitData->mWindowType != WindowType::Invisible);
5877+
58795878
// only set the base parent if we're going to be a dialog or a
58805879
// toplevel
58815880
nsIWidget* baseParent =
58825881
aInitData && (aInitData->mWindowType == WindowType::Dialog ||
5883-
aInitData->mWindowType == WindowType::TopLevel ||
5884-
aInitData->mWindowType == WindowType::Invisible)
5882+
aInitData->mWindowType == WindowType::TopLevel)
58855883
? nullptr
58865884
: aParent;
58875885

@@ -5914,9 +5912,9 @@ nsresult nsWindow::Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
59145912
ConstrainSize(&mBounds.width, &mBounds.height);
59155913
mLastSizeRequest = mBounds.Size();
59165914

5917-
bool popupNeedsAlphaVisual = mWindowType == WindowType::Popup &&
5918-
(aInitData && aInitData->mTransparencyMode ==
5919-
TransparencyMode::Transparent);
5915+
bool popupNeedsAlphaVisual =
5916+
mWindowType == WindowType::Popup && aInitData &&
5917+
aInitData->mTransparencyMode == TransparencyMode::Transparent;
59205918

59215919
// Figure out our parent window - only used for WindowType::Child
59225920
nsWindow* parentnsWindow = nullptr;
@@ -5946,8 +5944,7 @@ nsresult nsWindow::Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
59465944
MOZ_ASSERT_IF(mWindowType == WindowType::Popup, parentnsWindow);
59475945

59485946
if (mWindowType != WindowType::Dialog && mWindowType != WindowType::Popup &&
5949-
mWindowType != WindowType::TopLevel &&
5950-
mWindowType != WindowType::Invisible) {
5947+
mWindowType != WindowType::TopLevel) {
59515948
MOZ_ASSERT_UNREACHABLE("Unexpected eWindowType");
59525949
return NS_ERROR_FAILURE;
59535950
}

‎widget/windows/WinEventObserver.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@
3434
extern "C" IMAGE_DOS_HEADER __ImageBase;
3535
#define CURRENT_MODULE() reinterpret_cast<HMODULE>(&__ImageBase)
3636

37-
// N.B.: if and when we eliminate the existing `WindowType::Invisible` hidden
38-
// window, we must switch to use of `kClassNameHidden` for the class name. (See
39-
// commentary therebeside.)
40-
const wchar_t kClassNameHidden2[] = L"MozillaHiddenWindowClass2";
41-
4237
namespace mozilla::widget {
4338

4439
LazyLogModule gWinEventWindowLog("WinEventWindow");
@@ -66,7 +61,7 @@ void WinEventWindow::Ensure() {
6661
HMODULE const hSelf = CURRENT_MODULE();
6762
WNDCLASSW const wc = {.lpfnWndProc = WinEventWindow::WndProc,
6863
.hInstance = hSelf,
69-
.lpszClassName = kClassNameHidden2};
64+
.lpszClassName = kClassNameHidden};
7065
ATOM const atom = ::RegisterClassW(&wc);
7166
if (!atom) {
7267
// This is known to be possible when the atom table no longer has free

‎widget/windows/nsWindow.cpp

+26-39
Original file line numberDiff line numberDiff line change
@@ -873,12 +873,12 @@ nsresult nsWindow::Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
873873
widget::InitData defaultInitData;
874874
if (!aInitData) aInitData = &defaultInitData;
875875

876-
nsIWidget* baseParent =
877-
aInitData->mWindowType == WindowType::Dialog ||
878-
aInitData->mWindowType == WindowType::TopLevel ||
879-
aInitData->mWindowType == WindowType::Invisible
880-
? nullptr
881-
: aParent;
876+
MOZ_DIAGNOSTIC_ASSERT(aInitData->mWindowType != WindowType::Invisible);
877+
878+
nsIWidget* baseParent = aInitData->mWindowType == WindowType::Dialog ||
879+
aInitData->mWindowType == WindowType::TopLevel
880+
? nullptr
881+
: aParent;
882882

883883
mIsTopWidgetWindow = (nullptr == baseParent);
884884
mBounds = aRect;
@@ -888,7 +888,7 @@ nsresult nsWindow::Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
888888

889889
BaseCreate(baseParent, aInitData);
890890

891-
HWND parent;
891+
HWND parent = nullptr;
892892
if (aParent) { // has a nsIWidget parent
893893
parent = aParent ? (HWND)aParent->GetNativeData(NS_NATIVE_WINDOW) : nullptr;
894894
mParent = aParent;
@@ -913,9 +913,6 @@ nsresult nsWindow::Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
913913
if (!aParent) {
914914
parent = nullptr;
915915
}
916-
} else if (mWindowType == WindowType::Invisible) {
917-
// Make sure CreateWindowEx succeeds at creating a toplevel window
918-
desiredStyles.style &= ~WS_CHILDWINDOW;
919916
} else {
920917
// See if the caller wants to explictly set clip children and clip siblings
921918
if (aInitData->mClipChildren) {
@@ -1093,8 +1090,7 @@ nsresult nsWindow::Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
10931090
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
10941091
}
10951092

1096-
if (mWindowType != WindowType::Invisible &&
1097-
MouseScrollHandler::Device::IsFakeScrollableWindowNeeded()) {
1093+
if (MouseScrollHandler::Device::IsFakeScrollableWindowNeeded()) {
10981094
// Ugly Thinkpad Driver Hack (Bugs 507222 and 594977)
10991095
//
11001096
// We create two zero-sized windows as descendants of the top-level window,
@@ -1263,8 +1259,6 @@ static LPWSTR const gStockApplicationIcon = MAKEINTRESOURCEW(32512);
12631259
static const wchar_t* ChooseWindowClass(WindowType aWindowType) {
12641260
const wchar_t* className = [aWindowType] {
12651261
switch (aWindowType) {
1266-
case WindowType::Invisible:
1267-
return kClassNameHidden;
12681262
case WindowType::Dialog:
12691263
return kClassNameDialog;
12701264
case WindowType::Popup:
@@ -1348,7 +1342,6 @@ DWORD nsWindow::WindowStyle() {
13481342
[[fallthrough]];
13491343

13501344
case WindowType::TopLevel:
1351-
case WindowType::Invisible:
13521345
style = WS_OVERLAPPED | WS_CLIPCHILDREN | WS_DLGFRAME | WS_BORDER |
13531346
WS_THICKFRAME | kTitlebarItemsWindowStyles;
13541347
break;
@@ -5858,24 +5851,23 @@ bool nsWindow::ProcessMessageInternal(UINT msg, WPARAM& wParam, LPARAM& lParam,
58585851
break;
58595852

58605853
case WM_GESTURENOTIFY: {
5861-
if (mWindowType != WindowType::Invisible) {
5862-
// A GestureNotify event is dispatched to decide which single-finger
5863-
// panning direction should be active (including none) and if pan
5864-
// feedback should be displayed. Java and plugin windows can make their
5865-
// own calls.
5866-
5867-
GESTURENOTIFYSTRUCT* gestureinfo = (GESTURENOTIFYSTRUCT*)lParam;
5868-
nsPointWin touchPoint;
5869-
touchPoint = gestureinfo->ptsLocation;
5870-
touchPoint.ScreenToClient(mWnd);
5871-
WidgetGestureNotifyEvent gestureNotifyEvent(true, eGestureNotify, this);
5872-
gestureNotifyEvent.mRefPoint =
5873-
LayoutDeviceIntPoint::FromUnknownPoint(touchPoint);
5874-
nsEventStatus status;
5875-
DispatchEvent(&gestureNotifyEvent, status);
5876-
mDisplayPanFeedback = gestureNotifyEvent.mDisplayPanFeedback;
5877-
if (!mTouchWindow)
5878-
mGesture.SetWinGestureSupport(mWnd, gestureNotifyEvent.mPanDirection);
5854+
// A GestureNotify event is dispatched to decide which single-finger
5855+
// panning direction should be active (including none) and if pan
5856+
// feedback should be displayed. Java and plugin windows can make their
5857+
// own calls.
5858+
5859+
GESTURENOTIFYSTRUCT* gestureinfo = (GESTURENOTIFYSTRUCT*)lParam;
5860+
nsPointWin touchPoint;
5861+
touchPoint = gestureinfo->ptsLocation;
5862+
touchPoint.ScreenToClient(mWnd);
5863+
WidgetGestureNotifyEvent gestureNotifyEvent(true, eGestureNotify, this);
5864+
gestureNotifyEvent.mRefPoint =
5865+
LayoutDeviceIntPoint::FromUnknownPoint(touchPoint);
5866+
nsEventStatus status;
5867+
DispatchEvent(&gestureNotifyEvent, status);
5868+
mDisplayPanFeedback = gestureNotifyEvent.mDisplayPanFeedback;
5869+
if (!mTouchWindow) {
5870+
mGesture.SetWinGestureSupport(mWnd, gestureNotifyEvent.mPanDirection);
58795871
}
58805872
result = false; // should always bubble to DefWindowProc
58815873
} break;
@@ -6555,11 +6547,6 @@ void nsWindow::OnWindowPosChanging(WINDOWPOS* info) {
65556547
}
65566548
}
65576549

6558-
// prevent rude external programs from making hidden window visible
6559-
if (mWindowType == WindowType::Invisible) {
6560-
info->flags &= ~SWP_SHOWWINDOW;
6561-
}
6562-
65636550
// When waking from sleep or switching out of tablet mode, Windows 10
65646551
// Version 1809 will reopen popup windows that should be hidden. Detect
65656552
// this case and refuse to show the window.
@@ -7192,7 +7179,7 @@ a11y::LocalAccessible* nsWindow::GetAccessible() {
71927179
if (a11y::PlatformDisabledState() == a11y::ePlatformIsDisabled)
71937180
return nullptr;
71947181

7195-
if (mInDtor || mOnDestroyCalled || mWindowType == WindowType::Invisible) {
7182+
if (mInDtor || mOnDestroyCalled) {
71967183
return nullptr;
71977184
}
71987185

0 commit comments

Comments
 (0)
Failed to load comments.