Calling window.close() should indicate failure with warning message
Calling window.close() should indicate failure with warning message

Calling window.close() has no effect on the main page as the calling script has not created the window.
In such case, a warning message should be added to the console stating the failure to honor window.close().

Firefox is showing the message "Scripts may not close windows that were not opened by script."
The same has been documented here https://developer.mozilla.org/en-US/docs/DOM/window.close

Also there is a bug in the DOMWindow::close() which closes the newly opened tab if window.close() is executed
from the console of inspector. This is incorrect as the scripts are not allowed to close the window which is not
created by it. Also if this is the only tab open, then the browser is also closed.

The existing condition checks whether the page is opened by DOM or the page has more than 1 backward/forward history 
items or the browser doesn't allow the script to close the window.
With a new tab opened and the window.close() being called from the inspector console, the second condition i.e. 
having only 1 item in backward/forward history evaluates to true. Its negated and hence the browser
honors the closing of window.

Instead, the if condition should first check whether the closing of window is allowed for the given script. Then it should 
check the rest of the conditions. This way closing of browser/tab is avoided.

BUG=170760

R=abarth, pfeldman, yurys

Review URL: https://codereview.chromium.org/22929032

git-svn-id: bf5cd6ccde378db821296732a091cfbcf5285fbd@160700 bbb929c8-8fbe-4397-9dbb-9b2b20218538

ondra-novak/blink,kurli/blink-crosswalk,modulexcite/blink,jtg-gg/blink,nwjs/blink,Pluto-tv/blink-crosswalk,Bysmyyr/blink-crosswalk,hgl888/blink-crosswalk-efl,nwjs/blink,jtg-gg/blink,crosswalk-project/blink-crosswalk-efl,XiaosongWei/blink-crosswalk,smishenk/blink-crosswalk,kurli/blink-crosswalk,jtg-gg/blink,crosswalk-project/blink-crosswalk-efl,ondra-novak/blink,Pluto-tv/blink-crosswalk,crosswalk-project/blink-crosswalk-efl,nwjs/blink,hgl888/blink-crosswalk-efl,nwjs/blink,XiaosongWei/blink-crosswalk,Bysmyyr/blink-crosswalk,Pluto-tv/blink-crosswalk,smishenk/blink-crosswalk,PeterWangIntel/blink-crosswalk,smishenk/blink-crosswalk,Pluto-tv/blink-crosswalk,smishenk/blink-crosswalk,crosswalk-project/blink-crosswalk-efl,ondra-novak/blink,XiaosongWei/blink-crosswalk,ondra-novak/blink,crosswalk-project/blink-crosswalk-efl,kurli/blink-crosswalk,Pluto-tv/blink-crosswalk,PeterWangIntel/blink-crosswalk,kurli/blink-crosswalk,hgl888/blink-crosswalk-efl,crosswalk-project/blink-crosswalk-efl,Bysmyyr/blink-crosswalk,modulexcite/blink,smishenk/blink-crosswalk,PeterWangIntel/blink-crosswalk,PeterWangIntel/blink-crosswalk,modulexcite/blink,PeterWangIntel/blink-crosswalk,hgl888/blink-crosswalk-efl,Pluto-tv/blink-crosswalk,ondra-novak/blink,Pluto-tv/blink-crosswalk,ondra-novak/blink,nwjs/blink,XiaosongWei/blink-crosswalk,PeterWangIntel/blink-crosswalk,PeterWangIntel/blink-crosswalk,modulexcite/blink,nwjs/blink,hgl888/blink-crosswalk-efl,nwjs/blink,kurli/blink-crosswalk,Bysmyyr/blink-crosswalk,hgl888/blink-crosswalk-efl,XiaosongWei/blink-crosswalk,jtg-gg/blink,XiaosongWei/blink-crosswalk,jtg-gg/blink,Bysmyyr/blink-crosswalk,PeterWangIntel/blink-crosswalk,ondra-novak/blink,modulexcite/blink,jtg-gg/blink,modulexcite/blink,hgl888/blink-crosswalk-efl,XiaosongWei/blink-crosswalk,kurli/blink-crosswalk,Bysmyyr/blink-crosswalk,hgl888/blink-crosswalk-efl,crosswalk-project/blink-crosswalk-efl,Pluto-tv/blink-crosswalk,smishenk/blink-crosswalk,nwjs/blink,modulexcite/blink,PeterWangIntel/blink-crosswalk,kurli/blink-crosswalk,jtg-gg/blink,jtg-gg/blink,modulexcite/blink,crosswalk-project/blink-crosswalk-efl,nwjs/blink,kurli/blink-crosswalk,Bysmyyr/blink-crosswalk,crosswalk-project/blink-crosswalk-efl,ondra-novak/blink,PeterWangIntel/blink-crosswalk,hgl888/blink-crosswalk-efl,XiaosongWei/blink-crosswalk,Pluto-tv/blink-crosswalk,modulexcite/blink,kurli/blink-crosswalk,kurli/blink-crosswalk,smishenk/blink-crosswalk,smishenk/blink-crosswalk,jtg-gg/blink,jtg-gg/blink,Bysmyyr/blink-crosswalk,modulexcite/blink,hgl888/blink-crosswalk-efl,smishenk/blink-crosswalk,Bysmyyr/blink-crosswalk,Bysmyyr/blink-crosswalk,ondra-novak/blink,XiaosongWei/blink-crosswalk,XiaosongWei/blink-crosswalk,nwjs/blink,Pluto-tv/blink-crosswalk,smishenk/blink-crosswalk