WebProcessProxy.h revision 2fc2651226baac27029e38c9d6ef883fa32084db
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 "Connection.h" 30#include "PlatformProcessIdentifier.h" 31#include "PluginInfoStore.h" 32#include "ProcessLauncher.h" 33#include "ProcessModel.h" 34#include "ResponsivenessTimer.h" 35#include "ThreadLauncher.h" 36#include "WebPageProxy.h" 37#include <WebCore/LinkHash.h> 38#include <wtf/Forward.h> 39#include <wtf/HashMap.h> 40#include <wtf/PassRefPtr.h> 41#include <wtf/RefCounted.h> 42 43namespace WebCore { 44 class KURL; 45}; 46 47namespace WebKit { 48 49class WebBackForwardListItem; 50class WebContext; 51class WebPageGroup; 52struct WebNavigationDataStore; 53 54class WebProcessProxy : public RefCounted<WebProcessProxy>, CoreIPC::Connection::Client, ResponsivenessTimer::Client, ProcessLauncher::Client, ThreadLauncher::Client { 55public: 56 typedef HashMap<uint64_t, RefPtr<WebPageProxy> > WebPageProxyMap; 57 typedef WebPageProxyMap::const_iterator::Values pages_const_iterator; 58 typedef HashMap<uint64_t, RefPtr<WebFrameProxy> > WebFrameProxyMap; 59 typedef HashMap<uint64_t, RefPtr<WebBackForwardListItem> > WebBackForwardListItemMap; 60 61 static PassRefPtr<WebProcessProxy> create(WebContext*); 62 ~WebProcessProxy(); 63 64 void terminate(); 65 66 template<typename T> bool send(const T& message, uint64_t destinationID, unsigned messageSendFlags = 0); 67 template<typename U> bool sendSync(const U& message, const typename U::Reply& reply, uint64_t destinationID, double timeout = 1); 68 69 CoreIPC::Connection* connection() const 70 { 71 ASSERT(m_connection); 72 73 return m_connection.get(); 74 } 75 76 WebContext* context() const { return m_context; } 77 78 PlatformProcessIdentifier processIdentifier() const { return m_processLauncher->processIdentifier(); } 79 80 WebPageProxy* webPage(uint64_t pageID) const; 81 WebPageProxy* createWebPage(PageClient*, WebContext*, WebPageGroup*); 82 void addExistingWebPage(WebPageProxy*, uint64_t pageID); 83 void removeWebPage(uint64_t pageID); 84 85 pages_const_iterator pages_begin(); 86 pages_const_iterator pages_end(); 87 size_t numberOfPages(); 88 89 WebBackForwardListItem* webBackForwardItem(uint64_t itemID) const; 90 91 ResponsivenessTimer* responsivenessTimer() { return &m_responsivenessTimer; } 92 93 bool isValid() const { return m_connection; } 94 bool isLaunching() const; 95 bool canSendMessage() const { return isValid() || isLaunching(); } 96 97 WebFrameProxy* webFrame(uint64_t) const; 98 bool canCreateFrame(uint64_t frameID) const; 99 void frameCreated(uint64_t, WebFrameProxy*); 100 void didDestroyFrame(uint64_t); 101 void disconnectFramesFromPage(WebPageProxy*); // Including main frame. 102 size_t frameCountInPage(WebPageProxy*) const; // Including main frame. 103 104 void updateTextCheckerState(); 105 106 void registerNewWebBackForwardListItem(WebBackForwardListItem*); 107 108 // FIXME: This variant of send is deprecated. All clients should move to an overload that take a message type. 109 template<typename E, typename T> bool deprecatedSend(E messageID, uint64_t destinationID, const T& arguments); 110 111private: 112 explicit WebProcessProxy(WebContext*); 113 114 void connect(); 115 116 bool sendMessage(CoreIPC::MessageID, PassOwnPtr<CoreIPC::ArgumentEncoder>, unsigned messageSendFlags); 117 118 void addBackForwardItem(uint64_t itemID, const String& originalURLString, const String& urlString, const String& title, const CoreIPC::DataReference& backForwardData); 119 120#if ENABLE(PLUGIN_PROCESS) 121 void getPluginProcessConnection(const String& pluginPath, CoreIPC::ArgumentEncoder* reply); 122#endif 123 124 // CoreIPC::Connection::Client 125 void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*); 126 CoreIPC::SyncReplyMode didReceiveSyncMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, CoreIPC::ArgumentEncoder*); 127 void didClose(CoreIPC::Connection*); 128 void didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::MessageID); 129 130 // ResponsivenessTimer::Client 131 void didBecomeUnresponsive(ResponsivenessTimer*); 132 void didBecomeResponsive(ResponsivenessTimer*); 133 134 // ProcessLauncher::Client 135 virtual void didFinishLaunching(ProcessLauncher*, CoreIPC::Connection::Identifier); 136 137 // ThreadLauncher::Client 138 virtual void didFinishLaunching(ThreadLauncher*, CoreIPC::Connection::Identifier); 139 140 void didFinishLaunching(CoreIPC::Connection::Identifier); 141 142 // Implemented in generated WebProcessProxyMessageReceiver.cpp 143 void didReceiveWebProcessProxyMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*); 144 145 ResponsivenessTimer m_responsivenessTimer; 146 RefPtr<CoreIPC::Connection> m_connection; 147 148 Vector<std::pair<CoreIPC::Connection::OutgoingMessage, unsigned> > m_pendingMessages; 149 RefPtr<ProcessLauncher> m_processLauncher; 150 RefPtr<ThreadLauncher> m_threadLauncher; 151 152 WebContext* m_context; 153 154 WebPageProxyMap m_pageMap; 155 WebFrameProxyMap m_frameMap; 156 WebBackForwardListItemMap m_backForwardListItemMap; 157}; 158 159template<typename E, typename T> 160bool WebProcessProxy::deprecatedSend(E messageID, uint64_t destinationID, const T& arguments) 161{ 162 OwnPtr<CoreIPC::ArgumentEncoder> argumentEncoder = CoreIPC::ArgumentEncoder::create(destinationID); 163 argumentEncoder->encode(arguments); 164 165 return sendMessage(CoreIPC::MessageID(messageID), argumentEncoder.release(), 0); 166} 167 168template<typename T> 169bool WebProcessProxy::send(const T& message, uint64_t destinationID, unsigned messageSendFlags) 170{ 171 OwnPtr<CoreIPC::ArgumentEncoder> argumentEncoder = CoreIPC::ArgumentEncoder::create(destinationID); 172 argumentEncoder->encode(message); 173 174 return sendMessage(CoreIPC::MessageID(T::messageID), argumentEncoder.release(), messageSendFlags); 175} 176 177template<typename U> 178bool WebProcessProxy::sendSync(const U& message, const typename U::Reply& reply, uint64_t destinationID, double timeout) 179{ 180 return m_connection->sendSync(message, reply, destinationID, timeout); 181} 182 183} // namespace WebKit 184 185#endif // WebProcessProxy_h 186