| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 29 */ | |
| 30 | |
| 31 #include "bindings/core/v8/V8DOMWrapper.h" | |
| 32 | |
| 33 #include "bindings/core/v8/V8Binding.h" | |
| 34 #include "bindings/core/v8/V8ObjectConstructor.h" | |
| 35 #include "bindings/core/v8/V8PerContextData.h" | |
| 36 #include "bindings/core/v8/V8PerIsolateData.h" | |
| 37 | |
| 38 namespace blink { | |
| 39 | |
| 40 v8::Local<v8::Object> V8DOMWrapper::CreateWrapper( | |
| 41 v8::Isolate* isolate, | |
| 42 v8::Local<v8::Object> creation_context, | |
| 43 const WrapperTypeInfo* type) { | |
| 44 // TODO(adithyas): We should abort wrapper creation if the context access | |
| 45 // check fails and throws an exception. | |
| 46 V8WrapperInstantiationScope scope(creation_context, isolate, type); | |
| 47 | |
| 48 V8PerContextData* per_context_data = | |
| 49 V8PerContextData::From(scope.GetContext()); | |
| 50 v8::Local<v8::Object> wrapper; | |
| 51 if (per_context_data) { | |
| 52 wrapper = per_context_data->CreateWrapperFromCache(type); | |
| 53 } else { | |
| 54 // The context is detached, but still accessible. | |
| 55 // TODO(yukishiino): This code does not create a wrapper with | |
| 56 // the correct settings. Should follow the same way as | |
| 57 // V8PerContextData::createWrapperFromCache, though there is no need to | |
| 58 // cache resulting objects or their constructors. | |
| 59 const DOMWrapperWorld& world = DOMWrapperWorld::World(scope.GetContext()); | |
| 60 wrapper = type->domTemplate(isolate, world) | |
| 61 ->InstanceTemplate() | |
| 62 ->NewInstance(scope.GetContext()) | |
| 63 .ToLocalChecked(); | |
| 64 } | |
| 65 return wrapper; | |
| 66 } | |
| 67 | |
| 68 bool V8DOMWrapper::IsWrapper(v8::Isolate* isolate, v8::Local<v8::Value> value) { | |
| 69 if (value.IsEmpty() || !value->IsObject()) | |
| 70 return false; | |
| 71 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value); | |
| 72 | |
| 73 if (object->InternalFieldCount() < kV8DefaultWrapperInternalFieldCount) | |
| 74 return false; | |
| 75 | |
| 76 const WrapperTypeInfo* untrusted_wrapper_type_info = | |
| 77 ToWrapperTypeInfo(object); | |
| 78 V8PerIsolateData* per_isolate_data = V8PerIsolateData::From(isolate); | |
| 79 if (!(untrusted_wrapper_type_info && per_isolate_data)) | |
| 80 return false; | |
| 81 return per_isolate_data->HasInstance(untrusted_wrapper_type_info, object); | |
| 82 } | |
| 83 | |
| 84 bool V8DOMWrapper::HasInternalFieldsSet(v8::Local<v8::Value> value) { | |
| 85 if (value.IsEmpty() || !value->IsObject()) | |
| 86 return false; | |
| 87 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value); | |
| 88 | |
| 89 if (object->InternalFieldCount() < kV8DefaultWrapperInternalFieldCount) | |
| 90 return false; | |
| 91 | |
| 92 const ScriptWrappable* untrusted_script_wrappable = ToScriptWrappable(object); | |
| 93 const WrapperTypeInfo* untrusted_wrapper_type_info = | |
| 94 ToWrapperTypeInfo(object); | |
| 95 return untrusted_script_wrappable && untrusted_wrapper_type_info && | |
| 96 untrusted_wrapper_type_info->gin_embedder == gin::kEmbedderBlink; | |
| 97 } | |
| 98 | |
| 99 } // namespace blink | |
| OLD | NEW |