| Index: Source/core/frame/DOMWindow.cpp | 
| diff --git a/Source/core/frame/DOMWindow.cpp b/Source/core/frame/DOMWindow.cpp | 
| index ee9a4a4773ae5fcf5ea58c659767e6c503d1814a..713fb660ef29868dd7c46689b3a0527bde006a96 100644 | 
| --- a/Source/core/frame/DOMWindow.cpp | 
| +++ b/Source/core/frame/DOMWindow.cpp | 
| @@ -12,12 +12,18 @@ | 
| #include "core/events/MessageEvent.h" | 
| #include "core/frame/Frame.h" | 
| #include "core/frame/FrameClient.h" | 
| +#include "core/frame/FrameConsole.h" | 
| #include "core/frame/LocalDOMWindow.h" | 
| #include "core/frame/Location.h" | 
| +#include "core/frame/Settings.h" | 
| #include "core/frame/UseCounter.h" | 
| +#include "core/inspector/ConsoleMessageStorage.h" | 
| #include "core/inspector/InspectorInstrumentation.h" | 
| #include "core/inspector/ScriptCallStack.h" | 
| +#include "core/loader/FrameLoaderClient.h" | 
| #include "core/loader/MixedContentChecker.h" | 
| +#include "core/page/ChromeClient.h" | 
| +#include "core/page/Page.h" | 
| #include "platform/weborigin/KURL.h" | 
| #include "platform/weborigin/SecurityOrigin.h" | 
|  | 
| @@ -278,6 +284,50 @@ String DOMWindow::crossDomainAccessErrorMessage(LocalDOMWindow* callingWindow) | 
| return message + "Protocols, domains, and ports must match."; | 
| } | 
|  | 
| +void DOMWindow::close(ExecutionContext* context) | 
| +{ | 
| +    if (!frame() || !frame()->isMainFrame()) | 
| +        return; | 
| + | 
| +    Page* page = frame()->page(); | 
| +    if (!page) | 
| +        return; | 
| + | 
| +    Document* activeDocument = nullptr; | 
| +    if (context) { | 
| +        ASSERT(isMainThread()); | 
| +        activeDocument = toDocument(context); | 
| +        if (!activeDocument) | 
| +            return; | 
| + | 
| +        if (!activeDocument->frame() || !activeDocument->frame()->canNavigate(*frame())) | 
| +            return; | 
| +    } | 
| + | 
| +    Settings* settings = frame()->settings(); | 
| +    bool allowScriptsToCloseWindows = settings && settings->allowScriptsToCloseWindows(); | 
| + | 
| +    if (!page->openedByDOM() && frame()->client()->backForwardLength() > 1 && !allowScriptsToCloseWindows) { | 
| +        if (activeDocument) { | 
| +            activeDocument->domWindow()->frameConsole()->addMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel, "Scripts may close only the windows that were opened by it.")); | 
| +        } | 
| +        return; | 
| +    } | 
| + | 
| +    if (!frame()->shouldClose()) | 
| +        return; | 
| + | 
| +    InspectorInstrumentation::willCloseWindow(context); | 
| + | 
| +    page->chromeClient().closeWindowSoon(); | 
| + | 
| +    // So as to make window.closed return the expected result | 
| +    // after window.close(), separately record the to-be-closed | 
| +    // state of this window. Scripts may access window.closed | 
| +    // before the deferred close operation has gone ahead. | 
| +    m_windowIsClosing = true; | 
| +} | 
| + | 
| DEFINE_TRACE(DOMWindow) | 
| { | 
| visitor->trace(m_location); | 
|  |