2 * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef WebProcessProxy_h
27 #define WebProcessProxy_h
29 #include "PlatformProcessIdentifier.h"
30 #include "PluginInfoStore.h"
31 #include "ProcessLauncher.h"
32 #include "ProcessModel.h"
33 #include "ResponsivenessTimer.h"
34 #include "ThreadLauncher.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 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
44 #include <PlatformSurfaceTexturePoolEfl.h>
53 #if USE(SECURITY_FRAMEWORK)
54 class SecItemRequestData;
55 class SecItemResponseData;
58 class WebBackForwardListItem;
61 struct WebNavigationDataStore;
62 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
63 class PlatformSurfaceTexturePool;
66 class WebProcessProxy : public RefCounted<WebProcessProxy>, CoreIPC::Connection::Client, ResponsivenessTimer::Client, ProcessLauncher::Client, ThreadLauncher::Client, CoreIPC::Connection::QueueClient {
68 typedef HashMap<uint64_t, RefPtr<WebFrameProxy> > WebFrameProxyMap;
69 typedef HashMap<uint64_t, RefPtr<WebBackForwardListItem> > WebBackForwardListItemMap;
71 static PassRefPtr<WebProcessProxy> create(PassRefPtr<WebContext>);
76 template<typename T> bool send(const T& message, uint64_t destinationID, unsigned messageSendFlags = 0);
77 template<typename U> bool sendSync(const U& message, const typename U::Reply& reply, uint64_t destinationID, double timeout = 1);
79 CoreIPC::Connection* connection() const
83 return m_connection->connection();
85 WebConnection* webConnection() const { return m_connection.get(); }
87 WebContext* context() const { return m_context.get(); }
89 PlatformProcessIdentifier processIdentifier() const { return m_processLauncher->processIdentifier(); }
91 WebPageProxy* webPage(uint64_t pageID) const;
92 PassRefPtr<WebPageProxy> createWebPage(PageClient*, WebContext*, WebPageGroup*);
93 void addExistingWebPage(WebPageProxy*, uint64_t pageID);
94 void removeWebPage(uint64_t pageID);
96 WebBackForwardListItem* webBackForwardItem(uint64_t itemID) const;
98 ResponsivenessTimer* responsivenessTimer() { return &m_responsivenessTimer; }
100 bool isValid() const { return m_connection; }
101 bool isLaunching() const;
102 bool canSendMessage() const { return isValid() || isLaunching(); }
104 WebFrameProxy* webFrame(uint64_t) const;
105 bool canCreateFrame(uint64_t frameID) const;
106 void frameCreated(uint64_t, WebFrameProxy*);
107 void disconnectFramesFromPage(WebPageProxy*); // Including main frame.
108 size_t frameCountInPage(WebPageProxy*) const; // Including main frame.
110 void updateTextCheckerState();
112 void registerNewWebBackForwardListItem(WebBackForwardListItem*);
114 void willAcquireUniversalFileReadSandboxExtension() { m_mayHaveUniversalFileReadSandboxExtension = true; }
115 void assumeReadAccessToBaseURL(const String&);
117 bool checkURLReceivedFromWebProcess(const String&);
118 bool checkURLReceivedFromWebProcess(const WebCore::KURL&);
120 static bool fullKeyboardAccessEnabled();
122 // FIXME: This variant of send is deprecated. All clients should move to an overload that take a message type.
123 template<typename E, typename T> bool deprecatedSend(E messageID, uint64_t destinationID, const T& arguments);
125 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
126 RefPtr<PlatformSurfaceTexturePool> platformSurfaceTexturePool() { return m_platformSurfaceTexturePool.get(); }
127 void removePlatformSurfaceTextureFromPool(int platformSurfaceId);
129 #if ENABLE(TIZEN_WEBKIT2_MEMORY_SAVING_MODE)
130 void setMemorySavingMode(bool);
131 bool memorySavingModeEnabled() { return m_memorySavingModeEnabled; }
133 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
134 void releaseBackingStoreMemory();
138 explicit WebProcessProxy(PassRefPtr<WebContext>);
140 // Initializes the process or thread launcher which will begin launching the process.
143 // Called when the web process has crashed or we know that it will terminate soon.
144 // Will potentially cause the WebProcessProxy object to be freed.
147 bool sendMessage(CoreIPC::MessageID, PassOwnPtr<CoreIPC::ArgumentEncoder>, unsigned messageSendFlags);
149 // CoreIPC message handlers.
150 void addBackForwardItem(uint64_t itemID, const String& originalURLString, const String& urlString, const String& title, const CoreIPC::DataReference& backForwardData);
151 void didDestroyFrame(uint64_t);
153 void shouldTerminate(bool& shouldTerminate);
155 #if ENABLE(PLUGIN_PROCESS)
156 void getPluginProcessConnection(const String& pluginPath, PassRefPtr<Messages::WebProcessProxy::GetPluginProcessConnection::DelayedReply>);
157 void pluginSyncMessageSendTimedOut(const String& pluginPath);
159 #if USE(SECURITY_FRAMEWORK)
160 void secItemRequest(CoreIPC::Connection*, uint64_t requestID, const SecItemRequestData&);
161 void secKeychainItemRequest(CoreIPC::Connection*, uint64_t requestID, const SecKeychainItemRequestData&);
164 // CoreIPC::Connection::Client
165 friend class WebConnectionToWebProcess;
166 virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
167 virtual void didReceiveSyncMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, OwnPtr<CoreIPC::ArgumentEncoder>&);
168 virtual void didClose(CoreIPC::Connection*);
169 virtual void didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::MessageID);
170 virtual void syncMessageSendTimedOut(CoreIPC::Connection*);
172 virtual Vector<HWND> windowsToReceiveSentMessagesWhileWaitingForSyncReply();
175 // CoreIPC::Connection::QueueClient
176 virtual void didReceiveMessageOnConnectionWorkQueue(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, bool& didHandleMessage);
178 // ResponsivenessTimer::Client
179 void didBecomeUnresponsive(ResponsivenessTimer*) OVERRIDE;
180 void interactionOccurredWhileUnresponsive(ResponsivenessTimer*) OVERRIDE;
181 void didBecomeResponsive(ResponsivenessTimer*) OVERRIDE;
183 // ProcessLauncher::Client
184 virtual void didFinishLaunching(ProcessLauncher*, CoreIPC::Connection::Identifier);
186 // ThreadLauncher::Client
187 virtual void didFinishLaunching(ThreadLauncher*, CoreIPC::Connection::Identifier);
189 void didFinishLaunching(CoreIPC::Connection::Identifier);
191 // Implemented in generated WebProcessProxyMessageReceiver.cpp
192 void didReceiveWebProcessProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
193 void didReceiveSyncWebProcessProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder* arguments, OwnPtr<CoreIPC::ArgumentEncoder>& reply);
194 void didReceiveWebProcessProxyMessageOnConnectionWorkQueue(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder* arguments, bool& didHandleMessage);
196 ResponsivenessTimer m_responsivenessTimer;
198 // This is not a CoreIPC::Connection so that we can wrap the CoreIPC::Connection in
200 RefPtr<WebConnectionToWebProcess> m_connection;
202 Vector<std::pair<CoreIPC::Connection::OutgoingMessage, unsigned> > m_pendingMessages;
203 RefPtr<ProcessLauncher> m_processLauncher;
204 RefPtr<ThreadLauncher> m_threadLauncher;
206 RefPtr<WebContext> m_context;
208 bool m_mayHaveUniversalFileReadSandboxExtension; // True if a read extension for "/" was ever granted - we don't track whether WebProcess still has it.
209 HashSet<String> m_localPathsWithAssumedReadAccess;
211 HashMap<uint64_t, WebPageProxy*> m_pageMap;
212 WebFrameProxyMap m_frameMap;
213 WebBackForwardListItemMap m_backForwardListItemMap;
215 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
216 OwnPtr<PlatformSurfaceTexturePool> m_platformSurfaceTexturePool;
218 #if ENABLE(TIZEN_WEBKIT2_MEMORY_SAVING_MODE)
219 bool m_memorySavingModeEnabled;
223 template<typename E, typename T>
224 bool WebProcessProxy::deprecatedSend(E messageID, uint64_t destinationID, const T& arguments)
226 OwnPtr<CoreIPC::ArgumentEncoder> argumentEncoder = CoreIPC::ArgumentEncoder::create(destinationID);
227 argumentEncoder->encode(arguments);
229 return sendMessage(CoreIPC::MessageID(messageID), argumentEncoder.release(), 0);
233 bool WebProcessProxy::send(const T& message, uint64_t destinationID, unsigned messageSendFlags)
235 OwnPtr<CoreIPC::ArgumentEncoder> argumentEncoder = CoreIPC::ArgumentEncoder::create(destinationID);
236 argumentEncoder->encode(message);
238 return sendMessage(CoreIPC::MessageID(T::messageID), argumentEncoder.release(), messageSendFlags);
242 bool WebProcessProxy::sendSync(const U& message, const typename U::Reply& reply, uint64_t destinationID, double timeout)
247 return connection()->sendSync(message, reply, destinationID, timeout);
250 } // namespace WebKit
252 #endif // WebProcessProxy_h