Bug 9254 - Quirksmode: Safari ignores window.close() after form submission
Summary: Quirksmode: Safari ignores window.close() after form submission
Status: RESOLVED WONTFIX
Alias: None
Product: WebKit
Classification: Unclassified
Component: Forms (show other bugs)
Version: 420+
Hardware: PC OS X 10.4
: P2 Normal
Assignee: Mark Hahnenberg
URL:
Keywords: NeedsReduction
Depends on:
Blocks: 9610 39021
  Show dependency treegraph
 
Reported: 2006-06-02 14:36 PDT by Adele Peterson
Modified: 2013-05-13 18:24 PDT (History)
11 users (show)

See Also:


Attachments
recovered test case from www.archive.org (466 bytes, text/html)
2009-01-02 01:34 PST, Robert Blaut
no flags Details
Modified test case (453 bytes, text/html)
2011-07-22 14:29 PDT, Mark Hahnenberg
no flags Details
Patch (1.68 KB, patch)
2011-07-22 15:24 PDT, Mark Hahnenberg
no flags Details | Formatted Diff | Diff
More general test case (233 bytes, text/html)
2011-07-22 16:46 PDT, Mark Hahnenberg
no flags Details
Patch (5.51 KB, patch)
2011-07-25 11:42 PDT, Mark Hahnenberg
no flags Details | Formatted Diff | Diff
Patch (5.48 KB, patch)
2011-07-26 08:51 PDT, Mark Hahnenberg
webkit.review.bot: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Adele Peterson 2006-06-02 14:36:02 PDT
http://www.quirksmode.org/bugreports/archives/safari/index.html

"Safari 2.0.2 (416.12) seems to be unable to process the javascript:window.close() function after a form submission. The first time into the test page, the 'close' button works as expected. However after you've used the submit button, it is no longer functional. The click event is firing, but the close request is not being honoured.

Test page http://www.evergreenplayers.org/cheddar/test/testclose.php
Workaround is not included
Reported by: ray berry."
Comment 1 Joost de Valk (AlthA) 2006-06-24 13:36:10 PDT
I think i've seen this one before, but i can't find it. This needs reduction as the testcase is gone. Changing component.
Comment 2 Joost de Valk (AlthA) 2006-06-24 13:36:31 PDT
adding keyword as per previous comment.
Comment 3 Robert Blaut 2008-02-11 12:09:47 PST
The test page is broken. Is the bug still alive?
Comment 4 Robert Blaut 2009-01-02 01:34:38 PST
Created attachment 26364 [details]
recovered test case from www.archive.org

I've recovered the test case, but in this state sending form doesn't work.
Comment 5 Mark Hahnenberg 2011-07-22 14:21:46 PDT
I looked into this and it appears to be the fact that when calling the Page constructor, m_allowScriptsToCloseWindows is set to false, but initially in Page.h it is set to true.
Comment 6 Mark Hahnenberg 2011-07-22 14:23:27 PDT
Sorry, all of this happens in Settings.h and Settings.cpp, not Page.h.
Comment 7 Mark Hahnenberg 2011-07-22 14:29:36 PDT
Created attachment 101767 [details]
Modified test case

I changed the form action to be blank so that the form submission would still occur but wouldn't depend on any other external script.  Still seems to show the behavior described above.
Comment 8 Mark Hahnenberg 2011-07-22 15:24:34 PDT
Created attachment 101777 [details]
Patch
Comment 9 Mark Hahnenberg 2011-07-22 15:29:11 PDT
Another question we might want to ask ourselves is whether or not scripts should be allowed to call window.close() if they didn't call window.open().  Here's a brief summary of what the other major browsers do:

Firefox: disallows window.close() for scripts that didn't call window.open()
Chrome: same bug as in Safari, since they rely on WebCore
IE9: asks the user with a modal dialogue box if they want to allow the script to close the window
Opera 11.50: allows window.close()
Comment 10 Alexey Proskuryakov 2011-07-22 16:22:06 PDT
Comment on attachment 101777 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=101777&action=review

Does the proposed behavior match HTML5, Firefox and IE?

> Source/WebCore/ChangeLog:8
> +        No new tests. (OOPS!)

We'll need them.
Comment 11 Mark Hahnenberg 2011-07-22 16:40:26 PDT
> Does the proposed behavior match HTML5, Firefox and IE?
Since Firefox and IE don't match, then it's obvious that we can't match both.

As far as HTML5 goes, the following passage from http://www.w3.org/TR/html5/browsers.html#window is the most detailed that I can find about the behavior of window.close():

"The close() method on Window objects should, if the corresponding browsing context A is an auxiliary browsing context that was created by a script (as opposed to by an action of the user), and if the browsing context of the script that invokes the method is allowed to navigate the browsing context A, close the browsing context A (and may discard it too)."

This doesn't explicitly forbid closing the window if it's not an auxiliary browsing context, but it seems to suggest that we should forbid it.

This patch does the very opposite of this, so perhaps it's back to the drawing board?
Comment 12 Mark Hahnenberg 2011-07-22 16:46:04 PDT
Created attachment 101793 [details]
More general test case

