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/core/v8/V8DOMWrapper.h" | 32 #include "bindings/core/v8/V8DOMWrapper.h" |
33 | 33 |
34 #include "bindings/core/v8/V8Binding.h" | 34 #include "bindings/core/v8/V8Binding.h" |
35 #include "bindings/core/v8/V8HTMLCollection.h" | 35 #include "bindings/core/v8/V8HTMLCollection.h" |
36 #include "bindings/core/v8/V8HTMLDocument.h" | 36 #include "bindings/core/v8/V8HTMLDocument.h" |
| 37 #include "bindings/core/v8/V8Location.h" |
37 #include "bindings/core/v8/V8ObjectConstructor.h" | 38 #include "bindings/core/v8/V8ObjectConstructor.h" |
38 #include "bindings/core/v8/V8PerContextData.h" | 39 #include "bindings/core/v8/V8PerContextData.h" |
39 #include "bindings/core/v8/V8PerIsolateData.h" | 40 #include "bindings/core/v8/V8PerIsolateData.h" |
40 #include "bindings/core/v8/V8ScriptRunner.h" | 41 #include "bindings/core/v8/V8ScriptRunner.h" |
41 #include "bindings/core/v8/V8Window.h" | 42 #include "bindings/core/v8/V8Window.h" |
42 | 43 |
43 namespace blink { | 44 namespace blink { |
44 | 45 |
45 static v8::Local<v8::Object> wrapInShadowTemplate(v8::Local<v8::Object> wrapper,
ScriptWrappable* scriptWrappable, v8::Isolate* isolate) | 46 static v8::Local<v8::Object> wrapInShadowTemplate(v8::Local<v8::Object> wrapper,
ScriptWrappable* scriptWrappable, v8::Isolate* isolate) |
46 { | 47 { |
(...skipping 18 matching lines...) Expand all Loading... |
65 if (!V8ScriptRunner::instantiateObject(isolate, shadowConstructor).ToLocal(&
shadow)) | 66 if (!V8ScriptRunner::instantiateObject(isolate, shadowConstructor).ToLocal(&
shadow)) |
66 return v8::Local<v8::Object>(); | 67 return v8::Local<v8::Object>(); |
67 if (!v8CallBoolean(shadow->SetPrototype(isolate->GetCurrentContext(), wrappe
r))) | 68 if (!v8CallBoolean(shadow->SetPrototype(isolate->GetCurrentContext(), wrappe
r))) |
68 return v8::Local<v8::Object>(); | 69 return v8::Local<v8::Object>(); |
69 V8DOMWrapper::setNativeInfo(wrapper, &V8HTMLDocument::wrapperTypeInfo, scrip
tWrappable); | 70 V8DOMWrapper::setNativeInfo(wrapper, &V8HTMLDocument::wrapperTypeInfo, scrip
tWrappable); |
70 return shadow; | 71 return shadow; |
71 } | 72 } |
72 | 73 |
73 v8::Local<v8::Object> V8DOMWrapper::createWrapper(v8::Isolate* isolate, v8::Loca
l<v8::Object> creationContext, const WrapperTypeInfo* type, ScriptWrappable* scr
iptWrappable) | 74 v8::Local<v8::Object> V8DOMWrapper::createWrapper(v8::Isolate* isolate, v8::Loca
l<v8::Object> creationContext, const WrapperTypeInfo* type, ScriptWrappable* scr
iptWrappable) |
74 { | 75 { |
75 V8WrapperInstantiationScope scope(creationContext, isolate); | 76 ASSERT(!type->equals(&V8Window::wrapperTypeInfo)); |
| 77 // According to https://html.spec.whatwg.org/multipage/browsers.html#securit
y-location, |
| 78 // cross-origin script access to a few properties of Location is allowed. |
| 79 // Location already implements the necessary security checks. |
| 80 bool withSecurityCheck = !type->equals(&V8Location::wrapperTypeInfo); |
| 81 V8WrapperInstantiationScope scope(creationContext, isolate, withSecurityChec
k); |
76 | 82 |
77 V8PerContextData* perContextData = V8PerContextData::from(scope.context()); | 83 V8PerContextData* perContextData = V8PerContextData::from(scope.context()); |
78 v8::Local<v8::Object> wrapper; | 84 v8::Local<v8::Object> wrapper; |
79 if (perContextData) { | 85 if (perContextData) { |
80 wrapper = perContextData->createWrapperFromCache(type); | 86 wrapper = perContextData->createWrapperFromCache(type); |
81 } else { | 87 } else { |
82 v8::Local<v8::Function> function; | 88 v8::Local<v8::Function> function; |
83 if (!type->domTemplate(isolate)->GetFunction(isolate->GetCurrentContext(
)).ToLocal(&function)) | 89 if (!type->domTemplate(isolate)->GetFunction(isolate->GetCurrentContext(
)).ToLocal(&function)) |
84 return v8::Local<v8::Object>(); | 90 return v8::Local<v8::Object>(); |
85 if (!V8ObjectConstructor::newInstance(isolate, function).ToLocal(&wrappe
r)) | 91 if (!V8ObjectConstructor::newInstance(isolate, function).ToLocal(&wrappe
r)) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 if (object->InternalFieldCount() < v8DefaultWrapperInternalFieldCount) | 123 if (object->InternalFieldCount() < v8DefaultWrapperInternalFieldCount) |
118 return false; | 124 return false; |
119 | 125 |
120 const ScriptWrappable* untrustedScriptWrappable = toScriptWrappable(object); | 126 const ScriptWrappable* untrustedScriptWrappable = toScriptWrappable(object); |
121 const WrapperTypeInfo* untrustedWrapperTypeInfo = toWrapperTypeInfo(object); | 127 const WrapperTypeInfo* untrustedWrapperTypeInfo = toWrapperTypeInfo(object); |
122 return untrustedScriptWrappable | 128 return untrustedScriptWrappable |
123 && untrustedWrapperTypeInfo | 129 && untrustedWrapperTypeInfo |
124 && untrustedWrapperTypeInfo->ginEmbedder == gin::kEmbedderBlink; | 130 && untrustedWrapperTypeInfo->ginEmbedder == gin::kEmbedderBlink; |
125 } | 131 } |
126 | 132 |
| 133 void V8WrapperInstantiationScope::SecurityCheck(v8::Isolate* isolate, v8::Local<
v8::Context> contextForWrapper) |
| 134 { |
| 135 if (!m_context.IsEmpty()) { |
| 136 // If the context is different, we need to make sure that the current |
| 137 // context has access to the creation context. |
| 138 Frame* frame = toFrameIfNotDetached(contextForWrapper); |
| 139 RELEASE_ASSERT(!frame || BindingSecurity::shouldAllowAccessToFrame(isola
te, frame, DoNotReportSecurityError)); |
| 140 } |
| 141 } |
| 142 |
127 } // namespace blink | 143 } // namespace blink |
OLD | NEW |