| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 LinkPreloadResourceClients_h | 5 #ifndef LinkPreloadResourceClients_h |
| 6 #define LinkPreloadResourceClients_h | 6 #define LinkPreloadResourceClients_h |
| 7 | 7 |
| 8 #include "core/loader/resource/CSSStyleSheetResource.h" | 8 #include "core/loader/resource/CSSStyleSheetResource.h" |
| 9 #include "core/loader/resource/FontResource.h" | 9 #include "core/loader/resource/FontResource.h" |
| 10 #include "core/loader/resource/ImageResource.h" | 10 #include "core/loader/resource/ImageResource.h" |
| 11 #include "core/loader/resource/ScriptResource.h" | 11 #include "core/loader/resource/ScriptResource.h" |
| 12 #include "core/loader/resource/StyleSheetResourceClient.h" | 12 #include "core/loader/resource/StyleSheetResourceClient.h" |
| 13 #include "platform/loader/fetch/RawResource.h" | 13 #include "platform/loader/fetch/RawResource.h" |
| 14 #include "platform/loader/fetch/ResourceOwner.h" | 14 #include "platform/loader/fetch/ResourceOwner.h" |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 | 17 |
| 18 class LinkLoader; | 18 class LinkLoader; |
| 19 | 19 |
| 20 class LinkPreloadResourceClient | 20 class LinkPreloadResourceClient |
| 21 : public GarbageCollectedFinalized<LinkPreloadResourceClient> { | 21 : public GarbageCollectedFinalized<LinkPreloadResourceClient> { |
| 22 public: | 22 public: |
| 23 virtual ~LinkPreloadResourceClient() {} | 23 virtual ~LinkPreloadResourceClient() {} |
| 24 | 24 |
| 25 void triggerEvents(const Resource*); | 25 void triggerEvents(const Resource*); |
| 26 virtual Resource* resource() = 0; |
| 26 virtual void clear() = 0; | 27 virtual void clear() = 0; |
| 27 | 28 |
| 28 DEFINE_INLINE_VIRTUAL_TRACE() { visitor->trace(m_loader); } | 29 DEFINE_INLINE_VIRTUAL_TRACE() { visitor->trace(m_loader); } |
| 29 | 30 |
| 30 protected: | 31 protected: |
| 31 explicit LinkPreloadResourceClient(LinkLoader* loader) : m_loader(loader) { | 32 explicit LinkPreloadResourceClient(LinkLoader* loader) : m_loader(loader) { |
| 32 DCHECK(loader); | 33 DCHECK(loader); |
| 33 } | 34 } |
| 34 | 35 |
| 35 private: | 36 private: |
| 36 Member<LinkLoader> m_loader; | 37 Member<LinkLoader> m_loader; |
| 37 }; | 38 }; |
| 38 | 39 |
| 39 class LinkPreloadScriptResourceClient | 40 class LinkPreloadScriptResourceClient |
| 40 : public LinkPreloadResourceClient, | 41 : public LinkPreloadResourceClient, |
| 41 public ResourceOwner<ScriptResource, ScriptResourceClient> { | 42 public ResourceOwner<ScriptResource, ScriptResourceClient> { |
| 42 USING_GARBAGE_COLLECTED_MIXIN(LinkPreloadScriptResourceClient); | 43 USING_GARBAGE_COLLECTED_MIXIN(LinkPreloadScriptResourceClient); |
| 43 | 44 |
| 44 public: | 45 public: |
| 45 static LinkPreloadScriptResourceClient* create(LinkLoader* loader, | 46 static LinkPreloadScriptResourceClient* create(LinkLoader* loader, |
| 46 ScriptResource* resource) { | 47 ScriptResource* resource) { |
| 47 return new LinkPreloadScriptResourceClient(loader, resource); | 48 return new LinkPreloadScriptResourceClient(loader, resource); |
| 48 } | 49 } |
| 49 | 50 |
| 50 virtual String debugName() const { return "LinkPreloadScript"; } | 51 virtual String debugName() const { return "LinkPreloadScript"; } |
| 51 virtual ~LinkPreloadScriptResourceClient() {} | 52 virtual ~LinkPreloadScriptResourceClient() {} |
| 52 | 53 |
| 54 Resource* resource() override { |
| 55 return ResourceOwner<ScriptResource>::resource(); |
| 56 } |
| 53 void clear() override { clearResource(); } | 57 void clear() override { clearResource(); } |
| 54 | 58 |
| 55 void notifyFinished(Resource* resource) override { | 59 void notifyFinished(Resource* resource) override { |
| 56 DCHECK_EQ(this->resource(), resource); | 60 DCHECK_EQ(this->resource(), resource); |
| 57 triggerEvents(resource); | 61 triggerEvents(resource); |
| 58 } | 62 } |
| 59 | 63 |
| 60 DEFINE_INLINE_VIRTUAL_TRACE() { | 64 DEFINE_INLINE_VIRTUAL_TRACE() { |
| 61 LinkPreloadResourceClient::trace(visitor); | 65 LinkPreloadResourceClient::trace(visitor); |
| 62 ResourceOwner<ScriptResource, ScriptResourceClient>::trace(visitor); | 66 ResourceOwner<ScriptResource, ScriptResourceClient>::trace(visitor); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 77 public: | 81 public: |
| 78 static LinkPreloadStyleResourceClient* create( | 82 static LinkPreloadStyleResourceClient* create( |
| 79 LinkLoader* loader, | 83 LinkLoader* loader, |
| 80 CSSStyleSheetResource* resource) { | 84 CSSStyleSheetResource* resource) { |
| 81 return new LinkPreloadStyleResourceClient(loader, resource); | 85 return new LinkPreloadStyleResourceClient(loader, resource); |
| 82 } | 86 } |
| 83 | 87 |
| 84 virtual String debugName() const { return "LinkPreloadStyle"; } | 88 virtual String debugName() const { return "LinkPreloadStyle"; } |
| 85 virtual ~LinkPreloadStyleResourceClient() {} | 89 virtual ~LinkPreloadStyleResourceClient() {} |
| 86 | 90 |
| 91 Resource* resource() override { |
| 92 return ResourceOwner<CSSStyleSheetResource>::resource(); |
| 93 } |
| 87 void clear() override { clearResource(); } | 94 void clear() override { clearResource(); } |
| 88 | 95 |
| 89 void setCSSStyleSheet(const String&, | 96 void setCSSStyleSheet(const String&, |
| 90 const KURL&, | 97 const KURL&, |
| 91 ReferrerPolicy, | 98 ReferrerPolicy, |
| 92 const String&, | 99 const String&, |
| 93 const CSSStyleSheetResource* resource) override { | 100 const CSSStyleSheetResource* resource) override { |
| 94 DCHECK_EQ(this->resource(), resource); | 101 DCHECK_EQ(this->resource(), resource); |
| 95 triggerEvents(static_cast<const Resource*>(resource)); | 102 triggerEvents(static_cast<const Resource*>(resource)); |
| 96 } | 103 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 115 | 122 |
| 116 public: | 123 public: |
| 117 static LinkPreloadImageResourceClient* create(LinkLoader* loader, | 124 static LinkPreloadImageResourceClient* create(LinkLoader* loader, |
| 118 ImageResource* resource) { | 125 ImageResource* resource) { |
| 119 return new LinkPreloadImageResourceClient(loader, resource); | 126 return new LinkPreloadImageResourceClient(loader, resource); |
| 120 } | 127 } |
| 121 | 128 |
| 122 virtual String debugName() const { return "LinkPreloadImage"; } | 129 virtual String debugName() const { return "LinkPreloadImage"; } |
| 123 virtual ~LinkPreloadImageResourceClient() {} | 130 virtual ~LinkPreloadImageResourceClient() {} |
| 124 | 131 |
| 132 Resource* resource() override { |
| 133 return ResourceOwner<ImageResource>::resource(); |
| 134 } |
| 125 void clear() override { clearResource(); } | 135 void clear() override { clearResource(); } |
| 126 | 136 |
| 127 void notifyFinished(Resource* resource) override { | 137 void notifyFinished(Resource* resource) override { |
| 128 DCHECK_EQ(this->resource(), toImageResource(resource)); | 138 DCHECK_EQ(this->resource(), toImageResource(resource)); |
| 129 triggerEvents(resource); | 139 triggerEvents(resource); |
| 130 } | 140 } |
| 131 | 141 |
| 132 DEFINE_INLINE_VIRTUAL_TRACE() { | 142 DEFINE_INLINE_VIRTUAL_TRACE() { |
| 133 LinkPreloadResourceClient::trace(visitor); | 143 LinkPreloadResourceClient::trace(visitor); |
| 134 ResourceOwner<ImageResource>::trace(visitor); | 144 ResourceOwner<ImageResource>::trace(visitor); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 148 | 158 |
| 149 public: | 159 public: |
| 150 static LinkPreloadFontResourceClient* create(LinkLoader* loader, | 160 static LinkPreloadFontResourceClient* create(LinkLoader* loader, |
| 151 FontResource* resource) { | 161 FontResource* resource) { |
| 152 return new LinkPreloadFontResourceClient(loader, resource); | 162 return new LinkPreloadFontResourceClient(loader, resource); |
| 153 } | 163 } |
| 154 | 164 |
| 155 virtual String debugName() const { return "LinkPreloadFont"; } | 165 virtual String debugName() const { return "LinkPreloadFont"; } |
| 156 virtual ~LinkPreloadFontResourceClient() {} | 166 virtual ~LinkPreloadFontResourceClient() {} |
| 157 | 167 |
| 168 Resource* resource() override { |
| 169 return ResourceOwner<FontResource>::resource(); |
| 170 } |
| 158 void clear() override { clearResource(); } | 171 void clear() override { clearResource(); } |
| 159 | 172 |
| 160 void notifyFinished(Resource* resource) override { | 173 void notifyFinished(Resource* resource) override { |
| 161 DCHECK_EQ(this->resource(), toFontResource(resource)); | 174 DCHECK_EQ(this->resource(), toFontResource(resource)); |
| 162 triggerEvents(resource); | 175 triggerEvents(resource); |
| 163 } | 176 } |
| 164 | 177 |
| 165 DEFINE_INLINE_VIRTUAL_TRACE() { | 178 DEFINE_INLINE_VIRTUAL_TRACE() { |
| 166 LinkPreloadResourceClient::trace(visitor); | 179 LinkPreloadResourceClient::trace(visitor); |
| 167 ResourceOwner<FontResource, FontResourceClient>::trace(visitor); | 180 ResourceOwner<FontResource, FontResourceClient>::trace(visitor); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 181 | 194 |
| 182 public: | 195 public: |
| 183 static LinkPreloadRawResourceClient* create(LinkLoader* loader, | 196 static LinkPreloadRawResourceClient* create(LinkLoader* loader, |
| 184 RawResource* resource) { | 197 RawResource* resource) { |
| 185 return new LinkPreloadRawResourceClient(loader, resource); | 198 return new LinkPreloadRawResourceClient(loader, resource); |
| 186 } | 199 } |
| 187 | 200 |
| 188 virtual String debugName() const { return "LinkPreloadRaw"; } | 201 virtual String debugName() const { return "LinkPreloadRaw"; } |
| 189 virtual ~LinkPreloadRawResourceClient() {} | 202 virtual ~LinkPreloadRawResourceClient() {} |
| 190 | 203 |
| 204 Resource* resource() override { |
| 205 return ResourceOwner<RawResource>::resource(); |
| 206 } |
| 191 void clear() override { clearResource(); } | 207 void clear() override { clearResource(); } |
| 192 | 208 |
| 193 void notifyFinished(Resource* resource) override { | 209 void notifyFinished(Resource* resource) override { |
| 194 DCHECK_EQ(this->resource(), toRawResource(resource)); | 210 DCHECK_EQ(this->resource(), toRawResource(resource)); |
| 195 triggerEvents(resource); | 211 triggerEvents(resource); |
| 196 } | 212 } |
| 197 | 213 |
| 198 DEFINE_INLINE_VIRTUAL_TRACE() { | 214 DEFINE_INLINE_VIRTUAL_TRACE() { |
| 199 LinkPreloadResourceClient::trace(visitor); | 215 LinkPreloadResourceClient::trace(visitor); |
| 200 ResourceOwner<RawResource, RawResourceClient>::trace(visitor); | 216 ResourceOwner<RawResource, RawResourceClient>::trace(visitor); |
| 201 } | 217 } |
| 202 | 218 |
| 203 private: | 219 private: |
| 204 LinkPreloadRawResourceClient(LinkLoader* loader, RawResource* resource) | 220 LinkPreloadRawResourceClient(LinkLoader* loader, RawResource* resource) |
| 205 : LinkPreloadResourceClient(loader) { | 221 : LinkPreloadResourceClient(loader) { |
| 206 setResource(resource, Resource::DontMarkAsReferenced); | 222 setResource(resource, Resource::DontMarkAsReferenced); |
| 207 } | 223 } |
| 208 }; | 224 }; |
| 209 | 225 |
| 210 } // namespace blink | 226 } // namespace blink |
| 211 | 227 |
| 212 #endif // LinkPreloadResourceClients_h | 228 #endif // LinkPreloadResourceClients_h |
| OLD | NEW |