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

Side by Side Diff: third_party/WebKit/Source/core/dom/PendingScript.h

Issue 2653923008: Reland of Split PendingScript into PendingScript and ClassicPendingScript (Closed)
Patch Set: Fix file header Created 3 years, 8 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) 2010 Google, Inc. All Rights Reserved. 2 * Copyright (C) 2010 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 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 10 matching lines...) Expand all
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #ifndef PendingScript_h 26 #ifndef PendingScript_h
27 #define PendingScript_h 27 #define PendingScript_h
28 28
29 #include "bindings/core/v8/ScriptStreamer.h" 29 #include "bindings/core/v8/ScriptStreamer.h"
30 #include "core/CoreExport.h" 30 #include "core/CoreExport.h"
31 #include "core/dom/Script.h"
31 #include "core/dom/ScriptElementBase.h" 32 #include "core/dom/ScriptElementBase.h"
32 #include "core/loader/resource/ScriptResource.h"
33 #include "platform/MemoryCoordinator.h"
34 #include "platform/heap/Handle.h" 33 #include "platform/heap/Handle.h"
35 #include "platform/loader/fetch/ResourceOwner.h" 34 #include "platform/weborigin/KURL.h"
36 #include "wtf/Noncopyable.h"
37 #include "wtf/text/TextPosition.h" 35 #include "wtf/text/TextPosition.h"
38 36
39 namespace blink { 37 namespace blink {
40 38
39 class Document;
41 class PendingScript; 40 class PendingScript;
42 class ClassicScript; 41 class Script;
43 42
44 class CORE_EXPORT PendingScriptClient : public GarbageCollectedMixin { 43 class CORE_EXPORT PendingScriptClient : public GarbageCollectedMixin {
45 public: 44 public:
46 virtual ~PendingScriptClient() {} 45 virtual ~PendingScriptClient() {}
47 46
48 // Invoked when the pending script has finished loading. This could be during 47 // Invoked when the pending script has finished loading. This could be during
49 // |watchForLoad| (if the pending script was already ready), or when the 48 // |watchForLoad| (if the pending script was already ready), or when the
50 // resource loads (if script streaming is not occurring), or when script 49 // resource loads (if script streaming is not occurring), or when script
51 // streaming finishes. 50 // streaming finishes.
52 virtual void pendingScriptFinished(PendingScript*) = 0; 51 virtual void pendingScriptFinished(PendingScript*) = 0;
53 52
54 DEFINE_INLINE_VIRTUAL_TRACE() {} 53 DEFINE_INLINE_VIRTUAL_TRACE() {}
55 }; 54 };
56 55
57 // A container for an external script which may be loaded and executed. 56 class CORE_EXPORT PendingScript
58 // 57 : public GarbageCollectedFinalized<PendingScript> {
59 // TODO(kochi): The comment below is from pre-oilpan age and may not be correct
60 // now.
61 // A RefPtr alone does not prevent the underlying Resource from purging its data
62 // buffer. This class holds a dummy client open for its lifetime in order to
63 // guarantee that the data buffer will not be purged.
64 class CORE_EXPORT PendingScript final
65 : public GarbageCollectedFinalized<PendingScript>,
66 public ResourceOwner<ScriptResource>,
67 public MemoryCoordinatorClient {
68 USING_GARBAGE_COLLECTED_MIXIN(PendingScript);
69 USING_PRE_FINALIZER(PendingScript, dispose); 58 USING_PRE_FINALIZER(PendingScript, dispose);
70 WTF_MAKE_NONCOPYABLE(PendingScript); 59 WTF_MAKE_NONCOPYABLE(PendingScript);
71 60
72 public: 61 public:
73 // For script from an external file. 62 virtual ~PendingScript();
74 static PendingScript* create(ScriptElementBase*, ScriptResource*);
75 // For inline script.
76 static PendingScript* create(ScriptElementBase*, const TextPosition&);
77
78 static PendingScript* createForTesting(ScriptResource*);
79
80 ~PendingScript() override;
81 63
82 TextPosition startingPosition() const { return m_startingPosition; } 64 TextPosition startingPosition() const { return m_startingPosition; }
83 void markParserBlockingLoadStartTime(); 65 void markParserBlockingLoadStartTime();
84 // Returns the time the load of this script started blocking the parser, or 66 // Returns the time the load of this script started blocking the parser, or
85 // zero if this script hasn't yet blocked the parser, in 67 // zero if this script hasn't yet blocked the parser, in
86 // monotonicallyIncreasingTime. 68 // monotonicallyIncreasingTime.
87 double parserBlockingLoadStartTime() const { 69 double parserBlockingLoadStartTime() const {
88 return m_parserBlockingLoadStartTime; 70 return m_parserBlockingLoadStartTime;
89 } 71 }
90 72
91 void watchForLoad(PendingScriptClient*); 73 void watchForLoad(PendingScriptClient*);
92 void stopWatchingForLoad(); 74 void stopWatchingForLoad();
93 75
94 ScriptElementBase* element() const; 76 ScriptElementBase* element() const;
95 77
96 DECLARE_TRACE(); 78 virtual ScriptType scriptType() const = 0;
97 79
98 ClassicScript* getSource(const KURL& documentURL, bool& errorOccurred) const; 80 DECLARE_VIRTUAL_TRACE();
99 81
100 void setStreamer(ScriptStreamer*); 82 virtual Script* getSource(const KURL& documentURL,
101 void streamingFinished(); 83 bool& errorOccurred) const = 0;
84 virtual bool isReady() const = 0;
85 virtual KURL url() const = 0;
86 virtual bool isExternal() const = 0;
87 virtual bool errorOccurred() const = 0;
88 virtual bool wasCanceled() const = 0;
89 virtual void startStreamingIfPossible(Document*, ScriptStreamer::Type) = 0;
102 90
103 bool isReady() const;
104 bool errorOccurred() const;
105
106 void startStreamingIfPossible(Document*, ScriptStreamer::Type);
107 void dispose(); 91 void dispose();
108 92
93 protected:
94 PendingScript(ScriptElementBase*, const TextPosition& startingPosition);
95
96 virtual void disposeInternal() = 0;
97
98 PendingScriptClient* client() { return m_client; }
99 bool isWatchingForLoad() const { return m_watchingForLoad; }
100
101 virtual void checkState() const = 0;
102
109 private: 103 private:
110 PendingScript(ScriptElementBase*,
111 ScriptResource*,
112 const TextPosition&,
113 bool isForTesting = false);
114 PendingScript() = delete;
115
116 void checkState() const;
117
118 // ScriptResourceClient
119 void notifyFinished(Resource*) override;
120 String debugName() const override { return "PendingScript"; }
121 void notifyAppendData(ScriptResource*) override;
122
123 // MemoryCoordinatorClient
124 void onPurgeMemory() override;
125
126 bool m_watchingForLoad; 104 bool m_watchingForLoad;
127 105
128 // |m_element| must points to the corresponding ScriptLoader's 106 // |m_element| must points to the corresponding ScriptLoader's
129 // ScriptElementBase and thus must be non-null before dispose() is called 107 // ScriptElementBase and thus must be non-null before dispose() is called
130 // (except for unit tests). 108 // (except for unit tests).
131 Member<ScriptElementBase> m_element; 109 Member<ScriptElementBase> m_element;
132 110
133 TextPosition m_startingPosition; // Only used for inline script tags. 111 TextPosition m_startingPosition; // Only used for inline script tags.
134 bool m_integrityFailure;
135 double m_parserBlockingLoadStartTime; 112 double m_parserBlockingLoadStartTime;
136 113
137 Member<ScriptStreamer> m_streamer;
138 Member<PendingScriptClient> m_client; 114 Member<PendingScriptClient> m_client;
139
140 // This flag is used to skip non-null checks of |m_element| in unit
141 // tests, because |m_element| can be null in unit tests.
142 const bool m_isForTesting;
143 }; 115 };
144 116
145 } // namespace blink 117 } // namespace blink
146 118
147 #endif // PendingScript_h 119 #endif // PendingScript_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698