Chromium Code Reviews| 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 16 matching lines...) Expand all Loading... | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "bindings/v8/BindingSecurity.h" | 32 #include "bindings/v8/BindingSecurity.h" |
| 33 | 33 |
| 34 #include "bindings/v8/V8Binding.h" | 34 #include "bindings/v8/V8Binding.h" |
| 35 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
| 36 #include "core/html/HTMLFrameElementBase.h" | 36 #include "core/html/HTMLFrameElementBase.h" |
| 37 #include "core/html/parser/HTMLParserIdioms.h" | |
| 38 #include "core/page/DOMWindow.h" | 37 #include "core/page/DOMWindow.h" |
| 39 #include "core/page/Frame.h" | 38 #include "core/page/Frame.h" |
| 40 #include "core/page/Settings.h" | 39 #include "core/page/Settings.h" |
| 41 #include "weborigin/SecurityOrigin.h" | 40 #include "weborigin/SecurityOrigin.h" |
| 42 | 41 |
| 43 namespace WebCore { | 42 namespace WebCore { |
| 44 | 43 |
| 45 static bool canAccessDocument(Document* targetDocument, SecurityReportingOption reportingOption = ReportSecurityError) | 44 static bool isDocumentAccessibleFromActiveDOMWindow(Document* targetDocument) |
| 46 { | 45 { |
| 47 if (!targetDocument) | 46 if (!targetDocument) |
| 48 return false; | 47 return false; |
| 49 | 48 |
| 50 DOMWindow* active = activeDOMWindow(); | 49 DOMWindow* active = activeDOMWindow(); |
| 51 if (!active) | 50 if (!active) |
| 52 return false; | 51 return false; |
| 53 | 52 |
| 54 if (active->document()->securityOrigin()->canAccess(targetDocument->security Origin())) | 53 if (active->document()->securityOrigin()->canAccess(targetDocument->security Origin())) |
| 55 return true; | 54 return true; |
| 56 | 55 |
| 56 return false; | |
| 57 } | |
| 58 | |
| 59 static bool canAccessDocument(Document* targetDocument, ExceptionState& es) | |
|
abarth-chromium
2013/08/12 19:57:03
What's the point of having this be a separate func
Mike West
2013/08/13 08:30:51
This is the first patch that throws an exception o
| |
| 60 { | |
| 61 if (isDocumentAccessibleFromActiveDOMWindow(targetDocument)) | |
| 62 return true; | |
| 63 | |
| 64 es.throwDOMException(SecurityError, targetDocument->domWindow()->crossDomain AccessErrorMessage(activeDOMWindow())); | |
|
abarth-chromium
2013/08/12 19:58:26
Wait a minute. not lgtm. This leaks the current
| |
| 65 return false; | |
| 66 } | |
| 67 | |
| 68 static bool canAccessDocument(Document* targetDocument, SecurityReportingOption reportingOption = ReportSecurityError) | |
| 69 { | |
| 70 if (isDocumentAccessibleFromActiveDOMWindow(targetDocument)) | |
| 71 return true; | |
| 72 | |
| 57 if (reportingOption == ReportSecurityError) { | 73 if (reportingOption == ReportSecurityError) { |
| 58 if (Frame* frame = targetDocument->frame()) | 74 if (Frame* frame = targetDocument->frame()) |
| 59 frame->domWindow()->printErrorMessage(targetDocument->domWindow()->c rossDomainAccessErrorMessage(active)); | 75 frame->domWindow()->printErrorMessage(targetDocument->domWindow()->c rossDomainAccessErrorMessage(activeDOMWindow())); |
|
abarth-chromium
2013/08/12 19:57:03
It's kine of lame that we call activeDOMWindow twi
Mike West
2013/08/13 08:30:51
Good point. Fixed.
| |
| 60 } | 76 } |
| 61 | 77 |
| 62 return false; | 78 return false; |
| 63 } | 79 } |
| 64 | 80 |
| 65 bool BindingSecurity::shouldAllowAccessToFrame(Frame* target, SecurityReportingO ption reportingOption) | 81 bool BindingSecurity::shouldAllowAccessToFrame(Frame* target, SecurityReportingO ption reportingOption) |
| 66 { | 82 { |
| 67 return target && canAccessDocument(target->document(), reportingOption); | 83 return target && canAccessDocument(target->document(), reportingOption); |
| 68 } | 84 } |
| 69 | 85 |
| 86 bool BindingSecurity::shouldAllowAccessToFrame(Frame* target, ExceptionState& es ) | |
| 87 { | |
| 88 return target && canAccessDocument(target->document(), es); | |
| 89 } | |
| 90 | |
| 70 bool BindingSecurity::shouldAllowAccessToNode(Node* target) | 91 bool BindingSecurity::shouldAllowAccessToNode(Node* target) |
| 71 { | 92 { |
| 72 return target && canAccessDocument(target->document()); | 93 return target && canAccessDocument(target->document()); |
| 73 } | 94 } |
| 74 | 95 |
| 75 bool BindingSecurity::allowSettingFrameSrcToJavascriptUrl(HTMLFrameElementBase* frame, const String& value) | |
| 76 { | |
| 77 return !protocolIsJavaScript(stripLeadingAndTrailingHTMLSpaces(value)) || ca nAccessDocument(frame->contentDocument()); | |
| 78 } | 96 } |
| 79 | |
| 80 } | |
| OLD | NEW |