Chromium Code Reviews| Index: Source/core/frame/DOMWindow.cpp |
| diff --git a/Source/core/frame/DOMWindow.cpp b/Source/core/frame/DOMWindow.cpp |
| index e37b3401677ba447e87e551ccb4595e5e5ddb34b..3b3a9430e4629f918babb56abce0ac766b32ffd8 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,58 @@ 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(); |
| + |
| + // FIXME: The session history length should be implemented for RemoteFrame and |
|
dcheng
2015/06/16 20:08:23
TODO(japhet) for this one? (if you're OK with this
nasko
2015/06/16 22:58:54
Done.
|
| + // this check should be made unconditionally. |
| + bool hasNavigated = true; |
| + if (frame()->isLocalFrame()) |
| + hasNavigated = toLocalFrame(frame())->loader().client()->backForwardLength() > 1; |
|
dcheng
2015/06/16 20:08:23
Maybe let's move this to FrameClient and leave the
nasko
2015/06/16 22:58:54
Done.
|
| + |
| + if (!page->openedByDOM() && hasNavigated && !allowScriptsToCloseWindows) { |
| + if (activeDocument) { |
| + activeDocument->domWindow()->frameConsole()->addMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel, "Scripts may close only the windows that were opened by it.")); |
| + } |
| + return; |
| + } |
| + |
| + // FIXME: The shouldClose functionality should be implemented for RemoteFrame |
|
dcheng
2015/06/16 20:08:23
TODO(username) is the style now. Ditto on linking
nasko
2015/06/16 22:58:54
Done.
|
| + // and the check should be made unconditionally. |
| + if (frame()->isLocalFrame() && !toLocalFrame(frame())->loader().shouldClose()) |
|
dcheng
2015/06/16 20:08:23
Same idea: maybe make this a virtual on Frame and
nasko
2015/06/16 22:58:54
Done.
|
| + 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); |