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

Side by Side Diff: Source/bindings/dart/DartCustomElement.cpp

Issue 24677002: Revert "Revert "Dartium changes for custom element lifecycle events."" (Closed) Base URL: svn://svn.chromium.org/multivm/trunk/webkit
Patch Set: Created 7 years, 2 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
OLDNEW
(Empty)
1 // Copyright 2013, Google Inc.
2 // 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 #include "config.h"
31 #include "DartCustomElement.h"
32
33 namespace WebCore {
34
35 Dart_Handle DartCustomElement::createWrapper(Element* impl, CreateWrapperFunctio n createWrapper)
36 {
37 if (!impl)
38 return Dart_Null();
39
40 HTMLElement* element = reinterpret_cast<HTMLElement*>(impl);
41
42 // FIXME: Streamline the common path. If an element is already upgraded prop erly,
43 // we shouldn't need all this checking.
44
45 // Look up custom Dart type.
46 DartDOMData* domData = DartDOMData::current();
47
48 ASSERT(!DartDOMWrapper::lookupWrapper(domData, DartHTMLElement::isNode, elem ent));
49
50 String name = element->localName();
51 DartCustomElementMap* map = domData->customElementMap();
52 Dart_PersistentHandle persistent = map->get(name);
53 if (!persistent) {
54 // Not a custom tag. Check for type extension.
55 if (element->hasAttribute("is")) {
56 name = element->getAttribute("is");
57 persistent = map->get(name);
58 }
59
60 // No custom type. Fall back onto builtin wrapper type.
61 if (!persistent) {
62 return createWrapper.invoke(element);
63 }
64 }
65
66 Dart_Handle type = Dart_HandleFromPersistent(persistent);
67 ASSERT(!Dart_IsError(type));
68
69 DartCustomElementMap* nativeMap = domData->customBaseElementMap();
70 Dart_Handle expectedNativeType = Dart_HandleFromPersistent(nativeMap->get(na me));
71 ASSERT(!Dart_IsError(expectedNativeType));
72
73 // FIXME: Avoid allocating the fallback wrapper until we know we need it.
74 Dart_Handle fallback = createWrapper.invoke(element);
75 Dart_Handle actualNativeType = Dart_InstanceGetType(fallback);
76 ASSERT(!Dart_IsError(actualNativeType));
77
78 if (!Dart_IdentityEquals(actualNativeType, expectedNativeType)) {
79 // The registered custom type does not match. Just fallback.
80 return fallback;
81 }
82 DartDOMWrapper::disassociateWrapper<DartHTMLElement>(element, fallback);
83
84 Dart_Handle newInstance = Dart_Allocate(type);
85 ASSERT(!Dart_IsError(newInstance));
86
87 Dart_Handle result = Dart_SetNativeInstanceField(newInstance, 0, reinterpret _cast<intptr_t>(element));
88 UNUSED_PARAM(result);
89 ASSERT(!Dart_IsError(result));
90
91 DartDOMWrapper::associateWrapper<DartHTMLElement>(element, newInstance);
92 Dart_Invoke(newInstance, Dart_NewStringFromCString("created"), 0, 0);
93 return newInstance;
94 }
95
96 Dart_WeakPersistentHandle DartCustomElement::lookupWrapper(
97 DartDOMData* domData, Dart_WeakPersistentHandle wrapper, Element* impl)
98 {
99 ASSERT(impl);
100 ASSERT(wrapper);
101
102 HTMLElement* element = reinterpret_cast<HTMLElement*>(impl);
103
104 // FIXME: Streamline the common path. If an element is already upgraded prop erly,
105 // we shouldn't need all this checking.
106
107 // Look up custom Dart type.
108 String name = element->localName();
109 DartCustomElementMap* map = domData->customElementMap();
110 Dart_PersistentHandle persistent = map->get(name);
111 if (!persistent) {
112 // Not a custom tag. Check for type extension.
113 if (element->hasAttribute("is")) {
114 name = element->getAttribute("is");
115 persistent = map->get(name);
116 }
117
118 // No custom type. Fall back onto builtin wrapper type.
119 if (!persistent) {
120 return wrapper;
121 }
122 }
123 // Previous wrapper exists. Test for upgrade.
124 Dart_Handle type = Dart_HandleFromPersistent(persistent);
125 Dart_Handle oldInstance = Dart_HandleFromWeakPersistent(wrapper);
126 Dart_Handle oldType = Dart_InstanceGetType(oldInstance);
127 ASSERT(!Dart_IsError(oldType));
128 if (Dart_IdentityEquals(oldType, type))
129 return wrapper;
130
131 DartCustomElementMap* nativeMap = domData->customBaseElementMap();
132 Dart_Handle expectedNativeType = Dart_HandleFromPersistent(nativeMap->get(na me));
133 ASSERT(!Dart_IsError(expectedNativeType));
134
135 if (!Dart_IdentityEquals(oldType, expectedNativeType)) {
136 // The registered custom type does not match. Just fallback.
137 return wrapper;
138 }
139
140 return 0;
141 }
142
143 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/dart/DartCustomElement.h ('k') | Source/bindings/dart/DartCustomElementBinding.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698