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

Side by Side Diff: third_party/WebKit/Source/core/frame/DOMWindow.cpp

Issue 2668753006: Special-case LocalDOMWindow for same-origin access in bindings. (Closed)
Patch Set: . Created 3 years, 10 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
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 "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
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() const {
116 DEFINE_STATIC_LOCAL(Persistent<External>, external, (new External));
117 return external;
118 }
119
120 DOMWindow* DOMWindow::anonymousIndexedGetter(uint32_t index) const { 109 DOMWindow* DOMWindow::anonymousIndexedGetter(uint32_t index) const {
121 if (!frame()) 110 if (!frame())
122 return nullptr; 111 return nullptr;
123 112
124 Frame* child = frame()->tree().scopedChild(index); 113 Frame* child = frame()->tree().scopedChild(index);
125 return child ? child->domWindow() : nullptr; 114 return child ? child->domWindow() : nullptr;
126 } 115 }
127 116
128 bool DOMWindow::isCurrentlyDisplayedInFrame() const { 117 bool DOMWindow::isCurrentlyDisplayedInFrame() const {
129 if (frame()) 118 if (frame())
(...skipping 29 matching lines...) Expand all
159 148
160 void DOMWindow::resetLocation() { 149 void DOMWindow::resetLocation() {
161 // 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
162 // Frame pointer. 151 // Frame pointer.
163 if (m_location) { 152 if (m_location) {
164 m_location->reset(); 153 m_location->reset();
165 m_location = nullptr; 154 m_location = nullptr;
166 } 155 }
167 } 156 }
168 157
169 bool DOMWindow::isSecureContext() const {
170 if (!frame())
171 return false;
172
173 return document()->isSecureContext(
174 ExecutionContext::StandardSecureContextCheck);
175 }
176
177 void DOMWindow::postMessage(PassRefPtr<SerializedScriptValue> message, 158 void DOMWindow::postMessage(PassRefPtr<SerializedScriptValue> message,
178 const MessagePortArray& ports, 159 const MessagePortArray& ports,
179 const String& targetOrigin, 160 const String& targetOrigin,
180 LocalDOMWindow* source, 161 LocalDOMWindow* source,
181 ExceptionState& exceptionState) { 162 ExceptionState& exceptionState) {
182 if (!isCurrentlyDisplayedInFrame()) 163 if (!isCurrentlyDisplayedInFrame())
183 return; 164 return;
184 165
185 Document* sourceDocument = source->document(); 166 Document* sourceDocument = source->document();
186 167
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 String sourceOrigin = 203 String sourceOrigin =
223 (hasSuborigin && 204 (hasSuborigin &&
224 securityOrigin->suborigin()->policyContains(unsafeSendOpt)) 205 securityOrigin->suborigin()->policyContains(unsafeSendOpt))
225 ? securityOrigin->toPhysicalOriginString() 206 ? securityOrigin->toPhysicalOriginString()
226 : securityOrigin->toString(); 207 : securityOrigin->toString();
227 String sourceSuborigin = 208 String sourceSuborigin =
228 hasSuborigin ? securityOrigin->suborigin()->name() : String(); 209 hasSuborigin ? securityOrigin->suborigin()->name() : String();
229 210
230 KURL targetUrl = 211 KURL targetUrl =
231 isLocalDOMWindow() 212 isLocalDOMWindow()
232 ? document()->url() 213 ? blink::toLocalDOMWindow(this)->document()->url()
dcheng 2017/02/01 07:22:59 I did this to explicitly call the non-method versi
233 : KURL(KURL(), 214 : KURL(KURL(),
234 frame()->securityContext()->getSecurityOrigin()->toString()); 215 frame()->securityContext()->getSecurityOrigin()->toString());
235 if (MixedContentChecker::isMixedContent(sourceDocument->getSecurityOrigin(), 216 if (MixedContentChecker::isMixedContent(sourceDocument->getSecurityOrigin(),
236 targetUrl)) { 217 targetUrl)) {
237 UseCounter::count(frame(), UseCounter::PostMessageFromSecureToInsecure); 218 UseCounter::count(frame(), UseCounter::PostMessageFromSecureToInsecure);
238 } else if (MixedContentChecker::isMixedContent( 219 } else if (MixedContentChecker::isMixedContent(
239 frame()->securityContext()->getSecurityOrigin(), 220 frame()->securityContext()->getSecurityOrigin(),
240 sourceDocument->url())) { 221 sourceDocument->url())) {
241 UseCounter::count(frame(), UseCounter::PostMessageFromInsecureToSecure); 222 UseCounter::count(frame(), UseCounter::PostMessageFromInsecureToSecure);
242 if (MixedContentChecker::isMixedContent( 223 if (MixedContentChecker::isMixedContent(
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 "\" from accessing a frame with origin \"" + 286 "\" from accessing a frame with origin \"" +
306 targetOrigin->toString() + "\". "; 287 targetOrigin->toString() + "\". ";
307 288
308 // 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
309 // 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").
310 KURL activeURL = callingWindow->document()->url(); 291 KURL activeURL = callingWindow->document()->url();
311 // TODO(alexmos): RemoteFrames do not have a document, and their URLs 292 // TODO(alexmos): RemoteFrames do not have a document, and their URLs
312 // aren't replicated. For now, construct the URL using the replicated 293 // aren't replicated. For now, construct the URL using the replicated
313 // origin for RemoteFrames. If the target frame is remote and sandboxed, 294 // origin for RemoteFrames. If the target frame is remote and sandboxed,
314 // 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.
315 KURL targetURL = isLocalDOMWindow() ? document()->url() 296 KURL targetURL = isLocalDOMWindow()
316 : KURL(KURL(), targetOrigin->toString()); 297 ? blink::toLocalDOMWindow(this)->document()->url()
298 : KURL(KURL(), targetOrigin->toString());
317 if (frame()->securityContext()->isSandboxed(SandboxOrigin) || 299 if (frame()->securityContext()->isSandboxed(SandboxOrigin) ||
318 callingWindow->document()->isSandboxed(SandboxOrigin)) { 300 callingWindow->document()->isSandboxed(SandboxOrigin)) {
319 message = "Blocked a frame at \"" + 301 message = "Blocked a frame at \"" +
320 SecurityOrigin::create(activeURL)->toString() + 302 SecurityOrigin::create(activeURL)->toString() +
321 "\" from accessing a frame at \"" + 303 "\" from accessing a frame at \"" +
322 SecurityOrigin::create(targetURL)->toString() + "\". "; 304 SecurityOrigin::create(targetURL)->toString() + "\". ";
323 if (frame()->securityContext()->isSandboxed(SandboxOrigin) && 305 if (frame()->securityContext()->isSandboxed(SandboxOrigin) &&
324 callingWindow->document()->isSandboxed(SandboxOrigin)) 306 callingWindow->document()->isSandboxed(SandboxOrigin))
325 return "Sandbox access violation: " + message + 307 return "Sandbox access violation: " + message +
326 " Both frames are sandboxed and lack the \"allow-same-origin\" " 308 " Both frames are sandboxed and lack the \"allow-same-origin\" "
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 page->focusController().focusDocumentView(frame(), true /* notifyEmbedder */); 425 page->focusController().focusDocumentView(frame(), true /* notifyEmbedder */);
444 } 426 }
445 427
446 DEFINE_TRACE(DOMWindow) { 428 DEFINE_TRACE(DOMWindow) {
447 visitor->trace(m_frame); 429 visitor->trace(m_frame);
448 visitor->trace(m_location); 430 visitor->trace(m_location);
449 EventTargetWithInlineData::trace(visitor); 431 EventTargetWithInlineData::trace(visitor);
450 } 432 }
451 433
452 } // namespace blink 434 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698