Skip to content

Commit

Permalink
Bug 1925401: Require BUTTON_NONE in nsIPrompt for button-less dialogs…
Browse files Browse the repository at this point in the history
… r=Gijs,necko-reviewers

This will prevent devs from accidentally requesting no buttons, since
the only way to dismiss such a prompt is with an intentional call to
prompt.close().  A request that indicates that button 0's label is
the empty string previously indicated button 0 is hidden, which means no
buttons.  Now, that case is an exception unless BUTTON_NONE is set.

Differential Revision: https://phabricator.services.mozilla.com/D226081

UltraBlame original commit: 80b0b1f6f80610d09dfd79275e7ededf2089205e
  • Loading branch information
marco-c committed Oct 22, 2024
1 parent 96db453 commit 1bb7f98
Show file tree
Hide file tree
Showing 6 changed files with 533 additions and 57 deletions.
29 changes: 5 additions & 24 deletions dom/geolocation/Geolocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2097,20 +2097,16 @@ combination
of
flags
removes
the
default
yes
and
no
all
buttons
and
adds
a
/
/
spinner
to
the
/
/
title
.
const
Expand All @@ -2120,23 +2116,8 @@ kSpinnerNoButtonFlags
nsIPromptService
:
:
BUTTON_TITLE_IS_STRING
*
nsIPromptService
:
:
BUTTON_POS_0
+
nsIPromptService
:
:
BUTTON_TITLE_IS_STRING
*
nsIPromptService
:
:
BUTTON_POS_1
+
BUTTON_NONE
|
nsIPromptService
:
:
Expand Down
34 changes: 34 additions & 0 deletions netwerk/base/nsIPrompt.idl
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,40 @@ SHOW_SPINNER
<
27
;
/
/
Part
of
BUTTON_NONE
.
This
is
not
a
button
flag
.
const
unsigned
long
BUTTON_NONE_ENABLE_BIT
=
1
<
<
28
;
const
unsigned
long
BUTTON_NONE
=
BUTTON_NONE_ENABLE_BIT
|
BUTTON_TITLE_IS_STRING
*
BUTTON_POS_0
;
const
unsigned
long
Expand Down
34 changes: 34 additions & 0 deletions toolkit/components/prompts/src/CommonDialog.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,40 @@ numButtons
+
;
}
if
(
numButtons
=
=
0
&
&
!
this
.
args
.
allowNoButtons
)
{
throw
new
Error
(
"
A
dialog
with
no
buttons
requires
the
allowNoButtons
argument
"
)
;
}
this
.
numButtons
Expand Down
157 changes: 157 additions & 0 deletions toolkit/components/prompts/src/Prompter.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6382,6 +6382,155 @@ BUTTON_DELAY_ENABLE
;
/
/
Sanity
check
:
If
the
flags
indicate
there
should
be
no
button0
then
flags
/
/
must
equal
BUTTON_NONE
(
notably
it
must
include
BUTTON_NONE_ENABLE_BIT
)
.
let
allowNoButtons
=
flags
=
=
Ci
.
nsIPromptService
.
BUTTON_NONE
;
const
NO_BUTTON0
=
Ci
.
nsIPrompt
.
BUTTON_POS_0
*
Ci
.
nsIPrompt
.
BUTTON_TITLE_IS_STRING
;
if
(
!
allowNoButtons
&
&
!
button0
&
&
(
flags
&
NO_BUTTON0
)
=
=
NO_BUTTON0
)
{
throw
new
Error
(
Request
for
modal
prompt
with
no
buttons
requires
flags
to
be
+
BUTTON_NONE
.
Got
{
flags
}
)
;
}
if
(
allowNoButtons
&
&
(
button0
|
|
button1
|
|
button2
)
)
{
throw
new
Error
(
Request
for
modal
prompt
with
no
buttons
requires
button
names
to
be
+
null
.
Got
{
button0
}
{
button1
}
{
button2
}
)
;
}
/
/
Flags
can
be
Expand Down Expand Up @@ -6667,6 +6816,7 @@ buttonLabels
]
defaultButtonNum
isDelayEnabled
allowNoButtons
]
;
}
Expand Down Expand Up @@ -10962,6 +11112,7 @@ label1
label2
defaultButtonNum
isDelayEnabled
allowNoButtons
]
=
InternalPromptUtils
Expand All @@ -10986,6 +11137,12 @@ enableDelay
=
isDelayEnabled
;
args
.
allowNoButtons
=
allowNoButtons
;
if
(
label0
Expand Down
Loading

0 comments on commit 1bb7f98

Please sign in to comment.