Btw, this issue is not specific to form submission.  This test case uses just plain links.
Comment 13 Mark Hahnenberg 2011-07-22 20:10:39 PDT
As was pointed out to me, I shouldn't use the spec from which I quoted and should instead use something along the lines of http://www.whatwg.org/specs/web-apps/current-work/complete/.  In reference to the window.close() specification, they are identical in this instance, but I figured I'd correct myself anyways.
Comment 14 Mark Hahnenberg 2011-07-25 11:42:08 PDT
Created attachment 101888 [details]
Patch
Comment 15 WebKit Review Bot 2011-07-25 12:08:49 PDT
Comment on attachment 101888 [details]
Patch

Attachment 101888 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/9249055

New failing tests:
fast/harness/show-modal-dialog.html
inspector/console/console-long-eval-crash.html
http/tests/security/javascriptURL/xss-ALLOWED-from-javascript-url-window-open.html
fast/events/show-modal-dialog-onblur-onfocus.html
fast/frames/crash-removed-iframe.html
Comment 16 Mark Hahnenberg 2011-07-26 08:51:55 PDT
Created attachment 102014 [details]
Patch
Comment 17 Adam Barth 2011-07-26 11:02:24 PDT
Comment on attachment 102014 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=102014&action=review

> Source/WebCore/ChangeLog:17
> +        even when allowScriptsToCloseWindows was false.  This change should make us consistent
> +        with the HTML5 specification with respect to when scripts should be allowed to 
> +        call window.close().

Yay!
Comment 18 WebKit Review Bot 2011-07-26 11:54:18 PDT
Comment on attachment 102014 [details]
Patch

Attachment 102014 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/9251397

New failing tests:
fast/harness/show-modal-dialog.html
inspector/console/console-long-eval-crash.html
http/tests/security/javascriptURL/xss-ALLOWED-from-javascript-url-window-open.html
fast/events/show-modal-dialog-onblur-onfocus.html
fast/frames/crash-removed-iframe.html
Comment 19 Elliott Sprehn 2012-06-25 20:50:20 PDT
This never got landed due to failed tests? Is it worth fixing? What happened? :)
Comment 20 Darin Adler 2013-05-08 09:06:39 PDT
I’d like to see this get fixed; not sure what the status of the patch is.
Comment 21 Mark Hahnenberg 2013-05-09 10:43:30 PDT
I think the actual issue is there was a bit of code from back in the KJS/KHTML days where having a back-forward list of length > 1 would cause us to close the window, even if the window wasn't opened by a script (see http://trac.webkit.org/changeset/24028/trunk/WebCore/bindings/js/kjs_window.cpp).

Just removing this one condition makes the behavior consistent with that described in the comments above. Patch should follow shortly.
Comment 22 Mark Hahnenberg 2013-05-09 10:49:55 PDT
(In reply to comment #21)
> I think the actual issue is there was a bit of code from back in the KJS/KHTML days where having a back-forward list of length > 1 would cause us to close the window, even if the window wasn't opened by a script (see http://trac.webkit.org/changeset/24028/trunk/WebCore/bindings/js/kjs_window.cpp).

Just to be clear, the code linked to wasn't removed--it was moved to DOMWindow::close in DOMWindow.cpp in that same patch where it has survived in various forms to this day.
Comment 23 Darin Adler 2013-05-09 11:19:03 PDT
Comment on attachment 102014 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=102014&action=review

> Source/WebCore/page/DOMWindow.cpp:1821
> +        targetFrame->page()->settings()->setAllowScriptsToCloseWindows(true);

It does not seem quite right to change the settings at this level. Settings normally come from WebKit clients, and are not set by WebKit itself. Maybe there’s another way to accomplish the same thing.
Comment 24 Mark Hahnenberg 2013-05-09 11:20:57 PDT
(In reply to comment #23)
> (From update of attachment 102014 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=102014&action=review
> 
> > Source/WebCore/page/DOMWindow.cpp:1821
> > +        targetFrame->page()->settings()->setAllowScriptsToCloseWindows(true);
> 
> It does not seem quite right to change the settings at this level. Settings normally come from WebKit clients, and are not set by WebKit itself. Maybe there’s another way to accomplish the same thing.

My initial approach was incorrect. I don't think this bug has to do with the allowScriptsToCloseWindows setting.
Comment 25 Mark Hahnenberg 2013-05-09 11:35:11 PDT
> "The close() method on Window objects should, if the corresponding browsing context A is an auxiliary browsing context that was created by a script (as opposed to by an action of the user), and if the browsing context of the script that invokes the method is allowed to navigate the browsing context A, close the browsing context A (and may discard it too)."

Hmm, the spec has changed slightly to the following (according to http://www.whatwg.org/specs/web-apps/current-work/multipage/browsers.html#dom-window-close):

"The close() method on Window objects should, if the corresponding browsing context A is script-closable and the browsing context of the script that invokes the method is allowed to navigate the browsing context A, close the browsing context A.

A browsing context is script-closable if it is an auxiliary browsing context that was created by a script (as opposed to by an action of the user), or if it is a browsing context whose session history contains only one Document."

So according to the spec, our behavior is now considered correct B-)
Comment 26 Mark Hahnenberg 2013-05-13 18:24:53 PDT
Based on my comments above, I'll close this as WONTFIX.