1/* 2 * Copyright (C) 2010 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 PluginProcessProxy_h 27#define PluginProcessProxy_h 28 29#if ENABLE(PLUGIN_PROCESS) 30 31#include "ChildProcessProxy.h" 32#include "Connection.h" 33#include "PluginModuleInfo.h" 34#include "PluginProcess.h" 35#include "PluginProcessAttributes.h" 36#include "ProcessLauncher.h" 37#include "WebProcessProxyMessages.h" 38#include <wtf/Deque.h> 39 40#if PLATFORM(MAC) 41#include <wtf/RetainPtr.h> 42OBJC_CLASS NSObject; 43OBJC_CLASS WKPlaceholderModalWindow; 44#endif 45 46// FIXME: This is platform specific. 47namespace CoreIPC { 48 class MachPort; 49} 50 51namespace WebKit { 52 53class PluginProcessManager; 54class WebPluginSiteDataManager; 55class WebProcessProxy; 56struct PluginProcessCreationParameters; 57 58#if PLUGIN_ARCHITECTURE(X11) 59struct RawPluginMetaData { 60 String name; 61 String description; 62 String mimeDescription; 63}; 64#endif 65 66class PluginProcessProxy : public ChildProcessProxy { 67public: 68 static PassRefPtr<PluginProcessProxy> create(PluginProcessManager*, const PluginProcessAttributes&, uint64_t pluginProcessToken); 69 ~PluginProcessProxy(); 70 71 const PluginProcessAttributes& pluginProcessAttributes() const { return m_pluginProcessAttributes; } 72 uint64_t pluginProcessToken() const { return m_pluginProcessToken; } 73 74 // Asks the plug-in process to create a new connection to a web process. The connection identifier will be 75 // encoded in the given argument encoder and sent back to the connection of the given web process. 76 void getPluginProcessConnection(PassRefPtr<Messages::WebProcessProxy::GetPluginProcessConnection::DelayedReply>); 77 78 // Asks the plug-in process to get a list of domains for which the plug-in has data stored. 79 void getSitesWithData(WebPluginSiteDataManager*, uint64_t callbackID); 80 81 // Asks the plug-in process to clear the data for the given sites. 82 void clearSiteData(WebPluginSiteDataManager*, const Vector<String>& sites, uint64_t flags, uint64_t maxAgeInSeconds, uint64_t callbackID); 83 84 bool isValid() const { return m_connection; } 85 86#if PLATFORM(MAC) 87 void setProcessSuppressionEnabled(bool); 88 89 // Returns whether the plug-in needs the heap to be marked executable. 90 static bool pluginNeedsExecutableHeap(const PluginModuleInfo&); 91 92 // Creates a property list in ~/Library/Preferences that contains all the MIME types supported by the plug-in. 93 static bool createPropertyListFile(const PluginModuleInfo&); 94#endif 95 96#if PLUGIN_ARCHITECTURE(X11) 97 static bool scanPlugin(const String& pluginPath, RawPluginMetaData& result); 98#endif 99 100private: 101 PluginProcessProxy(PluginProcessManager*, const PluginProcessAttributes&, uint64_t pluginProcessToken); 102 103 virtual void getLaunchOptions(ProcessLauncher::LaunchOptions&) OVERRIDE; 104 void platformGetLaunchOptions(ProcessLauncher::LaunchOptions&, const PluginProcessAttributes&); 105 106 void pluginProcessCrashedOrFailedToLaunch(); 107 108 // CoreIPC::Connection::Client 109 virtual void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&) OVERRIDE; 110 virtual void didReceiveSyncMessage(CoreIPC::Connection*, CoreIPC::MessageDecoder&, OwnPtr<CoreIPC::MessageEncoder>&) OVERRIDE; 111 112 virtual void didClose(CoreIPC::Connection*) OVERRIDE; 113 virtual void didReceiveInvalidMessage(CoreIPC::Connection*, CoreIPC::StringReference messageReceiverName, CoreIPC::StringReference messageName) OVERRIDE; 114 115 // ProcessLauncher::Client 116 virtual void didFinishLaunching(ProcessLauncher*, CoreIPC::Connection::Identifier); 117 118 // Message handlers 119 void didCreateWebProcessConnection(const CoreIPC::Attachment&, bool supportsAsynchronousPluginInitialization); 120 void didGetSitesWithData(const Vector<String>& sites, uint64_t callbackID); 121 void didClearSiteData(uint64_t callbackID); 122 123#if PLATFORM(MAC) 124 bool getPluginProcessSerialNumber(ProcessSerialNumber&); 125 void makePluginProcessTheFrontProcess(); 126 void makeUIProcessTheFrontProcess(); 127 128 void setFullscreenWindowIsShowing(bool); 129 void enterFullscreen(); 130 void exitFullscreen(); 131 132 void setModalWindowIsShowing(bool); 133 void beginModal(); 134 void endModal(); 135 136 void applicationDidBecomeActive(); 137 void openPluginPreferencePane(); 138 void launchProcess(const String& launchPath, const Vector<String>& arguments, bool& result); 139 void launchApplicationAtURL(const String& urlString, const Vector<String>& arguments, bool& result); 140 void openURL(const String& url, bool& result, int32_t& status, String& launchedURLString); 141 void openFile(const String& fullPath, bool& result); 142#endif 143 144 void platformInitializePluginProcess(PluginProcessCreationParameters& parameters); 145 146 // The plug-in host process manager. 147 PluginProcessManager* m_pluginProcessManager; 148 149 PluginProcessAttributes m_pluginProcessAttributes; 150 uint64_t m_pluginProcessToken; 151 152 // The connection to the plug-in host process. 153 RefPtr<CoreIPC::Connection> m_connection; 154 155 Deque<RefPtr<Messages::WebProcessProxy::GetPluginProcessConnection::DelayedReply>> m_pendingConnectionReplies; 156 157 Vector<uint64_t> m_pendingGetSitesRequests; 158 HashMap<uint64_t, RefPtr<WebPluginSiteDataManager>> m_pendingGetSitesReplies; 159 160 struct ClearSiteDataRequest { 161 Vector<String> sites; 162 uint64_t flags; 163 uint64_t maxAgeInSeconds; 164 uint64_t callbackID; 165 }; 166 Vector<ClearSiteDataRequest> m_pendingClearSiteDataRequests; 167 HashMap<uint64_t, RefPtr<WebPluginSiteDataManager>> m_pendingClearSiteDataReplies; 168 169 // If createPluginConnection is called while the process is still launching we'll keep count of it and send a bunch of requests 170 // when the process finishes launching. 171 unsigned m_numPendingConnectionRequests; 172 173#if PLATFORM(MAC) 174 RetainPtr<NSObject> m_activationObserver; 175 RetainPtr<WKPlaceholderModalWindow *> m_placeholderWindow; 176 bool m_modalWindowIsShowing; 177 bool m_fullscreenWindowIsShowing; 178 unsigned m_preFullscreenAppPresentationOptions; 179#endif 180}; 181 182} // namespace WebKit 183 184#endif // ENABLE(PLUGIN_PROCESS) 185 186#endif // PluginProcessProxy_h 187