| OLD | NEW |
| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 template<typename ElementType> | 87 template<typename ElementType> |
| 88 Dart_Handle DartCustomElementWrapper<ElementType>::wrap(PassRefPtr<ElementType>
element, Dart_Handle (*createSpecificWrapper)(DartDOMData* domData, ElementType*
)) | 88 Dart_Handle DartCustomElementWrapper<ElementType>::wrap(PassRefPtr<ElementType>
element, Dart_Handle (*createSpecificWrapper)(DartDOMData* domData, ElementType*
)) |
| 89 { | 89 { |
| 90 if (!element->isUpgradedCustomElement()) | 90 if (!element->isUpgradedCustomElement()) |
| 91 return createUpgradeCandidateWrapper(element.get(), createSpecificWrappe
r); | 91 return createUpgradeCandidateWrapper(element.get(), createSpecificWrappe
r); |
| 92 | 92 |
| 93 return upgradeDartWrapper(element.get(), createSpecificWrapper); | 93 return upgradeDartWrapper(element.get(), createSpecificWrapper); |
| 94 } | 94 } |
| 95 | 95 |
| 96 template<> | 96 template<> |
| 97 Dart_Handle DartCustomElementWrapper<HTMLElement>::upgradeDartWrapper(HTMLElemen
t* element, Dart_Handle (*createSpecificWrapper)(DartDOMData*, HTMLElement*)) | 97 Dart_Handle DartCustomElementWrapper<HTMLElement>::swapElementWrapper(DartDOMDat
a* domData, HTMLElement* element, Dart_Handle wrapperType, intptr_t nativeClassI
d) |
| 98 { | 98 { |
| 99 DartDOMData* domData = DartDOMData::current(); | |
| 100 DartCustomElementBinding* binding = domData->customElementBinding( | |
| 101 CustomElement::definitionFor(element)); | |
| 102 if (!binding) | |
| 103 return createUpgradeCandidateWrapper(element, createSpecificWrapper); | |
| 104 | |
| 105 Dart_PersistentHandle customType = binding->customType(); | |
| 106 ASSERT(!Dart_IsError(customType)); | |
| 107 | |
| 108 Dart_WeakPersistentHandle oldInstance = DartDOMWrapper::lookupWrapper<DartHT
MLElement>( | 99 Dart_WeakPersistentHandle oldInstance = DartDOMWrapper::lookupWrapper<DartHT
MLElement>( |
| 109 domData, reinterpret_cast<HTMLElement*>(element)); | 100 domData, reinterpret_cast<HTMLElement*>(element)); |
| 110 Dart_Handle oldWrapper = 0; | 101 Dart_Handle oldWrapper = 0; |
| 111 if (oldInstance) { | 102 if (oldInstance) { |
| 112 oldWrapper = Dart_HandleFromWeakPersistent(oldInstance); | 103 oldWrapper = Dart_HandleFromWeakPersistent(oldInstance); |
| 113 DartDOMWrapper::disassociateWrapper<DartHTMLElement>( | 104 DartDOMWrapper::disassociateWrapper<DartHTMLElement>( |
| 114 domData, | 105 domData, |
| 115 reinterpret_cast<HTMLElement*>(element), | 106 reinterpret_cast<HTMLElement*>(element), |
| 116 oldWrapper); | 107 oldWrapper); |
| 117 } | 108 } |
| 118 | 109 |
| 119 Dart_Handle newInstance = Dart_Allocate(customType); | 110 Dart_Handle newWrapper = Dart_Allocate(wrapperType); |
| 120 ASSERT(!Dart_IsError(newInstance)); | 111 ASSERT(!Dart_IsError(newWrapper)); |
| 121 DartDOMWrapper::writeNativePointer(newInstance, element, binding->nativeClas
sId()); | 112 DartDOMWrapper::writeNativePointer(newWrapper, element, nativeClassId); |
| 122 | 113 |
| 123 Dart_Handle result = Dart_InvokeConstructor(newInstance, Dart_NewStringFromC
String("created"), 0, 0); | 114 Dart_Handle result = Dart_InvokeConstructor(newWrapper, Dart_NewStringFromCS
tring("created"), 0, 0); |
| 124 | 115 |
| 125 if (Dart_IsError(result)) { | 116 if (Dart_IsError(result)) { |
| 126 DartUtilities::reportProblem(domData->scriptExecutionContext(), result); | 117 DartUtilities::reportProblem(domData->scriptExecutionContext(), result); |
| 127 | 118 |
| 128 // Fall back to the old wrapper if possible. | 119 // Fall back to the old wrapper if possible. |
| 129 if (oldWrapper) { | 120 if (oldWrapper) { |
| 130 DartDOMWrapper::associateWrapper<DartHTMLElement>(domData, element,
oldWrapper); | 121 DartDOMWrapper::associateWrapper<DartHTMLElement>(domData, element,
oldWrapper); |
| 131 return oldWrapper; | 122 return oldWrapper; |
| 132 } | 123 } |
| 124 return result; |
| 125 } |
| 126 return newWrapper; |
| 127 } |
| 133 | 128 |
| 129 template<> |
| 130 Dart_Handle DartCustomElementWrapper<HTMLElement>::upgradeDartWrapper(HTMLElemen
t* element, Dart_Handle (*createSpecificWrapper)(DartDOMData*, HTMLElement*)) |
| 131 { |
| 132 DartDOMData* domData = DartDOMData::current(); |
| 133 DartCustomElementBinding* binding = domData->customElementBinding(CustomElem
ent::definitionFor(element)); |
| 134 if (!binding) |
| 135 return createUpgradeCandidateWrapper(element, createSpecificWrapper); |
| 136 |
| 137 Dart_PersistentHandle customType = binding->customType(); |
| 138 ASSERT(!Dart_IsError(customType)); |
| 139 |
| 140 Dart_Handle newWrapper = swapElementWrapper(domData, element, customType, bi
nding->nativeClassId()); |
| 141 if (Dart_IsError(newWrapper)) { |
| 134 // When the upgrade fails the failed wrapper may have been associated, | 142 // When the upgrade fails the failed wrapper may have been associated, |
| 135 // so we need to create a new one and re-associate it. | 143 // so we need to create a new one and re-associate it. |
| 136 Dart_Handle fallbackWrapper = createUpgradeCandidateWrapper(element, cre
ateSpecificWrapper); | 144 Dart_Handle fallbackWrapper = createUpgradeCandidateWrapper(element, cre
ateSpecificWrapper); |
| 137 | 145 |
| 138 DartDOMWrapper::associateWrapper<DartHTMLElement>(domData, element, fall
backWrapper); | 146 DartDOMWrapper::associateWrapper<DartHTMLElement>(domData, element, fall
backWrapper); |
| 139 DartDOMWrapper::writeNativePointer(fallbackWrapper, element, binding->na
tiveClassId()); | 147 DartDOMWrapper::writeNativePointer(fallbackWrapper, element, binding->na
tiveClassId()); |
| 140 return fallbackWrapper; | 148 return fallbackWrapper; |
| 141 } | 149 } |
| 142 return newInstance; | 150 return newWrapper; |
| 143 } | 151 } |
| 144 | 152 |
| 145 template<> | 153 template<> |
| 154 Dart_Handle DartCustomElementWrapper<HTMLElement>::changeElementWrapper(Dart_Han
dle element, Dart_Handle wrapperType) |
| 155 { |
| 156 DartDOMData* domData = DartDOMData::current(); |
| 157 |
| 158 intptr_t nativeClassId = reinterpret_cast<intptr_t>(DartDOMWrapper::readNati
vePointer(element, DartDOMWrapper::kNativeTypeIndex)); |
| 159 Dart_Handle exception = 0; |
| 160 HTMLElement* nativeElement = DartDOMWrapper::unwrapDartWrapper<DartHTMLEleme
nt>(domData, element, exception); |
| 161 if (exception) { |
| 162 return exception; |
| 163 } |
| 164 return swapElementWrapper(domData, nativeElement, wrapperType, nativeClassId
); |
| 165 } |
| 166 |
| 167 template<> |
| 146 Dart_Handle DartCustomElementWrapper<SVGElement>::upgradeDartWrapper(SVGElement*
element, Dart_Handle (*createSpecificWrapper)(DartDOMData*, SVGElement*)) | 168 Dart_Handle DartCustomElementWrapper<SVGElement>::upgradeDartWrapper(SVGElement*
element, Dart_Handle (*createSpecificWrapper)(DartDOMData*, SVGElement*)) |
| 147 { | 169 { |
| 148 // TODO: support SVG elements. | 170 // TODO: support SVG elements. |
| 149 ASSERT(FALSE); | 171 ASSERT(FALSE); |
| 150 return Dart_Handle(); | 172 return Dart_Handle(); |
| 151 } | 173 } |
| 152 | 174 |
| 153 template<> | 175 template<> |
| 154 void DartCustomElementWrapper<HTMLElement>::initializeCustomElement(Dart_Handle
wrapper, Dart_Handle& exception) | 176 void DartCustomElementWrapper<HTMLElement>::initializeCustomElement(Dart_Handle
wrapper, Dart_Handle& exception) |
| 155 { | 177 { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 173 ASSERT(FALSE); | 195 ASSERT(FALSE); |
| 174 } | 196 } |
| 175 | 197 |
| 176 template | 198 template |
| 177 class DartCustomElementWrapper<HTMLElement>; | 199 class DartCustomElementWrapper<HTMLElement>; |
| 178 | 200 |
| 179 template | 201 template |
| 180 class DartCustomElementWrapper<SVGElement>; | 202 class DartCustomElementWrapper<SVGElement>; |
| 181 | 203 |
| 182 } // namespace WebCore | 204 } // namespace WebCore |
| OLD | NEW |