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

Side by Side Diff: Source/core/dom/ScriptLoader.h

Issue 271533002: Make ScriptLoader into a ResourceOwner (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details. 12 * Library General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU Library General Public License 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 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, 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA. 17 * Boston, MA 02110-1301, USA.
18 * 18 *
19 */ 19 */
20 20
21 #ifndef ScriptLoader_h 21 #ifndef ScriptLoader_h
22 #define ScriptLoader_h 22 #define ScriptLoader_h
23 23
24 #include "core/fetch/ResourceClient.h" 24 #include "core/fetch/ResourceClient.h"
25 #include "core/fetch/ResourceOwner.h"
25 #include "core/fetch/ResourcePtr.h" 26 #include "core/fetch/ResourcePtr.h"
27 #include "core/fetch/ScriptResource.h"
26 #include "wtf/text/TextPosition.h" 28 #include "wtf/text/TextPosition.h"
27 #include "wtf/text/WTFString.h" 29 #include "wtf/text/WTFString.h"
28 30
29 namespace WebCore { 31 namespace WebCore {
30 32
31 class ScriptResource; 33 class ScriptResource;
32 class ContainerNode; 34 class ContainerNode;
33 class Document; 35 class Document;
34 class Element; 36 class Element;
35 class ScriptLoaderClient; 37 class ScriptLoaderClient;
38 class ScriptRunner;
36 class ScriptSourceCode; 39 class ScriptSourceCode;
37 40
38 41 class ScriptLoader FINAL : public ResourceOwner<ScriptResource> {
39 class ScriptLoader FINAL : private ResourceClient {
40 public: 42 public:
41 static PassOwnPtr<ScriptLoader> create(Element*, bool createdByParser, bool isEvaluated); 43 static PassOwnPtr<ScriptLoader> create(Element*, bool createdByParser, bool isEvaluated);
42 virtual ~ScriptLoader(); 44 virtual ~ScriptLoader();
43 45
44 Element* element() const { return m_element; } 46 Element* element() const { return m_element; }
45 47
46 enum LegacyTypeSupport { DisallowLegacyTypeInTypeAttribute, AllowLegacyTypeI nTypeAttribute }; 48 enum LegacyTypeSupport { DisallowLegacyTypeInTypeAttribute, AllowLegacyTypeI nTypeAttribute };
47 bool prepareScript(const TextPosition& scriptStartPosition = TextPosition::m inimumPosition(), LegacyTypeSupport = DisallowLegacyTypeInTypeAttribute); 49 bool prepareScript(ResourcePtr<ScriptResource>* = 0, const TextPosition& scr iptStartPosition = TextPosition::minimumPosition(), LegacyTypeSupport = Disallow LegacyTypeInTypeAttribute);
Nate Chapin 2014/05/07 18:13:10 It looks like the return value will be false if th
Hajime Morrita 2014/05/07 18:27:28 Sometimes it can be true but return null. I agree
48 50
49 String scriptCharset() const { return m_characterEncoding; } 51 String scriptCharset() const { return m_characterEncoding; }
50 String scriptContent() const; 52 String scriptContent() const;
51 void executeScript(const ScriptSourceCode&); 53 void executeScript(const ScriptSourceCode&);
52 void execute(ScriptResource*); 54 void execute(ScriptResource*);
53 55
54 // XML parser calls these 56 // XML parser calls these
55 void dispatchLoadEvent(); 57 void dispatchLoadEvent();
56 void dispatchErrorEvent(); 58 void dispatchErrorEvent();
57 bool isScriptTypeSupported(LegacyTypeSupport) const; 59 bool isScriptTypeSupported(LegacyTypeSupport) const;
58 60
59 bool haveFiredLoadEvent() const { return m_haveFiredLoad; } 61 bool haveFiredLoadEvent() const { return m_haveFiredLoad; }
60 bool willBeParserExecuted() const { return m_willBeParserExecuted; } 62 bool willBeParserExecuted() const { return m_willBeParserExecuted; }
61 bool readyToBeParserExecuted() const { return m_readyToBeParserExecuted; } 63 bool readyToBeParserExecuted() const { return m_readyToBeParserExecuted; }
62 bool willExecuteWhenDocumentFinishedParsing() const { return m_willExecuteWh enDocumentFinishedParsing; } 64 bool willExecuteWhenDocumentFinishedParsing() const { return m_willExecuteWh enDocumentFinishedParsing; }
63 ResourcePtr<ScriptResource> resource() { return m_resource; }
64 65
65 void setHaveFiredLoadEvent(bool haveFiredLoad) { m_haveFiredLoad = haveFired Load; } 66 void setHaveFiredLoadEvent(bool haveFiredLoad) { m_haveFiredLoad = haveFired Load; }
66 bool isParserInserted() const { return m_parserInserted; } 67 bool isParserInserted() const { return m_parserInserted; }
67 bool alreadyStarted() const { return m_alreadyStarted; } 68 bool alreadyStarted() const { return m_alreadyStarted; }
68 bool forceAsync() const { return m_forceAsync; } 69 bool forceAsync() const { return m_forceAsync; }
69 70
70 // Helper functions used by our parent classes. 71 // Helper functions used by our parent classes.
71 void didNotifySubtreeInsertionsToDocument(); 72 void didNotifySubtreeInsertionsToDocument();
72 void childrenChanged(); 73 void childrenChanged();
73 void handleSourceAttribute(const String& sourceUrl); 74 void handleSourceAttribute(const String& sourceUrl);
74 void handleAsyncAttribute(); 75 void handleAsyncAttribute();
75 void cancel(Document* contextDocument); 76 void cancel(Document* contextDocument);
76 77
77 private: 78 private:
78 ScriptLoader(Element*, bool createdByParser, bool isEvaluated); 79 ScriptLoader(Element*, bool createdByParser, bool isEvaluated);
79 80
80 bool ignoresLoadRequest() const; 81 bool ignoresLoadRequest() const;
81 bool isScriptForEventSupported() const; 82 bool isScriptForEventSupported() const;
82 83
83 bool fetchScript(const String& sourceUrl); 84 ResourcePtr<ScriptResource> fetchScript(const String& sourceUrl);
84 void stopLoadRequest();
85 85
86 ScriptLoaderClient* client() const; 86 ScriptLoaderClient* client() const;
87 87
88 // ResourceClient 88 // ResourceClient
89 virtual void notifyFinished(Resource*) OVERRIDE; 89 virtual void notifyFinished(Resource*) OVERRIDE;
90 90
91 enum FinishType { 91 enum FinishType {
92 FinishSuccessfully, 92 FinishSuccessfully,
93 FinishWithCancel, 93 FinishWithCancel,
94 FinishWithError 94 FinishWithError
95 }; 95 };
96 96
97 void finishLoading(Document* contextDocument, FinishType); 97 void finishLoading(Document* contextDocument, FinishType);
98 void notifyRunnerFinishLoading(ScriptRunner*, FinishType);
98 99
99 Element* m_element; 100 Element* m_element;
100 ResourcePtr<ScriptResource> m_resource;
101 WTF::OrdinalNumber m_startLineNumber; 101 WTF::OrdinalNumber m_startLineNumber;
102 bool m_parserInserted : 1; 102 bool m_parserInserted : 1;
103 bool m_isExternalScript : 1; 103 bool m_isExternalScript : 1;
104 bool m_alreadyStarted : 1; 104 bool m_alreadyStarted : 1;
105 bool m_haveFiredLoad : 1; 105 bool m_haveFiredLoad : 1;
106 bool m_willBeParserExecuted : 1; // Same as "The parser will handle executin g the script." 106 bool m_willBeParserExecuted : 1; // Same as "The parser will handle executin g the script."
107 bool m_readyToBeParserExecuted : 1; 107 bool m_readyToBeParserExecuted : 1;
108 bool m_willExecuteWhenDocumentFinishedParsing : 1; 108 bool m_willExecuteWhenDocumentFinishedParsing : 1;
109 bool m_forceAsync : 1; 109 bool m_forceAsync : 1;
110 bool m_willExecuteInOrder : 1; 110 bool m_willExecuteInOrder : 1;
111 String m_characterEncoding; 111 String m_characterEncoding;
112 String m_fallbackCharacterEncoding; 112 String m_fallbackCharacterEncoding;
113 }; 113 };
114 114
115 ScriptLoader* toScriptLoaderIfPossible(Element*); 115 ScriptLoader* toScriptLoaderIfPossible(Element*);
116 116
117 inline PassOwnPtr<ScriptLoader> ScriptLoader::create(Element* element, bool crea tedByParser, bool isEvaluated) 117 inline PassOwnPtr<ScriptLoader> ScriptLoader::create(Element* element, bool crea tedByParser, bool isEvaluated)
118 { 118 {
119 return adoptPtr(new ScriptLoader(element, createdByParser, isEvaluated)); 119 return adoptPtr(new ScriptLoader(element, createdByParser, isEvaluated));
120 } 120 }
121 121
122 } 122 }
123 123
124 124
125 #endif 125 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698