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

Side by Side Diff: sky/engine/bindings-dart/core/dart/DartCustomElementConstructorBuilder.cpp

Issue 918273002: Remove bindings-dart (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2013 Google Inc. 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
31 #include "config.h"
32 #include "bindings/core/dart/DartCustomElementConstructorBuilder.h"
33
34 #include "core/HTMLNames.h"
35 #include "core/SVGNames.h"
36 #include "bindings/core/dart/DartCustomElementBinding.h"
37 #include "bindings/core/dart/DartCustomElementLifecycleCallbacks.h"
38 #include "bindings/core/dart/DartDOMData.h"
39 #include "bindings/core/dart/DartDOMWrapper.h"
40 #include "bindings/core/dart/DartHTMLElement.h"
41 #include "bindings/core/dart/DartUtilities.h"
42 #include "bindings/core/v8/V8Binding.h"
43 #include "bindings/dart/DartWebkitClassIds.h"
44 #include "core/dom/Document.h"
45 #include "core/dom/custom/CustomElementException.h"
46
47 namespace blink {
48
49 DartCustomElementConstructorBuilder::DartCustomElementConstructorBuilder(Dart_Ha ndle customType, const AtomicString& extendsTagName, DartScriptState* state, con st Dictionary* options)
50 : CustomElementConstructorBuilder(state, options)
51 , m_customType(customType)
52 , m_nativeClassId(_InvalidClassId)
53 , m_extendsTagName(extendsTagName)
54 , m_scriptState(state)
55 {
56 }
57
58 bool DartCustomElementConstructorBuilder::isFeatureAllowed() const
59 {
60 // Check that we are in the main world
61 return DartDOMData::current()->isDOMEnabled();
62 }
63
64 bool DartCustomElementConstructorBuilder::validateOptions(const AtomicString& ty pe, QualifiedName& tagName, ExceptionState& es)
65 {
66 AtomicString namespaceURI;
67 DartDOMData* domData = DartDOMData::current();
68
69 if (DartUtilities::isTypeSubclassOf(m_customType, domData->htmlLibrary(), "H tmlElement")) {
70 namespaceURI = HTMLNames::xhtmlNamespaceURI;
71 } else if (DartUtilities::isTypeSubclassOf(m_customType, domData->svgLibrary (), "SvgElement")) {
72 //namespaceURI = SVGNames::svgNamespaceURI;
73 // TODO(blois): Support SVG custom elements.
74 CustomElementException::throwException(CustomElementException::ExtendsIs InvalidName, type, es);
75 return false;
76 } else {
77 CustomElementException::throwException(CustomElementException::ExtendsIs InvalidName, type, es);
78 return false;
79 }
80
81 AtomicString localName;
82 if (!m_extendsTagName.isNull() && !m_extendsTagName.isEmpty()) {
83 localName = m_extendsTagName.lower();
84
85 Dart_Handle nativeElement = DartUtilities::getAndValidateNativeType(m_cu stomType, m_extendsTagName);
86 if (!nativeElement || Dart_IsNull(nativeElement)) {
87 CustomElementException::throwException(CustomElementException::Exten dsIsInvalidName, type, es);
88 return false;
89 }
90
91 m_nativeClassId = reinterpret_cast<intptr_t>(DartDOMWrapper::readNativeP ointer(nativeElement, DartDOMWrapper::NativeTypeIndex));
92
93 if (!Document::isValidName(localName)) {
94 CustomElementException::throwException(CustomElementException::Exten dsIsInvalidName, type, es);
95 return false;
96 }
97 if (CustomElement::isValidName(localName)) {
98 CustomElementException::throwException(CustomElementException::Exten dsIsCustomElementName, type, es);
99 return false;
100 }
101 } else {
102 localName = type;
103 m_nativeClassId = DartHTMLElement::dartClassId;
104 }
105
106 m_localName = localName;
107 m_namespaceURI = namespaceURI;
108 findTagName(type, tagName);
109 return true;
110 }
111
112 bool DartCustomElementConstructorBuilder::findTagName(const AtomicString& custom ElementType, QualifiedName& tagName)
113 {
114 if (!m_extendsTagName.isNull() && !m_extendsTagName.isEmpty()) {
115 tagName = QualifiedName(nullAtom, m_extendsTagName, m_namespaceURI);
116 } else {
117 tagName = QualifiedName(nullAtom, m_localName, m_namespaceURI);
118 }
119 return true;
120 }
121
122 PassRefPtr<CustomElementLifecycleCallbacks> DartCustomElementConstructorBuilder: :createCallbacks()
123 {
124 m_callbacks = DartCustomElementLifecycleCallbacks::create(m_scriptState.get( ));
125 return m_callbacks.get();
126 }
127
128 bool DartCustomElementConstructorBuilder::createConstructor(Document* document, CustomElementDefinition* definition, ExceptionState& es)
129 {
130 return true;
131 }
132
133 bool DartCustomElementConstructorBuilder::didRegisterDefinition(CustomElementDef inition* definition) const
134 {
135 return m_callbacks->setBinding(definition, DartCustomElementBinding::create( m_customType, m_nativeClassId));
136 }
137
138 ScriptValue DartCustomElementConstructorBuilder::bindingsReturnValue() const
139 {
140 // Dart does not return a constructor.
141 return ScriptValue();
142 }
143 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698