| 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 "core/frame/DOMWindow.h" | 5 #include "core/frame/DOMWindow.h" |
| 6 | 6 |
| 7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
| 8 #include "core/dom/ExceptionCode.h" | |
| 9 #include "core/dom/ExecutionContext.h" | 8 #include "core/dom/ExecutionContext.h" |
| 10 #include "core/dom/SecurityContext.h" | 9 #include "core/dom/SecurityContext.h" |
| 11 #include "core/events/MessageEvent.h" | 10 #include "core/events/MessageEvent.h" |
| 12 #include "core/frame/External.h" | |
| 13 #include "core/frame/Frame.h" | 11 #include "core/frame/Frame.h" |
| 14 #include "core/frame/FrameClient.h" | 12 #include "core/frame/FrameClient.h" |
| 15 #include "core/frame/FrameConsole.h" | 13 #include "core/frame/FrameConsole.h" |
| 16 #include "core/frame/LocalDOMWindow.h" | 14 #include "core/frame/LocalDOMWindow.h" |
| 17 #include "core/frame/Location.h" | 15 #include "core/frame/Location.h" |
| 18 #include "core/frame/RemoteDOMWindow.h" | |
| 19 #include "core/frame/RemoteFrame.h" | |
| 20 #include "core/frame/Settings.h" | 16 #include "core/frame/Settings.h" |
| 21 #include "core/frame/UseCounter.h" | 17 #include "core/frame/UseCounter.h" |
| 22 #include "core/input/EventHandler.h" | |
| 23 #include "core/inspector/ConsoleMessage.h" | 18 #include "core/inspector/ConsoleMessage.h" |
| 24 #include "core/inspector/InspectorInstrumentation.h" | 19 #include "core/inspector/InspectorInstrumentation.h" |
| 25 #include "core/loader/FrameLoaderClient.h" | |
| 26 #include "core/loader/MixedContentChecker.h" | 20 #include "core/loader/MixedContentChecker.h" |
| 27 #include "core/page/ChromeClient.h" | 21 #include "core/page/ChromeClient.h" |
| 28 #include "core/page/FocusController.h" | 22 #include "core/page/FocusController.h" |
| 29 #include "core/page/Page.h" | 23 #include "core/page/Page.h" |
| 30 #include "platform/weborigin/KURL.h" | 24 #include "platform/weborigin/KURL.h" |
| 31 #include "platform/weborigin/SecurityOrigin.h" | 25 #include "platform/weborigin/SecurityOrigin.h" |
| 32 #include "platform/weborigin/Suborigin.h" | 26 #include "platform/weborigin/Suborigin.h" |
| 33 #include <memory> | 27 #include <memory> |
| 34 | 28 |
| 35 namespace blink { | 29 namespace blink { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 return parent ? parent->domWindow() : frame()->domWindow(); | 99 return parent ? parent->domWindow() : frame()->domWindow(); |
| 106 } | 100 } |
| 107 | 101 |
| 108 DOMWindow* DOMWindow::top() const { | 102 DOMWindow* DOMWindow::top() const { |
| 109 if (!frame()) | 103 if (!frame()) |
| 110 return nullptr; | 104 return nullptr; |
| 111 | 105 |
| 112 return frame()->tree().top()->domWindow(); | 106 return frame()->tree().top()->domWindow(); |
| 113 } | 107 } |
| 114 | 108 |
| 115 External* DOMWindow::external() { | |
| 116 if (!m_external) | |
| 117 m_external = new External; | |
| 118 return m_external; | |
| 119 } | |
| 120 | |
| 121 DOMWindow* DOMWindow::anonymousIndexedGetter(uint32_t index) const { | 109 DOMWindow* DOMWindow::anonymousIndexedGetter(uint32_t index) const { |
| 122 if (!frame()) | 110 if (!frame()) |
| 123 return nullptr; | 111 return nullptr; |
| 124 | 112 |
| 125 Frame* child = frame()->tree().scopedChild(index); | 113 Frame* child = frame()->tree().scopedChild(index); |
| 126 return child ? child->domWindow() : nullptr; | 114 return child ? child->domWindow() : nullptr; |
| 127 } | 115 } |
| 128 | 116 |
| 129 bool DOMWindow::isCurrentlyDisplayedInFrame() const { | 117 bool DOMWindow::isCurrentlyDisplayedInFrame() const { |
| 130 if (frame()) | 118 if (frame()) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 160 | 148 |
| 161 void DOMWindow::resetLocation() { | 149 void DOMWindow::resetLocation() { |
| 162 // Location needs to be reset manually so that it doesn't retain a stale | 150 // Location needs to be reset manually so that it doesn't retain a stale |
| 163 // Frame pointer. | 151 // Frame pointer. |
| 164 if (m_location) { | 152 if (m_location) { |
| 165 m_location->reset(); | 153 m_location->reset(); |
| 166 m_location = nullptr; | 154 m_location = nullptr; |
| 167 } | 155 } |
| 168 } | 156 } |
| 169 | 157 |
| 170 bool DOMWindow::isSecureContext() const { | |
| 171 if (!frame()) | |
| 172 return false; | |
| 173 | |
| 174 return document()->isSecureContext( | |
| 175 ExecutionContext::StandardSecureContextCheck); | |
| 176 } | |
| 177 | |
| 178 void DOMWindow::postMessage(PassRefPtr<SerializedScriptValue> message, | 158 void DOMWindow::postMessage(PassRefPtr<SerializedScriptValue> message, |
| 179 const MessagePortArray& ports, | 159 const MessagePortArray& ports, |
| 180 const String& targetOrigin, | 160 const String& targetOrigin, |
| 181 LocalDOMWindow* source, | 161 LocalDOMWindow* source, |
| 182 ExceptionState& exceptionState) { | 162 ExceptionState& exceptionState) { |
| 183 if (!isCurrentlyDisplayedInFrame()) | 163 if (!isCurrentlyDisplayedInFrame()) |
| 184 return; | 164 return; |
| 185 | 165 |
| 186 Document* sourceDocument = source->document(); | 166 Document* sourceDocument = source->document(); |
| 187 | 167 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 String sourceOrigin = | 203 String sourceOrigin = |
| 224 (hasSuborigin && | 204 (hasSuborigin && |
| 225 securityOrigin->suborigin()->policyContains(unsafeSendOpt)) | 205 securityOrigin->suborigin()->policyContains(unsafeSendOpt)) |
| 226 ? securityOrigin->toPhysicalOriginString() | 206 ? securityOrigin->toPhysicalOriginString() |
| 227 : securityOrigin->toString(); | 207 : securityOrigin->toString(); |
| 228 String sourceSuborigin = | 208 String sourceSuborigin = |
| 229 hasSuborigin ? securityOrigin->suborigin()->name() : String(); | 209 hasSuborigin ? securityOrigin->suborigin()->name() : String(); |
| 230 | 210 |
| 231 KURL targetUrl = | 211 KURL targetUrl = |
| 232 isLocalDOMWindow() | 212 isLocalDOMWindow() |
| 233 ? document()->url() | 213 ? blink::toLocalDOMWindow(this)->document()->url() |
| 234 : KURL(KURL(), | 214 : KURL(KURL(), |
| 235 frame()->securityContext()->getSecurityOrigin()->toString()); | 215 frame()->securityContext()->getSecurityOrigin()->toString()); |
| 236 if (MixedContentChecker::isMixedContent(sourceDocument->getSecurityOrigin(), | 216 if (MixedContentChecker::isMixedContent(sourceDocument->getSecurityOrigin(), |
| 237 targetUrl)) { | 217 targetUrl)) { |
| 238 UseCounter::count(frame(), UseCounter::PostMessageFromSecureToInsecure); | 218 UseCounter::count(frame(), UseCounter::PostMessageFromSecureToInsecure); |
| 239 } else if (MixedContentChecker::isMixedContent( | 219 } else if (MixedContentChecker::isMixedContent( |
| 240 frame()->securityContext()->getSecurityOrigin(), | 220 frame()->securityContext()->getSecurityOrigin(), |
| 241 sourceDocument->url())) { | 221 sourceDocument->url())) { |
| 242 UseCounter::count(frame(), UseCounter::PostMessageFromInsecureToSecure); | 222 UseCounter::count(frame(), UseCounter::PostMessageFromInsecureToSecure); |
| 243 if (MixedContentChecker::isMixedContent( | 223 if (MixedContentChecker::isMixedContent( |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 "\" from accessing a frame with origin \"" + | 286 "\" from accessing a frame with origin \"" + |
| 307 targetOrigin->toString() + "\". "; | 287 targetOrigin->toString() + "\". "; |
| 308 | 288 |
| 309 // Sandbox errors: Use the origin of the frames' location, rather than their | 289 // Sandbox errors: Use the origin of the frames' location, rather than their |
| 310 // actual origin (since we know that at least one will be "null"). | 290 // actual origin (since we know that at least one will be "null"). |
| 311 KURL activeURL = callingWindow->document()->url(); | 291 KURL activeURL = callingWindow->document()->url(); |
| 312 // TODO(alexmos): RemoteFrames do not have a document, and their URLs | 292 // TODO(alexmos): RemoteFrames do not have a document, and their URLs |
| 313 // aren't replicated. For now, construct the URL using the replicated | 293 // aren't replicated. For now, construct the URL using the replicated |
| 314 // origin for RemoteFrames. If the target frame is remote and sandboxed, | 294 // origin for RemoteFrames. If the target frame is remote and sandboxed, |
| 315 // there isn't anything else to show other than "null" for its origin. | 295 // there isn't anything else to show other than "null" for its origin. |
| 316 KURL targetURL = isLocalDOMWindow() ? document()->url() | 296 KURL targetURL = isLocalDOMWindow() |
| 317 : KURL(KURL(), targetOrigin->toString()); | 297 ? blink::toLocalDOMWindow(this)->document()->url() |
| 298 : KURL(KURL(), targetOrigin->toString()); |
| 318 if (frame()->securityContext()->isSandboxed(SandboxOrigin) || | 299 if (frame()->securityContext()->isSandboxed(SandboxOrigin) || |
| 319 callingWindow->document()->isSandboxed(SandboxOrigin)) { | 300 callingWindow->document()->isSandboxed(SandboxOrigin)) { |
| 320 message = "Blocked a frame at \"" + | 301 message = "Blocked a frame at \"" + |
| 321 SecurityOrigin::create(activeURL)->toString() + | 302 SecurityOrigin::create(activeURL)->toString() + |
| 322 "\" from accessing a frame at \"" + | 303 "\" from accessing a frame at \"" + |
| 323 SecurityOrigin::create(targetURL)->toString() + "\". "; | 304 SecurityOrigin::create(targetURL)->toString() + "\". "; |
| 324 if (frame()->securityContext()->isSandboxed(SandboxOrigin) && | 305 if (frame()->securityContext()->isSandboxed(SandboxOrigin) && |
| 325 callingWindow->document()->isSandboxed(SandboxOrigin)) | 306 callingWindow->document()->isSandboxed(SandboxOrigin)) |
| 326 return "Sandbox access violation: " + message + | 307 return "Sandbox access violation: " + message + |
| 327 " Both frames are sandboxed and lack the \"allow-same-origin\" " | 308 " Both frames are sandboxed and lack the \"allow-same-origin\" " |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 // If we're a top level window, bring the window to the front. | 421 // If we're a top level window, bring the window to the front. |
| 441 if (frame()->isMainFrame() && allowFocus) | 422 if (frame()->isMainFrame() && allowFocus) |
| 442 page->chromeClient().focus(); | 423 page->chromeClient().focus(); |
| 443 | 424 |
| 444 page->focusController().focusDocumentView(frame(), true /* notifyEmbedder */); | 425 page->focusController().focusDocumentView(frame(), true /* notifyEmbedder */); |
| 445 } | 426 } |
| 446 | 427 |
| 447 DEFINE_TRACE(DOMWindow) { | 428 DEFINE_TRACE(DOMWindow) { |
| 448 visitor->trace(m_frame); | 429 visitor->trace(m_frame); |
| 449 visitor->trace(m_location); | 430 visitor->trace(m_location); |
| 450 visitor->trace(m_external); | |
| 451 EventTargetWithInlineData::trace(visitor); | 431 EventTargetWithInlineData::trace(visitor); |
| 452 } | 432 } |
| 453 | 433 |
| 454 } // namespace blink | 434 } // namespace blink |
| OLD | NEW |