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 PluginProcessConnection_h
27#define PluginProcessConnection_h
28
29#if ENABLE(NETSCAPE_PLUGIN_API)
30
31#include "Connection.h"
32#include "Plugin.h"
33#include "PluginProcess.h"
34#include "PluginProcessAttributes.h"
35#include <wtf/RefCounted.h>
36
37namespace WebKit {
38
39class NPRemoteObjectMap;
40class PluginProcessConnectionManager;
41class PluginProxy;
42
43class PluginProcessConnection : public RefCounted<PluginProcessConnection>, IPC::Connection::Client {
44public:
45 static Ref<PluginProcessConnection> create(PluginProcessConnectionManager* pluginProcessConnectionManager, uint64_t pluginProcessToken, IPC::Connection::Identifier connectionIdentifier, bool supportsAsynchronousPluginInitialization)
46 {
47 return adoptRef(*new PluginProcessConnection(pluginProcessConnectionManager, pluginProcessToken, connectionIdentifier, supportsAsynchronousPluginInitialization));
48 }
49 ~PluginProcessConnection();
50
51 uint64_t pluginProcessToken() const { return m_pluginProcessToken; }
52
53 IPC::Connection* connection() const { return m_connection.get(); }
54
55 void addPluginProxy(PluginProxy*);
56 void removePluginProxy(PluginProxy*);
57
58 NPRemoteObjectMap* npRemoteObjectMap() const { return m_npRemoteObjectMap.get(); }
59
60 bool supportsAsynchronousPluginInitialization() const { return m_supportsAsynchronousPluginInitialization; }
61
62private:
63 PluginProcessConnection(PluginProcessConnectionManager*, uint64_t pluginProcessToken, IPC::Connection::Identifier connectionIdentifier, bool supportsAsynchronousInitialization);
64
65 // IPC::Connection::Client
66 void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
67 void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&) override;
68 void didClose(IPC::Connection&) override;
69 void didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference messageReceiverName, IPC::StringReference messageName) override;
70
71 // Message handlers.
72 void didReceiveSyncPluginProcessConnectionMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&);
73 void setException(const String&, CompletionHandler<void()>&&);
74
75 PluginProcessConnectionManager* m_pluginProcessConnectionManager;
76 uint64_t m_pluginProcessToken;
77
78 // The connection from the web process to the plug-in process.
79 RefPtr<IPC::Connection> m_connection;
80
81 // The plug-ins. We use a weak reference to the plug-in proxies because the plug-in view holds the strong reference.
82 HashMap<uint64_t, PluginProxy*> m_plugins;
83
84 RefPtr<NPRemoteObjectMap> m_npRemoteObjectMap;
85
86 bool m_supportsAsynchronousPluginInitialization;
87};
88
89} // namespace WebKit
90
91#endif // ENABLE(NETSCAPE_PLUGIN_API)
92
93#endif // PluginProcessConnection_h
94