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 PluginProcess_h 27#define PluginProcess_h 28 29#if ENABLE(NETSCAPE_PLUGIN_API) 30 31#include "ChildProcess.h" 32#include <WebCore/CountedUserActivity.h> 33#include <WebCore/AudioHardwareListener.h> 34#include <wtf/Forward.h> 35#include <wtf/NeverDestroyed.h> 36#include <wtf/text/WTFString.h> 37 38namespace WebKit { 39 40class NetscapePluginModule; 41class WebProcessConnection; 42struct PluginProcessCreationParameters; 43 44class PluginProcess : public ChildProcess, private WebCore::AudioHardwareListener::Client 45{ 46 WTF_MAKE_NONCOPYABLE(PluginProcess); 47 friend class NeverDestroyed<PluginProcess>; 48public: 49 static PluginProcess& shared(); 50 51 void removeWebProcessConnection(WebProcessConnection*); 52 53 NetscapePluginModule* netscapePluginModule(); 54 55 const String& pluginPath() const { return m_pluginPath; } 56 57#if PLATFORM(COCOA) 58 void setModalWindowIsShowing(bool); 59 void setFullscreenWindowIsShowing(bool); 60 61 mach_port_t compositingRenderServerPort() const { return m_compositingRenderServerPort; } 62 63 bool launchProcess(const String& launchPath, const Vector<String>& arguments); 64 bool launchApplicationAtURL(const String& urlString, const Vector<String>& arguments); 65 bool openURL(const String& urlString, int32_t& status, String& launchedURLString); 66 bool openFile(const String& urlString); 67#endif 68 69 CountedUserActivity& connectionActivity() { return m_connectionActivity; } 70 71 void pluginsForWebProcessDidBecomeHidden(); 72 void pluginsForWebProcessDidBecomeVisible(); 73 74private: 75 PluginProcess(); 76 ~PluginProcess(); 77 78 // ChildProcess 79 virtual void initializeProcess(const ChildProcessInitializationParameters&) override; 80 virtual void initializeProcessName(const ChildProcessInitializationParameters&) override; 81 virtual void initializeSandbox(const ChildProcessInitializationParameters&, SandboxInitializationParameters&) override; 82 virtual bool shouldTerminate() override; 83 void platformInitializeProcess(const ChildProcessInitializationParameters&); 84 85#if USE(APPKIT) 86 virtual void stopRunLoop() override; 87#endif 88 89 // IPC::Connection::Client 90 virtual void didReceiveMessage(IPC::Connection*, IPC::MessageDecoder&) override; 91 virtual void didClose(IPC::Connection*) override; 92 virtual void didReceiveInvalidMessage(IPC::Connection*, IPC::StringReference messageReceiverName, IPC::StringReference messageName) override; 93 94 // Message handlers. 95 void didReceivePluginProcessMessage(IPC::Connection*, IPC::MessageDecoder&); 96 void initializePluginProcess(const PluginProcessCreationParameters&); 97 void createWebProcessConnection(); 98 void getSitesWithData(uint64_t callbackID); 99 void clearSiteData(const Vector<String>& sites, uint64_t flags, uint64_t maxAgeInSeconds, uint64_t callbackID); 100 101 // AudioHardwareListenerClient 102 virtual void audioHardwareDidBecomeActive() override; 103 virtual void audioHardwareDidBecomeInactive() override; 104 virtual void audioOutputDeviceChanged() override { } 105 106 void platformInitializePluginProcess(const PluginProcessCreationParameters&); 107 108 void setMinimumLifetime(double); 109 void minimumLifetimeTimerFired(); 110 // Our web process connections. 111 Vector<RefPtr<WebProcessConnection>> m_webProcessConnections; 112 113 // The plug-in path. 114 String m_pluginPath; 115 116#if PLATFORM(COCOA) 117 String m_pluginBundleIdentifier; 118#endif 119 120 // The plug-in module. 121 RefPtr<NetscapePluginModule> m_pluginModule; 122 123 bool m_supportsAsynchronousPluginInitialization; 124 125 RunLoop::Timer<PluginProcess> m_minimumLifetimeTimer; 126 127#if PLATFORM(COCOA) 128 // The Mach port used for accelerated compositing. 129 mach_port_t m_compositingRenderServerPort; 130 131 String m_nsurlCacheDirectory; 132#endif 133 134 static void lowMemoryHandler(bool critical); 135 CountedUserActivity m_connectionActivity; 136 CountedUserActivity m_visiblePluginsActivity; 137 138 RefPtr<WebCore::AudioHardwareListener> m_audioHardwareListener; 139}; 140 141} // namespace WebKit 142 143#endif // ENABLE(NETSCAPE_PLUGIN_API) 144 145#endif // PluginProcess_h 146