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

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

Issue 2745313003: Move securityCheck out of V8WrapperInstantiationScope (Closed)
Patch Set: Add comments and DCHECKs 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/bindings/core/v8/V8DOMWrapper.h
diff --git a/third_party/WebKit/Source/bindings/core/v8/V8DOMWrapper.h b/third_party/WebKit/Source/bindings/core/v8/V8DOMWrapper.h
index f94378d9e9259ace8b61beb38207c72407a7bf26..f57f6d879aab9a8063cfe1fac77414703e7a8be3 100644
--- a/third_party/WebKit/Source/bindings/core/v8/V8DOMWrapper.h
+++ b/third_party/WebKit/Source/bindings/core/v8/V8DOMWrapper.h
@@ -31,10 +31,10 @@
#ifndef V8DOMWrapper_h
#define V8DOMWrapper_h
-#include "bindings/core/v8/BindingSecurity.h"
#include "bindings/core/v8/DOMDataStore.h"
#include "bindings/core/v8/ScriptWrappable.h"
#include "bindings/core/v8/V8Binding.h"
+#include "bindings/core/v8/WrapperCreationSecurityCheck.h"
#include "core/CoreExport.h"
#include "platform/wtf/Compiler.h"
#include "platform/wtf/text/AtomicString.h"
@@ -125,11 +125,12 @@ class V8WrapperInstantiationScope {
public:
V8WrapperInstantiationScope(v8::Local<v8::Object> creationContext,
v8::Isolate* isolate,
- bool withSecurityCheck)
+ const WrapperTypeInfo* type)
: m_didEnterContext(false),
m_context(isolate->GetCurrentContext()),
m_tryCatch(isolate),
- m_convertExceptions(false) {
+ m_type(type),
+ m_accessCheckFailed(false) {
// creationContext should not be empty. Because if we have an
// empty creationContext, we will end up creating
// a new object in the context currently entered. This is wrong.
@@ -141,12 +142,16 @@ class V8WrapperInstantiationScope {
// context is different from the context that we are about to enter.
if (contextForWrapper == m_context)
return;
- if (withSecurityCheck) {
- securityCheck(isolate, contextForWrapper);
- } else {
- m_convertExceptions = true;
+ m_context = contextForWrapper;
+
+ if (!WrapperCreationSecurityCheck::verifyContextAccess(isolate, m_context,
+ m_type)) {
+ DCHECK(m_tryCatch.HasCaught());
+ m_tryCatch.ReThrow();
+ m_accessCheckFailed = true;
+ return;
}
- m_context = v8::Local<v8::Context>::New(isolate, contextForWrapper);
+
m_didEnterContext = true;
m_context->Enter();
}
@@ -157,26 +162,31 @@ class V8WrapperInstantiationScope {
return;
}
m_context->Exit();
- // Rethrow any cross-context exceptions as security error.
- if (m_tryCatch.HasCaught()) {
- if (m_convertExceptions) {
- m_tryCatch.Reset();
- convertException();
- }
- m_tryCatch.ReThrow();
- }
+
+ if (!m_tryCatch.HasCaught())
+ return;
+
+ // Any exception caught here is a cross context exception and it may not be
+ // safe to directly rethrow the exception in the current context (without
+ // converting it). rethrowCrossContextException converts the exception in
+ // such a scenario.
+ v8::Isolate* isolate = m_context->GetIsolate();
+ v8::Local<v8::Value> caughtException = m_tryCatch.Exception();
+ m_tryCatch.Reset();
+ WrapperCreationSecurityCheck::rethrowCrossContextException(
+ isolate, m_context, m_type, caughtException);
+ m_tryCatch.ReThrow();
}
v8::Local<v8::Context> context() const { return m_context; }
+ bool accessCheckFailed() const { return m_accessCheckFailed; }
private:
- void securityCheck(v8::Isolate*, v8::Local<v8::Context> contextForWrapper);
- void convertException();
-
bool m_didEnterContext;
v8::Local<v8::Context> m_context;
v8::TryCatch m_tryCatch;
- bool m_convertExceptions;
+ const WrapperTypeInfo* m_type;
+ bool m_accessCheckFailed;
};
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698