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 NetworkProcessProxy_h
27#define NetworkProcessProxy_h
28
29#if ENABLE(NETWORK_PROCESS)
30
31#include "ChildProcessProxy.h"
32#include "ProcessLauncher.h"
33#include "WebProcessProxyMessages.h"
34#include <memory>
35#include <wtf/Deque.h>
36
37#if ENABLE(CUSTOM_PROTOCOLS)
38#include "CustomProtocolManagerProxy.h"
39#endif
40
41#if PLATFORM(IOS)
42#include "ProcessAssertion.h"
43#endif
44
45namespace WebCore {
46class AuthenticationChallenge;
47}
48
49namespace WebKit {
50
51class DownloadProxy;
52class DownloadProxyMap;
53class WebContext;
54struct NetworkProcessCreationParameters;
55
56class NetworkProcessProxy : public ChildProcessProxy {
57public:
58    static PassRefPtr<NetworkProcessProxy> create(WebContext&);
59    ~NetworkProcessProxy();
60
61    void getNetworkProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply>);
62
63    DownloadProxy* createDownloadProxy();
64
65#if PLATFORM(COCOA)
66    void setProcessSuppressionEnabled(bool);
67#endif
68
69private:
70    NetworkProcessProxy(WebContext&);
71
72    // ChildProcessProxy
73    virtual void getLaunchOptions(ProcessLauncher::LaunchOptions&) override;
74    virtual void connectionWillOpen(IPC::Connection*) override;
75    virtual void connectionWillClose(IPC::Connection*) override;
76
77    void platformGetLaunchOptions(ProcessLauncher::LaunchOptions&);
78    void networkProcessCrashedOrFailedToLaunch();
79
80    // IPC::Connection::Client
81    virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override;
82    virtual void didReceiveSyncMessage(IPC::Connection*, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&) override;
83    virtual void didClose(IPC::Connection*) override;
84    virtual void didReceiveInvalidMessage(IPC::Connection*, IPC::StringReference messageReceiverName, IPC::StringReference messageName) override;
85
86    // Message handlers
87    void didReceiveNetworkProcessProxyMessage(IPC::Connection*, IPC::MessageDecoder&);
88    void didCreateNetworkConnectionToWebProcess(const IPC::Attachment&);
89    void didReceiveAuthenticationChallenge(uint64_t pageID, uint64_t frameID, const WebCore::AuthenticationChallenge&, uint64_t challengeID);
90
91    // ProcessLauncher::Client
92    virtual void didFinishLaunching(ProcessLauncher*, IPC::Connection::Identifier);
93
94    WebContext& m_webContext;
95
96    unsigned m_numPendingConnectionRequests;
97    Deque<RefPtr<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply>> m_pendingConnectionReplies;
98
99    std::unique_ptr<DownloadProxyMap> m_downloadProxyMap;
100
101#if ENABLE(CUSTOM_PROTOCOLS)
102    CustomProtocolManagerProxy m_customProtocolManagerProxy;
103#endif
104
105#if PLATFORM(IOS)
106    std::unique_ptr<ProcessAssertion> m_assertion;
107#endif
108};
109
110} // namespace WebKit
111
112#endif // ENABLE(NETWORK_PROCESS)
113
114#endif // NetworkProcessProxy_h
115