2
* Copyright (C) 2010 Apple Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
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.
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.
26
#ifndef NPJSObjectWrapperMap_h
27
#define NPJSObjectWrapperMap_h
29
#if ENABLE(NETSCAPE_PLUGIN_API)
31
#include <WebCore/RunLoop.h>
32
#include <heap/Weak.h>
33
#include <wtf/Forward.h>
34
#include <wtf/HashMap.h>
37
typedef struct _NPVariant NPVariant;
53
// A per plug-in map of NPObjects that wrap JavaScript objects.
54
class NPRuntimeObjectMap : private JSC::WeakHandleOwner {
56
explicit NPRuntimeObjectMap(PluginView*);
58
class PluginProtector {
60
explicit PluginProtector(NPRuntimeObjectMap* npRuntimeObjectMap);
64
RefPtr<PluginView> m_pluginView;
67
// Returns an NPObject that wraps the given JSObject object. If there is already an NPObject that wraps this JSObject, it will
68
// retain it and return it.
69
NPObject* getOrCreateNPObject(JSC::JSGlobalData&, JSC::JSObject*);
70
void npJSObjectDestroyed(NPJSObject*);
72
// Returns a JSObject object that wraps the given NPObject.
73
JSC::JSObject* getOrCreateJSObject(JSC::JSGlobalObject*, NPObject*);
74
void jsNPObjectDestroyed(JSNPObject*);
76
void convertJSValueToNPVariant(JSC::ExecState*, JSC::JSValue, NPVariant&);
77
JSC::JSValue convertNPVariantToJSValue(JSC::ExecState*, JSC::JSGlobalObject*, const NPVariant&);
79
bool evaluate(NPObject*, const String& scriptString, NPVariant* result);
81
// Called when the plug-in is destroyed. Will invalidate all the NPObjects.
84
JSC::JSGlobalObject* globalObject() const;
85
JSC::ExecState* globalExec() const;
87
static void setGlobalException(const String& exceptionString);
88
static void moveGlobalExceptionToExecState(JSC::ExecState*);
92
virtual void finalize(JSC::Handle<JSC::Unknown>, void* context);
93
void addToInvalidationQueue(NPObject*);
94
void invalidateQueuedObjects();
96
PluginView* m_pluginView;
98
HashMap<JSC::JSObject*, NPJSObject*> m_npJSObjects;
99
HashMap<NPObject*, JSC::Weak<JSNPObject> > m_jsNPObjects;
100
Vector<NPObject*> m_npObjectsToFinalize;
101
WebCore::RunLoop::Timer<NPRuntimeObjectMap> m_finalizationTimer;
104
} // namespace WebKit
106
#endif // ENABLE(NETSCAPE_PLUGIN_API)
108
#endif // NPJSObjectWrapperMap_h