OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 23 matching lines...) Expand all Loading... | |
34 #include "bindings/core/v8/V8Binding.h" | 34 #include "bindings/core/v8/V8Binding.h" |
35 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
36 #include "core/frame/LocalDOMWindow.h" | 36 #include "core/frame/LocalDOMWindow.h" |
37 #include "core/frame/LocalFrame.h" | 37 #include "core/frame/LocalFrame.h" |
38 #include "core/frame/Settings.h" | 38 #include "core/frame/Settings.h" |
39 #include "core/html/HTMLFrameElementBase.h" | 39 #include "core/html/HTMLFrameElementBase.h" |
40 #include "platform/weborigin/SecurityOrigin.h" | 40 #include "platform/weborigin/SecurityOrigin.h" |
41 | 41 |
42 namespace blink { | 42 namespace blink { |
43 | 43 |
44 static bool isDocumentAccessibleFromDOMWindow(Document* targetDocument, LocalDOM Window* callingWindow) | 44 static bool isOriginAccessibleFromDOMWindow(SecurityOrigin* targetOrigin, LocalD OMWindow* callingWindow) |
45 { | 45 { |
46 if (!targetDocument) | 46 return callingWindow && callingWindow->document()->securityOrigin()->canAcce ss(targetOrigin); |
47 return false; | 47 } |
48 | 48 |
49 if (!callingWindow) | 49 static bool canAccessFrame(v8::Isolate* isolate, SecurityOrigin* targetFrameOrig in, DOMWindow* targetWindow, ExceptionState& exceptionState) |
50 return false; | 50 { |
51 | 51 LocalDOMWindow* callingWindow = callingDOMWindow(isolate); |
52 if (callingWindow->document()->securityOrigin()->canAccess(targetDocument->s ecurityOrigin())) | 52 if (isOriginAccessibleFromDOMWindow(targetFrameOrigin, callingWindow)) |
53 return true; | 53 return true; |
54 | 54 |
55 if (targetWindow) | |
56 exceptionState.throwSecurityError(targetWindow->sanitizedCrossDomainAcce ssErrorMessage(callingWindow), targetWindow->crossDomainAccessErrorMessage(calli ngWindow)); | |
55 return false; | 57 return false; |
56 } | 58 } |
57 | 59 |
58 static bool canAccessDocument(v8::Isolate* isolate, Document* targetDocument, Ex ceptionState& exceptionState) | 60 static bool canAccessFrame(v8::Isolate* isolate, SecurityOrigin* targetFrameOrig in, DOMWindow* targetWindow, SecurityReportingOption reportingOption = ReportSec urityError) |
59 { | 61 { |
60 LocalDOMWindow* callingWindow = callingDOMWindow(isolate); | 62 LocalDOMWindow* callingWindow = callingDOMWindow(isolate); |
61 if (isDocumentAccessibleFromDOMWindow(targetDocument, callingWindow)) | 63 if (isOriginAccessibleFromDOMWindow(targetFrameOrigin, callingWindow)) |
62 return true; | 64 return true; |
63 | 65 |
64 if (targetDocument->domWindow()) | 66 if (reportingOption == ReportSecurityError && targetWindow) |
65 exceptionState.throwSecurityError(targetDocument->domWindow()->sanitized CrossDomainAccessErrorMessage(callingWindow), targetDocument->domWindow()->cross DomainAccessErrorMessage(callingWindow)); | 67 callingWindow->printErrorMessage(targetWindow->crossDomainAccessErrorMes sage(callingWindow)); |
66 return false; | |
67 } | |
68 | |
69 static bool canAccessDocument(v8::Isolate* isolate, Document* targetDocument, Se curityReportingOption reportingOption = ReportSecurityError) | |
70 { | |
71 LocalDOMWindow* callingWindow = callingDOMWindow(isolate); | |
72 if (isDocumentAccessibleFromDOMWindow(targetDocument, callingWindow)) | |
73 return true; | |
74 | |
75 if (reportingOption == ReportSecurityError && targetDocument->domWindow()) | |
76 callingWindow->printErrorMessage(targetDocument->domWindow()->crossDomai nAccessErrorMessage(callingWindow)); | |
77 | |
78 return false; | 68 return false; |
79 } | 69 } |
80 | 70 |
81 bool BindingSecurity::shouldAllowAccessToFrame(v8::Isolate* isolate, Frame* targ et, SecurityReportingOption reportingOption) | 71 bool BindingSecurity::shouldAllowAccessToFrame(v8::Isolate* isolate, Frame* targ et, SecurityReportingOption reportingOption) |
82 { | 72 { |
83 if (!target || !target->isLocalFrame()) | 73 if (!target || !target->securityContext()) |
84 return false; | 74 return false; |
85 return canAccessDocument(isolate, toLocalFrame(target)->document(), reportin gOption); | 75 return canAccessFrame(isolate, target->securityContext()->securityOrigin(), target->domWindow(), reportingOption); |
86 } | 76 } |
87 | 77 |
88 bool BindingSecurity::shouldAllowAccessToFrame(v8::Isolate* isolate, Frame* targ et, ExceptionState& exceptionState) | 78 bool BindingSecurity::shouldAllowAccessToFrame(v8::Isolate* isolate, Frame* targ et, ExceptionState& exceptionState) |
89 { | 79 { |
90 if (!target || !target->isLocalFrame()) | 80 if (!target || !target->securityContext()) |
91 return false; | 81 return false; |
92 return canAccessDocument(isolate, toLocalFrame(target)->document(), exceptio nState); | 82 return canAccessFrame(isolate, target->securityContext()->securityOrigin(), target->domWindow(), exceptionState); |
93 } | 83 } |
94 | 84 |
95 bool BindingSecurity::shouldAllowAccessToNode(v8::Isolate* isolate, Node* target , ExceptionState& exceptionState) | 85 bool BindingSecurity::shouldAllowAccessToNode(v8::Isolate* isolate, Node* target , ExceptionState& exceptionState) |
96 { | 86 { |
97 return target && canAccessDocument(isolate, &target->document(), exceptionSt ate); | 87 return target && canAccessFrame(isolate, target->document().securityOrigin() , target->document().domWindow(), exceptionState); |
dcheng
2015/04/23 17:39:57
Would it make sense to have canAccessFrame() take
alexmos
2015/04/23 17:45:28
That was the first thing I tried, and unfortunatel
dcheng
2015/04/23 18:01:24
Do we actually return a true value in that case? O
alexmos
2015/04/23 21:25:23
That particular test returns false - I think it ha
| |
98 } | 88 } |
99 | 89 |
100 } | 90 } |
OLD | NEW |