Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 1 | /* |
| 2 | IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 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 |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 6 | redistribute this Apple software. |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 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 AppleĆs 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 |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 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 |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 18 | herein, including but not limited to any patent rights that may be infringed by your |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 19 | derivative works or by other works in which the Apple Software may be incorporated. |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 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 |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 24 | USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 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 |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 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 | |
Derek Sollenberger | bb660dd | 2009-10-13 11:43:48 -0400 | [diff] [blame] | 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 | |
Derek Sollenberger | 51cce58 | 2009-12-01 08:26:20 -0500 | [diff] [blame^] | 48 | void SurfaceSubPlugin::setJavaInterface(jobject javaInterface) { |
| 49 | |
| 50 | // if one exists then free its reference and notify the object that it is no |
| 51 | // longer attached to the native instance |
| 52 | JNIEnv* env = NULL; |
| 53 | if (m_javaInterface && gVM->GetEnv((void**) &env, JNI_VERSION_1_4) == JNI_OK) { |
| 54 | |
| 55 | // detach the native code from the object |
| 56 | jclass javaClass = env->GetObjectClass(m_javaInterface); |
| 57 | jmethodID invalMethod = env->GetMethodID(javaClass, "invalidateNPP", "()V"); |
| 58 | env->CallVoidMethod(m_javaInterface, invalMethod); |
| 59 | |
| 60 | // delete the reference |
| 61 | env->DeleteGlobalRef(m_javaInterface); |
| 62 | m_javaInterface = NULL; |
| 63 | } |
| 64 | |
| 65 | //set the value |
| 66 | m_javaInterface = javaInterface; |
| 67 | } |
| 68 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 69 | static void pluginInvalidate(NPObject *obj); |
| 70 | static bool pluginHasProperty(NPObject *obj, NPIdentifier name); |
| 71 | static bool pluginHasMethod(NPObject *obj, NPIdentifier name); |
| 72 | static bool pluginGetProperty(NPObject *obj, NPIdentifier name, NPVariant *variant); |
| 73 | static bool pluginSetProperty(NPObject *obj, NPIdentifier name, const NPVariant *variant); |
| 74 | static bool pluginInvoke(NPObject *obj, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result); |
| 75 | static bool pluginInvokeDefault(NPObject *obj, const NPVariant *args, uint32_t argCount, NPVariant *result); |
| 76 | static NPObject *pluginAllocate(NPP npp, NPClass *theClass); |
| 77 | static void pluginDeallocate(NPObject *obj); |
| 78 | static bool pluginRemoveProperty(NPObject *npobj, NPIdentifier name); |
| 79 | static bool pluginEnumerate(NPObject *npobj, NPIdentifier **value, uint32_t *count); |
| 80 | |
| 81 | |
| 82 | |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 83 | static NPClass pluginClass = { |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 84 | NP_CLASS_STRUCT_VERSION, |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 85 | pluginAllocate, |
| 86 | pluginDeallocate, |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 87 | pluginInvalidate, |
| 88 | pluginHasMethod, |
| 89 | pluginInvoke, |
| 90 | pluginInvokeDefault, |
| 91 | pluginHasProperty, |
| 92 | pluginGetProperty, |
| 93 | pluginSetProperty, |
| 94 | pluginRemoveProperty, |
| 95 | pluginEnumerate |
| 96 | }; |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 97 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 98 | NPClass *getPluginClass(void) |
| 99 | { |
| 100 | return &pluginClass; |
| 101 | } |
| 102 | |
| 103 | static bool identifiersInitialized = false; |
| 104 | |
| 105 | #define ID_TESTFILE_PROPERTY 0 |
| 106 | #define NUM_PROPERTY_IDENTIFIERS 1 |
| 107 | |
| 108 | static NPIdentifier pluginPropertyIdentifiers[NUM_PROPERTY_IDENTIFIERS]; |
| 109 | static const NPUTF8 *pluginPropertyIdentifierNames[NUM_PROPERTY_IDENTIFIERS] = { |
| 110 | "testfile" |
| 111 | }; |
| 112 | |
| 113 | #define ID_GETTESTFILE_METHOD 0 |
| 114 | #define NUM_METHOD_IDENTIFIERS 1 |
| 115 | |
| 116 | static NPIdentifier pluginMethodIdentifiers[NUM_METHOD_IDENTIFIERS]; |
| 117 | static const NPUTF8 *pluginMethodIdentifierNames[NUM_METHOD_IDENTIFIERS] = { |
| 118 | "getTestFile" |
| 119 | }; |
| 120 | |
| 121 | static void initializeIdentifiers(void) |
| 122 | { |
| 123 | browser->getstringidentifiers(pluginPropertyIdentifierNames, NUM_PROPERTY_IDENTIFIERS, pluginPropertyIdentifiers); |
| 124 | browser->getstringidentifiers(pluginMethodIdentifierNames, NUM_METHOD_IDENTIFIERS, pluginMethodIdentifiers); |
| 125 | } |
| 126 | |
| 127 | static bool pluginHasProperty(NPObject *obj, NPIdentifier name) |
| 128 | { |
| 129 | int i; |
| 130 | for (i = 0; i < NUM_PROPERTY_IDENTIFIERS; i++) |
| 131 | if (name == pluginPropertyIdentifiers[i]) |
| 132 | return true; |
| 133 | return false; |
| 134 | } |
| 135 | |
| 136 | static bool pluginHasMethod(NPObject *obj, NPIdentifier name) |
| 137 | { |
| 138 | int i; |
| 139 | for (i = 0; i < NUM_METHOD_IDENTIFIERS; i++) |
| 140 | if (name == pluginMethodIdentifiers[i]) |
| 141 | return true; |
| 142 | return false; |
| 143 | } |
| 144 | |
| 145 | static bool pluginGetProperty(NPObject *obj, NPIdentifier name, NPVariant *variant) |
| 146 | { |
| 147 | PluginObject *plugin = (PluginObject *)obj; |
| 148 | if (name == pluginPropertyIdentifiers[ID_TESTFILE_PROPERTY]) { |
| 149 | BOOLEAN_TO_NPVARIANT(true, *variant); |
| 150 | return true; |
| 151 | } |
| 152 | return false; |
| 153 | } |
| 154 | |
| 155 | static bool pluginSetProperty(NPObject *obj, NPIdentifier name, const NPVariant *variant) |
| 156 | { |
| 157 | return false; |
| 158 | } |
| 159 | |
| 160 | static bool pluginInvoke(NPObject *obj, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result) |
| 161 | { |
| 162 | PluginObject *plugin = (PluginObject *)obj; |
| 163 | if (name == pluginMethodIdentifiers[ID_GETTESTFILE_METHOD]) { |
| 164 | return true; |
| 165 | } |
| 166 | return false; |
| 167 | } |
| 168 | |
| 169 | static bool pluginInvokeDefault(NPObject *obj, const NPVariant *args, uint32_t argCount, NPVariant *result) |
| 170 | { |
| 171 | return false; |
| 172 | } |
| 173 | |
| 174 | static void pluginInvalidate(NPObject *obj) |
| 175 | { |
| 176 | // Release any remaining references to JavaScript objects. |
| 177 | } |
| 178 | |
| 179 | static NPObject *pluginAllocate(NPP npp, NPClass *theClass) |
| 180 | { |
| 181 | PluginObject *newInstance = (PluginObject*) malloc(sizeof(PluginObject)); |
| 182 | newInstance->header._class = theClass; |
| 183 | newInstance->header.referenceCount = 1; |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 184 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 185 | if (!identifiersInitialized) { |
| 186 | identifiersInitialized = true; |
| 187 | initializeIdentifiers(); |
| 188 | } |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 189 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 190 | newInstance->npp = npp; |
| 191 | |
| 192 | return &newInstance->header; |
| 193 | } |
| 194 | |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 195 | static void pluginDeallocate(NPObject *obj) |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 196 | { |
| 197 | free(obj); |
| 198 | } |
| 199 | |
| 200 | static bool pluginRemoveProperty(NPObject *npobj, NPIdentifier name) |
| 201 | { |
| 202 | return false; |
| 203 | } |
| 204 | |
| 205 | static bool pluginEnumerate(NPObject *npobj, NPIdentifier **value, uint32_t *count) |
| 206 | { |
| 207 | return false; |
| 208 | } |