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

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: Rebase Created 3 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
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 "platform/wtf/Noncopyable.h" 35 #include "platform/wtf/Noncopyable.h"
37 #include "platform/wtf/text/TextPosition.h" 36 #include "platform/wtf/text/TextPosition.h"
38 37
39 namespace blink { 38 namespace blink {
40 39
40 class Document;
41 class PendingScript; 41 class PendingScript;
42 class ClassicScript;
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 is ready. 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 // A container for an external script which may be loaded and executed.
58 // 57 // This is used to receive a notification of "script is ready"
59 // TODO(kochi): The comment below is from pre-oilpan age and may not be correct 58 // https://html.spec.whatwg.org/#the-script-is-ready via PendingScriptClient.
60 // now. 59 class CORE_EXPORT PendingScript
61 // A RefPtr alone does not prevent the underlying Resource from purging its data 60 : public GarbageCollectedFinalized<PendingScript> {
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); 61 USING_PRE_FINALIZER(PendingScript, Dispose);
70 WTF_MAKE_NONCOPYABLE(PendingScript); 62 WTF_MAKE_NONCOPYABLE(PendingScript);
71 63
72 public: 64 public:
73 // For script from an external file. 65 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 66
82 TextPosition StartingPosition() const { return starting_position_; } 67 TextPosition StartingPosition() const { return starting_position_; }
83 void MarkParserBlockingLoadStartTime(); 68 void MarkParserBlockingLoadStartTime();
84 // Returns the time the load of this script started blocking the parser, or 69 // 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 70 // zero if this script hasn't yet blocked the parser, in
86 // monotonicallyIncreasingTime. 71 // monotonicallyIncreasingTime.
87 double ParserBlockingLoadStartTime() const { 72 double ParserBlockingLoadStartTime() const {
88 return parser_blocking_load_start_time_; 73 return parser_blocking_load_start_time_;
89 } 74 }
90 75
91 void WatchForLoad(PendingScriptClient*); 76 void WatchForLoad(PendingScriptClient*);
92 void StopWatchingForLoad(); 77 void StopWatchingForLoad();
93 78
94 ScriptElementBase* GetElement() const; 79 ScriptElementBase* GetElement() const;
95 80
96 DECLARE_TRACE(); 81 virtual ScriptType GetScriptType() const = 0;
97 82
98 ClassicScript* GetSource(const KURL& document_url, 83 DECLARE_VIRTUAL_TRACE();
99 bool& error_occurred) const;
100 84
101 void SetStreamer(ScriptStreamer*); 85 virtual Script* GetSource(const KURL& document_url,
102 void StreamingFinished(); 86 bool& error_occurred) const = 0;
103 87
104 bool IsReady() const; 88 // https://html.spec.whatwg.org/#the-script-is-ready
105 bool ErrorOccurred() const; 89 virtual bool IsReady() const = 0;
106 90
107 void StartStreamingIfPossible(Document*, ScriptStreamer::Type); 91 virtual KURL Url() const = 0;
92 virtual bool IsExternal() const = 0;
93 virtual bool ErrorOccurred() const = 0;
94 virtual bool WasCanceled() const = 0;
95 virtual void StartStreamingIfPossible(Document*, ScriptStreamer::Type) = 0;
96
97 // Used for document.write() intervention.
98 // Has effects only for classic scripts.
99 virtual void RemoveFromMemoryCache() = 0;
100
108 void Dispose(); 101 void Dispose();
109 102
103 protected:
104 PendingScript(ScriptElementBase*, const TextPosition& starting_position);
105
106 virtual void DisposeInternal() = 0;
107
108 PendingScriptClient* Client() { return client_; }
109 bool IsWatchingForLoad() const { return watching_for_load_; }
110
111 virtual void CheckState() const = 0;
112
110 private: 113 private:
111 PendingScript(ScriptElementBase*,
112 ScriptResource*,
113 const TextPosition&,
114 bool is_for_testing = false);
115 PendingScript() = delete;
116
117 void CheckState() const;
118
119 // ScriptResourceClient
120 void NotifyFinished(Resource*) override;
121 String DebugName() const override { return "PendingScript"; }
122 void NotifyAppendData(ScriptResource*) override;
123
124 // MemoryCoordinatorClient
125 void OnPurgeMemory() override;
126
127 bool watching_for_load_; 114 bool watching_for_load_;
128 115
129 // |m_element| must points to the corresponding ScriptLoader's 116 // |m_element| must points to the corresponding ScriptLoader's
130 // ScriptElementBase and thus must be non-null before dispose() is called 117 // ScriptElementBase and thus must be non-null before dispose() is called
131 // (except for unit tests). 118 // (except for unit tests).
132 Member<ScriptElementBase> element_; 119 Member<ScriptElementBase> element_;
133 120
134 TextPosition starting_position_; // Only used for inline script tags. 121 TextPosition starting_position_; // Only used for inline script tags.
135 bool integrity_failure_;
136 double parser_blocking_load_start_time_; 122 double parser_blocking_load_start_time_;
137 123
138 Member<ScriptStreamer> streamer_;
139 Member<PendingScriptClient> client_; 124 Member<PendingScriptClient> client_;
140
141 // This flag is used to skip non-null checks of |m_element| in unit
142 // tests, because |m_element| can be null in unit tests.
143 const bool is_for_testing_;
144 }; 125 };
145 126
146 } // namespace blink 127 } // namespace blink
147 128
148 #endif // PendingScript_h 129 #endif // PendingScript_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698