Remove "virtual" from all lines that have both "virtual" and "override".
[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 "PluginInfoStore.h"
34 #include "ProcessLauncher.h"
35 #include "ProcessThrottlerClient.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 NetworkProcessProxy;
60 class WebBackForwardListItem;
61 class WebPageGroup;
62 class WebProcessPool;
63 enum class WebsiteDataType;
64 struct WebNavigationDataStore;
65     
66 class WebProcessProxy : public ChildProcessProxy, ResponsivenessTimer::Client, private ProcessThrottlerClient {
67 public:
68     typedef HashMap<uint64_t, RefPtr<WebBackForwardListItem>> WebBackForwardListItemMap;
69     typedef HashMap<uint64_t, RefPtr<WebFrameProxy>> WebFrameProxyMap;
70     typedef HashMap<uint64_t, WebPageProxy*> WebPageProxyMap;
71
72     static Ref<WebProcessProxy> create(WebProcessPool&);
73     ~WebProcessProxy();
74
75     static WebProcessProxy* fromConnection(IPC::Connection* connection)
76     {
77         return static_cast<WebProcessProxy*>(ChildProcessProxy::fromConnection(connection));
78     }
79
80     WebConnection* webConnection() const { return m_webConnection.get(); }
81
82     WebProcessPool& processPool() { return m_processPool; }
83
84     static WebPageProxy* webPage(uint64_t pageID);
85     Ref<WebPageProxy> createWebPage(PageClient&, Ref<API::PageConfiguration>&&);
86     void addExistingWebPage(WebPageProxy*, uint64_t pageID);
87     void removeWebPage(uint64_t pageID);
88
89     WTF::IteratorRange<WebPageProxyMap::const_iterator::Values> pages() const { return m_pageMap.values(); }
90     unsigned pageCount() const { return m_pageMap.size(); }
91
92     void addVisitedLinkStore(VisitedLinkStore&);
93     void addWebUserContentControllerProxy(WebUserContentControllerProxy&);
94     void didDestroyVisitedLinkStore(VisitedLinkStore&);
95     void didDestroyWebUserContentControllerProxy(WebUserContentControllerProxy&);
96
97     WebBackForwardListItem* webBackForwardItem(uint64_t itemID) const;
98
99     ResponsivenessTimer& responsivenessTimer() { return m_responsivenessTimer; }
100
101     WebFrameProxy* webFrame(uint64_t) const;
102     bool canCreateFrame(uint64_t frameID) const;
103     void frameCreated(uint64_t, WebFrameProxy*);
104     void disconnectFramesFromPage(WebPageProxy*); // Including main frame.
105     size_t frameCountInPage(WebPageProxy*) const; // Including main frame.
106
107     void updateTextCheckerState();
108
109     void registerNewWebBackForwardListItem(WebBackForwardListItem*);
110     void removeBackForwardItem(uint64_t);
111
112     void willAcquireUniversalFileReadSandboxExtension() { m_mayHaveUniversalFileReadSandboxExtension = true; }
113     void assumeReadAccessToBaseURL(const String&);
114     bool hasAssumedReadAccessToURL(const WebCore::URL&) const;
115
116     bool checkURLReceivedFromWebProcess(const String&);
117     bool checkURLReceivedFromWebProcess(const WebCore::URL&);
118
119     static bool fullKeyboardAccessEnabled();
120
121     void didSaveToPageCache();
122     void releasePageCache();
123
124     void fetchWebsiteData(WebCore::SessionID, OptionSet<WebsiteDataType>, std::function<void (WebsiteData)> completionHandler);
125     void deleteWebsiteData(WebCore::SessionID, OptionSet<WebsiteDataType>, std::chrono::system_clock::time_point modifiedSince, std::function<void ()> completionHandler);
126     void deleteWebsiteDataForOrigins(WebCore::SessionID, OptionSet<WebsiteDataType>, const Vector<RefPtr<WebCore::SecurityOrigin>>& origins, std::function<void ()> completionHandler);
127
128     void enableSuddenTermination();
129     void disableSuddenTermination();
130     bool isSuddenTerminationEnabled() { return !m_numberOfTimesSuddenTerminationWasDisabled; }
131
132     void requestTermination();
133
134     RefPtr<API::Object> transformHandlesToObjects(API::Object*);
135     static RefPtr<API::Object> transformObjectsToHandles(API::Object*);
136
137 #if PLATFORM(COCOA)
138     RefPtr<ObjCObjectGraph> transformHandlesToObjects(ObjCObjectGraph&);
139     static RefPtr<ObjCObjectGraph> transformObjectsToHandles(ObjCObjectGraph&);
140 #endif
141
142     void windowServerConnectionStateChanged();
143
144     void processReadyToSuspend();
145     void didCancelProcessSuspension();
146
147     void setIsHoldingLockedFiles(bool);
148
149     ProcessThrottler& throttler() { return m_throttler; }
150
151     void reinstateNetworkProcessAssertionState(NetworkProcessProxy&);
152
153     void isResponsive(std::function<void(bool isWebProcessResponsive)>);
154     void didReceiveMainThreadPing();
155
156 private:
157     explicit WebProcessProxy(WebProcessPool&);
158
159     // From ChildProcessProxy
160     void getLaunchOptions(ProcessLauncher::LaunchOptions&) override;
161     void platformGetLaunchOptions(ProcessLauncher::LaunchOptions&);
162     void connectionWillOpen(IPC::Connection&) override;
163     void processWillShutDown(IPC::Connection&) override;
164
165     // Called when the web process has crashed or we know that it will terminate soon.
166     // Will potentially cause the WebProcessProxy object to be freed.
167     void shutDown();
168
169     // IPC message handlers.
170     void addBackForwardItem(uint64_t itemID, uint64_t pageID, const PageState&);
171     void didDestroyFrame(uint64_t);
172     
173     void shouldTerminate(bool& shouldTerminate);
174
175     void didFetchWebsiteData(uint64_t callbackID, const WebsiteData&);
176     void didDeleteWebsiteData(uint64_t callbackID);
177     void didDeleteWebsiteDataForOrigins(uint64_t callbackID);
178
179     // Plugins
180 #if ENABLE(NETSCAPE_PLUGIN_API)
181     void getPlugins(bool refresh, Vector<WebCore::PluginInfo>& plugins, Vector<WebCore::PluginInfo>& applicationPlugins);
182 #endif // ENABLE(NETSCAPE_PLUGIN_API)
183 #if ENABLE(NETSCAPE_PLUGIN_API)
184     void getPluginProcessConnection(uint64_t pluginProcessToken, PassRefPtr<Messages::WebProcessProxy::GetPluginProcessConnection::DelayedReply>);
185 #endif
186     void getNetworkProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetNetworkProcessConnection::DelayedReply>);
187 #if ENABLE(DATABASE_PROCESS)
188     void getDatabaseProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetDatabaseProcessConnection::DelayedReply>);
189 #endif
190
191     void retainIconForPageURL(const String& pageURL);
192     void releaseIconForPageURL(const String& pageURL);
193     void releaseRemainingIconsForPageURLs();
194
195     // IPC::Connection::Client
196     friend class WebConnectionToWebProcess;
197     void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override;
198     void didReceiveSyncMessage(IPC::Connection&, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&) override;
199     void didClose(IPC::Connection&) override;
200     void didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference messageReceiverName, IPC::StringReference messageName) override;
201     IPC::ProcessType localProcessType() override { return IPC::ProcessType::UI; }
202     IPC::ProcessType remoteProcessType() override { return IPC::ProcessType::Web; }
203
204     // ResponsivenessTimer::Client
205     void didBecomeUnresponsive() override;
206     void didBecomeResponsive() override;
207     void willChangeIsResponsive() override;
208     void didChangeIsResponsive() override;
209
210     // ProcessThrottlerClient
211     void sendProcessWillSuspendImminently() override;
212     void sendPrepareToSuspend() override;
213     void sendCancelPrepareToSuspend() override;
214     void sendProcessDidResume() override;
215     void didSetAssertionState(AssertionState) override;
216
217     // ProcessLauncher::Client
218     void didFinishLaunching(ProcessLauncher*, IPC::Connection::Identifier) override;
219
220     // Implemented in generated WebProcessProxyMessageReceiver.cpp
221     void didReceiveWebProcessProxyMessage(IPC::Connection&, IPC::MessageDecoder&);
222     void didReceiveSyncWebProcessProxyMessage(IPC::Connection&, IPC::MessageDecoder&, std::unique_ptr<IPC::MessageEncoder>&);
223
224     bool canTerminateChildProcess();
225
226     ResponsivenessTimer m_responsivenessTimer;
227     
228     RefPtr<WebConnectionToWebProcess> m_webConnection;
229     Ref<WebProcessPool> m_processPool;
230
231     bool m_mayHaveUniversalFileReadSandboxExtension; // True if a read extension for "/" was ever granted - we don't track whether WebProcess still has it.
232     HashSet<String> m_localPathsWithAssumedReadAccess;
233
234     WebPageProxyMap m_pageMap;
235     WebFrameProxyMap m_frameMap;
236     WebBackForwardListItemMap m_backForwardListItemMap;
237
238     HashSet<VisitedLinkStore*> m_visitedLinkStores;
239     HashSet<WebUserContentControllerProxy*> m_webUserContentControllerProxies;
240
241     CustomProtocolManagerProxy m_customProtocolManagerProxy;
242
243     HashMap<uint64_t, std::function<void (WebsiteData)>> m_pendingFetchWebsiteDataCallbacks;
244     HashMap<uint64_t, std::function<void ()>> m_pendingDeleteWebsiteDataCallbacks;
245     HashMap<uint64_t, std::function<void ()>> m_pendingDeleteWebsiteDataForOriginsCallbacks;
246
247     int m_numberOfTimesSuddenTerminationWasDisabled;
248     ProcessThrottler m_throttler;
249     ProcessThrottler::BackgroundActivityToken m_tokenForHoldingLockedFiles;
250 #if PLATFORM(IOS)
251     ProcessThrottler::ForegroundActivityToken m_foregroundTokenForNetworkProcess;
252     ProcessThrottler::BackgroundActivityToken m_backgroundTokenForNetworkProcess;
253 #endif
254
255     HashMap<String, uint64_t> m_pageURLRetainCountMap;
256
257     enum class NoOrMaybe { No, Maybe } m_isResponsive;
258     Vector<std::function<void(bool webProcessIsResponsive)>> m_isResponsiveCallbacks;
259 };
260
261 } // namespace WebKit
262
263 #endif // WebProcessProxy_h