| OLD | NEW |
| 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 Loading... |
| 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" | |
| 32 #include "core/dom/ScriptElementBase.h" | 31 #include "core/dom/ScriptElementBase.h" |
| 32 #include "core/loader/resource/ScriptResource.h" |
| 33 #include "platform/MemoryCoordinator.h" |
| 33 #include "platform/heap/Handle.h" | 34 #include "platform/heap/Handle.h" |
| 34 #include "platform/weborigin/KURL.h" | 35 #include "platform/loader/fetch/ResourceOwner.h" |
| 35 #include "platform/wtf/Noncopyable.h" | 36 #include "platform/wtf/Noncopyable.h" |
| 36 #include "platform/wtf/text/TextPosition.h" | 37 #include "platform/wtf/text/TextPosition.h" |
| 37 | 38 |
| 38 namespace blink { | 39 namespace blink { |
| 39 | 40 |
| 40 class Document; | |
| 41 class PendingScript; | 41 class PendingScript; |
| 42 class ClassicScript; |
| 42 | 43 |
| 43 class CORE_EXPORT PendingScriptClient : public GarbageCollectedMixin { | 44 class CORE_EXPORT PendingScriptClient : public GarbageCollectedMixin { |
| 44 public: | 45 public: |
| 45 virtual ~PendingScriptClient() {} | 46 virtual ~PendingScriptClient() {} |
| 46 | 47 |
| 47 // Invoked when the pending script is ready. This could be during | 48 // Invoked when the pending script has finished loading. This could be during |
| 48 // WatchForLoad() (if the pending script was already ready), or when the | 49 // |watchForLoad| (if the pending script was already ready), or when the |
| 49 // resource loads (if script streaming is not occurring), or when script | 50 // resource loads (if script streaming is not occurring), or when script |
| 50 // streaming finishes. | 51 // streaming finishes. |
| 51 virtual void PendingScriptFinished(PendingScript*) = 0; | 52 virtual void PendingScriptFinished(PendingScript*) = 0; |
| 52 | 53 |
| 53 DEFINE_INLINE_VIRTUAL_TRACE() {} | 54 DEFINE_INLINE_VIRTUAL_TRACE() {} |
| 54 }; | 55 }; |
| 55 | 56 |
| 56 // A container for an external script which may be loaded and executed. | 57 // A container for an external script which may be loaded and executed. |
| 57 // This is used to receive a notification of "script is ready" | 58 // |
| 58 // https://html.spec.whatwg.org/#the-script-is-ready via PendingScriptClient. | 59 // TODO(kochi): The comment below is from pre-oilpan age and may not be correct |
| 59 class CORE_EXPORT PendingScript | 60 // now. |
| 60 : public GarbageCollectedFinalized<PendingScript> { | 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); |
| 61 USING_PRE_FINALIZER(PendingScript, Dispose); | 69 USING_PRE_FINALIZER(PendingScript, Dispose); |
| 62 WTF_MAKE_NONCOPYABLE(PendingScript); | 70 WTF_MAKE_NONCOPYABLE(PendingScript); |
| 63 | 71 |
| 64 public: | 72 public: |
| 65 virtual ~PendingScript(); | 73 // For script from an external file. |
| 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; |
| 66 | 81 |
| 67 TextPosition StartingPosition() const { return starting_position_; } | 82 TextPosition StartingPosition() const { return starting_position_; } |
| 68 void MarkParserBlockingLoadStartTime(); | 83 void MarkParserBlockingLoadStartTime(); |
| 69 // Returns the time the load of this script started blocking the parser, or | 84 // Returns the time the load of this script started blocking the parser, or |
| 70 // zero if this script hasn't yet blocked the parser, in | 85 // zero if this script hasn't yet blocked the parser, in |
| 71 // monotonicallyIncreasingTime. | 86 // monotonicallyIncreasingTime. |
| 72 double ParserBlockingLoadStartTime() const { | 87 double ParserBlockingLoadStartTime() const { |
| 73 return parser_blocking_load_start_time_; | 88 return parser_blocking_load_start_time_; |
| 74 } | 89 } |
| 75 | 90 |
| 76 void WatchForLoad(PendingScriptClient*); | 91 void WatchForLoad(PendingScriptClient*); |
| 77 void StopWatchingForLoad(); | 92 void StopWatchingForLoad(); |
| 78 | 93 |
| 79 ScriptElementBase* GetElement() const; | 94 ScriptElementBase* GetElement() const; |
| 80 | 95 |
| 81 virtual ScriptType GetScriptType() const = 0; | 96 DECLARE_TRACE(); |
| 82 | 97 |
| 83 DECLARE_VIRTUAL_TRACE(); | 98 ClassicScript* GetSource(const KURL& document_url, |
| 99 bool& error_occurred) const; |
| 84 | 100 |
| 85 virtual Script* GetSource(const KURL& document_url, | 101 void SetStreamer(ScriptStreamer*); |
| 86 bool& error_occurred) const = 0; | 102 void StreamingFinished(); |
| 87 | 103 |
| 88 // https://html.spec.whatwg.org/#the-script-is-ready | 104 bool IsReady() const; |
| 89 virtual bool IsReady() const = 0; | 105 bool ErrorOccurred() const; |
| 90 | 106 |
| 91 virtual KURL Url() const = 0; | 107 void StartStreamingIfPossible(Document*, ScriptStreamer::Type); |
| 92 virtual bool IsExternal() const = 0; | |
| 93 virtual bool ErrorOccurred() const = 0; | |
| 94 virtual bool WasCanceled() const = 0; | |
| 95 virtual void StartStreamingIfPossible(Document*, ScriptStreamer::Type) = 0; | |
| 96 | |
| 97 // Used for document.write() intervention. | |
| 98 // Has effects only for classic scripts. | |
| 99 virtual void RemoveFromMemoryCache() = 0; | |
| 100 | |
| 101 void Dispose(); | 108 void Dispose(); |
| 102 | 109 |
| 103 protected: | 110 private: |
| 104 PendingScript(ScriptElementBase*, const TextPosition& starting_position); | 111 PendingScript(ScriptElementBase*, |
| 112 ScriptResource*, |
| 113 const TextPosition&, |
| 114 bool is_for_testing = false); |
| 115 PendingScript() = delete; |
| 105 | 116 |
| 106 virtual void DisposeInternal() = 0; | 117 void CheckState() const; |
| 107 | 118 |
| 108 PendingScriptClient* Client() { return client_; } | 119 // ScriptResourceClient |
| 109 bool IsWatchingForLoad() const { return watching_for_load_; } | 120 void NotifyFinished(Resource*) override; |
| 121 String DebugName() const override { return "PendingScript"; } |
| 122 void NotifyAppendData(ScriptResource*) override; |
| 110 | 123 |
| 111 virtual void CheckState() const = 0; | 124 // MemoryCoordinatorClient |
| 125 void OnPurgeMemory() override; |
| 112 | 126 |
| 113 private: | |
| 114 bool watching_for_load_; | 127 bool watching_for_load_; |
| 115 | 128 |
| 116 // |m_element| must points to the corresponding ScriptLoader's | 129 // |m_element| must points to the corresponding ScriptLoader's |
| 117 // ScriptElementBase and thus must be non-null before dispose() is called | 130 // ScriptElementBase and thus must be non-null before dispose() is called |
| 118 // (except for unit tests). | 131 // (except for unit tests). |
| 119 Member<ScriptElementBase> element_; | 132 Member<ScriptElementBase> element_; |
| 120 | 133 |
| 121 TextPosition starting_position_; // Only used for inline script tags. | 134 TextPosition starting_position_; // Only used for inline script tags. |
| 135 bool integrity_failure_; |
| 122 double parser_blocking_load_start_time_; | 136 double parser_blocking_load_start_time_; |
| 123 | 137 |
| 138 Member<ScriptStreamer> streamer_; |
| 124 Member<PendingScriptClient> client_; | 139 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_; |
| 125 }; | 144 }; |
| 126 | 145 |
| 127 } // namespace blink | 146 } // namespace blink |
| 128 | 147 |
| 129 #endif // PendingScript_h | 148 #endif // PendingScript_h |
| OLD | NEW |