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#ifndef WebResourceLoader_h
27#define WebResourceLoader_h
28
29#if ENABLE(NETWORK_PROCESS)
30
31#include "Connection.h"
32#include "MessageSender.h"
33#include "ShareableResource.h"
34#include <wtf/PassRefPtr.h>
35#include <wtf/RefCounted.h>
36#include <wtf/RefPtr.h>
37
38#if USE(QUICK_LOOK)
39#include <WebCore/QuickLook.h>
40#endif
41
42namespace IPC {
43class DataReference;
44}
45
46namespace WebCore {
47class CertificateInfo;
48class ProtectionSpace;
49class ResourceBuffer;
50class ResourceError;
51class ResourceLoader;
52class ResourceRequest;
53class ResourceResponse;
54}
55
56namespace WebKit {
57
58typedef uint64_t ResourceLoadIdentifier;
59
60class WebResourceLoader : public RefCounted<WebResourceLoader>, public IPC::MessageSender {
61public:
62    static PassRefPtr<WebResourceLoader> create(PassRefPtr<WebCore::ResourceLoader>);
63
64    ~WebResourceLoader();
65
66    void didReceiveWebResourceLoaderMessage(IPC::Connection*, IPC::MessageDecoder&);
67
68    WebCore::ResourceLoader* resourceLoader() const { return m_coreLoader.get(); }
69
70    void detachFromCoreLoader();
71
72private:
73    WebResourceLoader(PassRefPtr<WebCore::ResourceLoader>);
74
75    // IPC::MessageSender
76    virtual IPC::Connection* messageSenderConnection() override;
77    virtual uint64_t messageSenderDestinationID() override;
78
79    void cancelResourceLoader();
80
81    void willSendRequest(const WebCore::ResourceRequest&, const WebCore::ResourceResponse& redirectResponse);
82    void didSendData(uint64_t bytesSent, uint64_t totalBytesToBeSent);
83    void didReceiveResponseWithCertificateInfo(const WebCore::ResourceResponse&, const WebCore::CertificateInfo&, bool needsContinueDidReceiveResponseMessage);
84    void didReceiveData(const IPC::DataReference&, int64_t encodedDataLength);
85    void didFinishResourceLoad(double finishTime);
86    void didFailResourceLoad(const WebCore::ResourceError&);
87#if ENABLE(SHAREABLE_RESOURCE)
88    void didReceiveResource(const ShareableResource::Handle&, double finishTime);
89#endif
90
91#if USE(PROTECTION_SPACE_AUTH_CALLBACK)
92    void canAuthenticateAgainstProtectionSpace(const WebCore::ProtectionSpace&);
93#endif
94
95    RefPtr<WebCore::ResourceLoader> m_coreLoader;
96};
97
98} // namespace WebKit
99
100#endif // ENABLE(NETWORK_PROCESS)
101
102#endif // WebResourceLoader_h
103