Index: sky/engine/core/dom/custom2/new_custom_element_registry.cc |
diff --git a/sky/engine/core/dom/custom2/new_custom_element_registry.cc b/sky/engine/core/dom/custom2/new_custom_element_registry.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..171d0203f7f045d95e89db2e313a826b38c3390d |
--- /dev/null |
+++ b/sky/engine/core/dom/custom2/new_custom_element_registry.cc |
@@ -0,0 +1,48 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "sky/engine/config.h" |
+#include "sky/engine/core/dom/custom2/new_custom_element_registry.h" |
+ |
+#include "sky/engine/core/dom/Element.h" |
+#include "sky/engine/core/html/HTMLElement.h" |
+ |
+namespace blink { |
+ |
+NewCustomElementRegistry::NewCustomElementRegistry() { |
+} |
+ |
+NewCustomElementRegistry::~NewCustomElementRegistry() { |
+} |
+ |
+void NewCustomElementRegistry::RegisterElement(const AtomicString& name, |
+ PassRefPtr<DartValue> type) { |
+ if (!dart_state_) |
+ dart_state_ = type->dart_state(); |
+ DCHECK(dart_state_.get() == type->dart_state().get()); |
+ |
+ auto result = registrations_.add(name, type); |
+ if (!result.isNewEntry) { |
+ // TODO(abarth): Handle the case of multiple registrations. |
+ } |
+} |
+ |
+PassRefPtr<Element> NewCustomElementRegistry::CreateElement( |
+ Document& document, const AtomicString& name) { |
+ const auto& it = registrations_.find(name); |
+ if (it != registrations_.end()) { |
+ DartState::Scope scope(dart_state_.get()); |
+ Dart_Handle type = it->value->dart_value(); |
+ Dart_Handle wrapper = Dart_New(type, Dart_EmptyString(), 0, nullptr); |
+ if (!LogIfError(wrapper)) { |
+ RefPtr<Element> element = DartConverter<Element*>::FromDart(wrapper); |
+ DCHECK(element); |
+ DCHECK(element->isUpgradedCustomElement()); |
+ return element.release(); |
+ } |
+ } |
+ return HTMLElement::create(QualifiedName(name), document); |
+} |
+ |
+} // namespace blink |