| 1 | /* |
| 2 | * Copyright (C) 2010-2018 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 | #pragma once |
| 27 | |
| 28 | #if ENABLE(NETSCAPE_PLUGIN_API) |
| 29 | |
| 30 | #include "AuxiliaryProcess.h" |
| 31 | #include <WebCore/CountedUserActivity.h> |
| 32 | #include <wtf/Forward.h> |
| 33 | #include <wtf/text/WTFString.h> |
| 34 | |
| 35 | #if PLATFORM(COCOA) |
| 36 | #include <wtf/MachSendRight.h> |
| 37 | #endif |
| 38 | |
| 39 | namespace WebKit { |
| 40 | |
| 41 | class NetscapePluginModule; |
| 42 | class WebProcessConnection; |
| 43 | struct PluginProcessCreationParameters; |
| 44 | |
| 45 | class PluginProcess : public AuxiliaryProcess |
| 46 | { |
| 47 | WTF_MAKE_NONCOPYABLE(PluginProcess); |
| 48 | friend NeverDestroyed<PluginProcess>; |
| 49 | |
| 50 | public: |
| 51 | static PluginProcess& singleton(); |
| 52 | static constexpr ProcessType processType = ProcessType::Plugin; |
| 53 | |
| 54 | void removeWebProcessConnection(WebProcessConnection*); |
| 55 | |
| 56 | NetscapePluginModule* netscapePluginModule(); |
| 57 | |
| 58 | const String& pluginPath() const { return m_pluginPath; } |
| 59 | |
| 60 | #if PLATFORM(COCOA) |
| 61 | void setModalWindowIsShowing(bool); |
| 62 | void setFullscreenWindowIsShowing(bool); |
| 63 | |
| 64 | const WTF::MachSendRight& compositingRenderServerPort() const { return m_compositingRenderServerPort; } |
| 65 | |
| 66 | bool launchProcess(const String& launchPath, const Vector<String>& arguments); |
| 67 | bool launchApplicationAtURL(const String& urlString, const Vector<String>& arguments); |
| 68 | bool openURL(const String& urlString, int32_t& status, String& launchedURLString); |
| 69 | bool openFile(const String& urlString); |
| 70 | #endif |
| 71 | |
| 72 | CountedUserActivity& connectionActivity() { return m_connectionActivity; } |
| 73 | |
| 74 | private: |
| 75 | PluginProcess(); |
| 76 | ~PluginProcess(); |
| 77 | |
| 78 | #if PLATFORM(MAC) |
| 79 | bool shouldOverrideQuarantine() final; |
| 80 | #endif |
| 81 | |
| 82 | // AuxiliaryProcess |
| 83 | void initializeProcess(const AuxiliaryProcessInitializationParameters&) override; |
| 84 | void initializeProcessName(const AuxiliaryProcessInitializationParameters&) override; |
| 85 | void initializeConnection(IPC::Connection*) override; |
| 86 | void initializeSandbox(const AuxiliaryProcessInitializationParameters&, SandboxInitializationParameters&) override; |
| 87 | bool shouldTerminate() override; |
| 88 | void platformInitializeProcess(const AuxiliaryProcessInitializationParameters&); |
| 89 | |
| 90 | #if USE(APPKIT) |
| 91 | void stopRunLoop() override; |
| 92 | #endif |
| 93 | |
| 94 | // IPC::Connection::Client |
| 95 | void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override; |
| 96 | |
| 97 | // Message handlers. |
| 98 | void didReceivePluginProcessMessage(IPC::Connection&, IPC::Decoder&); |
| 99 | void initializePluginProcess(PluginProcessCreationParameters&&); |
| 100 | void createWebProcessConnection(); |
| 101 | |
| 102 | void getSitesWithData(uint64_t callbackID); |
| 103 | void deleteWebsiteData(WallTime modifiedSince, uint64_t callbackID); |
| 104 | void deleteWebsiteDataForHostNames(const Vector<String>& hostNames, uint64_t callbackID); |
| 105 | |
| 106 | void platformInitializePluginProcess(PluginProcessCreationParameters&&); |
| 107 | |
| 108 | void setMinimumLifetime(Seconds); |
| 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 | WTF::MachSendRight m_compositingRenderServerPort; |
| 130 | |
| 131 | String m_nsurlCacheDirectory; |
| 132 | #endif |
| 133 | |
| 134 | CountedUserActivity m_connectionActivity; |
| 135 | }; |
| 136 | |
| 137 | } // namespace WebKit |
| 138 | |
| 139 | #endif // ENABLE(NETSCAPE_PLUGIN_API) |
| 140 | |