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

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: refine 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 "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 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
haraken 2017/04/13 01:03:58 Add a class-level comment.
hiroshige 2017/04/13 17:08:31 Done.
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 starting_position_; } 64 TextPosition StartingPosition() const { return starting_position_; }
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 parser_blocking_load_start_time_; 70 return parser_blocking_load_start_time_;
89 } 71 }
90 72
91 void WatchForLoad(PendingScriptClient*); 73 void WatchForLoad(PendingScriptClient*);
92 void StopWatchingForLoad(); 74 void StopWatchingForLoad();
93 75
94 ScriptElementBase* GetElement() const; 76 ScriptElementBase* GetElement() const;
95 77
96 DECLARE_TRACE(); 78 virtual ScriptType GetScriptType() const = 0;
97 79
98 ClassicScript* GetSource(const KURL& document_url, 80 DECLARE_VIRTUAL_TRACE();
99 bool& error_occurred) const;
100 81
101 void SetStreamer(ScriptStreamer*); 82 virtual Script* GetSource(const KURL& document_url,
102 void StreamingFinished(); 83 bool& error_occurred) const = 0;
103 84
104 bool IsReady() const; 85 // https://html.spec.whatwg.org/#the-script-is-ready
105 bool ErrorOccurred() const; 86 virtual bool IsReady() const = 0;
106 87
107 void StartStreamingIfPossible(Document*, ScriptStreamer::Type); 88 virtual KURL Url() const = 0;
89 virtual bool IsExternal() const = 0;
90 virtual bool ErrorOccurred() const = 0;
91 virtual bool WasCanceled() const = 0;
92 virtual void StartStreamingIfPossible(Document*, ScriptStreamer::Type) = 0;
93
94 // Used for document.write() intervention.
95 // Has effects only for classic scripts.
96 virtual void RemoveFromMemoryCache() = 0;
97
108 void Dispose(); 98 void Dispose();
109 99
100 protected:
101 PendingScript(ScriptElementBase*, const TextPosition& starting_position);
102
103 virtual void DisposeInternal() = 0;
104
105 PendingScriptClient* Client() { return client_; }
106 bool IsWatchingForLoad() const { return watching_for_load_; }
107
108 virtual void CheckState() const = 0;
109
110 private: 110 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_; 111 bool watching_for_load_;
128 112
129 // |m_element| must points to the corresponding ScriptLoader's 113 // |m_element| must points to the corresponding ScriptLoader's
130 // ScriptElementBase and thus must be non-null before dispose() is called 114 // ScriptElementBase and thus must be non-null before dispose() is called
131 // (except for unit tests). 115 // (except for unit tests).
132 Member<ScriptElementBase> element_; 116 Member<ScriptElementBase> element_;
133 117
134 TextPosition starting_position_; // Only used for inline script tags. 118 TextPosition starting_position_; // Only used for inline script tags.
135 bool integrity_failure_;
136 double parser_blocking_load_start_time_; 119 double parser_blocking_load_start_time_;
137 120
138 Member<ScriptStreamer> streamer_;
139 Member<PendingScriptClient> client_; 121 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 }; 122 };
145 123
146 } // namespace blink 124 } // namespace blink
147 125
148 #endif // PendingScript_h 126 #endif // PendingScript_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698