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

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: 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 // 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 "platform/wtf/Noncopyable.h"
37 #include "platform/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 final
haraken 2017/04/13 01:03:58 Add a class-level comment and explain what Classic
hiroshige 2017/04/13 17:08:31 Done.
25 : public PendingScript,
66 public ResourceOwner<ScriptResource>, 26 public ResourceOwner<ScriptResource>,
67 public MemoryCoordinatorClient { 27 public MemoryCoordinatorClient {
68 USING_GARBAGE_COLLECTED_MIXIN(PendingScript); 28 USING_GARBAGE_COLLECTED_MIXIN(ClassicPendingScript);
69 USING_PRE_FINALIZER(PendingScript, Dispose);
70 WTF_MAKE_NONCOPYABLE(PendingScript);
71 29
72 public: 30 public:
73 // For script from an external file. 31 // For script from an external file.
74 static PendingScript* Create(ScriptElementBase*, ScriptResource*); 32 static ClassicPendingScript* Create(ScriptElementBase*, ScriptResource*);
75 // For inline script. 33 // For inline script.
76 static PendingScript* Create(ScriptElementBase*, const TextPosition&); 34 static ClassicPendingScript* Create(ScriptElementBase*, const TextPosition&);
77 35
78 static PendingScript* CreateForTesting(ScriptResource*); 36 static ClassicPendingScript* CreateForTesting(ScriptResource*);
79 37
80 ~PendingScript() override; 38 ~ClassicPendingScript() override;
81
82 TextPosition StartingPosition() const { return starting_position_; }
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 parser_blocking_load_start_time_;
89 }
90
91 void WatchForLoad(PendingScriptClient*);
92 void StopWatchingForLoad();
93
94 ScriptElementBase* GetElement() const;
95
96 DECLARE_TRACE();
97
98 ClassicScript* GetSource(const KURL& document_url,
99 bool& error_occurred) const;
100 39
101 void SetStreamer(ScriptStreamer*); 40 void SetStreamer(ScriptStreamer*);
102 void StreamingFinished(); 41 void StreamingFinished();
103 42
104 bool IsReady() const; 43 DECLARE_TRACE();
105 bool ErrorOccurred() const;
106 44
107 void StartStreamingIfPossible(Document*, ScriptStreamer::Type); 45 blink::ScriptType GetScriptType() const override {
108 void Dispose(); 46 return blink::ScriptType::kClassic;
47 }
48
49 ClassicScript* GetSource(const KURL& document_url,
50 bool& error_occurred) const override;
51 bool IsReady() const override;
52 KURL Url() const override;
53 bool IsExternal() const override { return GetResource(); }
54 bool ErrorOccurred() const override;
55 bool WasCanceled() const override;
56 void StartStreamingIfPossible(Document*, ScriptStreamer::Type) override;
57 void RemoveFromMemoryCache() override;
58 void DisposeInternal() override;
109 59
110 private: 60 private:
111 PendingScript(ScriptElementBase*, 61 ClassicPendingScript(ScriptElementBase*,
112 ScriptResource*, 62 ScriptResource*,
113 const TextPosition&, 63 const TextPosition&,
114 bool is_for_testing = false); 64 bool is_for_testing = false);
115 PendingScript() = delete; 65 ClassicPendingScript() = delete;
116 66
117 void CheckState() const; 67 void CheckState() const override;
118 68
119 // ScriptResourceClient 69 // ScriptResourceClient
120 void NotifyFinished(Resource*) override; 70 void NotifyFinished(Resource*) override;
121 String DebugName() const override { return "PendingScript"; } 71 String DebugName() const override { return "PendingScript"; }
122 void NotifyAppendData(ScriptResource*) override; 72 void NotifyAppendData(ScriptResource*) override;
123 73
124 // MemoryCoordinatorClient 74 // MemoryCoordinatorClient
125 void OnPurgeMemory() override; 75 void OnPurgeMemory() override;
126 76
127 bool watching_for_load_;
128
129 // |m_element| must points to the corresponding ScriptLoader's
130 // ScriptElementBase and thus must be non-null before dispose() is called
131 // (except for unit tests).
132 Member<ScriptElementBase> element_;
133
134 TextPosition starting_position_; // Only used for inline script tags.
135 bool integrity_failure_; 77 bool integrity_failure_;
136 double parser_blocking_load_start_time_;
137 78
138 Member<ScriptStreamer> streamer_; 79 Member<ScriptStreamer> streamer_;
139 Member<PendingScriptClient> client_;
140 80
141 // This flag is used to skip non-null checks of |m_element| in unit 81 // 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. 82 // tests, because |m_element| can be null in unit tests.
143 const bool is_for_testing_; 83 const bool is_for_testing_;
144 }; 84 };
145 85
146 } // namespace blink 86 } // namespace blink
147 87
148 #endif // PendingScript_h 88 #endif // PendingScript_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698