Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 // FIXME: The session history length should be implemented for RemoteFrame a nd | |
|
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.
| |
| 311 // this check should be made unconditionally. | |
| 312 bool hasNavigated = true; | |
| 313 if (frame()->isLocalFrame()) | |
| 314 hasNavigated = toLocalFrame(frame())->loader().client()->backForwardLeng th() > 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.
| |
| 315 | |
| 316 if (!page->openedByDOM() && hasNavigated && !allowScriptsToCloseWindows) { | |
| 317 if (activeDocument) { | |
| 318 activeDocument->domWindow()->frameConsole()->addMessage(ConsoleMessa ge::create(JSMessageSource, WarningMessageLevel, "Scripts may close only the win dows that were opened by it.")); | |
| 319 } | |
| 320 return; | |
| 321 } | |
| 322 | |
| 323 // FIXME: The shouldClose functionality should be implemented for RemoteFram e | |
|
dcheng
2015/06/16 20:08:23
TODO(username) is the style now. Ditto on linking
nasko
2015/06/16 22:58:54
Done.
| |
| 324 // and the check should be made unconditionally. | |
| 325 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.
| |
| 326 return; | |
| 327 | |
| 328 InspectorInstrumentation::willCloseWindow(context); | |
| 329 | |
| 330 page->chromeClient().closeWindowSoon(); | |
| 331 | |
| 332 // So as to make window.closed return the expected result | |
| 333 // after window.close(), separately record the to-be-closed | |
| 334 // state of this window. Scripts may access window.closed | |
| 335 // before the deferred close operation has gone ahead. | |
| 336 m_windowIsClosing = true; | |
| 337 } | |
| 338 | |
| 281 DEFINE_TRACE(DOMWindow) | 339 DEFINE_TRACE(DOMWindow) |
| 282 { | 340 { |
| 283 visitor->trace(m_location); | 341 visitor->trace(m_location); |
| 284 EventTargetWithInlineData::trace(visitor); | 342 EventTargetWithInlineData::trace(visitor); |
| 285 } | 343 } |
| 286 | 344 |
| 287 } // namespace blink | 345 } // namespace blink |
| OLD | NEW |