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

Side by Side Diff: sky/engine/core/dom/custom/CustomElementRegistry.cpp

Issue 922893002: Merge the Sky Engine changes from the SkyDart branch (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
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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "sky/engine/config.h" 31 #include "sky/engine/config.h"
32 #include "sky/engine/core/dom/custom/CustomElementRegistry.h" 32 #include "sky/engine/core/dom/custom/CustomElementRegistry.h"
33 33
34 #include "sky/engine/bindings/core/v8/CustomElementConstructorBuilder.h"
35 #include "sky/engine/core/dom/DocumentLifecycleObserver.h" 34 #include "sky/engine/core/dom/DocumentLifecycleObserver.h"
36 #include "sky/engine/core/dom/custom/CustomElementException.h" 35 #include "sky/engine/core/dom/custom/CustomElementException.h"
37 #include "sky/engine/core/dom/custom/CustomElementRegistrationContext.h" 36 #include "sky/engine/core/dom/custom/CustomElementRegistrationContext.h"
38 37
39 namespace blink { 38 namespace blink {
40 39
41 class RegistrationContextObserver : public DocumentLifecycleObserver { 40 class RegistrationContextObserver : public DocumentLifecycleObserver {
42 public: 41 public:
43 explicit RegistrationContextObserver(Document* document) 42 explicit RegistrationContextObserver(Document* document)
44 : DocumentLifecycleObserver(document) 43 : DocumentLifecycleObserver(document)
45 , m_wentAway(!document) 44 , m_wentAway(!document)
46 { 45 {
47 } 46 }
48 47
49 bool registrationContextWentAway() { return m_wentAway; } 48 bool registrationContextWentAway() { return m_wentAway; }
50 49
51 private: 50 private:
52 #if ENABLE(OILPAN) 51 #if ENABLE(OILPAN)
53 // In oilpan we don't have the disposed phase for context lifecycle observer . 52 // In oilpan we don't have the disposed phase for context lifecycle observer .
54 virtual void documentWasDetached() override { m_wentAway = true; } 53 virtual void documentWasDetached() override { m_wentAway = true; }
55 #else 54 #else
56 virtual void documentWasDisposed() override { m_wentAway = true; } 55 virtual void documentWasDisposed() override { m_wentAway = true; }
57 #endif 56 #endif
58 57
59 bool m_wentAway; 58 bool m_wentAway;
60 }; 59 };
61 60
62 CustomElementDefinition* CustomElementRegistry::registerElement(Document* docume nt, CustomElementConstructorBuilder* constructorBuilder, const AtomicString& use rSuppliedName, ExceptionState& exceptionState) 61 CustomElementDefinition* CustomElementRegistry::registerElement(Document* docume nt, CustomElementConstructorBuilder* constructorBuilder, const AtomicString& use rSuppliedName, ExceptionState& exceptionState)
63 { 62 {
64 // FIXME: In every instance except one it is the 63 // TODO(dart): Figure out how to register a custom element.
65 // CustomElementConstructorBuilder that observes document 64 return 0;
66 // destruction during registration. This responsibility should be
67 // consolidated in one place.
68 RegistrationContextObserver observer(document);
69
70 AtomicString type = userSuppliedName.lower();
71
72 if (!CustomElement::isValidName(type)) {
73 CustomElementException::throwException(CustomElementException::InvalidNa me, type, exceptionState);
74 return 0;
75 }
76
77 if (m_definitions.contains(type)) {
78 CustomElementException::throwException(CustomElementException::TypeAlrea dyRegistered, type, exceptionState);
79 return 0;
80 }
81
82 QualifiedName tagName = nullName;
83 if (!constructorBuilder->validateOptions(type, tagName, exceptionState))
84 return 0;
85
86 ASSERT(!observer.registrationContextWentAway());
87
88 RefPtr<CustomElementLifecycleCallbacks> lifecycleCallbacks = constructorBuil der->createCallbacks();
89
90 // Consulting the constructor builder could execute script and
91 // kill the document.
92 if (observer.registrationContextWentAway()) {
93 CustomElementException::throwException(CustomElementException::ContextDe stroyedCreatingCallbacks, type, exceptionState);
94 return 0;
95 }
96
97 RefPtr<CustomElementDefinition> definition = CustomElementDefinition::create (tagName.localName(), lifecycleCallbacks);
98
99 if (!constructorBuilder->createConstructor(document, definition.get(), excep tionState))
100 return 0;
101
102 m_definitions.add(tagName.localName(), definition);
103
104 if (!constructorBuilder->didRegisterDefinition(definition.get())) {
105 CustomElementException::throwException(CustomElementException::ContextDe stroyedRegisteringDefinition, type, exceptionState);
106 return 0;
107 }
108
109 return definition.get();
110 } 65 }
111 66
112 CustomElementDefinition* CustomElementRegistry::find(const AtomicString& localNa me) const 67 CustomElementDefinition* CustomElementRegistry::find(const AtomicString& localNa me) const
113 { 68 {
114 return m_definitions.get(localName); 69 return m_definitions.get(localName);
115 } 70 }
116 71
117 } // namespace blink 72 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/dom/custom/CustomElementRegistrationContext.cpp ('k') | sky/engine/core/dom/shadow/ShadowRoot.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698