| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2005, 2006, 2011 Apple Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * | |
| 8 * 1. Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | |
| 11 * notice, this list of conditions and the following disclaimer in the | |
| 12 * documentation and/or other materials provided with the distribution. | |
| 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of | |
| 14 * its contributors may be used to endorse or promote products derived | |
| 15 * from this software without specific prior written permission. | |
| 16 * | |
| 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | |
| 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
| 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | |
| 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
| 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 27 */ | |
| 28 | |
| 29 #ifndef ResourceLoader_h | |
| 30 #define ResourceLoader_h | |
| 31 | |
| 32 #include "core/CoreExport.h" | |
| 33 #include "core/fetch/ResourceLoaderOptions.h" | |
| 34 #include "platform/network/ResourceRequest.h" | |
| 35 #include "public/platform/WebURLLoader.h" | |
| 36 #include "public/platform/WebURLLoaderClient.h" | |
| 37 #include "wtf/Forward.h" | |
| 38 #include <memory> | |
| 39 | |
| 40 namespace blink { | |
| 41 | |
| 42 class FetchContext; | |
| 43 class Resource; | |
| 44 class ResourceError; | |
| 45 class ResourceFetcher; | |
| 46 | |
| 47 // A ResourceLoader is created for each Resource by the ResourceFetcher when it | |
| 48 // needs to load the specified resource. A ResourceLoader creates a | |
| 49 // WebURLLoader and loads the resource using it. Any per-load logic should be | |
| 50 // implemented in this class basically. | |
| 51 class CORE_EXPORT ResourceLoader final | |
| 52 : public GarbageCollectedFinalized<ResourceLoader>, | |
| 53 protected WebURLLoaderClient { | |
| 54 USING_PRE_FINALIZER(ResourceLoader, dispose); | |
| 55 | |
| 56 public: | |
| 57 static ResourceLoader* create(ResourceFetcher*, Resource*); | |
| 58 ~ResourceLoader() override; | |
| 59 DECLARE_TRACE(); | |
| 60 | |
| 61 void start(const ResourceRequest&); | |
| 62 | |
| 63 void cancel(); | |
| 64 | |
| 65 void setDefersLoading(bool); | |
| 66 | |
| 67 void didChangePriority(ResourceLoadPriority, int intraPriorityValue); | |
| 68 | |
| 69 // Called before start() to activate cache-aware loading if enabled in | |
| 70 // |m_resource->options()| and applicable. | |
| 71 void activateCacheAwareLoadingIfNeeded(const ResourceRequest&); | |
| 72 | |
| 73 bool isCacheAwareLoadingActivated() const { | |
| 74 return m_isCacheAwareLoadingActivated; | |
| 75 } | |
| 76 | |
| 77 // WebURLLoaderClient | |
| 78 // | |
| 79 // A succesful load will consist of: | |
| 80 // 0+ willFollowRedirect() | |
| 81 // 0+ didSendData() | |
| 82 // 1 didReceiveResponse() | |
| 83 // 0-1 didReceiveCachedMetadata() | |
| 84 // 0+ didReceiveData() or didDownloadData(), but never both | |
| 85 // 1 didFinishLoading() | |
| 86 // A failed load is indicated by 1 didFail(), which can occur at any time | |
| 87 // before didFinishLoading(), including synchronous inside one of the other | |
| 88 // callbacks via ResourceLoader::cancel() | |
| 89 bool willFollowRedirect(WebURLRequest&, | |
| 90 const WebURLResponse& redirectResponse) override; | |
| 91 void didSendData(unsigned long long bytesSent, | |
| 92 unsigned long long totalBytesToBeSent) override; | |
| 93 void didReceiveResponse(const WebURLResponse&) override; | |
| 94 void didReceiveResponse(const WebURLResponse&, | |
| 95 std::unique_ptr<WebDataConsumerHandle>) override; | |
| 96 void didReceiveCachedMetadata(const char* data, int length) override; | |
| 97 void didReceiveData(const char*, int) override; | |
| 98 void didReceiveTransferSizeUpdate(int transferSizeDiff) override; | |
| 99 void didDownloadData(int, int) override; | |
| 100 void didFinishLoading(double finishTime, | |
| 101 int64_t encodedDataLength, | |
| 102 int64_t encodedBodyLength) override; | |
| 103 void didFail(const WebURLError&, | |
| 104 int64_t encodedDataLength, | |
| 105 int64_t encodedBodyLength) override; | |
| 106 void handleError(const ResourceError&); | |
| 107 | |
| 108 void didFinishLoadingFirstPartInMultipart(); | |
| 109 | |
| 110 private: | |
| 111 // Assumes ResourceFetcher and Resource are non-null. | |
| 112 ResourceLoader(ResourceFetcher*, Resource*); | |
| 113 | |
| 114 // This method is currently only used for service worker fallback request and | |
| 115 // cache-aware loading, other users should be careful not to break | |
| 116 // ResourceLoader state. | |
| 117 void restart(const ResourceRequest&); | |
| 118 | |
| 119 FetchContext& context() const; | |
| 120 ResourceRequestBlockedReason canAccessResponse(Resource*, | |
| 121 const ResourceResponse&) const; | |
| 122 | |
| 123 void cancelForRedirectAccessCheckError(const KURL&, | |
| 124 ResourceRequestBlockedReason); | |
| 125 void requestSynchronously(const ResourceRequest&); | |
| 126 void dispose(); | |
| 127 | |
| 128 std::unique_ptr<WebURLLoader> m_loader; | |
| 129 Member<ResourceFetcher> m_fetcher; | |
| 130 Member<Resource> m_resource; | |
| 131 bool m_isCacheAwareLoadingActivated; | |
| 132 }; | |
| 133 | |
| 134 } // namespace blink | |
| 135 | |
| 136 #endif | |
| OLD | NEW |