e2c5561d2d577ea9ce976b85b898f749eb8360a7
[WebKit-https.git] / Source / WebKit / WebProcess / Network / WebLoaderStrategy.h
1 /*
2  * Copyright (C) 2012, 2015 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  * 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.
12  *
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.
24  */
25
26 #pragma once
27
28 #include "WebResourceLoader.h"
29 #include <WebCore/LoaderStrategy.h>
30 #include <WebCore/ResourceLoader.h>
31 #include <wtf/HashSet.h>
32 #include <wtf/RunLoop.h>
33
34 namespace WebCore {
35 struct FetchOptions;
36 }
37
38 namespace WebKit {
39
40 class NetworkProcessConnection;
41 class WebURLSchemeTaskProxy;
42 typedef uint64_t ResourceLoadIdentifier;
43
44 class WebLoaderStrategy final : public WebCore::LoaderStrategy {
45     WTF_MAKE_NONCOPYABLE(WebLoaderStrategy); WTF_MAKE_FAST_ALLOCATED;
46 public:
47     WebLoaderStrategy();
48     ~WebLoaderStrategy() final;
49     
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::StoredCredentialsPolicy, WebCore::ClientCredentialPolicy, WebCore::ResourceError&, WebCore::ResourceResponse&, Vector<char>& data) final;
52
53     void remove(WebCore::ResourceLoader*) final;
54     void setDefersLoading(WebCore::ResourceLoader*, bool) final;
55     void crossOriginRedirectReceived(WebCore::ResourceLoader*, const WebCore::URL& redirectURL) final;
56     
57     void servePendingRequests(WebCore::ResourceLoadPriority minimumPriority) final;
58
59     void suspendPendingRequests() final;
60     void resumePendingRequests() final;
61
62     void startPingLoad(WebCore::Frame&, WebCore::ResourceRequest&, const WebCore::HTTPHeaderMap& originalRequestHeaders, const WebCore::FetchOptions&, PingLoadCompletionHandler&&) final;
63     void didFinishPingLoad(uint64_t pingLoadIdentifier, WebCore::ResourceError&&, WebCore::ResourceResponse&&);
64
65     void preconnectTo(WebCore::NetworkingContext&, const WebCore::URL&, WebCore::StoredCredentialsPolicy, PreconnectCompletionHandler&&) final;
66     void didFinishPreconnection(uint64_t preconnectionIdentifier, WebCore::ResourceError&&);
67
68     void storeDerivedDataToCache(const SHA1::Digest& bodyHash, const String& type, const String& partition, WebCore::SharedBuffer&) final;
69
70     void setCaptureExtraNetworkLoadMetricsEnabled(bool) final;
71
72     WebResourceLoader* webResourceLoaderForIdentifier(ResourceLoadIdentifier identifier) const { return m_webResourceLoaders.get(identifier); }
73     RefPtr<WebCore::NetscapePlugInStreamLoader> schedulePluginStreamLoad(WebCore::Frame&, WebCore::NetscapePlugInStreamLoaderClient&, const WebCore::ResourceRequest&);
74
75     void networkProcessCrashed();
76
77     void addURLSchemeTaskProxy(WebURLSchemeTaskProxy&);
78     void removeURLSchemeTaskProxy(WebURLSchemeTaskProxy&);
79
80     void scheduleLoadFromNetworkProcess(WebCore::ResourceLoader&, const WebCore::ResourceRequest&, const WebResourceLoader::TrackingParameters&, PAL::SessionID, bool shouldClearReferrerOnHTTPSToHTTPRedirect, Seconds maximumBufferingTime);
81
82 private:
83     void scheduleLoad(WebCore::ResourceLoader&, WebCore::CachedResource*, bool shouldClearReferrerOnHTTPSToHTTPRedirect);
84     void scheduleInternallyFailedLoad(WebCore::ResourceLoader&);
85     void internallyFailedLoadTimerFired();
86     void startLocalLoad(WebCore::ResourceLoader&);
87
88     HashSet<RefPtr<WebCore::ResourceLoader>> m_internallyFailedResourceLoaders;
89     RunLoop::Timer<WebLoaderStrategy> m_internallyFailedLoadTimer;
90     
91     HashMap<unsigned long, RefPtr<WebResourceLoader>> m_webResourceLoaders;
92     HashMap<unsigned long, WebURLSchemeTaskProxy*> m_urlSchemeTasks;
93     HashMap<unsigned long, PingLoadCompletionHandler> m_pingLoadCompletionHandlers;
94     HashMap<unsigned long, PreconnectCompletionHandler> m_preconnectCompletionHandlers;
95 };
96
97 } // namespace WebKit