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