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

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

Issue 24294002: Dartium changes for custom element lifecycle events. (Closed) Base URL: svn://svn.chromium.org/multivm/trunk/webkit
Patch Set: Created 7 years, 3 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::toDart(Element* impl, CreateWrapperFunction creat eWrapper)
36 {
37 if (!impl)
38 return Dart_Null();
39
40 HTMLElement* element = reinterpret_cast<HTMLElement*>(impl);
41
42 Dart_Handle oldInstance = DartDOMWrapper::lookupWrapper<DartHTMLElement>(ele ment);
43
44 // FIXME: Streamline the common path. It an element is already upgraded prop erly,
45 // we shouldn't need all this checking.
46
47 // Look up custom Dart type.
48 DartDOMData* domData = DartDOMData::current();
49 String name = element->localName();
50 DartCustomElementMap* map = domData->customElementMap();
51 Dart_PersistentHandle persistent = map->get(name);
52 if (!persistent) {
53 // Not a custom tag. Check for type extension.
54 if (element->hasAttribute("is")) {
55 name = element->getAttribute("is");
56 persistent = map->get(name);
57 }
58
59 // No custom type. Fall back onto builtin wrapper type.
60 if (!persistent) {
61 if (oldInstance)
62 return oldInstance;
63 return createWrapper.invoke(element);
64 }
65 }
66
67 Dart_Handle type = Dart_HandleFromPersistent(persistent);
68 ASSERT(!Dart_IsError(type));
69
70 if (oldInstance) {
71 // Previous wrapper exists. Test for upgrade.
72 Dart_Handle oldType = Dart_InstanceGetType(oldInstance);
73 if (Dart_IdentityEquals(oldType, type))
74 return oldInstance;
75 }
76
77 DartCustomElementMap* nativeMap = domData->customBaseElementMap();
78 Dart_Handle expectedNativeType = Dart_HandleFromPersistent(nativeMap->get(na me));
79 ASSERT(!Dart_IsError(expectedNativeType));
80
81 // FIXME: Avoid allocating the fallback wrapper until we know we need it.
82 Dart_Handle fallback = oldInstance ? oldInstance : createWrapper.invoke(elem ent);
83 Dart_Handle actualNativeType = Dart_InstanceGetType(fallback);
84 ASSERT(!Dart_IsError(actualNativeType));
85
86 if (!Dart_IdentityEquals(actualNativeType, expectedNativeType)) {
87 // The registered custom type does not match. Just fallback.
88 return fallback;
89 }
90 DartDOMWrapper::disassociateWrapper<DartHTMLElement>(element, fallback);
91
92 Dart_Handle newInstance = Dart_Allocate(type);
93 ASSERT(!Dart_IsError(newInstance));
94
95 Dart_Handle result = Dart_SetNativeInstanceField(newInstance, 0, reinterpret _cast<intptr_t>(element));
96 UNUSED_PARAM(result);
97 ASSERT(!Dart_IsError(result));
98
99 Dart_Handle wrapper = DartDOMWrapper::associateWrapper<DartHTMLElement>(elem ent, newInstance);
100 Dart_Invoke(wrapper, Dart_NewStringFromCString("created"), 0, 0);
101 return wrapper;
102 }
103
104 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698