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