| OLD | NEW |
| 1 /* | 1 /* |
| 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) | 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) |
| 3 Copyright (C) 2001 Dirk Mueller <mueller@kde.org> | 3 Copyright (C) 2001 Dirk Mueller <mueller@kde.org> |
| 4 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 4 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
| 5 Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. | 5 Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. |
| 6 | 6 |
| 7 This library is free software; you can redistribute it and/or | 7 This library is free software; you can redistribute it and/or |
| 8 modify it under the terms of the GNU Library General Public | 8 modify it under the terms of the GNU Library General Public |
| 9 License as published by the Free Software Foundation; either | 9 License as published by the Free Software Foundation; either |
| 10 version 2 of the License, or (at your option) any later version. | 10 version 2 of the License, or (at your option) any later version. |
| 11 | 11 |
| 12 This library is distributed in the hope that it will be useful, | 12 This library is distributed in the hope that it will be useful, |
| 13 but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 Library General Public License for more details. | 15 Library General Public License for more details. |
| 16 | 16 |
| 17 You should have received a copy of the GNU Library General Public License | 17 You should have received a copy of the GNU Library General Public License |
| 18 along with this library; see the file COPYING.LIB. If not, write to | 18 along with this library; see the file COPYING.LIB. If not, write to |
| 19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 20 Boston, MA 02110-1301, USA. | 20 Boston, MA 02110-1301, USA. |
| 21 */ | 21 */ |
| 22 | 22 |
| 23 #ifndef RawResource_h | 23 #ifndef RawResource_h |
| 24 #define RawResource_h | 24 #define RawResource_h |
| 25 | 25 |
| 26 #include "core/CoreExport.h" | 26 #include "core/CoreExport.h" |
| 27 #include "core/fetch/Resource.h" |
| 27 #include "core/fetch/ResourceClient.h" | 28 #include "core/fetch/ResourceClient.h" |
| 28 #include "core/fetch/ResourcePtr.h" | |
| 29 #include "public/platform/WebDataConsumerHandle.h" | 29 #include "public/platform/WebDataConsumerHandle.h" |
| 30 #include "wtf/PassOwnPtr.h" | 30 #include "wtf/PassOwnPtr.h" |
| 31 | 31 |
| 32 namespace blink { | 32 namespace blink { |
| 33 class FetchRequest; | 33 class FetchRequest; |
| 34 class RawResourceClient; | 34 class RawResourceClient; |
| 35 class ResourceFetcher; | 35 class ResourceFetcher; |
| 36 class SubstituteData; | 36 class SubstituteData; |
| 37 | 37 |
| 38 class CORE_EXPORT RawResource final : public Resource { | 38 class CORE_EXPORT RawResource final : public Resource { |
| 39 public: | 39 public: |
| 40 using ClientType = RawResourceClient; | 40 using ClientType = RawResourceClient; |
| 41 | 41 |
| 42 static ResourcePtr<Resource> fetchSynchronously(FetchRequest&, ResourceFetch
er*); | 42 static PassRefPtrWillBeRawPtr<Resource> fetchSynchronously(FetchRequest&, Re
sourceFetcher*); |
| 43 static ResourcePtr<RawResource> fetch(FetchRequest&, ResourceFetcher*); | 43 static PassRefPtrWillBeRawPtr<RawResource> fetch(FetchRequest&, ResourceFetc
her*); |
| 44 static ResourcePtr<RawResource> fetchMainResource(FetchRequest&, ResourceFet
cher*, const SubstituteData&); | 44 static PassRefPtrWillBeRawPtr<RawResource> fetchMainResource(FetchRequest&,
ResourceFetcher*, const SubstituteData&); |
| 45 static ResourcePtr<RawResource> fetchImport(FetchRequest&, ResourceFetcher*)
; | 45 static PassRefPtrWillBeRawPtr<RawResource> fetchImport(FetchRequest&, Resour
ceFetcher*); |
| 46 static ResourcePtr<RawResource> fetchMedia(FetchRequest&, ResourceFetcher*); | 46 static PassRefPtrWillBeRawPtr<RawResource> fetchMedia(FetchRequest&, Resourc
eFetcher*); |
| 47 static ResourcePtr<RawResource> fetchTextTrack(FetchRequest&, ResourceFetche
r*); | 47 static PassRefPtrWillBeRawPtr<RawResource> fetchTextTrack(FetchRequest&, Res
ourceFetcher*); |
| 48 static ResourcePtr<RawResource> fetchManifest(FetchRequest&, ResourceFetcher
*); | 48 static PassRefPtrWillBeRawPtr<RawResource> fetchManifest(FetchRequest&, Reso
urceFetcher*); |
| 49 | 49 |
| 50 // Exposed for testing | 50 // Exposed for testing |
| 51 RawResource(const ResourceRequest&, Type); | 51 static RefPtrWillBeRawPtr<RawResource> create(const ResourceRequest& request
, Type type) |
| 52 { |
| 53 return adoptRefWillBeNoop(new RawResource(request, type)); |
| 54 } |
| 52 | 55 |
| 53 // FIXME: AssociatedURLLoader shouldn't be a DocumentThreadableLoader and th
erefore shouldn't | 56 // FIXME: AssociatedURLLoader shouldn't be a DocumentThreadableLoader and th
erefore shouldn't |
| 54 // use RawResource. However, it is, and it needs to be able to defer loading
. | 57 // use RawResource. However, it is, and it needs to be able to defer loading
. |
| 55 // This can be fixed by splitting CORS preflighting out of DocumentThreacabl
eLoader. | 58 // This can be fixed by splitting CORS preflighting out of DocumentThreacabl
eLoader. |
| 56 void setDefersLoading(bool); | 59 void setDefersLoading(bool); |
| 57 | 60 |
| 58 bool canReuse(const ResourceRequest&) const override; | 61 bool canReuse(const ResourceRequest&) const override; |
| 59 | 62 |
| 60 private: | 63 private: |
| 61 class RawResourceFactory : public ResourceFactory { | 64 class RawResourceFactory : public ResourceFactory { |
| 62 public: | 65 public: |
| 63 RawResourceFactory(Resource::Type type) | 66 RawResourceFactory(Resource::Type type) |
| 64 : ResourceFactory(type) { } | 67 : ResourceFactory(type) { } |
| 65 | 68 |
| 66 Resource* create(const ResourceRequest& request, const String& charset)
const override | 69 PassRefPtrWillBeRawPtr<Resource> create(const ResourceRequest& request,
const String& charset) const override |
| 67 { | 70 { |
| 68 return new RawResource(request, m_type); | 71 return adoptRefWillBeNoop(new RawResource(request, m_type)); |
| 69 } | 72 } |
| 70 }; | 73 }; |
| 71 | 74 |
| 75 RawResource(const ResourceRequest&, Type); |
| 76 |
| 72 void didAddClient(ResourceClient*) override; | 77 void didAddClient(ResourceClient*) override; |
| 73 void appendData(const char*, size_t) override; | 78 void appendData(const char*, size_t) override; |
| 74 | 79 |
| 75 bool shouldIgnoreHTTPStatusCodeErrors() const override { return !isLinkPrelo
ad(); } | 80 bool shouldIgnoreHTTPStatusCodeErrors() const override { return !isLinkPrelo
ad(); } |
| 76 | 81 |
| 77 void willFollowRedirect(ResourceRequest&, const ResourceResponse&) override; | 82 void willFollowRedirect(ResourceRequest&, const ResourceResponse&) override; |
| 78 void updateRequest(const ResourceRequest&) override; | 83 void updateRequest(const ResourceRequest&) override; |
| 79 void responseReceived(const ResourceResponse&, PassOwnPtr<WebDataConsumerHan
dle>) override; | 84 void responseReceived(const ResourceResponse&, PassOwnPtr<WebDataConsumerHan
dle>) override; |
| 80 void setSerializedCachedMetadata(const char*, size_t) override; | 85 void setSerializedCachedMetadata(const char*, size_t) override; |
| 81 void didSendData(unsigned long long bytesSent, unsigned long long totalBytes
ToBeSent) override; | 86 void didSendData(unsigned long long bytesSent, unsigned long long totalBytes
ToBeSent) override; |
| 82 void didDownloadData(int) override; | 87 void didDownloadData(int) override; |
| 83 void reportResourceTimingToClients(const ResourceTimingInfo&) override; | 88 void reportResourceTimingToClients(const ResourceTimingInfo&) override; |
| 84 }; | 89 }; |
| 85 | 90 |
| 86 #if ENABLE(SECURITY_ASSERT) | 91 #if ENABLE(SECURITY_ASSERT) |
| 87 inline bool isRawResource(const Resource& resource) | 92 inline bool isRawResource(const Resource& resource) |
| 88 { | 93 { |
| 89 Resource::Type type = resource.type(); | 94 Resource::Type type = resource.type(); |
| 90 return type == Resource::MainResource || type == Resource::Raw || type == Re
source::TextTrack || type == Resource::Media || type == Resource::Manifest || ty
pe == Resource::ImportResource; | 95 return type == Resource::MainResource || type == Resource::Raw || type == Re
source::TextTrack || type == Resource::Media || type == Resource::Manifest || ty
pe == Resource::ImportResource; |
| 91 } | 96 } |
| 92 #endif | 97 #endif |
| 93 inline RawResource* toRawResource(const ResourcePtr<Resource>& resource) | 98 inline PassRefPtrWillBeRawPtr<RawResource> toRawResource(const PassRefPtrWillBeR
awPtr<Resource>& resource) |
| 94 { | 99 { |
| 95 ASSERT_WITH_SECURITY_IMPLICATION(!resource || isRawResource(*resource.get())
); | 100 ASSERT_WITH_SECURITY_IMPLICATION(!resource || isRawResource(*resource.get())
); |
| 96 return static_cast<RawResource*>(resource.get()); | 101 return static_cast<RawResource*>(resource.get()); |
| 97 } | 102 } |
| 98 | 103 |
| 99 class CORE_EXPORT RawResourceClient : public ResourceClient { | 104 class CORE_EXPORT RawResourceClient : public ResourceClient { |
| 100 public: | 105 public: |
| 101 ~RawResourceClient() override {} | 106 ~RawResourceClient() override {} |
| 102 static ResourceClientType expectedType() { return RawResourceType; } | 107 static ResourceClientType expectedType() { return RawResourceType; } |
| 103 ResourceClientType resourceClientType() const final { return expectedType();
} | 108 ResourceClientType resourceClientType() const final { return expectedType();
} |
| 104 | 109 |
| 105 virtual void dataSent(Resource*, unsigned long long /* bytesSent */, unsigne
d long long /* totalBytesToBeSent */) { } | 110 virtual void dataSent(Resource*, unsigned long long /* bytesSent */, unsigne
d long long /* totalBytesToBeSent */) { } |
| 106 virtual void responseReceived(Resource*, const ResourceResponse&, PassOwnPtr
<WebDataConsumerHandle>) { } | 111 virtual void responseReceived(Resource*, const ResourceResponse&, PassOwnPtr
<WebDataConsumerHandle>) { } |
| 107 virtual void setSerializedCachedMetadata(Resource*, const char*, size_t) { } | 112 virtual void setSerializedCachedMetadata(Resource*, const char*, size_t) { } |
| 108 virtual void dataReceived(Resource*, const char* /* data */, size_t /* lengt
h */) { } | 113 virtual void dataReceived(Resource*, const char* /* data */, size_t /* lengt
h */) { } |
| 109 virtual void redirectReceived(Resource*, ResourceRequest&, const ResourceRes
ponse&) { } | 114 virtual void redirectReceived(Resource*, ResourceRequest&, const ResourceRes
ponse&) { } |
| 110 virtual void updateRequest(Resource*, const ResourceRequest&) { } | 115 virtual void updateRequest(Resource*, const ResourceRequest&) { } |
| 111 virtual void dataDownloaded(Resource*, int) { } | 116 virtual void dataDownloaded(Resource*, int) { } |
| 112 virtual void didReceiveResourceTiming(Resource*, const ResourceTimingInfo&)
{ } | 117 virtual void didReceiveResourceTiming(Resource*, const ResourceTimingInfo&)
{ } |
| 113 }; | 118 }; |
| 114 | 119 |
| 115 } // namespace blink | 120 } // namespace blink |
| 116 | 121 |
| 117 #endif // RawResource_h | 122 #endif // RawResource_h |
| OLD | NEW |