Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rules for "prevent this page from creating additional dialogs"

I try to understand Firefox's behavior regarding the added "prevent this page from creating additional dialogs" on dialog boxes.

Using jquery, if I add the following listeners :

//html
<input class="testInput" />

//javascript
$('.testInput')
.click(function(){ alert('clicked') })
.keyup(function(){ alert('keyup') })
  1. When clicking on the input, the alert box appears normally, until the ~13th time.
  2. When hitting a key, on the other hand, the second message box already appears with the message "prevent this page from creating additional dialogs". Actually, there seems to be some tiemout, and if I wait like 2 seconds between two keystrokes, the message disappears.

From my informal tests, 2. actually applies whenever the alert box is not called from within a onclick callback (e.g : keyup callback, displaying an alert box in answer to an ajax action...)

I am using Firefox 9.0.1 under Ubuntu, as far as I know I haven't tweaked firefox's settings regarding these thresholds. I imagine it happens with any recent version of any browser.

I am using the jQuery library, but I don't think it is relevant here.

My question is : What are the exact rules which make this warning appear in a dialog box ?

[Edit]

Using Chromium/Ubuntu (version 17.0.963.26), the threshold seems to be only the delay between two dialog boxes.

You can test this from jsfiddle here (thx Rory McCrossan)

like image 864
LeGEC Avatar asked Jan 13 '12 13:01

LeGEC


2 Answers

The exact rule(s): A timed interval between the dialog boxes popping up. The value used to determine this is set in SUCCESSIVE_DIALOG_TIME_LIMIT

Check out line 2614 in the link below the snippet:

nsGlobalWindow::DialogOpenAttempted()

TimeDuration dialogDuration(TimeStamp::Now() - topWindow->mLastDialogQuitTime);

if (dialogDuration.ToSeconds() < Preferences::GetInt("dom.successive_dialog_time_limit",SUCCESSIVE_DIALOG_TIME_LIMIT)){topWindow->mDialogAbuseCount++;return (topWindow->GetPopupControlState() > openAllowed || topWindow->mDialogAbuseCount > MAX_DIALOG_COUNT);}topWindow->mDialogAbuseCount = 0; return false;}

Link to source

like image 124
DevCoDesign Avatar answered Oct 11 '22 14:10

DevCoDesign


You can kick around the Firefox source if you like. Note that different browsers will have different rules.

The relevant code for Firefox is in nsGlobalWindow.cpp and nsGlobalWindow.h (the links below are to line numbers, and so will slowly rot as the source changes). It appears to be controlled by the constants MAX_DIALOG_COUNT (10) in nsGlobalWindow.h and SUCCESSIVE_DIALOG_TIME_LIMIT (3, units are seconds). nsGlobalWindow.cpp keeps a count (mDialogAbuseCount). Apparently, the dialogDuration function either increments or clears mDialogAbuseCount depending on whether the dialog has been open longer than the SUCCESSIVE_DIALOG_TIME_LIMIT. The AreDialogsBlocked function uses the mDialogAbuseCount (in part) to decide whether they're blocked.

So in short: If you're repeatedly opening pop-ups and then closing them within three seconds, after 10 or so you'll trigger something.

like image 41
T.J. Crowder Avatar answered Oct 11 '22 13:10

T.J. Crowder