1 /* 2 IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in 3 consideration of your agreement to the following terms, and your use, installation, 4 modification or redistribution of this Apple software constitutes acceptance of these 5 terms. If you do not agree with these terms, please do not use, install, modify or 6 redistribute this Apple software. 7 8 In consideration of your agreement to abide by the following terms, and subject to these 9 terms, Apple grants you a personal, non-exclusive license, under Apples copyrights in 10 this original Apple software (the "Apple Software"), to use, reproduce, modify and 11 redistribute the Apple Software, with or without modifications, in source and/or binary 12 forms; provided that if you redistribute the Apple Software in its entirety and without 13 modifications, you must retain this notice and the following text and disclaimers in all 14 such redistributions of the Apple Software. Neither the name, trademarks, service marks 15 or logos of Apple Computer, Inc. may be used to endorse or promote products derived from 16 the Apple Software without specific prior written permission from Apple. Except as expressly 17 stated in this notice, no other rights or licenses, express or implied, are granted by Apple 18 herein, including but not limited to any patent rights that may be infringed by your 19 derivative works or by other works in which the Apple Software may be incorporated. 20 21 The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, 22 EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, 23 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS 24 USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 25 26 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL 27 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 28 OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, 29 REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND 30 WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR 31 OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #include <stdlib.h> 35 #include "main.h" 36 #include "PluginObject.h" 37 38 int SubPlugin::getPluginWidth() { 39 PluginObject *obj = (PluginObject*) inst()->pdata; 40 return obj->window->width; 41 } 42 43 int SubPlugin::getPluginHeight() { 44 PluginObject *obj = (PluginObject*) inst()->pdata; 45 return obj->window->height; 46 } 47 48 bool SurfaceSubPlugin::supportsDrawingModel(ANPDrawingModel model) { 49 return (model == kSurface_ANPDrawingModel); 50 } 51 52 void SurfaceSubPlugin::setContext(jobject context) { 53 JNIEnv* env = NULL; 54 if (gVM->GetEnv((void**) &env, JNI_VERSION_1_4) == JNI_OK) { 55 56 // if one exists then free its global reference 57 if (m_context) { 58 env->DeleteGlobalRef(m_context); 59 m_context = NULL; 60 } 61 62 // create a new global ref 63 if (context) { 64 context = env->NewGlobalRef(context); 65 } 66 67 // set the value 68 m_context = context; 69 } 70 } 71 72 static void pluginInvalidate(NPObject *obj); 73 static bool pluginHasProperty(NPObject *obj, NPIdentifier name); 74 static bool pluginHasMethod(NPObject *obj, NPIdentifier name); 75 static bool pluginGetProperty(NPObject *obj, NPIdentifier name, NPVariant *variant); 76 static bool pluginSetProperty(NPObject *obj, NPIdentifier name, const NPVariant *variant); 77 static bool pluginInvoke(NPObject *obj, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result); 78 static bool pluginInvokeDefault(NPObject *obj, const NPVariant *args, uint32_t argCount, NPVariant *result); 79 static NPObject *pluginAllocate(NPP npp, NPClass *theClass); 80 static void pluginDeallocate(NPObject *obj); 81 static bool pluginRemoveProperty(NPObject *npobj, NPIdentifier name); 82 static bool pluginEnumerate(NPObject *npobj, NPIdentifier **value, uint32_t *count); 83 84 85 86 static NPClass pluginClass = { 87 NP_CLASS_STRUCT_VERSION, 88 pluginAllocate, 89 pluginDeallocate, 90 pluginInvalidate, 91 pluginHasMethod, 92 pluginInvoke, 93 pluginInvokeDefault, 94 pluginHasProperty, 95 pluginGetProperty, 96 pluginSetProperty, 97 pluginRemoveProperty, 98 pluginEnumerate 99 }; 100 101 NPClass *getPluginClass(void) 102 { 103 return &pluginClass; 104 } 105 106 static bool identifiersInitialized = false; 107 108 #define ID_TESTFILE_PROPERTY 0 109 #define NUM_PROPERTY_IDENTIFIERS 1 110 111 static NPIdentifier pluginPropertyIdentifiers[NUM_PROPERTY_IDENTIFIERS]; 112 static const NPUTF8 *pluginPropertyIdentifierNames[NUM_PROPERTY_IDENTIFIERS] = { 113 "testfile" 114 }; 115 116 #define ID_GETTESTFILE_METHOD 0 117 #define NUM_METHOD_IDENTIFIERS 1 118 119 static NPIdentifier pluginMethodIdentifiers[NUM_METHOD_IDENTIFIERS]; 120 static const NPUTF8 *pluginMethodIdentifierNames[NUM_METHOD_IDENTIFIERS] = { 121 "getTestFile" 122 }; 123 124 static void initializeIdentifiers(void) 125 { 126 browser->getstringidentifiers(pluginPropertyIdentifierNames, NUM_PROPERTY_IDENTIFIERS, pluginPropertyIdentifiers); 127 browser->getstringidentifiers(pluginMethodIdentifierNames, NUM_METHOD_IDENTIFIERS, pluginMethodIdentifiers); 128 } 129 130 static bool pluginHasProperty(NPObject *obj, NPIdentifier name) 131 { 132 int i; 133 for (i = 0; i < NUM_PROPERTY_IDENTIFIERS; i++) 134 if (name == pluginPropertyIdentifiers[i]) 135 return true; 136 return false; 137 } 138 139 static bool pluginHasMethod(NPObject *obj, NPIdentifier name) 140 { 141 int i; 142 for (i = 0; i < NUM_METHOD_IDENTIFIERS; i++) 143 if (name == pluginMethodIdentifiers[i]) 144 return true; 145 return false; 146 } 147 148 static bool pluginGetProperty(NPObject *obj, NPIdentifier name, NPVariant *variant) 149 { 150 PluginObject *plugin = (PluginObject *)obj; 151 if (name == pluginPropertyIdentifiers[ID_TESTFILE_PROPERTY]) { 152 BOOLEAN_TO_NPVARIANT(true, *variant); 153 return true; 154 } 155 return false; 156 } 157 158 static bool pluginSetProperty(NPObject *obj, NPIdentifier name, const NPVariant *variant) 159 { 160 return false; 161 } 162 163 static bool pluginInvoke(NPObject *obj, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result) 164 { 165 PluginObject *plugin = (PluginObject *)obj; 166 if (name == pluginMethodIdentifiers[ID_GETTESTFILE_METHOD]) { 167 return true; 168 } 169 return false; 170 } 171 172 static bool pluginInvokeDefault(NPObject *obj, const NPVariant *args, uint32_t argCount, NPVariant *result) 173 { 174 return false; 175 } 176 177 static void pluginInvalidate(NPObject *obj) 178 { 179 // Release any remaining references to JavaScript objects. 180 } 181 182 static NPObject *pluginAllocate(NPP npp, NPClass *theClass) 183 { 184 PluginObject *newInstance = (PluginObject*) malloc(sizeof(PluginObject)); 185 newInstance->header._class = theClass; 186 newInstance->header.referenceCount = 1; 187 188 if (!identifiersInitialized) { 189 identifiersInitialized = true; 190 initializeIdentifiers(); 191 } 192 193 newInstance->npp = npp; 194 195 return &newInstance->header; 196 } 197 198 static void pluginDeallocate(NPObject *obj) 199 { 200 free(obj); 201 } 202 203 static bool pluginRemoveProperty(NPObject *npobj, NPIdentifier name) 204 { 205 return false; 206 } 207 208 static bool pluginEnumerate(NPObject *npobj, NPIdentifier **value, uint32_t *count) 209 { 210 return false; 211 } 212