2 * Copyright (C) 2012, 2015 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
28 #include "WebResourceLoader.h"
29 #include <WebCore/LoaderStrategy.h>
30 #include <WebCore/ResourceLoader.h>
31 #include <wtf/HashSet.h>
32 #include <wtf/RunLoop.h>
40 class NetworkProcessConnection;
41 class WebURLSchemeTaskProxy;
42 typedef uint64_t ResourceLoadIdentifier;
44 class WebLoaderStrategy final : public WebCore::LoaderStrategy {
45 WTF_MAKE_NONCOPYABLE(WebLoaderStrategy); WTF_MAKE_FAST_ALLOCATED;
48 ~WebLoaderStrategy() final;
50 RefPtr<WebCore::SubresourceLoader> loadResource(WebCore::Frame&, WebCore::CachedResource&, const WebCore::ResourceRequest&, const WebCore::ResourceLoaderOptions&) final;
51 void loadResourceSynchronously(WebCore::NetworkingContext*, unsigned long resourceLoadIdentifier, const WebCore::ResourceRequest&, WebCore::StoredCredentials, WebCore::ClientCredentialPolicy, WebCore::ResourceError&, WebCore::ResourceResponse&, Vector<char>& data) final;
53 void remove(WebCore::ResourceLoader*) final;
54 void setDefersLoading(WebCore::ResourceLoader*, bool) final;
55 void crossOriginRedirectReceived(WebCore::ResourceLoader*, const WebCore::URL& redirectURL) final;
57 void servePendingRequests(WebCore::ResourceLoadPriority minimumPriority) final;
59 void suspendPendingRequests() final;
60 void resumePendingRequests() final;
62 void createPingHandle(WebCore::NetworkingContext*, WebCore::ResourceRequest&, const WebCore::HTTPHeaderMap& originalRequestHeaders, Ref<WebCore::SecurityOrigin>&& sourceOrigin, WebCore::ContentSecurityPolicy*, const WebCore::FetchOptions&) final;
64 void storeDerivedDataToCache(const SHA1::Digest& bodyHash, const String& type, const String& partition, WebCore::SharedBuffer&) final;
66 void setCaptureExtraNetworkLoadMetricsEnabled(bool) final;
68 WebResourceLoader* webResourceLoaderForIdentifier(ResourceLoadIdentifier identifier) const { return m_webResourceLoaders.get(identifier); }
69 RefPtr<WebCore::NetscapePlugInStreamLoader> schedulePluginStreamLoad(WebCore::Frame&, WebCore::NetscapePlugInStreamLoaderClient&, const WebCore::ResourceRequest&);
71 void networkProcessCrashed();
73 void addURLSchemeTaskProxy(WebURLSchemeTaskProxy&);
74 void removeURLSchemeTaskProxy(WebURLSchemeTaskProxy&);
77 void scheduleLoad(WebCore::ResourceLoader&, WebCore::CachedResource*, bool shouldClearReferrerOnHTTPSToHTTPRedirect);
78 void scheduleInternallyFailedLoad(WebCore::ResourceLoader&);
79 void internallyFailedLoadTimerFired();
80 void startLocalLoad(WebCore::ResourceLoader&);
82 HashSet<RefPtr<WebCore::ResourceLoader>> m_internallyFailedResourceLoaders;
83 RunLoop::Timer<WebLoaderStrategy> m_internallyFailedLoadTimer;
85 HashMap<unsigned long, RefPtr<WebResourceLoader>> m_webResourceLoaders;
86 HashMap<unsigned long, WebURLSchemeTaskProxy*> m_urlSchemeTasks;