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

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

Issue 1760143003: bindings: Remove the hidden prototype from HTMLDocument. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/core/v8/WindowProxy.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "bindings/core/v8/V8DOMWrapper.h" 31 #include "bindings/core/v8/V8DOMWrapper.h"
32 32
33 #include "bindings/core/v8/V8Binding.h" 33 #include "bindings/core/v8/V8Binding.h"
34 #include "bindings/core/v8/V8HTMLCollection.h"
35 #include "bindings/core/v8/V8HTMLDocument.h"
36 #include "bindings/core/v8/V8Location.h" 34 #include "bindings/core/v8/V8Location.h"
37 #include "bindings/core/v8/V8ObjectConstructor.h" 35 #include "bindings/core/v8/V8ObjectConstructor.h"
38 #include "bindings/core/v8/V8PerContextData.h" 36 #include "bindings/core/v8/V8PerContextData.h"
39 #include "bindings/core/v8/V8PerIsolateData.h" 37 #include "bindings/core/v8/V8PerIsolateData.h"
40 #include "bindings/core/v8/V8ScriptRunner.h" 38 #include "bindings/core/v8/V8ScriptRunner.h"
41 #include "bindings/core/v8/V8Window.h" 39 #include "bindings/core/v8/V8Window.h"
42 40
43 namespace blink { 41 namespace blink {
44 42
45 static v8::Local<v8::Object> wrapInShadowTemplate(v8::Local<v8::Object> wrapper, ScriptWrappable* scriptWrappable, v8::Isolate* isolate)
46 {
47 static int shadowTemplateKey; // This address is used for a key to look up t he dom template.
48 V8PerIsolateData* data = V8PerIsolateData::from(isolate);
49 v8::Local<v8::FunctionTemplate> shadowTemplate = data->existingDOMTemplate(& shadowTemplateKey);
50 if (shadowTemplate.IsEmpty()) {
51 shadowTemplate = v8::FunctionTemplate::New(isolate);
52 if (shadowTemplate.IsEmpty())
53 return v8::Local<v8::Object>();
54 shadowTemplate->SetClassName(v8AtomicString(isolate, "HTMLDocument"));
55 shadowTemplate->Inherit(V8HTMLDocument::domTemplate(isolate));
56 shadowTemplate->InstanceTemplate()->SetInternalFieldCount(V8HTMLDocument ::internalFieldCount);
57 data->setDOMTemplate(&shadowTemplateKey, shadowTemplate);
58 }
59
60 v8::Local<v8::Function> shadowConstructor;
61 if (!shadowTemplate->GetFunction(isolate->GetCurrentContext()).ToLocal(&shad owConstructor))
62 return v8::Local<v8::Object>();
63
64 v8::Local<v8::Object> shadow;
65 if (!V8ScriptRunner::instantiateObject(isolate, shadowConstructor).ToLocal(& shadow))
66 return v8::Local<v8::Object>();
67 if (!v8CallBoolean(shadow->SetPrototype(isolate->GetCurrentContext(), wrappe r)))
68 return v8::Local<v8::Object>();
69 V8DOMWrapper::setNativeInfo(wrapper, &V8HTMLDocument::wrapperTypeInfo, scrip tWrappable);
70 return shadow;
71 }
72
73 v8::Local<v8::Object> V8DOMWrapper::createWrapper(v8::Isolate* isolate, v8::Loca l<v8::Object> creationContext, const WrapperTypeInfo* type, ScriptWrappable* scr iptWrappable) 43 v8::Local<v8::Object> V8DOMWrapper::createWrapper(v8::Isolate* isolate, v8::Loca l<v8::Object> creationContext, const WrapperTypeInfo* type, ScriptWrappable* scr iptWrappable)
74 { 44 {
75 ASSERT(!type->equals(&V8Window::wrapperTypeInfo)); 45 ASSERT(!type->equals(&V8Window::wrapperTypeInfo));
76 // According to https://html.spec.whatwg.org/multipage/browsers.html#securit y-location, 46 // According to https://html.spec.whatwg.org/multipage/browsers.html#securit y-location,
77 // cross-origin script access to a few properties of Location is allowed. 47 // cross-origin script access to a few properties of Location is allowed.
78 // Location already implements the necessary security checks. 48 // Location already implements the necessary security checks.
79 bool withSecurityCheck = !type->equals(&V8Location::wrapperTypeInfo); 49 bool withSecurityCheck = !type->equals(&V8Location::wrapperTypeInfo);
80 V8WrapperInstantiationScope scope(creationContext, isolate, withSecurityChec k); 50 V8WrapperInstantiationScope scope(creationContext, isolate, withSecurityChec k);
81 51
82 V8PerContextData* perContextData = V8PerContextData::from(scope.context()); 52 V8PerContextData* perContextData = V8PerContextData::from(scope.context());
83 v8::Local<v8::Object> wrapper; 53 v8::Local<v8::Object> wrapper;
84 if (perContextData) { 54 if (perContextData) {
85 wrapper = perContextData->createWrapperFromCache(type); 55 wrapper = perContextData->createWrapperFromCache(type);
86 } else { 56 } else {
87 if (!type->domTemplate(isolate)->InstanceTemplate()->NewInstance(scope.c ontext()).ToLocal(&wrapper)) 57 if (!type->domTemplate(isolate)->InstanceTemplate()->NewInstance(scope.c ontext()).ToLocal(&wrapper))
88 return v8::Local<v8::Object>(); 58 return v8::Local<v8::Object>();
89 } 59 }
90 60
91 if (type == &V8HTMLDocument::wrapperTypeInfo && !wrapper.IsEmpty())
92 wrapper = wrapInShadowTemplate(wrapper, scriptWrappable, isolate);
93
94 return wrapper; 61 return wrapper;
95 } 62 }
96 63
97 bool V8DOMWrapper::isWrapper(v8::Isolate* isolate, v8::Local<v8::Value> value) 64 bool V8DOMWrapper::isWrapper(v8::Isolate* isolate, v8::Local<v8::Value> value)
98 { 65 {
99 if (value.IsEmpty() || !value->IsObject()) 66 if (value.IsEmpty() || !value->IsObject())
100 return false; 67 return false;
101 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value); 68 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(value);
102 69
103 if (object->InternalFieldCount() < v8DefaultWrapperInternalFieldCount) 70 if (object->InternalFieldCount() < v8DefaultWrapperInternalFieldCount)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 v8::Isolate* isolate = m_context->GetIsolate(); 114 v8::Isolate* isolate = m_context->GetIsolate();
148 // TODO(jochen): Currently, Location is the only object for which we can rea ch this code path. Should be generalized. 115 // TODO(jochen): Currently, Location is the only object for which we can rea ch this code path. Should be generalized.
149 ExceptionState exceptionState(ExceptionState::ConstructionContext, "Location ", isolate->GetCurrentContext()->Global(), isolate); 116 ExceptionState exceptionState(ExceptionState::ConstructionContext, "Location ", isolate->GetCurrentContext()->Global(), isolate);
150 LocalDOMWindow* callingWindow = callingDOMWindow(isolate); 117 LocalDOMWindow* callingWindow = callingDOMWindow(isolate);
151 DOMWindow* targetWindow = toDOMWindow(m_context); 118 DOMWindow* targetWindow = toDOMWindow(m_context);
152 exceptionState.throwSecurityError(targetWindow->sanitizedCrossDomainAccessEr rorMessage(callingWindow), targetWindow->crossDomainAccessErrorMessage(callingWi ndow)); 119 exceptionState.throwSecurityError(targetWindow->sanitizedCrossDomainAccessEr rorMessage(callingWindow), targetWindow->crossDomainAccessErrorMessage(callingWi ndow));
153 exceptionState.throwIfNeeded(); 120 exceptionState.throwIfNeeded();
154 } 121 }
155 122
156 } // namespace blink 123 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/core/v8/WindowProxy.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698