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