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

Side by Side Diff: third_party/WebKit/Source/core/dom/ClassicPendingScript.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 // Copyright 2017 The Chromium Authors. All rights reserved.
2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. 2 // Use of this source code is governed by a BSD-style license that can be
3 * 3 // found in the LICENSE file.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
24 */
25 4
26 #ifndef PendingScript_h 5 #ifndef ClassicPendingScript_h
27 #define PendingScript_h 6 #define ClassicPendingScript_h
28 7
29 #include "bindings/core/v8/ScriptStreamer.h" 8 #include "core/dom/ClassicScript.h"
30 #include "core/CoreExport.h" 9 #include "core/dom/PendingScript.h"
31 #include "core/dom/ScriptElementBase.h"
32 #include "core/loader/resource/ScriptResource.h" 10 #include "core/loader/resource/ScriptResource.h"
33 #include "platform/MemoryCoordinator.h" 11 #include "platform/MemoryCoordinator.h"
34 #include "platform/heap/Handle.h"
35 #include "platform/loader/fetch/ResourceOwner.h" 12 #include "platform/loader/fetch/ResourceOwner.h"
36 #include "wtf/Noncopyable.h"
37 #include "wtf/text/TextPosition.h"
38 13
39 namespace blink { 14 namespace blink {
40 15
41 class PendingScript;
42 class ClassicScript;
43
44 class CORE_EXPORT PendingScriptClient : public GarbageCollectedMixin {
45 public:
46 virtual ~PendingScriptClient() {}
47
48 // Invoked when the pending script has finished loading. This could be during
49 // |watchForLoad| (if the pending script was already ready), or when the
50 // resource loads (if script streaming is not occurring), or when script
51 // streaming finishes.
52 virtual void pendingScriptFinished(PendingScript*) = 0;
53
54 DEFINE_INLINE_VIRTUAL_TRACE() {}
55 };
56
57 // A container for an external script which may be loaded and executed. 16 // A container for an external script which may be loaded and executed.
58 // 17 //
59 // TODO(kochi): The comment below is from pre-oilpan age and may not be correct 18 // TODO(kochi): The comment below is from pre-oilpan age and may not be correct
60 // now. 19 // now.
61 // A RefPtr alone does not prevent the underlying Resource from purging its data 20 // 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 21 // buffer. This class holds a dummy client open for its lifetime in order to
63 // guarantee that the data buffer will not be purged. 22 // guarantee that the data buffer will not be purged.
64 class CORE_EXPORT PendingScript final 23
65 : public GarbageCollectedFinalized<PendingScript>, 24 class CORE_EXPORT ClassicPendingScript : public PendingScript,
66 public ResourceOwner<ScriptResource>, 25 public ResourceOwner<ScriptResource>,
67 public MemoryCoordinatorClient { 26 public MemoryCoordinatorClient {
68 USING_GARBAGE_COLLECTED_MIXIN(PendingScript); 27 USING_GARBAGE_COLLECTED_MIXIN(ClassicPendingScript);
69 USING_PRE_FINALIZER(PendingScript, dispose);
70 WTF_MAKE_NONCOPYABLE(PendingScript);
71 28
72 public: 29 public:
73 // For script from an external file. 30 // For script from an external file.
74 static PendingScript* create(ScriptElementBase*, ScriptResource*); 31 static ClassicPendingScript* create(ScriptElementBase*, ScriptResource*);
75 // For inline script. 32 // For inline script.
76 static PendingScript* create(ScriptElementBase*, const TextPosition&); 33 static ClassicPendingScript* create(ScriptElementBase*, const TextPosition&);
77 34
78 static PendingScript* createForTesting(ScriptResource*); 35 static ClassicPendingScript* createForTesting(ScriptResource*);
79 36
80 ~PendingScript() override; 37 ~ClassicPendingScript() override;
81
82 TextPosition startingPosition() const { return m_startingPosition; }
83 void markParserBlockingLoadStartTime();
84 // 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
86 // monotonicallyIncreasingTime.
87 double parserBlockingLoadStartTime() const {
88 return m_parserBlockingLoadStartTime;
89 }
90
91 void watchForLoad(PendingScriptClient*);
92 void stopWatchingForLoad();
93
94 ScriptElementBase* element() const;
95
96 DECLARE_TRACE();
97
98 ClassicScript* getSource(const KURL& documentURL, bool& errorOccurred) const;
99 38
100 void setStreamer(ScriptStreamer*); 39 void setStreamer(ScriptStreamer*);
101 void streamingFinished(); 40 void streamingFinished();
102 41
103 bool isReady() const; 42 DECLARE_TRACE();
104 bool errorOccurred() const;
105 43
106 void startStreamingIfPossible(Document*, ScriptStreamer::Type); 44 blink::ScriptType scriptType() const override {
107 void dispose(); 45 return blink::ScriptType::Classic;
46 }
47
48 ClassicScript* getSource(const KURL& documentURL,
49 bool& errorOccurred) const override;
50 bool isReady() const override;
51 KURL url() const override;
52 bool isExternal() const override { return resource(); }
53 bool errorOccurred() const override;
54 bool wasCanceled() const override;
55 void startStreamingIfPossible(Document*, ScriptStreamer::Type) override;
56 void disposeInternal() override;
108 57
109 private: 58 private:
110 PendingScript(ScriptElementBase*, 59 ClassicPendingScript(ScriptElementBase*,
111 ScriptResource*, 60 ScriptResource*,
112 const TextPosition&, 61 const TextPosition&,
113 bool isForTesting = false); 62 bool isForTesting = false);
114 PendingScript() = delete; 63 ClassicPendingScript() = delete;
115 64
116 void checkState() const; 65 void checkState() const override;
117 66
118 // ScriptResourceClient 67 // ScriptResourceClient
119 void notifyFinished(Resource*) override; 68 void notifyFinished(Resource*) override;
120 String debugName() const override { return "PendingScript"; } 69 String debugName() const override { return "PendingScript"; }
121 void notifyAppendData(ScriptResource*) override; 70 void notifyAppendData(ScriptResource*) override;
122 71
123 // MemoryCoordinatorClient 72 // MemoryCoordinatorClient
124 void onPurgeMemory() override; 73 void onPurgeMemory() override;
125 74
126 bool m_watchingForLoad;
127
128 // |m_element| must points to the corresponding ScriptLoader's
129 // ScriptElementBase and thus must be non-null before dispose() is called
130 // (except for unit tests).
131 Member<ScriptElementBase> m_element;
132
133 TextPosition m_startingPosition; // Only used for inline script tags.
134 bool m_integrityFailure; 75 bool m_integrityFailure;
135 double m_parserBlockingLoadStartTime;
136 76
137 Member<ScriptStreamer> m_streamer; 77 Member<ScriptStreamer> m_streamer;
138 Member<PendingScriptClient> m_client;
139 78
140 // This flag is used to skip non-null checks of |m_element| in unit 79 // 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. 80 // tests, because |m_element| can be null in unit tests.
142 const bool m_isForTesting; 81 const bool m_isForTesting;
143 }; 82 };
144 83
145 } // namespace blink 84 } // namespace blink
146 85
147 #endif // PendingScript_h 86 #endif // PendingScript_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698