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>
31 #import <WebKit/nptextinput.h>
33 #import <WebKit/WebBaseNetscapePluginViewPrivate.h>
34 #import <WebKit/WebKitLogging.h>
36 WebBaseNetscapePluginView *pluginViewForInstance(NPP instance);
38 // general plug-in to browser functions
40 void* NPN_MemAlloc(uint32 size)
45 void NPN_MemFree(void* ptr)
50 uint32 NPN_MemFlush(uint32 size)
52 LOG(Plugins, "NPN_MemFlush");
56 void NPN_ReloadPlugins(NPBool reloadPages)
58 LOG(Plugins, "NPN_ReloadPlugins");
61 NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
63 LOG(Plugins, "NPN_RequestRead");
64 return NPERR_GENERIC_ERROR;
67 // instance-specific functions
68 // The plugin view is always the ndata of the instance. Sometimes, plug-ins will call an instance-specific function
69 // with a NULL instance. To workaround this, call the last plug-in view that made a call to a plug-in.
70 // Currently, the current plug-in view is only set before NPP_New in [WebBaseNetscapePluginView start].
71 // This specifically works around Flash and Shockwave. When we call NPP_New, they call NPN_UserAgent with a NULL instance.
72 WebBaseNetscapePluginView *pluginViewForInstance(NPP instance)
74 if (instance && instance->ndata)
75 return (WebBaseNetscapePluginView *)instance->ndata;
77 return [WebBaseNetscapePluginView currentPluginView];
80 NPError NPN_GetURLNotify(NPP instance, const char* URL, const char* target, void* notifyData)
82 return [pluginViewForInstance(instance) getURLNotify:URL target:target notifyData:notifyData];
85 NPError NPN_GetURL(NPP instance, const char* URL, const char* target)
87 return [pluginViewForInstance(instance) getURL:URL target:target];
90 NPError NPN_PostURLNotify(NPP instance, const char* URL, const char* target, uint32 len, const char* buf, NPBool file, void* notifyData)
92 return [pluginViewForInstance(instance) postURLNotify:URL target:target len:len buf:buf file:file notifyData:notifyData];
95 NPError NPN_PostURL(NPP instance, const char* URL, const char* target, uint32 len, const char* buf, NPBool file)
97 return [pluginViewForInstance(instance) postURL:URL target:target len:len buf:buf file:file];
100 NPError NPN_NewStream(NPP instance, NPMIMEType type, const char* target, NPStream** stream)
102 return [pluginViewForInstance(instance) newStream:type target:target stream:stream];
105 int32 NPN_Write(NPP instance, NPStream* stream, int32 len, void* buffer)
107 return [pluginViewForInstance(instance) write:stream len:len buffer:buffer];
110 NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPReason reason)
112 return [pluginViewForInstance(instance) destroyStream:stream reason:reason];
115 const char* NPN_UserAgent(NPP instance)
117 return [pluginViewForInstance(instance) userAgent];
120 void NPN_Status(NPP instance, const char* message)
122 [pluginViewForInstance(instance) status:message];
125 void NPN_InvalidateRect(NPP instance, NPRect *invalidRect)
127 [pluginViewForInstance(instance) invalidateRect:invalidRect];
130 void NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion)
132 [pluginViewForInstance(instance) invalidateRegion:invalidRegion];
135 void NPN_ForceRedraw(NPP instance)
137 [pluginViewForInstance(instance) forceRedraw];
140 NPError NPN_GetValue(NPP instance, NPNVariable variable, void *value)
142 return [pluginViewForInstance(instance) getVariable:variable value:value];
145 NPError NPN_SetValue(NPP instance, NPPVariable variable, void *value)
147 return [pluginViewForInstance(instance) setVariable:variable value:value];
150 // Unsupported functions
152 void* NPN_GetJavaEnv(void)
154 LOG(Plugins, "NPN_GetJavaEnv");
158 void* NPN_GetJavaPeer(NPP instance)
160 LOG(Plugins, "NPN_GetJavaPeer");
165 NPN_PushPopupsEnabledState(NPP instance, NPBool enabled)
170 NPN_PopPopupsEnabledState(NPP instance)
174 uint32 NPN_ScheduleTimer(NPP instance, uint32 interval, NPBool repeat, void (*timerFunc)(NPP npp, uint32 timerID))
176 return [pluginViewForInstance(instance) scheduleTimerWithInterval:interval repeat:repeat timerFunc:timerFunc];
179 void NPN_UnscheduleTimer(NPP instance, uint32 timerID)
181 [pluginViewForInstance(instance) unscheduleTimer:timerID];
184 NPError NPN_PopUpContextMenu(NPP instance, NPMenu *menu)
186 return [pluginViewForInstance(instance) popUpContextMenu:menu];
189 void NPN_MarkedTextAbandoned(NPP instance)
191 WebBaseNetscapePluginView *pluginView = pluginViewForInstance(instance);
193 [[NSInputManager currentInputManager] markedTextAbandoned:pluginView];
196 void NPN_MarkedTextSelectionChanged(NPP instance, NSRange newSel)
198 WebBaseNetscapePluginView *pluginView = pluginViewForInstance(instance);
200 [[NSInputManager currentInputManager] markedTextSelectionChanged:newSel client:pluginView];