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 | #pragma once |
27 | |
28 | #if ENABLE(NETSCAPE_PLUGIN_API) |
29 | |
30 | #include "AuxiliaryProcessProxy.h" |
31 | #include "Connection.h" |
32 | #include "PluginModuleInfo.h" |
33 | #include "PluginProcess.h" |
34 | #include "PluginProcessAttributes.h" |
35 | #include "ProcessLauncher.h" |
36 | #include "WebProcessProxyMessages.h" |
37 | #include <wtf/Deque.h> |
38 | |
39 | #if PLATFORM(COCOA) |
40 | #include <wtf/RetainPtr.h> |
41 | OBJC_CLASS NSObject; |
42 | OBJC_CLASS WKPlaceholderModalWindow; |
43 | #endif |
44 | |
45 | namespace WebKit { |
46 | |
47 | class PluginProcessManager; |
48 | class WebProcessProxy; |
49 | struct PluginProcessCreationParameters; |
50 | |
51 | #if PLUGIN_ARCHITECTURE(UNIX) |
52 | struct RawPluginMetaData { |
53 | String name; |
54 | String description; |
55 | String mimeDescription; |
56 | |
57 | #if PLATFORM(GTK) |
58 | bool requiresGtk2; |
59 | #endif |
60 | }; |
61 | #endif |
62 | |
63 | #if PLATFORM(COCOA) |
64 | int pluginProcessLatencyQOS(); |
65 | int pluginProcessThroughputQOS(); |
66 | #endif |
67 | |
68 | class PluginProcessProxy final : public AuxiliaryProcessProxy, public ThreadSafeRefCounted<PluginProcessProxy> { |
69 | public: |
70 | static Ref<PluginProcessProxy> create(PluginProcessManager*, const PluginProcessAttributes&, uint64_t pluginProcessToken); |
71 | ~PluginProcessProxy(); |
72 | |
73 | const PluginProcessAttributes& pluginProcessAttributes() const { return m_pluginProcessAttributes; } |
74 | uint64_t pluginProcessToken() const { return m_pluginProcessToken; } |
75 | |
76 | // Asks the plug-in process to create a new connection to a web process. The connection identifier will be |
77 | // encoded in the given argument encoder and sent back to the connection of the given web process. |
78 | void getPluginProcessConnection(Messages::WebProcessProxy::GetPluginProcessConnection::DelayedReply&&); |
79 | |
80 | void fetchWebsiteData(CompletionHandler<void (Vector<String>)>&&); |
81 | void deleteWebsiteData(WallTime modifiedSince, CompletionHandler<void ()>&&); |
82 | void deleteWebsiteDataForHostNames(const Vector<String>& hostNames, CompletionHandler<void ()>&&); |
83 | |
84 | #if OS(LINUX) |
85 | void sendMemoryPressureEvent(bool isCritical); |
86 | #endif |
87 | |
88 | bool isValid() const { return m_connection; } |
89 | |
90 | #if PLUGIN_ARCHITECTURE(UNIX) |
91 | static bool scanPlugin(const String& pluginPath, RawPluginMetaData& result); |
92 | #endif |
93 | |
94 | private: |
95 | PluginProcessProxy(PluginProcessManager*, const PluginProcessAttributes&, uint64_t pluginProcessToken); |
96 | |
97 | void getLaunchOptions(ProcessLauncher::LaunchOptions&) override; |
98 | void platformGetLaunchOptionsWithAttributes(ProcessLauncher::LaunchOptions&, const PluginProcessAttributes&); |
99 | void processWillShutDown(IPC::Connection&) override; |
100 | |
101 | void pluginProcessCrashedOrFailedToLaunch(); |
102 | |
103 | // IPC::Connection::Client |
104 | void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override; |
105 | void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&) override; |
106 | |
107 | void didClose(IPC::Connection&) override; |
108 | void didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference messageReceiverName, IPC::StringReference messageName) override; |
109 | |
110 | // ProcessLauncher::Client |
111 | void didFinishLaunching(ProcessLauncher*, IPC::Connection::Identifier) override; |
112 | |
113 | // Message handlers |
114 | void didCreateWebProcessConnection(const IPC::Attachment&, bool supportsAsynchronousPluginInitialization); |
115 | void didGetSitesWithData(const Vector<String>& sites, uint64_t callbackID); |
116 | void didDeleteWebsiteData(uint64_t callbackID); |
117 | void didDeleteWebsiteDataForHostNames(uint64_t callbackID); |
118 | |
119 | #if PLATFORM(COCOA) |
120 | bool getPluginProcessSerialNumber(ProcessSerialNumber&); |
121 | void makePluginProcessTheFrontProcess(); |
122 | void makeUIProcessTheFrontProcess(); |
123 | |
124 | void setFullscreenWindowIsShowing(bool); |
125 | void enterFullscreen(); |
126 | void exitFullscreen(); |
127 | |
128 | void setModalWindowIsShowing(bool); |
129 | void beginModal(); |
130 | void endModal(); |
131 | |
132 | void applicationDidBecomeActive(); |
133 | void launchProcess(const String& launchPath, const Vector<String>& arguments, CompletionHandler<void(bool)>&&); |
134 | void launchApplicationAtURL(const String& urlString, const Vector<String>& arguments, CompletionHandler<void(bool)>&&); |
135 | void openURL(const String& url, CompletionHandler<void(bool result, int32_t status, String launchedURLString)>&&); |
136 | void openFile(const String& fullPath, CompletionHandler<void(bool)>&&); |
137 | #endif |
138 | |
139 | void platformInitializePluginProcess(PluginProcessCreationParameters& parameters); |
140 | |
141 | // The plug-in host process manager. |
142 | PluginProcessManager* m_pluginProcessManager; |
143 | |
144 | PluginProcessAttributes m_pluginProcessAttributes; |
145 | uint64_t m_pluginProcessToken; |
146 | |
147 | // The connection to the plug-in host process. |
148 | RefPtr<IPC::Connection> m_connection; |
149 | |
150 | Deque<Messages::WebProcessProxy::GetPluginProcessConnection::DelayedReply> m_pendingConnectionReplies; |
151 | |
152 | Vector<uint64_t> m_pendingFetchWebsiteDataRequests; |
153 | HashMap<uint64_t, CompletionHandler<void (Vector<String>)>> m_pendingFetchWebsiteDataCallbacks; |
154 | |
155 | struct DeleteWebsiteDataRequest { |
156 | WallTime modifiedSince; |
157 | uint64_t callbackID; |
158 | }; |
159 | Vector<DeleteWebsiteDataRequest> m_pendingDeleteWebsiteDataRequests; |
160 | HashMap<uint64_t, CompletionHandler<void ()>> m_pendingDeleteWebsiteDataCallbacks; |
161 | |
162 | struct DeleteWebsiteDataForHostNamesRequest { |
163 | Vector<String> hostNames; |
164 | uint64_t callbackID; |
165 | }; |
166 | Vector<DeleteWebsiteDataForHostNamesRequest> m_pendingDeleteWebsiteDataForHostNamesRequests; |
167 | HashMap<uint64_t, CompletionHandler<void ()>> m_pendingDeleteWebsiteDataForHostNamesCallbacks; |
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(COCOA) |
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(NETSCAPE_PLUGIN_API) |
185 | |