Upstream version 5.34.98.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / bindings / v8 / CustomElementConstructorBuilder.h
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 #ifndef CustomElementConstructorBuilder_h
32 #define CustomElementConstructorBuilder_h
33
34 #include "bindings/v8/ScriptValue.h"
35 #include "bindings/v8/V8CustomElementLifecycleCallbacks.h"
36 #include "core/dom/QualifiedName.h"
37 #include "core/dom/custom/CustomElementLifecycleCallbacks.h"
38 #include "wtf/Noncopyable.h"
39 #include "wtf/PassRefPtr.h"
40 #include "wtf/RefPtr.h"
41 #include "wtf/text/AtomicString.h"
42 #include <v8.h>
43
44 namespace WebCore {
45
46 class CustomElementDefinition;
47 class Dictionary;
48 class Document;
49 class Element;
50 class ExceptionState;
51 class QualifiedName;
52 class ScriptState;
53 class V8PerContextData;
54 struct WrapperTypeInfo;
55
56 // Handles the scripting-specific parts of the Custom Elements element
57 // registration algorithm and constructor generation algorithm. It is
58 // used in the implementation of those algorithms in
59 // Document::registerElement.
60 class CustomElementConstructorBuilder {
61     WTF_MAKE_NONCOPYABLE(CustomElementConstructorBuilder);
62 public:
63     CustomElementConstructorBuilder(ScriptState*, const Dictionary* options);
64
65     // The builder accumulates state and may run script at specific
66     // points. These methods must be called in order. When one fails
67     // (returns false), the calls must stop.
68
69     bool isFeatureAllowed() const;
70     bool validateOptions(const AtomicString& type, QualifiedName& tagName, ExceptionState&);
71     PassRefPtr<CustomElementLifecycleCallbacks> createCallbacks();
72     bool createConstructor(Document*, CustomElementDefinition*, ExceptionState&);
73     bool didRegisterDefinition(CustomElementDefinition*) const;
74
75     // This method collects a return value for the bindings. It is
76     // safe to call this method even if the builder failed; it will
77     // return an empty value.
78     ScriptValue bindingsReturnValue() const;
79
80 private:
81     bool hasValidPrototypeChainFor(const WrapperTypeInfo*) const;
82     bool prototypeIsValid(const AtomicString& type, ExceptionState&) const;
83     v8::Handle<v8::Function> retrieveCallback(v8::Isolate*, const char* name);
84
85     v8::Handle<v8::Context> m_context;
86     const Dictionary* m_options;
87     v8::Handle<v8::Object> m_prototype;
88     const WrapperTypeInfo* m_wrapperType;
89     v8::Handle<v8::Function> m_constructor;
90     RefPtr<V8CustomElementLifecycleCallbacks> m_callbacks;
91 };
92
93 }
94
95 #endif // CustomElementConstructorBuilder_h