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