1 | /* |
2 | * Copyright (C) 2012 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 "Connection.h" |
29 | #include "MessageSender.h" |
30 | #include "ShareableResource.h" |
31 | #include <WebCore/PageIdentifier.h> |
32 | #include <wtf/RefCounted.h> |
33 | #include <wtf/RefPtr.h> |
34 | |
35 | namespace IPC { |
36 | class DataReference; |
37 | } |
38 | |
39 | namespace WebCore { |
40 | class NetworkLoadMetrics; |
41 | class ResourceError; |
42 | class ResourceLoader; |
43 | class ResourceRequest; |
44 | class ResourceResponse; |
45 | } |
46 | |
47 | namespace WebKit { |
48 | |
49 | typedef uint64_t ResourceLoadIdentifier; |
50 | |
51 | class WebResourceLoader : public RefCounted<WebResourceLoader>, public IPC::MessageSender { |
52 | public: |
53 | struct TrackingParameters { |
54 | WebCore::PageIdentifier pageID; |
55 | uint64_t frameID { 0 }; |
56 | ResourceLoadIdentifier resourceID { 0 }; |
57 | }; |
58 | |
59 | static Ref<WebResourceLoader> create(Ref<WebCore::ResourceLoader>&&, const TrackingParameters&); |
60 | |
61 | ~WebResourceLoader(); |
62 | |
63 | void didReceiveWebResourceLoaderMessage(IPC::Connection&, IPC::Decoder&); |
64 | |
65 | WebCore::ResourceLoader* resourceLoader() const { return m_coreLoader.get(); } |
66 | |
67 | void detachFromCoreLoader(); |
68 | |
69 | bool isAlwaysOnLoggingAllowed() const; |
70 | |
71 | private: |
72 | WebResourceLoader(Ref<WebCore::ResourceLoader>&&, const TrackingParameters&); |
73 | |
74 | // IPC::MessageSender |
75 | IPC::Connection* messageSenderConnection() const override; |
76 | uint64_t messageSenderDestinationID() const override; |
77 | |
78 | void willSendRequest(WebCore::ResourceRequest&&, WebCore::ResourceResponse&&); |
79 | void didSendData(uint64_t bytesSent, uint64_t totalBytesToBeSent); |
80 | void didReceiveResponse(const WebCore::ResourceResponse&, bool needsContinueDidReceiveResponseMessage); |
81 | void didReceiveData(const IPC::DataReference&, int64_t encodedDataLength); |
82 | void didRetrieveDerivedData(const String& type, const IPC::DataReference&); |
83 | void didFinishResourceLoad(const WebCore::NetworkLoadMetrics&); |
84 | void didFailResourceLoad(const WebCore::ResourceError&); |
85 | void didBlockAuthenticationChallenge(); |
86 | |
87 | void stopLoadingAfterXFrameOptionsOrContentSecurityPolicyDenied(const WebCore::ResourceResponse&); |
88 | |
89 | #if ENABLE(SHAREABLE_RESOURCE) |
90 | void didReceiveResource(const ShareableResource::Handle&); |
91 | #endif |
92 | |
93 | RefPtr<WebCore::ResourceLoader> m_coreLoader; |
94 | TrackingParameters m_trackingParameters; |
95 | size_t m_numBytesReceived { 0 }; |
96 | |
97 | #if !ASSERT_DISABLED |
98 | bool m_isProcessingNetworkResponse { false }; |
99 | #endif |
100 | }; |
101 | |
102 | } // namespace WebKit |
103 | |