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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/V8DOMWrapper.h

Issue 2745313003: Move securityCheck out of V8WrapperInstantiationScope (Closed)
Patch Set: Stop unecessary includes of BindingSecurity.h Created 3 years, 9 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 /* 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 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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 #ifndef V8DOMWrapper_h 31 #ifndef V8DOMWrapper_h
32 #define V8DOMWrapper_h 32 #define V8DOMWrapper_h
33 33
34 #include "bindings/core/v8/BindingSecurity.h"
35 #include "bindings/core/v8/DOMDataStore.h" 34 #include "bindings/core/v8/DOMDataStore.h"
36 #include "bindings/core/v8/ScriptWrappable.h" 35 #include "bindings/core/v8/ScriptWrappable.h"
37 #include "bindings/core/v8/V8Binding.h" 36 #include "bindings/core/v8/V8Binding.h"
38 #include "core/CoreExport.h" 37 #include "core/CoreExport.h"
39 #include "v8/include/v8.h" 38 #include "v8/include/v8.h"
40 #include "wtf/Compiler.h" 39 #include "wtf/Compiler.h"
41 #include "wtf/text/AtomicString.h" 40 #include "wtf/text/AtomicString.h"
42 41
43 namespace blink { 42 namespace blink {
44 43
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 SECURITY_CHECK(toScriptWrappable(wrapper) == impl); 117 SECURITY_CHECK(toScriptWrappable(wrapper) == impl);
119 return wrapper; 118 return wrapper;
120 } 119 }
121 120
122 class V8WrapperInstantiationScope { 121 class V8WrapperInstantiationScope {
123 STACK_ALLOCATED(); 122 STACK_ALLOCATED();
124 123
125 public: 124 public:
126 V8WrapperInstantiationScope(v8::Local<v8::Object> creationContext, 125 V8WrapperInstantiationScope(v8::Local<v8::Object> creationContext,
127 v8::Isolate* isolate, 126 v8::Isolate* isolate,
128 bool withSecurityCheck) 127 const WrapperTypeInfo* type)
129 : m_didEnterContext(false), 128 : m_didEnterContext(false),
130 m_context(isolate->GetCurrentContext()), 129 m_context(isolate->GetCurrentContext()),
131 m_tryCatch(isolate), 130 m_tryCatch(isolate),
132 m_convertExceptions(false) { 131 m_type(type) {
133 // creationContext should not be empty. Because if we have an 132 // creationContext should not be empty. Because if we have an
134 // empty creationContext, we will end up creating 133 // empty creationContext, we will end up creating
135 // a new object in the context currently entered. This is wrong. 134 // a new object in the context currently entered. This is wrong.
136 RELEASE_ASSERT(!creationContext.IsEmpty()); 135 RELEASE_ASSERT(!creationContext.IsEmpty());
137 v8::Local<v8::Context> contextForWrapper = 136 v8::Local<v8::Context> contextForWrapper =
138 creationContext->CreationContext(); 137 creationContext->CreationContext();
139 138
140 // For performance, we enter the context only if the currently running 139 // For performance, we enter the context only if the currently running
141 // context is different from the context that we are about to enter. 140 // context is different from the context that we are about to enter.
142 if (contextForWrapper == m_context) 141 if (contextForWrapper == m_context)
143 return; 142 return;
144 if (withSecurityCheck) { 143
jochen (gone - plz use gerrit) 2017/03/15 19:56:13 if you move this out, you'll want to make sure tha
adithyas 2017/03/28 20:35:41 Added an assertion.
145 securityCheck(isolate, contextForWrapper);
146 } else {
147 m_convertExceptions = true;
148 }
149 m_context = v8::Local<v8::Context>::New(isolate, contextForWrapper); 144 m_context = v8::Local<v8::Context>::New(isolate, contextForWrapper);
150 m_didEnterContext = true; 145 m_didEnterContext = true;
151 m_context->Enter(); 146 m_context->Enter();
152 } 147 }
153 148
154 ~V8WrapperInstantiationScope() { 149 ~V8WrapperInstantiationScope() {
155 if (!m_didEnterContext) { 150 if (!m_didEnterContext) {
156 m_tryCatch.ReThrow(); 151 m_tryCatch.ReThrow();
157 return; 152 return;
158 } 153 }
159 m_context->Exit(); 154 m_context->Exit();
160 // Rethrow any cross-context exceptions as security error. 155
161 if (m_tryCatch.HasCaught()) { 156 v8::Isolate* isolate = m_context->GetIsolate();
162 if (m_convertExceptions) { 157 v8::Local<v8::Value> caughtException = m_tryCatch.Exception();
163 m_tryCatch.Reset(); 158
164 convertException(); 159 m_tryCatch.Reset();
165 } 160 m_type->securityCheck(isolate, isolate->GetCurrentContext(), m_context,
jbroman 2017/03/15 19:58:41 Do ArrayBuffer/ArrayBufferViews not go through V8W
adithyas 2017/03/28 20:35:41 They do not (they don't call V8DOMWrapper::createW
161 m_type->interfaceName, caughtException);
162
163 if (m_tryCatch.HasCaught())
jochen (gone - plz use gerrit) 2017/03/15 19:56:13 that won't work as you reset the trycatch above
adithyas 2017/03/28 20:35:41 m_type->securityCheck can throw an exception, and
166 m_tryCatch.ReThrow(); 164 m_tryCatch.ReThrow();
167 }
168 } 165 }
169 166
170 v8::Local<v8::Context> context() const { return m_context; } 167 v8::Local<v8::Context> context() const { return m_context; }
171 168
172 private: 169 private:
173 void securityCheck(v8::Isolate*, v8::Local<v8::Context> contextForWrapper);
174 void convertException();
175
176 bool m_didEnterContext; 170 bool m_didEnterContext;
177 v8::Local<v8::Context> m_context; 171 v8::Local<v8::Context> m_context;
178 v8::TryCatch m_tryCatch; 172 v8::TryCatch m_tryCatch;
179 bool m_convertExceptions; 173 const WrapperTypeInfo* m_type;
180 }; 174 };
181 175
182 } // namespace blink 176 } // namespace blink
183 177
184 #endif // V8DOMWrapper_h 178 #endif // V8DOMWrapper_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698