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

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

Issue 656113002: Refactor Script(Loader|Runner): don't access Resources all over the place... (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: code review (haraken) Created 6 years, 2 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) 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/dom/PendingScript.h"
24 #include "core/fetch/FetchRequest.h" 25 #include "core/fetch/FetchRequest.h"
25 #include "core/fetch/ResourceClient.h" 26 #include "core/fetch/ResourceClient.h"
26 #include "core/fetch/ResourcePtr.h" 27 #include "core/fetch/ResourcePtr.h"
27 #include "core/fetch/ScriptResource.h" 28 #include "core/fetch/ScriptResource.h"
28 #include "wtf/text/TextPosition.h" 29 #include "wtf/text/TextPosition.h"
29 #include "wtf/text/WTFString.h" 30 #include "wtf/text/WTFString.h"
30 31
31 namespace blink { 32 namespace blink {
32 33
33 class Element; 34 class Element;
34 class ScriptLoaderClient; 35 class ScriptLoaderClient;
35 class ScriptSourceCode; 36 class ScriptSourceCode;
36 37
37 38
38 class ScriptLoader final : private ScriptResourceClient { 39 class ScriptLoader final : private ScriptResourceClient {
39 public: 40 public:
40 static PassOwnPtr<ScriptLoader> create(Element*, bool createdByParser, bool isEvaluated); 41 static PassOwnPtr<ScriptLoader> create(Element*, bool createdByParser, bool isEvaluated);
41 virtual ~ScriptLoader(); 42 virtual ~ScriptLoader();
42 43
43 Element* element() const { return m_element; } 44 Element* element() const { return m_element; }
44 45
45 enum LegacyTypeSupport { DisallowLegacyTypeInTypeAttribute, AllowLegacyTypeI nTypeAttribute }; 46 enum LegacyTypeSupport { DisallowLegacyTypeInTypeAttribute, AllowLegacyTypeI nTypeAttribute };
46 bool prepareScript(const TextPosition& scriptStartPosition = TextPosition::m inimumPosition(), LegacyTypeSupport = DisallowLegacyTypeInTypeAttribute); 47 bool prepareScript(const TextPosition& scriptStartPosition = TextPosition::m inimumPosition(), LegacyTypeSupport = DisallowLegacyTypeInTypeAttribute);
47 48
48 String scriptCharset() const { return m_characterEncoding; } 49 String scriptCharset() const { return m_characterEncoding; }
49 String scriptContent() const; 50 String scriptContent() const;
50 void executeScript(const ScriptSourceCode&, double* compilationFinishTime = 0); 51 void executeScript(const ScriptSourceCode&, double* compilationFinishTime = 0);
51 void execute(ScriptResource*); 52 void execute();
52 53
53 // XML parser calls these 54 // XML parser calls these
54 void dispatchLoadEvent(); 55 void dispatchLoadEvent();
55 void dispatchErrorEvent(); 56 void dispatchErrorEvent();
56 bool isScriptTypeSupported(LegacyTypeSupport) const; 57 bool isScriptTypeSupported(LegacyTypeSupport) const;
57 58
58 bool haveFiredLoadEvent() const { return m_haveFiredLoad; } 59 bool haveFiredLoadEvent() const { return m_haveFiredLoad; }
59 bool willBeParserExecuted() const { return m_willBeParserExecuted; } 60 bool willBeParserExecuted() const { return m_willBeParserExecuted; }
60 bool readyToBeParserExecuted() const { return m_readyToBeParserExecuted; } 61 bool readyToBeParserExecuted() const { return m_readyToBeParserExecuted; }
61 bool willExecuteWhenDocumentFinishedParsing() const { return m_willExecuteWh enDocumentFinishedParsing; } 62 bool willExecuteWhenDocumentFinishedParsing() const { return m_willExecuteWh enDocumentFinishedParsing; }
62 ResourcePtr<ScriptResource> resource() { return m_resource; } 63 ResourcePtr<ScriptResource> resource() { return m_resource; }
63 64
64 void setHaveFiredLoadEvent(bool haveFiredLoad) { m_haveFiredLoad = haveFired Load; } 65 void setHaveFiredLoadEvent(bool haveFiredLoad) { m_haveFiredLoad = haveFired Load; }
65 bool isParserInserted() const { return m_parserInserted; } 66 bool isParserInserted() const { return m_parserInserted; }
66 bool alreadyStarted() const { return m_alreadyStarted; } 67 bool alreadyStarted() const { return m_alreadyStarted; }
67 bool forceAsync() const { return m_forceAsync; } 68 bool forceAsync() const { return m_forceAsync; }
68 69
69 // Helper functions used by our parent classes. 70 // Helper functions used by our parent classes.
70 void didNotifySubtreeInsertionsToDocument(); 71 void didNotifySubtreeInsertionsToDocument();
71 void childrenChanged(); 72 void childrenChanged();
72 void handleSourceAttribute(const String& sourceUrl); 73 void handleSourceAttribute(const String& sourceUrl);
73 void handleAsyncAttribute(); 74 void handleAsyncAttribute();
74 75
76 bool isReady() const { return m_pendingScript.isReady(); }
77
75 private: 78 private:
76 ScriptLoader(Element*, bool createdByParser, bool isEvaluated); 79 ScriptLoader(Element*, bool createdByParser, bool isEvaluated);
77 80
78 bool ignoresLoadRequest() const; 81 bool ignoresLoadRequest() const;
79 bool isScriptForEventSupported() const; 82 bool isScriptForEventSupported() const;
80 83
81 bool fetchScript(const String& sourceUrl, FetchRequest::DeferOption); 84 bool fetchScript(const String& sourceUrl, FetchRequest::DeferOption);
82 void stopLoadRequest();
83 85
84 ScriptLoaderClient* client() const; 86 ScriptLoaderClient* client() const;
85 87
86 // ResourceClient 88 // ResourceClient
87 virtual void notifyFinished(Resource*) override; 89 virtual void notifyFinished(Resource*) override;
88 90
89 // FIXME: Oilpan: This should become a Member once ResourceClient is moved t o the heap. 91 // FIXME: Oilpan: This should become a Member once ResourceClient is moved t o the heap.
90 Element* m_element; 92 Element* m_element;
91 ResourcePtr<ScriptResource> m_resource; 93 ResourcePtr<ScriptResource> m_resource;
92 WTF::OrdinalNumber m_startLineNumber; 94 WTF::OrdinalNumber m_startLineNumber;
93 bool m_parserInserted : 1; 95 bool m_parserInserted : 1;
94 bool m_isExternalScript : 1; 96 bool m_isExternalScript : 1;
95 bool m_alreadyStarted : 1; 97 bool m_alreadyStarted : 1;
96 bool m_haveFiredLoad : 1; 98 bool m_haveFiredLoad : 1;
97 bool m_willBeParserExecuted : 1; // Same as "The parser will handle executin g the script." 99 bool m_willBeParserExecuted : 1; // Same as "The parser will handle executin g the script."
98 bool m_readyToBeParserExecuted : 1; 100 bool m_readyToBeParserExecuted : 1;
99 bool m_willExecuteWhenDocumentFinishedParsing : 1; 101 bool m_willExecuteWhenDocumentFinishedParsing : 1;
100 bool m_forceAsync : 1; 102 bool m_forceAsync : 1;
101 bool m_willExecuteInOrder : 1; 103 bool m_willExecuteInOrder : 1;
102 String m_characterEncoding; 104 String m_characterEncoding;
103 String m_fallbackCharacterEncoding; 105 String m_fallbackCharacterEncoding;
106
107 PendingScript m_pendingScript;
sof 2014/10/17 10:23:17 This is a problem; PendingScript has traceable Mem
104 }; 108 };
105 109
106 ScriptLoader* toScriptLoaderIfPossible(Element*); 110 ScriptLoader* toScriptLoaderIfPossible(Element*);
107 111
108 inline PassOwnPtr<ScriptLoader> ScriptLoader::create(Element* element, bool crea tedByParser, bool isEvaluated) 112 inline PassOwnPtr<ScriptLoader> ScriptLoader::create(Element* element, bool crea tedByParser, bool isEvaluated)
109 { 113 {
110 return adoptPtr(new ScriptLoader(element, createdByParser, isEvaluated)); 114 return adoptPtr(new ScriptLoader(element, createdByParser, isEvaluated));
111 } 115 }
112 116
113 } 117 }
114 118
115 119
116 #endif 120 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698