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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 // guarantee that the data buffer will not be purged. | 63 // guarantee that the data buffer will not be purged. |
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 static PendingScript* create(Element*, ScriptResource*); | 74 static PendingScript* create(Element*, ScriptResource*); |
75 // For inline script. | |
76 static PendingScript* create(Element*, const TextPosition&); | |
77 | |
78 static PendingScript* createForTesting(ScriptResource*); | |
79 | |
74 ~PendingScript() override; | 80 ~PendingScript() override; |
75 | 81 |
76 TextPosition startingPosition() const { return m_startingPosition; } | 82 TextPosition startingPosition() const { return m_startingPosition; } |
77 void setStartingPosition(const TextPosition& position) { | |
78 m_startingPosition = position; | |
79 } | |
80 void markParserBlockingLoadStartTime(); | 83 void markParserBlockingLoadStartTime(); |
81 // 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 |
82 // zero if this script hasn't yet blocked the parser, in | 85 // zero if this script hasn't yet blocked the parser, in |
83 // monotonicallyIncreasingTime. | 86 // monotonicallyIncreasingTime. |
84 double parserBlockingLoadStartTime() const { | 87 double parserBlockingLoadStartTime() const { |
85 return m_parserBlockingLoadStartTime; | 88 return m_parserBlockingLoadStartTime; |
86 } | 89 } |
87 | 90 |
88 void watchForLoad(PendingScriptClient*); | 91 void watchForLoad(PendingScriptClient*); |
89 void stopWatchingForLoad(); | 92 void stopWatchingForLoad(); |
90 | 93 |
91 Element* element() const { return m_element.get(); } | 94 Element* element() const; |
92 void setElement(Element*); | |
93 | |
94 void setScriptResource(ScriptResource*); | |
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*, ScriptResource*); | 110 PendingScript(Element*, |
111 ScriptResource*, | |
112 const TextPosition&, | |
113 bool isForTesting = false); | |
111 PendingScript() = delete; | 114 PendingScript() = delete; |
112 | 115 |
113 // ScriptResourceClient | 116 // ScriptResourceClient |
114 void notifyFinished(Resource*) override; | 117 void notifyFinished(Resource*) override; |
115 String debugName() const override { return "PendingScript"; } | 118 String debugName() const override { return "PendingScript"; } |
116 void notifyAppendData(ScriptResource*) override; | 119 void notifyAppendData(ScriptResource*) override; |
117 | 120 |
118 // MemoryCoordinatorClient | 121 // MemoryCoordinatorClient |
119 void onPurgeMemory() override; | 122 void onPurgeMemory() override; |
120 | 123 |
121 bool m_watchingForLoad; | 124 bool m_watchingForLoad; |
125 | |
126 // |m_element| must points to the corresponding ScriptLoader's element and | |
127 // thus must be non-null before dispose() is called. | |
122 Member<Element> m_element; | 128 Member<Element> m_element; |
129 | |
123 TextPosition m_startingPosition; // Only used for inline script tags. | 130 TextPosition m_startingPosition; // Only used for inline script tags. |
124 bool m_integrityFailure; | 131 bool m_integrityFailure; |
125 double m_parserBlockingLoadStartTime; | 132 double m_parserBlockingLoadStartTime; |
126 | 133 |
127 Member<ScriptStreamer> m_streamer; | 134 Member<ScriptStreamer> m_streamer; |
128 Member<PendingScriptClient> m_client; | 135 Member<PendingScriptClient> m_client; |
136 | |
137 // In unit tests |m_element| can be null. | |
sof
2017/02/16 08:15:15
nit: null => false
hiroshige
2017/02/17 23:15:15
|m_element| is Member<Element> so it is |null|.
Re
| |
138 // This flag is used to skip non-null checks of |m_element| in tests. | |
139 const bool m_isForTesting; | |
129 }; | 140 }; |
130 | 141 |
131 } // namespace blink | 142 } // namespace blink |
132 | 143 |
133 #endif // PendingScript_h | 144 #endif // PendingScript_h |
OLD | NEW |