OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef ClassicPendingScript_h | 5 #ifndef ClassicPendingScript_h |
6 #define ClassicPendingScript_h | 6 #define ClassicPendingScript_h |
7 | 7 |
8 #include "bindings/core/v8/ScriptStreamer.h" | 8 #include "bindings/core/v8/ScriptStreamer.h" |
9 #include "core/dom/ClassicScript.h" | 9 #include "core/dom/ClassicScript.h" |
10 #include "core/dom/PendingScript.h" | 10 #include "core/dom/PendingScript.h" |
11 #include "core/loader/resource/ScriptResource.h" | 11 #include "core/loader/resource/ScriptResource.h" |
12 #include "platform/MemoryCoordinator.h" | 12 #include "platform/MemoryCoordinator.h" |
13 #include "platform/loader/fetch/ResourceOwner.h" | 13 #include "platform/loader/fetch/ResourceOwner.h" |
14 | 14 |
15 namespace blink { | 15 namespace blink { |
16 | 16 |
17 // PendingScript for a classic script | 17 // PendingScript for a classic script |
18 // https://html.spec.whatwg.org/#classic-script. | 18 // https://html.spec.whatwg.org/#classic-script. |
19 // | 19 // |
20 // TODO(kochi): The comment below is from pre-oilpan age and may not be correct | 20 // TODO(kochi): The comment below is from pre-oilpan age and may not be correct |
21 // now. | 21 // now. |
22 // A RefPtr alone does not prevent the underlying Resource from purging its data | 22 // A RefPtr alone does not prevent the underlying Resource from purging its data |
23 // buffer. This class holds a dummy client open for its lifetime in order to | 23 // buffer. This class holds a dummy client open for its lifetime in order to |
24 // guarantee that the data buffer will not be purged. | 24 // guarantee that the data buffer will not be purged. |
25 class CORE_EXPORT ClassicPendingScript final | 25 class CORE_EXPORT ClassicPendingScript final |
26 : public PendingScript, | 26 : public PendingScript, |
27 public ResourceOwner<ScriptResource>, | 27 public ResourceOwner<ScriptResource>, |
28 public MemoryCoordinatorClient { | 28 public MemoryCoordinatorClient { |
29 USING_GARBAGE_COLLECTED_MIXIN(ClassicPendingScript); | 29 USING_GARBAGE_COLLECTED_MIXIN(ClassicPendingScript); |
30 | 30 USING_PRE_FINALIZER(ClassicPendingScript, Prefinalize); |
haraken
2017/04/26 01:06:23
Nit: We normally use "Dispose".
kouhei (in TOK)
2017/04/26 01:09:35
We have PendingScript::Dispose, which is no longer
| |
31 // In order to call Dispose() before ResourceOwner's prefinalizer, we | |
32 // also register ClassicPendingScript::Dispose() as the prefinalizer of | |
33 // ClassicPendingScript here. https://crbug.com/711703 | |
34 USING_PRE_FINALIZER(ClassicPendingScript, Dispose); | |
35 | 31 |
36 public: | 32 public: |
37 // For script from an external file. | 33 // For script from an external file. |
38 static ClassicPendingScript* Create(ScriptElementBase*, ScriptResource*); | 34 static ClassicPendingScript* Create(ScriptElementBase*, ScriptResource*); |
39 // For inline script. | 35 // For inline script. |
40 static ClassicPendingScript* Create(ScriptElementBase*, const TextPosition&); | 36 static ClassicPendingScript* Create(ScriptElementBase*, const TextPosition&); |
41 | 37 |
42 ~ClassicPendingScript() override; | 38 ~ClassicPendingScript() override; |
43 | 39 |
44 void SetStreamer(ScriptStreamer*); | 40 void SetStreamer(ScriptStreamer*); |
45 void StreamingFinished(); | 41 void StreamingFinished(); |
46 | 42 |
47 DECLARE_TRACE(); | 43 DECLARE_TRACE(); |
48 | 44 |
49 blink::ScriptType GetScriptType() const override { | 45 blink::ScriptType GetScriptType() const override { |
50 return blink::ScriptType::kClassic; | 46 return blink::ScriptType::kClassic; |
51 } | 47 } |
52 | 48 |
53 ClassicScript* GetSource(const KURL& document_url, | 49 ClassicScript* GetSource(const KURL& document_url, |
54 bool& error_occurred) const override; | 50 bool& error_occurred) const override; |
55 bool IsReady() const override; | 51 bool IsReady() const override; |
56 bool IsExternal() const override { return GetResource(); } | 52 bool IsExternal() const override { return GetResource(); } |
57 bool ErrorOccurred() const override; | 53 bool ErrorOccurred() const override; |
58 bool WasCanceled() const override; | 54 bool WasCanceled() const override; |
59 void StartStreamingIfPossible(Document*, ScriptStreamer::Type) override; | 55 void StartStreamingIfPossible(Document*, ScriptStreamer::Type) override; |
60 KURL UrlForClassicScript() const override; | 56 KURL UrlForClassicScript() const override; |
61 void RemoveFromMemoryCache() override; | 57 void RemoveFromMemoryCache() override; |
62 void DisposeInternal() override; | 58 void DisposeInternal() override; |
63 | 59 |
64 // Just used as the prefinalizer, does the same as PendingScript::Dispose(). | 60 void Prefinalize(); |
65 // We define Dispose() with NOINLINE in ClassicPendingScript just to make | |
66 // the prefinalizers of PendingScript and ClassicPendingScript have | |
67 // different addresses to avoid assertion failures on Windows test bots. | |
68 void Dispose(); | |
69 | 61 |
70 private: | 62 private: |
71 ClassicPendingScript(ScriptElementBase*, | 63 ClassicPendingScript(ScriptElementBase*, |
72 ScriptResource*, | 64 ScriptResource*, |
73 const TextPosition&); | 65 const TextPosition&); |
74 ClassicPendingScript() = delete; | 66 ClassicPendingScript() = delete; |
75 | 67 |
76 void CheckState() const override; | 68 void CheckState() const override; |
77 | 69 |
78 // ScriptResourceClient | 70 // ScriptResourceClient |
(...skipping 11 matching lines...) Expand all Loading... | |
90 // This is a temporary flag to confirm that ClassicPendingScript is not | 82 // This is a temporary flag to confirm that ClassicPendingScript is not |
91 // touched after its refinalizer call and thus https://crbug.com/715309 | 83 // touched after its refinalizer call and thus https://crbug.com/715309 |
92 // doesn't break assumptions. | 84 // doesn't break assumptions. |
93 // TODO(hiroshige): Check the state in more general way. | 85 // TODO(hiroshige): Check the state in more general way. |
94 bool prefinalizer_called_ = false; | 86 bool prefinalizer_called_ = false; |
95 }; | 87 }; |
96 | 88 |
97 } // namespace blink | 89 } // namespace blink |
98 | 90 |
99 #endif // PendingScript_h | 91 #endif // PendingScript_h |
OLD | NEW |