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 NPJSObjectWrapperMap_h 27 #define NPJSObjectWrapperMap_h 28 29 #include <wtf/Forward.h> 30 #include <wtf/HashMap.h> 31 32 struct NPObject; 33 typedef struct _NPVariant NPVariant; 34 35 namespace JSC { 36 class ExecState; 37 class JSGlobalData; 38 class JSGlobalObject; 39 class JSObject; 40 class JSValue; 41 } 42 43 namespace WebKit { 44 45 class JSNPObject; 46 class NPJSObject; 47 class PluginView; 48 49 // A per plug-in map of NPObjects that wrap JavaScript objects. 50 class NPRuntimeObjectMap { 51 public: 52 explicit NPRuntimeObjectMap(PluginView*); 53 54 class PluginProtector { 55 public: 56 explicit PluginProtector(NPRuntimeObjectMap* npRuntimeObjectMap); 57 ~PluginProtector(); 58 59 private: 60 RefPtr<PluginView> m_pluginView; 61 }; 62 63 // Returns an NPObject that wraps the given JSObject object. If there is already an NPObject that wraps this JSObject, it will 64 // retain it and return it. 65 NPObject* getOrCreateNPObject(JSC::JSGlobalData&, JSC::JSObject*); 66 void npJSObjectDestroyed(NPJSObject*); 67 68 // Returns a JSObject object that wraps the given NPObject. 69 JSC::JSObject* getOrCreateJSObject(JSC::JSGlobalObject*, NPObject*); 70 void jsNPObjectDestroyed(JSNPObject*); 71 72 void convertJSValueToNPVariant(JSC::ExecState*, JSC::JSValue, NPVariant&); 73 JSC::JSValue convertNPVariantToJSValue(JSC::ExecState*, JSC::JSGlobalObject*, const NPVariant&); 74 75 bool evaluate(NPObject*, const String& scriptString, NPVariant* result); 76 77 // Called when the plug-in is destroyed. Will invalidate all the NPObjects. 78 void invalidate(); 79 80 JSC::JSGlobalObject* globalObject() const; 81 JSC::ExecState* globalExec() const; 82 83 static void setGlobalException(const String& exceptionString); 84 static void moveGlobalExceptionToExecState(JSC::ExecState*); 85 86 private: 87 PluginView* m_pluginView; 88 89 HashMap<JSC::JSObject*, NPJSObject*> m_npJSObjects; 90 HashMap<NPObject*, JSNPObject*> m_jsNPObjects; 91 }; 92 93 } // namespace WebKit 94 95 #endif // NPJSObjectWrapperMap_h 96