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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/frame/DOMWindow.h ('k') | Source/core/frame/Frame.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "core/frame/DOMWindow.h" 6 #include "core/frame/DOMWindow.h"
7 7
8 #include "bindings/core/v8/ScriptCallStackFactory.h" 8 #include "bindings/core/v8/ScriptCallStackFactory.h"
9 #include "core/dom/Document.h" 9 #include "core/dom/Document.h"
10 #include "core/dom/ExceptionCode.h" 10 #include "core/dom/ExceptionCode.h"
11 #include "core/dom/SecurityContext.h" 11 #include "core/dom/SecurityContext.h"
12 #include "core/events/MessageEvent.h" 12 #include "core/events/MessageEvent.h"
13 #include "core/frame/Frame.h" 13 #include "core/frame/Frame.h"
14 #include "core/frame/FrameClient.h" 14 #include "core/frame/FrameClient.h"
15 #include "core/frame/FrameConsole.h"
15 #include "core/frame/LocalDOMWindow.h" 16 #include "core/frame/LocalDOMWindow.h"
16 #include "core/frame/Location.h" 17 #include "core/frame/Location.h"
18 #include "core/frame/Settings.h"
17 #include "core/frame/UseCounter.h" 19 #include "core/frame/UseCounter.h"
20 #include "core/inspector/ConsoleMessageStorage.h"
18 #include "core/inspector/InspectorInstrumentation.h" 21 #include "core/inspector/InspectorInstrumentation.h"
19 #include "core/inspector/ScriptCallStack.h" 22 #include "core/inspector/ScriptCallStack.h"
23 #include "core/loader/FrameLoaderClient.h"
20 #include "core/loader/MixedContentChecker.h" 24 #include "core/loader/MixedContentChecker.h"
25 #include "core/page/ChromeClient.h"
26 #include "core/page/Page.h"
21 #include "platform/weborigin/KURL.h" 27 #include "platform/weborigin/KURL.h"
22 #include "platform/weborigin/SecurityOrigin.h" 28 #include "platform/weborigin/SecurityOrigin.h"
23 29
24 namespace blink { 30 namespace blink {
25 31
26 DOMWindow::DOMWindow() 32 DOMWindow::DOMWindow()
27 : m_windowIsClosing(false) 33 : m_windowIsClosing(false)
28 { 34 {
29 } 35 }
30 36
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 return message + "The frame requesting access set \"document.domain\" to \"" + activeOrigin->domain() + "\", the frame being accessed set it to \"" + ta rgetOrigin->domain() + "\". Both must set \"document.domain\" to the same value to allow access."; 277 return message + "The frame requesting access set \"document.domain\" to \"" + activeOrigin->domain() + "\", the frame being accessed set it to \"" + ta rgetOrigin->domain() + "\". Both must set \"document.domain\" to the same value to allow access.";
272 if (activeOrigin->domainWasSetInDOM()) 278 if (activeOrigin->domainWasSetInDOM())
273 return message + "The frame requesting access set \"document.domain\" to \"" + activeOrigin->domain() + "\", but the frame being accessed did not. Both must set \"document.domain\" to the same value to allow access."; 279 return message + "The frame requesting access set \"document.domain\" to \"" + activeOrigin->domain() + "\", but the frame being accessed did not. Both must set \"document.domain\" to the same value to allow access.";
274 if (targetOrigin->domainWasSetInDOM()) 280 if (targetOrigin->domainWasSetInDOM())
275 return message + "The frame being accessed set \"document.domain\" to \" " + targetOrigin->domain() + "\", but the frame requesting access did not. Both must set \"document.domain\" to the same value to allow access."; 281 return message + "The frame being accessed set \"document.domain\" to \" " + targetOrigin->domain() + "\", but the frame requesting access did not. Both must set \"document.domain\" to the same value to allow access.";
276 282
277 // Default. 283 // Default.
278 return message + "Protocols, domains, and ports must match."; 284 return message + "Protocols, domains, and ports must match.";
279 } 285 }
280 286
287 void DOMWindow::close(ExecutionContext* context)
288 {
289 if (!frame() || !frame()->isMainFrame())
290 return;
291
292 Page* page = frame()->page();
293 if (!page)
294 return;
295
296 Document* activeDocument = nullptr;
297 if (context) {
298 ASSERT(isMainThread());
299 activeDocument = toDocument(context);
300 if (!activeDocument)
301 return;
302
303 if (!activeDocument->frame() || !activeDocument->frame()->canNavigate(*f rame()))
304 return;
305 }
306
307 Settings* settings = frame()->settings();
308 bool allowScriptsToCloseWindows = settings && settings->allowScriptsToCloseW indows();
309
310 if (!page->openedByDOM() && frame()->client()->backForwardLength() > 1 && !a llowScriptsToCloseWindows) {
311 if (activeDocument) {
312 activeDocument->domWindow()->frameConsole()->addMessage(ConsoleMessa ge::create(JSMessageSource, WarningMessageLevel, "Scripts may close only the win dows that were opened by it."));
313 }
314 return;
315 }
316
317 if (!frame()->shouldClose())
318 return;
319
320 InspectorInstrumentation::willCloseWindow(context);
321
322 page->chromeClient().closeWindowSoon();
323
324 // So as to make window.closed return the expected result
325 // after window.close(), separately record the to-be-closed
326 // state of this window. Scripts may access window.closed
327 // before the deferred close operation has gone ahead.
328 m_windowIsClosing = true;
329 }
330
281 DEFINE_TRACE(DOMWindow) 331 DEFINE_TRACE(DOMWindow)
282 { 332 {
283 visitor->trace(m_location); 333 visitor->trace(m_location);
284 EventTargetWithInlineData::trace(visitor); 334 EventTargetWithInlineData::trace(visitor);
285 } 335 }
286 336
287 } // namespace blink 337 } // namespace blink
OLDNEW
« 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