Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / dom / ScriptLoader.h
1 /*
2  * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  *
19  */
20
21 #ifndef ScriptLoader_h
22 #define ScriptLoader_h
23
24 #include "core/fetch/ResourceClient.h"
25 #include "core/fetch/ResourcePtr.h"
26 #include "wtf/text/TextPosition.h"
27 #include "wtf/text/WTFString.h"
28
29 namespace blink {
30
31 class ScriptResource;
32 class Element;
33 class ScriptLoaderClient;
34 class ScriptSourceCode;
35
36
37 class ScriptLoader FINAL : private ResourceClient {
38 public:
39     static PassOwnPtr<ScriptLoader> create(Element*, bool createdByParser, bool isEvaluated);
40     virtual ~ScriptLoader();
41
42     Element* element() const { return m_element; }
43
44     enum LegacyTypeSupport { DisallowLegacyTypeInTypeAttribute, AllowLegacyTypeInTypeAttribute };
45     bool prepareScript(const TextPosition& scriptStartPosition = TextPosition::minimumPosition(), LegacyTypeSupport = DisallowLegacyTypeInTypeAttribute);
46
47     String scriptCharset() const { return m_characterEncoding; }
48     String scriptContent() const;
49     void executeScript(const ScriptSourceCode&);
50     void execute(ScriptResource*);
51
52     // XML parser calls these
53     void dispatchLoadEvent();
54     void dispatchErrorEvent();
55     bool isScriptTypeSupported(LegacyTypeSupport) const;
56
57     bool haveFiredLoadEvent() const { return m_haveFiredLoad; }
58     bool willBeParserExecuted() const { return m_willBeParserExecuted; }
59     bool readyToBeParserExecuted() const { return m_readyToBeParserExecuted; }
60     bool willExecuteWhenDocumentFinishedParsing() const { return m_willExecuteWhenDocumentFinishedParsing; }
61     ResourcePtr<ScriptResource> resource() { return m_resource; }
62
63     void setHaveFiredLoadEvent(bool haveFiredLoad) { m_haveFiredLoad = haveFiredLoad; }
64     bool isParserInserted() const { return m_parserInserted; }
65     bool alreadyStarted() const { return m_alreadyStarted; }
66     bool forceAsync() const { return m_forceAsync; }
67
68     // Helper functions used by our parent classes.
69     void didNotifySubtreeInsertionsToDocument();
70     void childrenChanged();
71     void handleSourceAttribute(const String& sourceUrl);
72     void handleAsyncAttribute();
73
74 private:
75     ScriptLoader(Element*, bool createdByParser, bool isEvaluated);
76
77     bool ignoresLoadRequest() const;
78     bool isScriptForEventSupported() const;
79
80     bool fetchScript(const String& sourceUrl);
81     void stopLoadRequest();
82
83     ScriptLoaderClient* client() const;
84
85     // ResourceClient
86     virtual void notifyFinished(Resource*) OVERRIDE;
87
88     // FIXME: Oilpan: This should become a Member once ResourceClient is moved to the heap.
89     Element* m_element;
90     ResourcePtr<ScriptResource> m_resource;
91     WTF::OrdinalNumber m_startLineNumber;
92     bool m_parserInserted : 1;
93     bool m_isExternalScript : 1;
94     bool m_alreadyStarted : 1;
95     bool m_haveFiredLoad : 1;
96     bool m_willBeParserExecuted : 1; // Same as "The parser will handle executing the script."
97     bool m_readyToBeParserExecuted : 1;
98     bool m_willExecuteWhenDocumentFinishedParsing : 1;
99     bool m_forceAsync : 1;
100     bool m_willExecuteInOrder : 1;
101     String m_characterEncoding;
102     String m_fallbackCharacterEncoding;
103 };
104
105 ScriptLoader* toScriptLoaderIfPossible(Element*);
106
107 inline PassOwnPtr<ScriptLoader> ScriptLoader::create(Element* element, bool createdByParser, bool isEvaluated)
108 {
109     return adoptPtr(new ScriptLoader(element, createdByParser, isEvaluated));
110 }
111
112 }
113
114
115 #endif