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

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

Issue 2745313003: Move securityCheck out of V8WrapperInstantiationScope (Closed)
Patch Set: Move functions into static class and remove flag bit Created 3 years, 8 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"
37 #include "bindings/core/v8/WrapperCreationSecurityCheck.h"
38 #include "core/CoreExport.h" 38 #include "core/CoreExport.h"
39 #include "v8/include/v8.h" 39 #include "v8/include/v8.h"
40 #include "wtf/Compiler.h" 40 #include "wtf/Compiler.h"
41 #include "wtf/text/AtomicString.h" 41 #include "wtf/text/AtomicString.h"
42 42
43 namespace blink { 43 namespace blink {
44 44
45 struct WrapperTypeInfo; 45 struct WrapperTypeInfo;
46 46
47 class V8DOMWrapper { 47 class V8DOMWrapper {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 SECURITY_CHECK(toScriptWrappable(wrapper) == impl); 118 SECURITY_CHECK(toScriptWrappable(wrapper) == impl);
119 return wrapper; 119 return wrapper;
120 } 120 }
121 121
122 class V8WrapperInstantiationScope { 122 class V8WrapperInstantiationScope {
123 STACK_ALLOCATED(); 123 STACK_ALLOCATED();
124 124
125 public: 125 public:
126 V8WrapperInstantiationScope(v8::Local<v8::Object> creationContext, 126 V8WrapperInstantiationScope(v8::Local<v8::Object> creationContext,
127 v8::Isolate* isolate, 127 v8::Isolate* isolate,
128 bool withSecurityCheck) 128 const WrapperTypeInfo* type)
129 : m_didEnterContext(false), 129 : m_didEnterContext(false),
130 m_context(isolate->GetCurrentContext()), 130 m_context(isolate->GetCurrentContext()),
131 m_tryCatch(isolate), 131 m_tryCatch(isolate),
132 m_convertExceptions(false) { 132 m_type(type) {
133 // creationContext should not be empty. Because if we have an 133 // creationContext should not be empty. Because if we have an
134 // empty creationContext, we will end up creating 134 // empty creationContext, we will end up creating
135 // a new object in the context currently entered. This is wrong. 135 // a new object in the context currently entered. This is wrong.
136 RELEASE_ASSERT(!creationContext.IsEmpty()); 136 RELEASE_ASSERT(!creationContext.IsEmpty());
137 v8::Local<v8::Context> contextForWrapper = 137 v8::Local<v8::Context> contextForWrapper =
138 creationContext->CreationContext(); 138 creationContext->CreationContext();
139 139
140 // For performance, we enter the context only if the currently running 140 // For performance, we enter the context only if the currently running
141 // context is different from the context that we are about to enter. 141 // context is different from the context that we are about to enter.
142 if (contextForWrapper == m_context) 142 if (contextForWrapper == m_context)
143 return; 143 return;
144 if (withSecurityCheck) { 144
145 securityCheck(isolate, contextForWrapper);
146 } else {
147 m_convertExceptions = true;
148 }
149 m_context = v8::Local<v8::Context>::New(isolate, contextForWrapper); 145 m_context = v8::Local<v8::Context>::New(isolate, contextForWrapper);
150 m_didEnterContext = true; 146 m_didEnterContext = true;
151 m_context->Enter(); 147 m_context->Enter();
152 } 148 }
153 149
154 ~V8WrapperInstantiationScope() { 150 ~V8WrapperInstantiationScope() {
155 if (!m_didEnterContext) { 151 if (!m_didEnterContext) {
156 m_tryCatch.ReThrow(); 152 m_tryCatch.ReThrow();
157 return; 153 return;
158 } 154 }
159 m_context->Exit(); 155 m_context->Exit();
160 // Rethrow any cross-context exceptions as security error. 156
161 if (m_tryCatch.HasCaught()) { 157 v8::Isolate* isolate = m_context->GetIsolate();
162 if (m_convertExceptions) { 158 v8::Local<v8::Value> caughtException = m_tryCatch.Exception();
163 m_tryCatch.Reset(); 159
164 convertException(); 160 m_tryCatch.Reset();
165 } 161 WrapperCreationSecurityCheck::securityCheck(
Yuki 2017/03/31 09:49:37 This code seems expected to (re)throw an exception
adithyas 2017/03/31 17:49:28 OK, changed to a more descriptive name.
162 isolate, isolate->GetCurrentContext(), m_context, m_type,
163 caughtException);
164
165 if (m_tryCatch.HasCaught())
Yuki 2017/03/31 09:49:37 You've reset m_tryCatch on line 160. This is mean
adithyas 2017/03/31 17:49:28 Hmm, does Reset() completely disable the TryCatch?
Yuki 2017/04/03 08:29:25 Ah, now I see the point. Then, I'd prefer an earl
adithyas 2017/04/03 15:20:54 I think verifyContextAccessAndHandleCrossContextEx
Yuki 2017/04/05 07:59:19 I'm getting better understanding. The original im
166 m_tryCatch.ReThrow(); 166 m_tryCatch.ReThrow();
167 }
168 } 167 }
169 168
170 v8::Local<v8::Context> context() const { return m_context; } 169 v8::Local<v8::Context> context() const { return m_context; }
171 170
172 private: 171 private:
173 void securityCheck(v8::Isolate*, v8::Local<v8::Context> contextForWrapper);
174 void convertException();
175
176 bool m_didEnterContext; 172 bool m_didEnterContext;
177 v8::Local<v8::Context> m_context; 173 v8::Local<v8::Context> m_context;
178 v8::TryCatch m_tryCatch; 174 v8::TryCatch m_tryCatch;
179 bool m_convertExceptions; 175 const WrapperTypeInfo* m_type;
180 }; 176 };
181 177
182 } // namespace blink 178 } // namespace blink
183 179
184 #endif // V8DOMWrapper_h 180 #endif // V8DOMWrapper_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698