2 * Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #if ENABLE(NETSCAPE_PLUGIN_API)
30 #import <WebKit/npapi.h>
32 #import <WebKit/WebBaseNetscapePluginViewPrivate.h>
33 #import <WebKit/WebKitLogging.h>
35 WebBaseNetscapePluginView *pluginViewForInstance(NPP instance);
37 // general plug-in to browser functions
39 void* NPN_MemAlloc(uint32 size)
44 void NPN_MemFree(void* ptr)
49 uint32 NPN_MemFlush(uint32 size)
51 LOG(Plugins, "NPN_MemFlush");
55 void NPN_ReloadPlugins(NPBool reloadPages)
57 LOG(Plugins, "NPN_ReloadPlugins");
60 NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
62 LOG(Plugins, "NPN_RequestRead");
63 return NPERR_GENERIC_ERROR;
66 // instance-specific functions
67 // The plugin view is always the ndata of the instance. Sometimes, plug-ins will call an instance-specific function
68 // with a NULL instance. To workaround this, call the last plug-in view that made a call to a plug-in.
69 // Currently, the current plug-in view is only set before NPP_New in [WebBaseNetscapePluginView start].
70 // This specifically works around Flash and Shockwave. When we call NPP_New, they call NPN_UserAgent with a NULL instance.
71 WebBaseNetscapePluginView *pluginViewForInstance(NPP instance)
73 if (instance && instance->ndata)
74 return (WebBaseNetscapePluginView *)instance->ndata;
76 return [WebBaseNetscapePluginView currentPluginView];
79 NPError NPN_GetURLNotify(NPP instance, const char* URL, const char* target, void* notifyData)
81 return [pluginViewForInstance(instance) getURLNotify:URL target:target notifyData:notifyData];
84 NPError NPN_GetURL(NPP instance, const char* URL, const char* target)
86 return [pluginViewForInstance(instance) getURL:URL target:target];
89 NPError NPN_PostURLNotify(NPP instance, const char* URL, const char* target, uint32 len, const char* buf, NPBool file, void* notifyData)
91 return [pluginViewForInstance(instance) postURLNotify:URL target:target len:len buf:buf file:file notifyData:notifyData];
94 NPError NPN_PostURL(NPP instance, const char* URL, const char* target, uint32 len, const char* buf, NPBool file)
96 return [pluginViewForInstance(instance) postURL:URL target:target len:len buf:buf file:file];
99 NPError NPN_NewStream(NPP instance, NPMIMEType type, const char* target, NPStream** stream)
101 return [pluginViewForInstance(instance) newStream:type target:target stream:stream];
104 int32 NPN_Write(NPP instance, NPStream* stream, int32 len, void* buffer)
106 return [pluginViewForInstance(instance) write:stream len:len buffer:buffer];
109 NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPReason reason)
111 return [pluginViewForInstance(instance) destroyStream:stream reason:reason];
114 const char* NPN_UserAgent(NPP instance)
116 return [pluginViewForInstance(instance) userAgent];
119 void NPN_Status(NPP instance, const char* message)
121 [pluginViewForInstance(instance) status:message];
124 void NPN_InvalidateRect(NPP instance, NPRect *invalidRect)
126 [pluginViewForInstance(instance) invalidateRect:invalidRect];
129 void NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion)
131 [pluginViewForInstance(instance) invalidateRegion:invalidRegion];
134 void NPN_ForceRedraw(NPP instance)
136 [pluginViewForInstance(instance) forceRedraw];
139 NPError NPN_GetValue(NPP instance, NPNVariable variable, void *value)
141 return [pluginViewForInstance(instance) getVariable:variable value:value];
144 NPError NPN_SetValue(NPP instance, NPPVariable variable, void *value)
146 return [pluginViewForInstance(instance) setVariable:variable value:value];
149 // Unsupported functions
151 void* NPN_GetJavaEnv(void)
153 LOG(Plugins, "NPN_GetJavaEnv");
157 void* NPN_GetJavaPeer(NPP instance)
159 LOG(Plugins, "NPN_GetJavaPeer");
164 NPN_PushPopupsEnabledState(NPP instance, NPBool enabled)
169 NPN_PopPopupsEnabledState(NPP instance)
173 uint32 NPN_ScheduleTimer(NPP instance, uint32 interval, NPBool repeat, void (*timerFunc)(NPP npp, uint32 timerID))
175 return [pluginViewForInstance(instance) scheduleTimerWithInterval:interval repeat:repeat timerFunc:timerFunc];
178 void NPN_UnscheduleTimer(NPP instance, uint32 timerID)
180 [pluginViewForInstance(instance) unscheduleTimer:timerID];
183 NPError NPN_PopUpContextMenu(NPP instance, NPMenu *menu)
185 return [pluginViewForInstance(instance) popUpContextMenu:menu];