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 NPRemoteObjectMap_h |
27 | #define NPRemoteObjectMap_h |
28 | |
29 | #if ENABLE(NETSCAPE_PLUGIN_API) |
30 | |
31 | #include "Connection.h" |
32 | #include <WebCore/npruntime.h> |
33 | #include <wtf/HashMap.h> |
34 | #include <wtf/HashSet.h> |
35 | #include <wtf/RefCounted.h> |
36 | |
37 | namespace WebKit { |
38 | |
39 | class NPObjectMessageReceiver; |
40 | class NPObjectProxy; |
41 | class NPVariantData; |
42 | class Plugin; |
43 | |
44 | class NPRemoteObjectMap : public RefCounted<NPRemoteObjectMap> { |
45 | public: |
46 | static Ref<NPRemoteObjectMap> create(IPC::Connection*); |
47 | ~NPRemoteObjectMap(); |
48 | |
49 | // Creates an NPObjectProxy wrapper for the remote object with the given remote object ID. |
50 | NPObject* createNPObjectProxy(uint64_t remoteObjectID, Plugin*); |
51 | void npObjectProxyDestroyed(NPObject*); |
52 | |
53 | // Expose the given NPObject as a remote object. Returns the objectID. |
54 | uint64_t registerNPObject(NPObject*, Plugin*); |
55 | void unregisterNPObject(uint64_t); |
56 | |
57 | NPVariantData npVariantToNPVariantData(const NPVariant&, Plugin*); |
58 | NPVariant npVariantDataToNPVariant(const NPVariantData&, Plugin*); |
59 | |
60 | IPC::Connection* connection() const { return m_connection; } |
61 | |
62 | void pluginDestroyed(Plugin*); |
63 | |
64 | void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&); |
65 | |
66 | private: |
67 | explicit NPRemoteObjectMap(IPC::Connection*); |
68 | IPC::Connection* m_connection; |
69 | |
70 | // A map of NPObjectMessageReceiver classes, wrapping objects that we export to the |
71 | // other end of the connection. |
72 | HashMap<uint64_t, NPObjectMessageReceiver*> m_registeredNPObjects; |
73 | |
74 | // A set of NPObjectProxy objects associated with this map. |
75 | HashSet<NPObjectProxy*> m_npObjectProxies; |
76 | }; |
77 | |
78 | } // namespace WebKit |
79 | |
80 | #endif // ENABLE(NETSCAPE_PLUGIN_API) |
81 | |
82 | #endif // NPRemoteObjectMap_h |
83 | |