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 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 48 | static void pluginInvalidate(NPObject *obj); |
| 49 | static bool pluginHasProperty(NPObject *obj, NPIdentifier name); |
| 50 | static bool pluginHasMethod(NPObject *obj, NPIdentifier name); |
| 51 | static bool pluginGetProperty(NPObject *obj, NPIdentifier name, NPVariant *variant); |
| 52 | static bool pluginSetProperty(NPObject *obj, NPIdentifier name, const NPVariant *variant); |
| 53 | static bool pluginInvoke(NPObject *obj, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result); |
| 54 | static bool pluginInvokeDefault(NPObject *obj, const NPVariant *args, uint32_t argCount, NPVariant *result); |
| 55 | static NPObject *pluginAllocate(NPP npp, NPClass *theClass); |
| 56 | static void pluginDeallocate(NPObject *obj); |
| 57 | static bool pluginRemoveProperty(NPObject *npobj, NPIdentifier name); |
| 58 | static bool pluginEnumerate(NPObject *npobj, NPIdentifier **value, uint32_t *count); |
| 59 | |
| 60 | |
| 61 | |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 62 | static NPClass pluginClass = { |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 63 | NP_CLASS_STRUCT_VERSION, |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 64 | pluginAllocate, |
| 65 | pluginDeallocate, |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 66 | pluginInvalidate, |
| 67 | pluginHasMethod, |
| 68 | pluginInvoke, |
| 69 | pluginInvokeDefault, |
| 70 | pluginHasProperty, |
| 71 | pluginGetProperty, |
| 72 | pluginSetProperty, |
| 73 | pluginRemoveProperty, |
| 74 | pluginEnumerate |
| 75 | }; |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 76 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 77 | NPClass *getPluginClass(void) |
| 78 | { |
| 79 | return &pluginClass; |
| 80 | } |
| 81 | |
| 82 | static bool identifiersInitialized = false; |
| 83 | |
| 84 | #define ID_TESTFILE_PROPERTY 0 |
| 85 | #define NUM_PROPERTY_IDENTIFIERS 1 |
| 86 | |
| 87 | static NPIdentifier pluginPropertyIdentifiers[NUM_PROPERTY_IDENTIFIERS]; |
| 88 | static const NPUTF8 *pluginPropertyIdentifierNames[NUM_PROPERTY_IDENTIFIERS] = { |
| 89 | "testfile" |
| 90 | }; |
| 91 | |
| 92 | #define ID_GETTESTFILE_METHOD 0 |
| 93 | #define NUM_METHOD_IDENTIFIERS 1 |
| 94 | |
| 95 | static NPIdentifier pluginMethodIdentifiers[NUM_METHOD_IDENTIFIERS]; |
| 96 | static const NPUTF8 *pluginMethodIdentifierNames[NUM_METHOD_IDENTIFIERS] = { |
| 97 | "getTestFile" |
| 98 | }; |
| 99 | |
| 100 | static void initializeIdentifiers(void) |
| 101 | { |
| 102 | browser->getstringidentifiers(pluginPropertyIdentifierNames, NUM_PROPERTY_IDENTIFIERS, pluginPropertyIdentifiers); |
| 103 | browser->getstringidentifiers(pluginMethodIdentifierNames, NUM_METHOD_IDENTIFIERS, pluginMethodIdentifiers); |
| 104 | } |
| 105 | |
| 106 | static bool pluginHasProperty(NPObject *obj, NPIdentifier name) |
| 107 | { |
| 108 | int i; |
| 109 | for (i = 0; i < NUM_PROPERTY_IDENTIFIERS; i++) |
| 110 | if (name == pluginPropertyIdentifiers[i]) |
| 111 | return true; |
| 112 | return false; |
| 113 | } |
| 114 | |
| 115 | static bool pluginHasMethod(NPObject *obj, NPIdentifier name) |
| 116 | { |
| 117 | int i; |
| 118 | for (i = 0; i < NUM_METHOD_IDENTIFIERS; i++) |
| 119 | if (name == pluginMethodIdentifiers[i]) |
| 120 | return true; |
| 121 | return false; |
| 122 | } |
| 123 | |
| 124 | static bool pluginGetProperty(NPObject *obj, NPIdentifier name, NPVariant *variant) |
| 125 | { |
| 126 | PluginObject *plugin = (PluginObject *)obj; |
| 127 | if (name == pluginPropertyIdentifiers[ID_TESTFILE_PROPERTY]) { |
| 128 | BOOLEAN_TO_NPVARIANT(true, *variant); |
| 129 | return true; |
| 130 | } |
| 131 | return false; |
| 132 | } |
| 133 | |
| 134 | static bool pluginSetProperty(NPObject *obj, NPIdentifier name, const NPVariant *variant) |
| 135 | { |
| 136 | return false; |
| 137 | } |
| 138 | |
| 139 | static bool pluginInvoke(NPObject *obj, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result) |
| 140 | { |
| 141 | PluginObject *plugin = (PluginObject *)obj; |
| 142 | if (name == pluginMethodIdentifiers[ID_GETTESTFILE_METHOD]) { |
| 143 | return true; |
| 144 | } |
| 145 | return false; |
| 146 | } |
| 147 | |
| 148 | static bool pluginInvokeDefault(NPObject *obj, const NPVariant *args, uint32_t argCount, NPVariant *result) |
| 149 | { |
| 150 | return false; |
| 151 | } |
| 152 | |
| 153 | static void pluginInvalidate(NPObject *obj) |
| 154 | { |
| 155 | // Release any remaining references to JavaScript objects. |
| 156 | } |
| 157 | |
| 158 | static NPObject *pluginAllocate(NPP npp, NPClass *theClass) |
| 159 | { |
| 160 | PluginObject *newInstance = (PluginObject*) malloc(sizeof(PluginObject)); |
| 161 | newInstance->header._class = theClass; |
| 162 | newInstance->header.referenceCount = 1; |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 163 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 164 | if (!identifiersInitialized) { |
| 165 | identifiersInitialized = true; |
| 166 | initializeIdentifiers(); |
| 167 | } |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 168 | |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 169 | newInstance->npp = npp; |
| 170 | |
| 171 | return &newInstance->header; |
| 172 | } |
| 173 | |
Derek Sollenberger | d7ebf27 | 2009-06-18 11:19:41 -0400 | [diff] [blame] | 174 | static void pluginDeallocate(NPObject *obj) |
Grace Kloba | fbe47c0 | 2009-05-14 17:31:45 -0700 | [diff] [blame] | 175 | { |
| 176 | free(obj); |
| 177 | } |
| 178 | |
| 179 | static bool pluginRemoveProperty(NPObject *npobj, NPIdentifier name) |
| 180 | { |
| 181 | return false; |
| 182 | } |
| 183 | |
| 184 | static bool pluginEnumerate(NPObject *npobj, NPIdentifier **value, uint32_t *count) |
| 185 | { |
| 186 | return false; |
| 187 | } |