06040a8a944d9778258f9f57e70ae5f46ecf3484
[WebKit-https.git] / Source / WebKit2 / UIProcess / WebProcessProxy.h
1 /*
2  * Copyright (C) 2010, 2011 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 WebProcessProxy_h
27 #define WebProcessProxy_h
28
29 #include "APISession.h"
30 #include "ChildProcessProxy.h"
31 #include "MessageReceiverMap.h"
32 #include "PlatformProcessIdentifier.h"
33 #include "PluginInfoStore.h"
34 #include "ProcessLauncher.h"
35 #include "ResponsivenessTimer.h"
36 #include "WebConnectionToWebProcess.h"
37 #include "WebPageProxy.h"
38 #include "WebProcessProxyMessages.h"
39 #include <WebCore/LinkHash.h>
40 #include <wtf/Forward.h>
41 #include <wtf/HashMap.h>
42 #include <wtf/PassRefPtr.h>
43 #include <wtf/RefCounted.h>
44
45 #if ENABLE(CUSTOM_PROTOCOLS)
46 #include "CustomProtocolManagerProxy.h"
47 #endif
48
49 namespace WebCore {
50 class URL;
51 struct PluginInfo;
52 };
53
54 namespace WebKit {
55
56 class DownloadProxyMap;
57 class WebBackForwardListItem;
58 class WebContext;
59 class WebPageGroup;
60 struct WebNavigationDataStore;
61
62 class WebProcessProxy : public ChildProcessProxy, ResponsivenessTimer::Client {
63 public:
64     typedef HashMap<uint64_t, RefPtr<WebBackForwardListItem>> WebBackForwardListItemMap;
65     typedef HashMap<uint64_t, RefPtr<WebFrameProxy>> WebFrameProxyMap;
66     typedef HashMap<uint64_t, WebPageProxy*> WebPageProxyMap;
67
68     static PassRefPtr<WebProcessProxy> create(WebContext&);
69     ~WebProcessProxy();
70
71     static WebProcessProxy* fromConnection(IPC::Connection* connection)
72     {
73         return static_cast<WebProcessProxy*>(ChildProcessProxy::fromConnection(connection));
74     }
75
76     WebConnection* webConnection() const { return m_webConnection.get(); }
77
78     WebContext& context() { return m_context.get(); }
79
80     static WebPageProxy* webPage(uint64_t pageID);
81     PassRefPtr<WebPageProxy> createWebPage(PageClient&, const WebPageConfiguration&);
82     void addExistingWebPage(WebPageProxy*, uint64_t pageID);
83     void removeWebPage(uint64_t pageID);
84     Vector<WebPageProxy*> pages() const;
85
86     WebBackForwardListItem* webBackForwardItem(uint64_t itemID) const;
87
88     ResponsivenessTimer* responsivenessTimer() { return &m_responsivenessTimer; }
89
90     WebFrameProxy* webFrame(uint64_t) const;
91     bool canCreateFrame(uint64_t frameID) const;
92     void frameCreated(uint64_t, WebFrameProxy*);
93     void disconnectFramesFromPage(WebPageProxy*); // Including main frame.
94     size_t frameCountInPage(WebPageProxy*) const; // Including main frame.
95
96     void updateTextCheckerState();
97
98     void registerNewWebBackForwardListItem(WebBackForwardListItem*);
99
100     void willAcquireUniversalFileReadSandboxExtension() { m_mayHaveUniversalFileReadSandboxExtension = true; }
101     void assumeReadAccessToBaseURL(const String&);
102
103     bool checkURLReceivedFromWebProcess(const String&);
104     bool checkURLReceivedFromWebProcess(const WebCore::URL&);
105
106     static bool fullKeyboardAccessEnabled();
107
108     DownloadProxy* createDownloadProxy();
109
110     void pageSuppressibilityChanged(WebPageProxy*);
111     void pagePreferencesChanged(WebPageProxy*);
112
113     void didSaveToPageCache();
114     void releasePageCache();
115
116 #if PLATFORM(COCOA)
117     bool allPagesAreProcessSuppressible() const;
118     void updateProcessSuppressionState();
119 #endif
120
121     void enableSuddenTermination();
122     void disableSuddenTermination();
123
124     void requestTermination();
125
126     RefPtr<API::Object> apiObjectByConvertingToHandles(API::Object*);
127
128     void windowServerConnectionStateChanged();
129
130     void updateProcessState();
131
132 private:
133     explicit WebProcessProxy(WebContext&);
134
135     // From ChildProcessProxy
136     virtual void getLaunchOptions(ProcessLauncher::LaunchOptions&) override;
137     void platformGetLaunchOptions(ProcessLauncher::LaunchOptions&);
138     virtual void connectionWillOpen(IPC::Connection*) override;
139     virtual void connectionWillClose(IPC::Connection*) override;
140
141     // Called when the web process has crashed or we know that it will terminate soon.
142     // Will potentially cause the WebProcessProxy object to be freed.
143     void disconnect();
144
145     // IPC message handlers.
146     void addBackForwardItem(uint64_t itemID, const String& originalURLString, const String& urlString, const String& title, const IPC::DataReference& backForwardData);
147     void didDestroyFrame(uint64_t);
148     
149     void shouldTerminate(bool& shouldTerminate);
150
151     // Plugins
152 #if ENABLE(NETSCAPE_PLUGIN_API)
153     void getPlugins(bool refresh, Vector<WebCore::PluginInfo>& plugins, Vector<WebCore::PluginInfo>& applicationPlugins);
154 #endif // ENABLE(NETSCAPE_PLUGIN_API)
155 #if ENABLE(NETSCAPE_PLUGIN_API)
156     void getPluginProcessConnection(uint64_t pluginProcessToken, PassRefPtr<Messages::WebProcessProxy::GetPluginProcessConnection::DelayedReply>);
157 #endif
158 #if ENABLE(NETWORK_PROCESS)
159     void getNetworkProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply>);
160 #endif
161 #if ENABLE(DATABASE_PROCESS)
162     void getDatabaseProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetDatabaseProcessConnection::DelayedReply>);
163 #endif
164
165     // IPC::Connection::Client
166     friend class WebConnectionToWebProcess;
167     virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override;
168     virtual void didReceiveSyncMessage(IPC::Connection*, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&) override;
169     virtual void didClose(IPC::Connection*) override;
170     virtual void didReceiveInvalidMessage(IPC::Connection*, IPC::StringReference messageReceiverName, IPC::StringReference messageName) override;
171
172     // ResponsivenessTimer::Client
173     void didBecomeUnresponsive(ResponsivenessTimer*) override;
174     void interactionOccurredWhileUnresponsive(ResponsivenessTimer*) override;
175     void didBecomeResponsive(ResponsivenessTimer*) override;
176
177     // ProcessLauncher::Client
178     virtual void didFinishLaunching(ProcessLauncher*, IPC::Connection::Identifier) override;
179
180     // History client
181     void didNavigateWithNavigationData(uint64_t pageID, const WebNavigationDataStore&, uint64_t frameID);
182     void didPerformClientRedirect(uint64_t pageID, const String& sourceURLString, const String& destinationURLString, uint64_t frameID);
183     void didPerformServerRedirect(uint64_t pageID, const String& sourceURLString, const String& destinationURLString, uint64_t frameID);
184     void didUpdateHistoryTitle(uint64_t pageID, const String& title, const String& url, uint64_t frameID);
185
186     // Implemented in generated WebProcessProxyMessageReceiver.cpp
187     void didReceiveWebProcessProxyMessage(IPC::Connection*, IPC::MessageDecoder&);
188     void didReceiveSyncWebProcessProxyMessage(IPC::Connection*, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&);
189
190     bool canTerminateChildProcess();
191
192     ResponsivenessTimer m_responsivenessTimer;
193     
194     RefPtr<WebConnectionToWebProcess> m_webConnection;
195     Ref<WebContext> m_context;
196
197     bool m_mayHaveUniversalFileReadSandboxExtension; // True if a read extension for "/" was ever granted - we don't track whether WebProcess still has it.
198     HashSet<String> m_localPathsWithAssumedReadAccess;
199
200     WebPageProxyMap m_pageMap;
201     WebFrameProxyMap m_frameMap;
202     WebBackForwardListItemMap m_backForwardListItemMap;
203
204     OwnPtr<DownloadProxyMap> m_downloadProxyMap;
205
206 #if ENABLE(CUSTOM_PROTOCOLS)
207     CustomProtocolManagerProxy m_customProtocolManagerProxy;
208 #endif
209
210 #if PLATFORM(COCOA)
211     HashSet<uint64_t> m_processSuppressiblePages;
212     bool m_processSuppressionEnabled;
213 #endif
214
215     int m_numberOfTimesSuddenTerminationWasDisabled;
216 };
217
218 #if !PLATFORM(IOS)
219 void WebProcessProxy::updateProcessState() { }
220 #endif
221
222 } // namespace WebKit
223
224 #endif // WebProcessProxy_h