OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef ClassicPendingScript_h |
| 6 #define ClassicPendingScript_h |
| 7 |
| 8 #include "core/dom/ClassicScript.h" |
| 9 #include "core/dom/PendingScript.h" |
| 10 #include "core/loader/resource/ScriptResource.h" |
| 11 #include "platform/MemoryCoordinator.h" |
| 12 #include "platform/loader/fetch/ResourceOwner.h" |
| 13 |
| 14 namespace blink { |
| 15 |
| 16 // PendingScript for a classic script |
| 17 // https://html.spec.whatwg.org/#classic-script. |
| 18 // |
| 19 // TODO(kochi): The comment below is from pre-oilpan age and may not be correct |
| 20 // now. |
| 21 // A RefPtr alone does not prevent the underlying Resource from purging its data |
| 22 // buffer. This class holds a dummy client open for its lifetime in order to |
| 23 // guarantee that the data buffer will not be purged. |
| 24 class CORE_EXPORT ClassicPendingScript final |
| 25 : public PendingScript, |
| 26 public ResourceOwner<ScriptResource>, |
| 27 public MemoryCoordinatorClient { |
| 28 USING_GARBAGE_COLLECTED_MIXIN(ClassicPendingScript); |
| 29 |
| 30 public: |
| 31 // For script from an external file. |
| 32 static ClassicPendingScript* Create(ScriptElementBase*, ScriptResource*); |
| 33 // For inline script. |
| 34 static ClassicPendingScript* Create(ScriptElementBase*, const TextPosition&); |
| 35 |
| 36 static ClassicPendingScript* CreateForTesting(ScriptResource*); |
| 37 |
| 38 ~ClassicPendingScript() override; |
| 39 |
| 40 void SetStreamer(ScriptStreamer*); |
| 41 void StreamingFinished(); |
| 42 |
| 43 DECLARE_TRACE(); |
| 44 |
| 45 blink::ScriptType GetScriptType() const override { |
| 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 bool IsExternal() const override { return GetResource(); } |
| 53 bool ErrorOccurred() const override; |
| 54 bool WasCanceled() const override; |
| 55 void StartStreamingIfPossible(Document*, ScriptStreamer::Type) override; |
| 56 KURL UrlForClassicScript() const override; |
| 57 void RemoveFromMemoryCache() override; |
| 58 void DisposeInternal() override; |
| 59 |
| 60 private: |
| 61 ClassicPendingScript(ScriptElementBase*, |
| 62 ScriptResource*, |
| 63 const TextPosition&, |
| 64 bool is_for_testing = false); |
| 65 ClassicPendingScript() = delete; |
| 66 |
| 67 void CheckState() const override; |
| 68 |
| 69 // ScriptResourceClient |
| 70 void NotifyFinished(Resource*) override; |
| 71 String DebugName() const override { return "PendingScript"; } |
| 72 void NotifyAppendData(ScriptResource*) override; |
| 73 |
| 74 // MemoryCoordinatorClient |
| 75 void OnPurgeMemory() override; |
| 76 |
| 77 bool integrity_failure_; |
| 78 |
| 79 Member<ScriptStreamer> streamer_; |
| 80 |
| 81 // This flag is used to skip non-null checks of |m_element| in unit |
| 82 // tests, because |m_element| can be null in unit tests. |
| 83 const bool is_for_testing_; |
| 84 }; |
| 85 |
| 86 } // namespace blink |
| 87 |
| 88 #endif // PendingScript_h |
OLD | NEW |