Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(987)

Unified Diff: Source/core/frame/DOMWindow.cpp

Issue 1176843006: Move window.close implementation to DOMWindow (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Remove resetting of the main view. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/frame/DOMWindow.h ('k') | Source/core/frame/Frame.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « Source/core/frame/DOMWindow.h ('k') | Source/core/frame/Frame.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698