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 NPObjectProxy_h
27#define NPObjectProxy_h
28
29#if ENABLE(NETSCAPE_PLUGIN_API)
30
31#include <WebCore/npruntime_internal.h>
32#include <wtf/Noncopyable.h>
33
34namespace WebKit {
35
36class NPRemoteObjectMap;
37class Plugin;
38
39class NPObjectProxy : public NPObject {
40 WTF_MAKE_NONCOPYABLE(NPObjectProxy);
41
42public:
43 static NPObjectProxy* create(NPRemoteObjectMap*, Plugin*, uint64_t npObjectID);
44
45 static bool isNPObjectProxy(NPObject*);
46
47 static NPObjectProxy* toNPObjectProxy(NPObject* npObject)
48 {
49 ASSERT_WITH_SECURITY_IMPLICATION(isNPObjectProxy(npObject));
50 return static_cast<NPObjectProxy*>(npObject);
51 }
52
53 Plugin* plugin() const { return m_plugin; }
54 uint64_t npObjectID() const { return m_npObjectID; }
55
56 void invalidate();
57
58private:
59 NPObjectProxy();
60 ~NPObjectProxy();
61
62 void initialize(NPRemoteObjectMap*, Plugin*, uint64_t npObjectID);
63
64 bool hasMethod(NPIdentifier methodName);
65 bool invoke(NPIdentifier methodName, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result);
66 bool invokeDefault(const NPVariant* arguments, uint32_t argumentCount, NPVariant* result);
67 bool hasProperty(NPIdentifier propertyName);
68 bool getProperty(NPIdentifier propertyName, NPVariant* result);
69 bool setProperty(NPIdentifier propertyName, const NPVariant* value);
70 bool removeProperty(NPIdentifier propertyName);
71 bool enumerate(NPIdentifier** identifiers, uint32_t* identifierCount);
72 bool construct(const NPVariant* arguments, uint32_t argumentCount, NPVariant* result);
73
74 static NPClass* npClass();
75 static NPObject* NP_Allocate(NPP, NPClass*);
76 static void NP_Deallocate(NPObject*);
77 static bool NP_HasMethod(NPObject*, NPIdentifier methodName);
78 static bool NP_Invoke(NPObject*, NPIdentifier methodName, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result);
79 static bool NP_InvokeDefault(NPObject*, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result);
80 static bool NP_HasProperty(NPObject*, NPIdentifier propertyName);
81 static bool NP_GetProperty(NPObject*, NPIdentifier propertyName, NPVariant* result);
82 static bool NP_SetProperty(NPObject*, NPIdentifier propertyName, const NPVariant* value);
83 static bool NP_RemoveProperty(NPObject*, NPIdentifier propertyName);
84 static bool NP_Enumerate(NPObject*, NPIdentifier** identifiers, uint32_t* identifierCount);
85 static bool NP_Construct(NPObject*, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result);
86
87 NPRemoteObjectMap* m_npRemoteObjectMap;
88 Plugin* m_plugin;
89 uint64_t m_npObjectID;
90};
91
92} // namespace WebKit
93
94#endif // ENABLE(NETSCAPE_PLUGIN_API)
95
96#endif // NPObjectProxy_h
97