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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/BindingSecurity.cpp

Issue 1417023006: bindings: Refactors BindingSecurity::shouldAllowAccessToXXX. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Synced. Created 5 years, 1 month 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 /* 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
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 isOriginAccessibleFromDOMWindow(SecurityOrigin* targetOrigin, LocalD OMWindow* accessingWindow) 44 static bool isOriginAccessibleFromDOMWindow(const SecurityOrigin* targetOrigin, const LocalDOMWindow* accessingWindow)
45 { 45 {
46 return accessingWindow && accessingWindow->document()->securityOrigin()->can AccessCheckSuborigins(targetOrigin); 46 return accessingWindow && accessingWindow->document()->securityOrigin()->can AccessCheckSuborigins(targetOrigin);
47 } 47 }
48 48
49 static bool canAccessFrame(v8::Isolate* isolate, LocalDOMWindow* accessingWindow , SecurityOrigin* targetFrameOrigin, DOMWindow* targetWindow, ExceptionState& ex ceptionState) 49 static bool canAccessFrame(v8::Isolate* isolate, const LocalDOMWindow* accessing Window, const SecurityOrigin* targetFrameOrigin, const DOMWindow* targetWindow, ExceptionState& exceptionState)
50 { 50 {
51 if (isOriginAccessibleFromDOMWindow(targetFrameOrigin, accessingWindow)) 51 if (isOriginAccessibleFromDOMWindow(targetFrameOrigin, accessingWindow))
52 return true; 52 return true;
53 53
54 if (targetWindow) 54 if (targetWindow)
55 exceptionState.throwSecurityError(targetWindow->sanitizedCrossDomainAcce ssErrorMessage(accessingWindow), targetWindow->crossDomainAccessErrorMessage(acc essingWindow)); 55 exceptionState.throwSecurityError(targetWindow->sanitizedCrossDomainAcce ssErrorMessage(accessingWindow), targetWindow->crossDomainAccessErrorMessage(acc essingWindow));
56 return false; 56 return false;
57 } 57 }
58 58
59 static bool canAccessFrame(v8::Isolate* isolate, LocalDOMWindow* accessingWindow , SecurityOrigin* targetFrameOrigin, DOMWindow* targetWindow, SecurityReportingO ption reportingOption = ReportSecurityError) 59 static bool canAccessFrame(v8::Isolate* isolate, const LocalDOMWindow* accessing Window, SecurityOrigin* targetFrameOrigin, const DOMWindow* targetWindow, Securi tyReportingOption reportingOption = ReportSecurityError)
60 { 60 {
61 if (isOriginAccessibleFromDOMWindow(targetFrameOrigin, accessingWindow)) 61 if (isOriginAccessibleFromDOMWindow(targetFrameOrigin, accessingWindow))
62 return true; 62 return true;
63 63
64 if (reportingOption == ReportSecurityError && targetWindow) 64 if (reportingOption == ReportSecurityError && targetWindow)
65 accessingWindow->printErrorMessage(targetWindow->crossDomainAccessErrorM essage(accessingWindow)); 65 accessingWindow->printErrorMessage(targetWindow->crossDomainAccessErrorM essage(accessingWindow));
66 return false; 66 return false;
67 } 67 }
68 68
69 bool BindingSecurity::shouldAllowAccessToFrame(v8::Isolate* isolate, LocalDOMWin dow* accessingWindow, Frame* target, SecurityReportingOption reportingOption) 69 bool BindingSecurity::shouldAllowAccessTo(v8::Isolate* isolate, const LocalDOMWi ndow* accessingWindow, const DOMWindow* target, ExceptionState& exceptionState)
70 {
71 ASSERT(target);
72 const Frame* frame = target->frame();
73 if (!frame || !frame->securityContext())
74 return false;
75 return canAccessFrame(isolate, accessingWindow, frame->securityContext()->se curityOrigin(), target, exceptionState);
haraken 2015/11/16 11:34:20 Can we add ASSERT(target == target->frame()->domWi
Yuki 2015/11/20 12:27:52 Done.
76 }
77
78 bool BindingSecurity::shouldAllowAccessTo(v8::Isolate* isolate, const LocalDOMWi ndow* accessingWindow, const DOMWindow* target, SecurityReportingOption reportin gOption)
79 {
80 ASSERT(target);
81 const Frame* frame = target->frame();
82 if (!frame || !frame->securityContext())
83 return false;
84 return canAccessFrame(isolate, accessingWindow, frame->securityContext()->se curityOrigin(), target, reportingOption);
85 }
86
87 bool BindingSecurity::shouldAllowAccessTo(v8::Isolate* isolate, const LocalDOMWi ndow* accessingWindow, const EventTarget* target, ExceptionState& exceptionState )
88 {
89 ASSERT(target);
90 const DOMWindow* window = target->toDOMWindow();
91 if (!window) {
92 // We only need to check the access to Window objects which are
93 // cross-origin accessible. If it's not a Window, the object's
94 // origin must always be the same origin (or it already leaked).
95 return true;
96 }
97 const Frame* frame = window->frame();
98 if (!frame || !frame->securityContext())
99 return false;
100 return canAccessFrame(isolate, accessingWindow, frame->securityContext()->se curityOrigin(), window, exceptionState);
101 }
102
103 bool BindingSecurity::shouldAllowAccessTo(v8::Isolate* isolate, const LocalDOMWi ndow* accessingWindow, const Location* target, ExceptionState& exceptionState)
104 {
105 ASSERT(target);
106 const Frame* frame = target->frame();
107 if (!frame || !frame->securityContext())
108 return false;
109 return canAccessFrame(isolate, accessingWindow, frame->securityContext()->se curityOrigin(), frame->domWindow(), exceptionState);
110 }
111
112 bool BindingSecurity::shouldAllowAccessTo(v8::Isolate* isolate, const LocalDOMWi ndow* accessingWindow, const Location* target, SecurityReportingOption reporting Option)
113 {
114 ASSERT(target);
115 const Frame* frame = target->frame();
116 if (!frame || !frame->securityContext())
117 return false;
118 return canAccessFrame(isolate, accessingWindow, frame->securityContext()->se curityOrigin(), frame->domWindow(), reportingOption);
119 }
120
121 bool BindingSecurity::shouldAllowAccessTo(v8::Isolate* isolate, const LocalDOMWi ndow* accessingWindow, const Node* target, ExceptionState& exceptionState)
122 {
123 if (!target)
124 return false;
125 return canAccessFrame(isolate, accessingWindow, target->document().securityO rigin(), target->document().domWindow(), exceptionState);
126 }
127
128 bool BindingSecurity::shouldAllowAccessTo(v8::Isolate* isolate, const LocalDOMWi ndow* accessingWindow, const Node* target, SecurityReportingOption reportingOpti on)
129 {
130 if (!target)
131 return false;
132 return canAccessFrame(isolate, accessingWindow, target->document().securityO rigin(), target->document().domWindow(), reportingOption);
133 }
134
135 bool BindingSecurity::shouldAllowAccessToFrame(v8::Isolate* isolate, const Local DOMWindow* accessingWindow, const Frame* target, SecurityReportingOption reporti ngOption)
70 { 136 {
71 if (!target || !target->securityContext()) 137 if (!target || !target->securityContext())
dcheng 2015/11/17 01:56:59 It seems like we make these checks for every Frame
Yuki 2015/11/20 12:27:52 Hmm, we can do it for DOMWindow* and EventTarget*.
72 return false; 138 return false;
73 return canAccessFrame(isolate, accessingWindow, target->securityContext()->s ecurityOrigin(), target->domWindow(), reportingOption); 139 return canAccessFrame(isolate, accessingWindow, target->securityContext()->s ecurityOrigin(), target->domWindow(), reportingOption);
74 } 140 }
75 141
76 bool BindingSecurity::shouldAllowAccessToFrame(v8::Isolate* isolate, LocalDOMWin dow* accessingWindow, Frame* target, ExceptionState& exceptionState)
77 {
78 if (!target || !target->securityContext())
79 return false;
80 return canAccessFrame(isolate, accessingWindow, target->securityContext()->s ecurityOrigin(), target->domWindow(), exceptionState);
81 }
82
83 bool BindingSecurity::shouldAllowAccessToNode(v8::Isolate* isolate, LocalDOMWind ow* accessingWindow, Node* target, SecurityReportingOption reportingOption)
84 {
85 return target && canAccessFrame(isolate, accessingWindow, target->document() .securityOrigin(), target->document().domWindow(), reportingOption);
86 }
87
88 bool BindingSecurity::shouldAllowAccessToNode(v8::Isolate* isolate, LocalDOMWind ow* accessingWindow, Node* target, ExceptionState& exceptionState)
89 {
90 return target && canAccessFrame(isolate, accessingWindow, target->document() .securityOrigin(), target->document().domWindow(), exceptionState);
91 }
92
93 } // namespace blink 142 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698