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.
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
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.
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.
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.
34
#import <WebKit/npapi.h>
35
#import <WebKit/npfunctions.h>
36
#import <WebKit/npruntime.h>
38
#import <Cocoa/Cocoa.h>
39
#import <Quartz/Quartz.h>
40
#import <QuartzCore/QuartzCore.h>
42
// Browser function table
43
static NPNetscapeFuncs* browser;
45
// Structure for per-instance storage
46
typedef struct PluginObject
52
QCCompositionLayer *layer;
56
NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved);
57
NPError NPP_Destroy(NPP instance, NPSavedData** save);
58
NPError NPP_SetWindow(NPP instance, NPWindow* window);
59
NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype);
60
NPError NPP_DestroyStream(NPP instance, NPStream* stream, NPReason reason);
61
int32 NPP_WriteReady(NPP instance, NPStream* stream);
62
int32 NPP_Write(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer);
63
void NPP_StreamAsFile(NPP instance, NPStream* stream, const char* fname);
64
void NPP_Print(NPP instance, NPPrint* platformPrint);
65
int16 NPP_HandleEvent(NPP instance, void* event);
66
void NPP_URLNotify(NPP instance, const char* URL, NPReason reason, void* notifyData);
67
NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value);
68
NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value);
71
// Mach-o entry points
72
NPError NP_Initialize(NPNetscapeFuncs *browserFuncs);
73
NPError NP_GetEntryPoints(NPPluginFuncs *pluginFuncs);
74
void NP_Shutdown(void);
77
NPError NP_Initialize(NPNetscapeFuncs* browserFuncs)
79
browser = browserFuncs;
80
return NPERR_NO_ERROR;
83
NPError NP_GetEntryPoints(NPPluginFuncs* pluginFuncs)
85
pluginFuncs->version = 11;
86
pluginFuncs->size = sizeof(pluginFuncs);
87
pluginFuncs->newp = NPP_New;
88
pluginFuncs->destroy = NPP_Destroy;
89
pluginFuncs->setwindow = NPP_SetWindow;
90
pluginFuncs->newstream = NPP_NewStream;
91
pluginFuncs->destroystream = NPP_DestroyStream;
92
pluginFuncs->asfile = NPP_StreamAsFile;
93
pluginFuncs->writeready = NPP_WriteReady;
94
pluginFuncs->write = (NPP_WriteProcPtr)NPP_Write;
95
pluginFuncs->print = NPP_Print;
96
pluginFuncs->event = NPP_HandleEvent;
97
pluginFuncs->urlnotify = NPP_URLNotify;
98
pluginFuncs->getvalue = NPP_GetValue;
99
pluginFuncs->setvalue = NPP_SetValue;
101
return NPERR_NO_ERROR;
104
void NP_Shutdown(void)
109
NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved)
111
// Create per-instance storage
112
PluginObject *obj = (PluginObject *)malloc(sizeof(PluginObject));
113
bzero(obj, sizeof(PluginObject));
116
instance->pdata = obj;
118
// Ask the browser if it supports the Core Animation drawing model
119
NPBool supportsCoreAnimation;
120
if (browser->getvalue(instance, NPNVsupportsCoreAnimationBool, &supportsCoreAnimation) != NPERR_NO_ERROR)
121
supportsCoreAnimation = FALSE;
123
if (!supportsCoreAnimation)
124
return NPERR_INCOMPATIBLE_VERSION_ERROR;
126
// If the browser supports the Core Animation drawing model, enable it.
127
browser->setvalue(instance, NPPVpluginDrawingModel, (void *)NPDrawingModelCoreAnimation);
129
// If the browser supports the Cocoa event model, enable it.
130
NPBool supportsCocoa;
131
if (browser->getvalue(instance, NPNVsupportsCocoaBool, &supportsCocoa) != NPERR_NO_ERROR)
132
supportsCocoa = FALSE;
135
return NPERR_INCOMPATIBLE_VERSION_ERROR;
137
browser->setvalue(instance, NPPVpluginEventModel, (void *)NPEventModelCocoa);
139
return NPERR_NO_ERROR;
142
NPError NPP_Destroy(NPP instance, NPSavedData** save)
144
// Free per-instance storage
145
PluginObject *obj = instance->pdata;
147
[obj->layer release];
151
return NPERR_NO_ERROR;
154
NPError NPP_SetWindow(NPP instance, NPWindow* window)
156
PluginObject *obj = instance->pdata;
157
obj->window = *window;
159
return NPERR_NO_ERROR;
163
NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype)
165
*stype = NP_ASFILEONLY;
166
return NPERR_NO_ERROR;
169
NPError NPP_DestroyStream(NPP instance, NPStream* stream, NPReason reason)
171
return NPERR_NO_ERROR;
174
int32 NPP_WriteReady(NPP instance, NPStream* stream)
179
int32 NPP_Write(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer)
184
void NPP_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
188
void NPP_Print(NPP instance, NPPrint* platformPrint)
193
static void handleMouseClick(PluginObject *obj, NPCocoaEvent *event)
195
obj->gold = !obj->gold;
197
[obj->layer setValue:[NSNumber numberWithBool:obj->gold] forInputKey:@"gold"];
200
int16 NPP_HandleEvent(NPP instance, void* event)
202
PluginObject *obj = instance->pdata;
204
NPCocoaEvent *cocoaEvent = event;
206
switch(cocoaEvent->type) {
207
case NPCocoaEventMouseDown:
208
handleMouseClick(obj, cocoaEvent);
215
void NPP_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData)
220
NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value)
222
PluginObject *obj = instance->pdata;
225
case NPPVpluginCoreAnimationLayer:
227
NSString *path = [[NSBundle bundleWithIdentifier:@"com.apple.netscapecoreanimationplugin"] pathForResource:@"Composition" ofType:@"qtz"];
229
QCComposition *composition = [QCComposition compositionWithFile:path];
230
obj->layer = [[QCCompositionLayer compositionLayerWithComposition:composition] retain];
233
// Make sure to return a retained layer
234
*((CALayer **)value) = [obj->layer retain];
236
return NPERR_NO_ERROR;
239
return NPERR_GENERIC_ERROR;
243
NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value)
245
return NPERR_GENERIC_ERROR;