Chromium Code Reviews| 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/ScriptLoaderClient.h" | |
| 31 #include "core/loader/resource/ScriptResource.h" | 32 #include "core/loader/resource/ScriptResource.h" |
| 32 #include "platform/MemoryCoordinator.h" | 33 #include "platform/MemoryCoordinator.h" |
| 33 #include "platform/heap/Handle.h" | 34 #include "platform/heap/Handle.h" |
| 34 #include "platform/loader/fetch/ResourceOwner.h" | 35 #include "platform/loader/fetch/ResourceOwner.h" |
| 35 #include "wtf/Noncopyable.h" | 36 #include "wtf/Noncopyable.h" |
| 36 #include "wtf/text/TextPosition.h" | 37 #include "wtf/text/TextPosition.h" |
| 37 | 38 |
| 38 namespace blink { | 39 namespace blink { |
| 39 | 40 |
| 40 class Element; | |
| 41 class PendingScript; | 41 class PendingScript; |
| 42 class ScriptSourceCode; | 42 class ScriptSourceCode; |
| 43 | 43 |
| 44 class CORE_EXPORT PendingScriptClient : public GarbageCollectedMixin { | 44 class CORE_EXPORT PendingScriptClient : public GarbageCollectedMixin { |
| 45 public: | 45 public: |
| 46 virtual ~PendingScriptClient() {} | 46 virtual ~PendingScriptClient() {} |
| 47 | 47 |
| 48 // Invoked when the pending script has finished loading. This could be during | 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 | 49 // |watchForLoad| (if the pending script was already ready), or when the |
| 50 // resource loads (if script streaming is not occurring), or when script | 50 // resource loads (if script streaming is not occurring), or when script |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 64 class CORE_EXPORT PendingScript final | 64 class CORE_EXPORT PendingScript final |
| 65 : public GarbageCollectedFinalized<PendingScript>, | 65 : public GarbageCollectedFinalized<PendingScript>, |
| 66 public ResourceOwner<ScriptResource>, | 66 public ResourceOwner<ScriptResource>, |
| 67 public MemoryCoordinatorClient { | 67 public MemoryCoordinatorClient { |
| 68 USING_GARBAGE_COLLECTED_MIXIN(PendingScript); | 68 USING_GARBAGE_COLLECTED_MIXIN(PendingScript); |
| 69 USING_PRE_FINALIZER(PendingScript, dispose); | 69 USING_PRE_FINALIZER(PendingScript, dispose); |
| 70 WTF_MAKE_NONCOPYABLE(PendingScript); | 70 WTF_MAKE_NONCOPYABLE(PendingScript); |
| 71 | 71 |
| 72 public: | 72 public: |
| 73 // For script from an external file. | 73 // For script from an external file. |
| 74 static PendingScript* create(Element*, ScriptResource*); | 74 static PendingScript* create(ScriptLoaderClient*, ScriptResource*); |
| 75 // For inline script. | 75 // For inline script. |
| 76 static PendingScript* create(Element*, const TextPosition&); | 76 static PendingScript* create(ScriptLoaderClient*, const TextPosition&); |
| 77 | 77 |
| 78 static PendingScript* createForTesting(ScriptResource*); | 78 static PendingScript* createForTesting(ScriptResource*); |
| 79 | 79 |
| 80 ~PendingScript() override; | 80 ~PendingScript() override; |
| 81 | 81 |
| 82 TextPosition startingPosition() const { return m_startingPosition; } | 82 TextPosition startingPosition() const { return m_startingPosition; } |
| 83 void markParserBlockingLoadStartTime(); | 83 void markParserBlockingLoadStartTime(); |
| 84 // 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 |
| 85 // zero if this script hasn't yet blocked the parser, in | 85 // zero if this script hasn't yet blocked the parser, in |
| 86 // monotonicallyIncreasingTime. | 86 // monotonicallyIncreasingTime. |
| 87 double parserBlockingLoadStartTime() const { | 87 double parserBlockingLoadStartTime() const { |
| 88 return m_parserBlockingLoadStartTime; | 88 return m_parserBlockingLoadStartTime; |
| 89 } | 89 } |
| 90 | 90 |
| 91 void watchForLoad(PendingScriptClient*); | 91 void watchForLoad(PendingScriptClient*); |
| 92 void stopWatchingForLoad(); | 92 void stopWatchingForLoad(); |
| 93 | 93 |
| 94 Element* element() const; | 94 ScriptLoaderClient* scriptLoaderClient() const; |
| 95 | 95 |
| 96 DECLARE_TRACE(); | 96 DECLARE_TRACE(); |
| 97 | 97 |
| 98 ScriptSourceCode getSource(const KURL& documentURL, | 98 ScriptSourceCode getSource(const KURL& documentURL, |
| 99 bool& errorOccurred) const; | 99 bool& errorOccurred) const; |
| 100 | 100 |
| 101 void setStreamer(ScriptStreamer*); | 101 void setStreamer(ScriptStreamer*); |
| 102 void streamingFinished(); | 102 void streamingFinished(); |
| 103 | 103 |
| 104 bool isReady() const; | 104 bool isReady() const; |
| 105 bool errorOccurred() const; | 105 bool errorOccurred() const; |
| 106 | 106 |
| 107 void dispose(); | 107 void dispose(); |
| 108 | 108 |
| 109 private: | 109 private: |
| 110 PendingScript(Element*, | 110 PendingScript(ScriptLoaderClient*, |
| 111 ScriptResource*, | 111 ScriptResource*, |
| 112 const TextPosition&, | 112 const TextPosition&, |
| 113 bool isForTesting = false); | 113 bool isForTesting = false); |
| 114 PendingScript() = delete; | 114 PendingScript() = delete; |
| 115 | 115 |
| 116 void checkState() const; | 116 void checkState() const; |
| 117 | 117 |
| 118 // ScriptResourceClient | 118 // ScriptResourceClient |
| 119 void notifyFinished(Resource*) override; | 119 void notifyFinished(Resource*) override; |
| 120 String debugName() const override { return "PendingScript"; } | 120 String debugName() const override { return "PendingScript"; } |
| 121 void notifyAppendData(ScriptResource*) override; | 121 void notifyAppendData(ScriptResource*) override; |
| 122 | 122 |
| 123 // MemoryCoordinatorClient | 123 // MemoryCoordinatorClient |
| 124 void onPurgeMemory() override; | 124 void onPurgeMemory() override; |
| 125 | 125 |
| 126 bool m_watchingForLoad; | 126 bool m_watchingForLoad; |
| 127 | 127 |
| 128 // |m_element| must points to the corresponding ScriptLoader's element and | 128 // |m_scriptLoaderClient| must points to the corresponding ScriptLoader's |
| 129 // thus must be non-null before dispose() is called (except for unit tests). | 129 // ScriptLoaderClient and thus must be non-null before dispose() is called |
| 130 Member<Element> m_element; | 130 // (except for unit tests). |
| 131 Member<ScriptLoaderClient> m_scriptLoaderClient; | |
|
hiroshige
2017/03/01 00:58:14
Replacing Element with ScriptLoaderClient is great
| |
| 131 | 132 |
| 132 TextPosition m_startingPosition; // Only used for inline script tags. | 133 TextPosition m_startingPosition; // Only used for inline script tags. |
| 133 bool m_integrityFailure; | 134 bool m_integrityFailure; |
| 134 double m_parserBlockingLoadStartTime; | 135 double m_parserBlockingLoadStartTime; |
| 135 | 136 |
| 136 Member<ScriptStreamer> m_streamer; | 137 Member<ScriptStreamer> m_streamer; |
| 137 Member<PendingScriptClient> m_client; | 138 Member<PendingScriptClient> m_client; |
| 138 | 139 |
| 139 // This flag is used to skip non-null checks of |m_element| in unit tests, | 140 // This flag is used to skip non-null checks of |m_scriptLoaderClient| in unit |
| 140 // because |m_element| can be null in unit tests. | 141 // tests, because |m_scriptLoaderClient| can be null in unit tests. |
| 141 const bool m_isForTesting; | 142 const bool m_isForTesting; |
| 142 }; | 143 }; |
| 143 | 144 |
| 144 } // namespace blink | 145 } // namespace blink |
| 145 | 146 |
| 146 #endif // PendingScript_h | 147 #endif // PendingScript_h |
| OLD | NEW |