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

Side by Side Diff: Source/bindings/v8/CustomElementWrapper.cpp

Issue 18332025: Split CustomElementRegistry into a registration context and a registry. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Synced to tip. Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « Source/bindings/v8/CustomElementWrapper.h ('k') | Source/core/core.gypi » ('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) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 "config.h" 31 #include "config.h"
32 #include "bindings/v8/CustomElementWrapper.h" 32 #include "bindings/v8/CustomElementWrapper.h"
33 33
34 #include "V8HTMLElement.h"
34 #include "V8HTMLElementWrapperFactory.h" 35 #include "V8HTMLElementWrapperFactory.h"
36 #include "V8SVGElement.h"
35 #include "V8SVGElementWrapperFactory.h" 37 #include "V8SVGElementWrapperFactory.h"
36 #include "bindings/v8/DOMDataStore.h" 38 #include "bindings/v8/DOMDataStore.h"
37 #include "bindings/v8/V8PerContextData.h" 39 #include "bindings/v8/V8PerContextData.h"
38 #include "core/dom/CustomElementRegistry.h" 40 #include "core/dom/CustomElementRegistrationContext.h"
39 #include "core/html/HTMLElement.h" 41 #include "core/html/HTMLElement.h"
40 #include "core/html/HTMLUnknownElement.h" 42 #include "core/html/HTMLUnknownElement.h"
41 #include "core/svg/SVGElement.h" 43 #include "core/svg/SVGElement.h"
42 44
43 namespace WebCore { 45 namespace WebCore {
44 46
45 template<typename ElementType> 47 template<typename ElementType>
46 v8::Handle<v8::Object> createDirectWrapper(ElementType*, v8::Handle<v8::Object> creationContext, v8::Isolate*); 48 v8::Handle<v8::Object> createDirectWrapper(ElementType*, v8::Handle<v8::Object> creationContext, v8::Isolate*);
47 49
48 template<> 50 template<>
(...skipping 19 matching lines...) Expand all
68 70
69 template<> 71 template<>
70 v8::Handle<v8::Object> createFallbackWrapper<SVGElement>(SVGElement* element, v8 ::Handle<v8::Object> creationContext, v8::Isolate* isolate) 72 v8::Handle<v8::Object> createFallbackWrapper<SVGElement>(SVGElement* element, v8 ::Handle<v8::Object> creationContext, v8::Isolate* isolate)
71 { 73 {
72 return createV8SVGFallbackWrapper(element, creationContext, isolate); 74 return createV8SVGFallbackWrapper(element, creationContext, isolate);
73 } 75 }
74 76
75 template<typename ElementType> 77 template<typename ElementType>
76 v8::Handle<v8::Object> createUpgradeCandidateWrapper(ElementType* element, v8::H andle<v8::Object> creationContext, v8::Isolate* isolate, v8::Handle<v8::Object> (*createSpecificWrapper)(ElementType* element, v8::Handle<v8::Object> creationCo ntext, v8::Isolate*)) 78 v8::Handle<v8::Object> createUpgradeCandidateWrapper(ElementType* element, v8::H andle<v8::Object> creationContext, v8::Isolate* isolate, v8::Handle<v8::Object> (*createSpecificWrapper)(ElementType* element, v8::Handle<v8::Object> creationCo ntext, v8::Isolate*))
77 { 79 {
78 if (CustomElementRegistry::isCustomTagName(element->localName())) 80 if (CustomElementRegistrationContext::isCustomTagName(element->localName()))
79 return createDirectWrapper(element, creationContext, isolate); 81 return createDirectWrapper(element, creationContext, isolate);
80 if (createSpecificWrapper) 82 if (createSpecificWrapper)
81 return createSpecificWrapper(element, creationContext, isolate); 83 return createSpecificWrapper(element, creationContext, isolate);
82 return createFallbackWrapper(element, creationContext, isolate); 84 return createFallbackWrapper(element, creationContext, isolate);
83 } 85 }
84 86
85 template<typename ElementType> 87 template<typename ElementType, typename WrapperType>
86 v8::Handle<v8::Object> CustomElementWrapper<ElementType>::wrap(PassRefPtr<Elemen tType> element, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate, v8 ::Handle<v8::Object> (*createSpecificWrapper)(ElementType* element, v8::Handle<v 8::Object> creationContext, v8::Isolate*)) 88 v8::Handle<v8::Object> CustomElementWrapper<ElementType, WrapperType>::wrap(Pass RefPtr<ElementType> element, v8::Handle<v8::Object> creationContext, v8::Isolate * isolate, v8::Handle<v8::Object> (*createSpecificWrapper)(ElementType* element, v8::Handle<v8::Object> creationContext, v8::Isolate*))
87 { 89 {
88 ASSERT(DOMDataStore::getWrapper<V8Element>(element.get(), isolate).IsEmpty() ); 90 ASSERT(DOMDataStore::getWrapper<V8Element>(element.get(), isolate).IsEmpty() );
89 91
90 // FIXME: creationContext.IsEmpty() should never happen. Remove 92 // FIXME: creationContext.IsEmpty() should never happen. Remove
91 // this when callers (like InspectorController::inspect) are fixed 93 // this when callers (like InspectorController::inspect) are fixed
92 // to never pass an empty creation context. 94 // to never pass an empty creation context.
93 v8::Handle<v8::Context> context = creationContext.IsEmpty() ? isolate->GetCu rrentContext() : creationContext->CreationContext(); 95 v8::Handle<v8::Context> context = creationContext.IsEmpty() ? isolate->GetCu rrentContext() : creationContext->CreationContext();
94 96
95 CustomElementRegistry* registry = element->document()->registry(); 97 if (!element->isUpgradedCustomElement())
96 RefPtr<CustomElementDefinition> definition = registry->findFor(element.get() );
97 if (!element->isUpgradedCustomElement() || !definition)
98 return createUpgradeCandidateWrapper(element.get(), creationContext, iso late, createSpecificWrapper); 98 return createUpgradeCandidateWrapper(element.get(), creationContext, iso late, createSpecificWrapper);
99 99
100 V8PerContextData* perContextData = V8PerContextData::from(context); 100 V8PerContextData* perContextData = V8PerContextData::from(context);
101 if (!perContextData) 101 if (!perContextData)
102 return v8::Handle<v8::Object>(); 102 return v8::Handle<v8::Object>();
103 103
104 CustomElementBinding* customElementBinding = perContextData->customElementBi nding(definition->descriptor().type()); 104 CustomElementDescriptor descriptor = element->document()->registrationContex t()->describe(element.get());
105 CustomElementBinding* binding = perContextData->customElementBinding(descrip tor.type());
105 106
106 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext , customElementBinding->wrapperType(), element.get(), isolate); 107 v8::Handle<v8::Object> wrapper = V8DOMWrapper::createWrapper(creationContext , binding->wrapperType(), element.get(), isolate);
107 if (wrapper.IsEmpty()) 108 if (wrapper.IsEmpty())
108 return v8::Handle<v8::Object>(); 109 return v8::Handle<v8::Object>();
109 110
110 wrapper->SetPrototype(customElementBinding->prototype()); 111 wrapper->SetPrototype(binding->prototype());
111 112
112 V8DOMWrapper::associateObjectWithWrapper<V8Element>(element, customElementBi nding->wrapperType(), wrapper, isolate, WrapperConfiguration::Dependent); 113 V8DOMWrapper::associateObjectWithWrapper<WrapperType>(element, binding->wrap perType(), wrapper, isolate, WrapperConfiguration::Dependent);
113 return wrapper; 114 return wrapper;
114 } 115 }
115 116
116 template 117 template
117 class CustomElementWrapper<HTMLElement>; 118 class CustomElementWrapper<HTMLElement, V8HTMLElement>;
118 119
119 template 120 template
120 class CustomElementWrapper<SVGElement>; 121 class CustomElementWrapper<SVGElement, V8SVGElement>;
121 122
122 } // namespace WebCore 123 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/CustomElementWrapper.h ('k') | Source/core/core.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698