| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sky/engine/config.h" | 5 #include "sky/engine/config.h" |
| 6 #include "sky/engine/core/dom/custom2/new_custom_element_registry.h" | 6 #include "sky/engine/core/dom/custom/custom_element_registry.h" |
| 7 | 7 |
| 8 #include "sky/engine/core/dom/Element.h" | 8 #include "sky/engine/core/dom/Element.h" |
| 9 #include "sky/engine/core/html/HTMLElement.h" | 9 #include "sky/engine/core/html/HTMLElement.h" |
| 10 | 10 |
| 11 namespace blink { | 11 namespace blink { |
| 12 | 12 |
| 13 NewCustomElementRegistry::NewCustomElementRegistry() { | 13 CustomElementRegistry::CustomElementRegistry() { |
| 14 } | 14 } |
| 15 | 15 |
| 16 NewCustomElementRegistry::~NewCustomElementRegistry() { | 16 CustomElementRegistry::~CustomElementRegistry() { |
| 17 } | 17 } |
| 18 | 18 |
| 19 void NewCustomElementRegistry::RegisterElement(const AtomicString& name, | 19 void CustomElementRegistry::RegisterElement(const AtomicString& name, |
| 20 PassRefPtr<DartValue> type) { | 20 PassRefPtr<DartValue> type) { |
| 21 if (!dart_state_) | 21 if (!dart_state_) |
| 22 dart_state_ = type->dart_state(); | 22 dart_state_ = type->dart_state(); |
| 23 DCHECK(dart_state_.get() == type->dart_state().get()); | 23 DCHECK(dart_state_.get() == type->dart_state().get()); |
| 24 | 24 |
| 25 auto result = registrations_.add(name, type); | 25 auto result = registrations_.add(name, type); |
| 26 if (!result.isNewEntry) { | 26 if (!result.isNewEntry) { |
| 27 // TODO(abarth): Handle the case of multiple registrations. | 27 // TODO(abarth): Handle the case of multiple registrations. |
| 28 } | 28 } |
| 29 } | 29 } |
| 30 | 30 |
| 31 PassRefPtr<Element> NewCustomElementRegistry::CreateElement( | 31 PassRefPtr<Element> CustomElementRegistry::CreateElement( |
| 32 Document& document, const AtomicString& name) { | 32 Document& document, const AtomicString& name) { |
| 33 const auto& it = registrations_.find(name); | 33 const auto& it = registrations_.find(name); |
| 34 if (it != registrations_.end()) { | 34 if (it != registrations_.end()) { |
| 35 DartState::Scope scope(dart_state_.get()); | 35 DartState::Scope scope(dart_state_.get()); |
| 36 Dart_Handle type = it->value->dart_value(); | 36 Dart_Handle type = it->value->dart_value(); |
| 37 Dart_Handle wrapper = Dart_New(type, Dart_EmptyString(), 0, nullptr); | 37 Dart_Handle wrapper = Dart_New(type, Dart_EmptyString(), 0, nullptr); |
| 38 if (!LogIfError(wrapper)) { | 38 if (!LogIfError(wrapper)) { |
| 39 RefPtr<Element> element = DartConverter<Element*>::FromDart(wrapper); | 39 RefPtr<Element> element = DartConverter<Element*>::FromDart(wrapper); |
| 40 DCHECK(element); | 40 DCHECK(element); |
| 41 DCHECK(element->isUpgradedCustomElement()); | 41 DCHECK(element->isUpgradedCustomElement()); |
| 42 return element.release(); | 42 return element.release(); |
| 43 } | 43 } |
| 44 } | 44 } |
| 45 return HTMLElement::create(QualifiedName(name), document); | 45 return HTMLElement::create(QualifiedName(name), document); |
| 46 } | 46 } |
| 47 | 47 |
| 48 } // namespace blink | 48 } // namespace blink |
| OLD | NEW |