1/*
2 * Copyright (C) 2010-2017 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 "PluginModuleInfo.h"
31#include "PluginProcess.h"
32#include "PluginProcessAttributes.h"
33#include "ProcessThrottler.h"
34#include "WebProcessProxyMessages.h"
35#include <wtf/Forward.h>
36#include <wtf/HashSet.h>
37#include <wtf/Noncopyable.h>
38#include <wtf/RefCounter.h>
39#include <wtf/Vector.h>
40
41namespace IPC {
42class Encoder;
43}
44
45namespace WebKit {
46
47class PluginInfoStore;
48class PluginProcessProxy;
49class WebProcessProxy;
50enum class WebsiteDataFetchOption;
51
52class PluginProcessManager {
53 WTF_MAKE_NONCOPYABLE(PluginProcessManager);
54 friend NeverDestroyed<PluginProcessManager>;
55public:
56 static PluginProcessManager& singleton();
57
58 uint64_t pluginProcessToken(const PluginModuleInfo&, PluginProcessType, PluginProcessSandboxPolicy);
59
60 void getPluginProcessConnection(uint64_t pluginProcessToken, Messages::WebProcessProxy::GetPluginProcessConnection::DelayedReply&&);
61 void removePluginProcessProxy(PluginProcessProxy*);
62
63 void fetchWebsiteData(const PluginModuleInfo&, OptionSet<WebsiteDataFetchOption>, WTF::Function<void (Vector<String>)>&& completionHandler);
64 void deleteWebsiteData(const PluginModuleInfo&, WallTime modifiedSince, WTF::Function<void ()>&& completionHandler);
65 void deleteWebsiteDataForHostNames(const PluginModuleInfo&, const Vector<String>& hostNames, WTF::Function<void ()>&& completionHandler);
66
67#if OS(LINUX)
68 void sendMemoryPressureEvent(bool isCritical);
69#endif
70
71#if PLATFORM(COCOA)
72 inline ProcessSuppressionDisabledToken processSuppressionDisabledToken();
73 inline bool processSuppressionDisabled() const;
74 void updateProcessSuppressionDisabled(RefCounterEvent);
75#endif
76
77 const Vector<RefPtr<PluginProcessProxy>>& pluginProcesses() const { return m_pluginProcesses; }
78
79#if PLATFORM(MAC)
80 void setExperimentalPlugInSandboxProfilesEnabled(bool);
81 bool experimentalPlugInSandboxProfilesEnabled() const { return m_experimentalPlugInSandboxProfilesEnabled; }
82#endif
83
84private:
85 PluginProcessManager();
86
87 PluginProcessProxy* getPluginProcess(uint64_t pluginProcessToken);
88 PluginProcessProxy* getOrCreatePluginProcess(uint64_t pluginProcessToken);
89
90 Vector<std::pair<PluginProcessAttributes, uint64_t>> m_pluginProcessTokens;
91 HashSet<uint64_t> m_knownTokens;
92
93 Vector<RefPtr<PluginProcessProxy>> m_pluginProcesses;
94
95#if PLATFORM(COCOA)
96 ProcessSuppressionDisabledCounter m_processSuppressionDisabledForPageCounter;
97#endif
98#if PLATFORM(MAC)
99 bool m_experimentalPlugInSandboxProfilesEnabled { false };
100#endif
101};
102
103#if PLATFORM(COCOA)
104inline ProcessSuppressionDisabledToken PluginProcessManager::processSuppressionDisabledToken()
105{
106 return m_processSuppressionDisabledForPageCounter.count();
107}
108
109inline bool PluginProcessManager::processSuppressionDisabled() const
110{
111 return m_processSuppressionDisabledForPageCounter.value();
112}
113#endif
114
115} // namespace WebKit
116
117#endif // ENABLE(NETSCAPE_PLUGIN_API)
118