Merge "[CherryPick] [EFL][Qt][WK2] Fixed position elements are not always fixed"...
[framework/web/webkit-efl.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 "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>
45 #endif
46
47 namespace WebCore {
48     class KURL;
49 };
50
51 namespace WebKit {
52
53 #if USE(SECURITY_FRAMEWORK)
54 class SecItemRequestData;
55 class SecItemResponseData;
56 #endif
57
58 class WebBackForwardListItem;
59 class WebContext;
60 class WebPageGroup;
61 struct WebNavigationDataStore;
62 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
63 class PlatformSurfaceTexturePool;
64 #endif
65
66 class WebProcessProxy : public RefCounted<WebProcessProxy>, CoreIPC::Connection::Client, ResponsivenessTimer::Client, ProcessLauncher::Client, ThreadLauncher::Client, CoreIPC::Connection::QueueClient {
67 public:
68     typedef HashMap<uint64_t, RefPtr<WebFrameProxy> > WebFrameProxyMap;
69     typedef HashMap<uint64_t, RefPtr<WebBackForwardListItem> > WebBackForwardListItemMap;
70
71     static PassRefPtr<WebProcessProxy> create(PassRefPtr<WebContext>);
72     ~WebProcessProxy();
73
74     void terminate();
75
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);
78     
79     CoreIPC::Connection* connection() const
80     { 
81         ASSERT(m_connection);
82         
83         return m_connection->connection(); 
84     }
85     WebConnection* webConnection() const { return m_connection.get(); }
86
87     WebContext* context() const { return m_context.get(); }
88
89     PlatformProcessIdentifier processIdentifier() const { return m_processLauncher->processIdentifier(); }
90
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);
95
96     WebBackForwardListItem* webBackForwardItem(uint64_t itemID) const;
97
98     ResponsivenessTimer* responsivenessTimer() { return &m_responsivenessTimer; }
99
100     bool isValid() const { return m_connection; }
101     bool isLaunching() const;
102     bool canSendMessage() const { return isValid() || isLaunching(); }
103
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.
109
110     void updateTextCheckerState();
111
112     void registerNewWebBackForwardListItem(WebBackForwardListItem*);
113
114     void willAcquireUniversalFileReadSandboxExtension() { m_mayHaveUniversalFileReadSandboxExtension = true; }
115     void assumeReadAccessToBaseURL(const String&);
116
117     bool checkURLReceivedFromWebProcess(const String&);
118     bool checkURLReceivedFromWebProcess(const WebCore::KURL&);
119
120     static bool fullKeyboardAccessEnabled();
121
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);
124
125 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
126     RefPtr<PlatformSurfaceTexturePool> platformSurfaceTexturePool() { return m_platformSurfaceTexturePool.get(); }
127     void removePlatformSurfaceTextureFromPool(int platformSurfaceId);
128 #endif
129 #if ENABLE(TIZEN_WEBKIT2_MEMORY_SAVING_MODE)
130     void setMemorySavingMode(bool);
131     bool memorySavingModeEnabled() { return m_memorySavingModeEnabled; }
132 #endif
133 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
134     void releaseBackingStoreMemory();
135 #endif
136
137 private:
138     explicit WebProcessProxy(PassRefPtr<WebContext>);
139
140     // Initializes the process or thread launcher which will begin launching the process.
141     void connect();
142
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.
145     void disconnect();
146
147     bool sendMessage(CoreIPC::MessageID, PassOwnPtr<CoreIPC::ArgumentEncoder>, unsigned messageSendFlags);
148
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);
152     
153     void shouldTerminate(bool& shouldTerminate);
154
155 #if ENABLE(PLUGIN_PROCESS)
156     void getPluginProcessConnection(const String& pluginPath, PassRefPtr<Messages::WebProcessProxy::GetPluginProcessConnection::DelayedReply>);
157     void pluginSyncMessageSendTimedOut(const String& pluginPath);
158 #endif
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&);
162 #endif
163
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*);
171 #if PLATFORM(WIN)
172     virtual Vector<HWND> windowsToReceiveSentMessagesWhileWaitingForSyncReply();
173 #endif
174
175     // CoreIPC::Connection::QueueClient
176     virtual void didReceiveMessageOnConnectionWorkQueue(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, bool& didHandleMessage);
177
178     // ResponsivenessTimer::Client
179     void didBecomeUnresponsive(ResponsivenessTimer*) OVERRIDE;
180     void interactionOccurredWhileUnresponsive(ResponsivenessTimer*) OVERRIDE;
181     void didBecomeResponsive(ResponsivenessTimer*) OVERRIDE;
182
183     // ProcessLauncher::Client
184     virtual void didFinishLaunching(ProcessLauncher*, CoreIPC::Connection::Identifier);
185
186     // ThreadLauncher::Client
187     virtual void didFinishLaunching(ThreadLauncher*, CoreIPC::Connection::Identifier);
188
189     void didFinishLaunching(CoreIPC::Connection::Identifier);
190
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);
195
196     ResponsivenessTimer m_responsivenessTimer;
197     
198     // This is not a CoreIPC::Connection so that we can wrap the CoreIPC::Connection in
199     // an API object.
200     RefPtr<WebConnectionToWebProcess> m_connection;
201
202     Vector<std::pair<CoreIPC::Connection::OutgoingMessage, unsigned> > m_pendingMessages;
203     RefPtr<ProcessLauncher> m_processLauncher;
204     RefPtr<ThreadLauncher> m_threadLauncher;
205
206     RefPtr<WebContext> m_context;
207
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;
210
211     HashMap<uint64_t, WebPageProxy*> m_pageMap;
212     WebFrameProxyMap m_frameMap;
213     WebBackForwardListItemMap m_backForwardListItemMap;
214
215 #if ENABLE(TIZEN_WEBKIT2_TILED_AC_SHARED_PLATFORM_SURFACE)
216     OwnPtr<PlatformSurfaceTexturePool> m_platformSurfaceTexturePool;
217 #endif
218 #if ENABLE(TIZEN_WEBKIT2_MEMORY_SAVING_MODE)
219     bool m_memorySavingModeEnabled;
220 #endif
221 };
222
223 template<typename E, typename T>
224 bool WebProcessProxy::deprecatedSend(E messageID, uint64_t destinationID, const T& arguments)
225 {
226     OwnPtr<CoreIPC::ArgumentEncoder> argumentEncoder = CoreIPC::ArgumentEncoder::create(destinationID);
227     argumentEncoder->encode(arguments);
228
229     return sendMessage(CoreIPC::MessageID(messageID), argumentEncoder.release(), 0);
230 }
231
232 template<typename T>
233 bool WebProcessProxy::send(const T& message, uint64_t destinationID, unsigned messageSendFlags)
234 {
235     OwnPtr<CoreIPC::ArgumentEncoder> argumentEncoder = CoreIPC::ArgumentEncoder::create(destinationID);
236     argumentEncoder->encode(message);
237
238     return sendMessage(CoreIPC::MessageID(T::messageID), argumentEncoder.release(), messageSendFlags);
239 }
240
241 template<typename U> 
242 bool WebProcessProxy::sendSync(const U& message, const typename U::Reply& reply, uint64_t destinationID, double timeout)
243 {
244     if (!m_connection)
245         return false;
246
247     return connection()->sendSync(message, reply, destinationID, timeout);
248 }
249     
250 } // namespace WebKit
251
252 #endif // WebProcessProxy_h