Rubber-stamped by Brady Eidson.
[webbrowser.git] / WebCore / plugins / npapi.cpp
blob4135b642039deacfba54dceb8041dad17ab7b649
1 /*
2 * Copyright (C) 2006, 2007 Apple 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
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #include "config.h"
28 #include "PluginInfoStore.h"
29 #include "PluginMainThreadScheduler.h"
30 #include "PluginView.h"
31 #include "npruntime_internal.h"
33 using namespace WebCore;
35 // The plugin view is always the ndata of the instance,. Sometimes, plug-ins will call an instance-specific function
36 // with a NULL instance. To workaround this, call the last plug-in view that made a call to a plug-in.
37 // Currently, the current plug-in view is only set before NPP_New in PluginView::start.
38 // This specifically works around Flash and Shockwave. When we call NPP_New, they call NPN_Useragent with a NULL instance.
39 static PluginView* pluginViewForInstance(NPP instance)
41 if (instance && instance->ndata)
42 return static_cast<PluginView*>(instance->ndata);
43 return PluginView::currentPluginView();
46 void* NPN_MemAlloc(uint32 size)
48 return malloc(size);
51 void NPN_MemFree(void* ptr)
53 free(ptr);
56 uint32 NPN_MemFlush(uint32 size)
58 // Do nothing
59 return 0;
62 void NPN_ReloadPlugins(NPBool reloadPages)
64 refreshPlugins(reloadPages);
67 NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
69 return NPERR_STREAM_NOT_SEEKABLE;
72 NPError NPN_GetURLNotify(NPP instance, const char* url, const char* target, void* notifyData)
74 return pluginViewForInstance(instance)->getURLNotify(url, target, notifyData);
77 NPError NPN_GetURL(NPP instance, const char* url, const char* target)
79 return pluginViewForInstance(instance)->getURL(url, target);
82 NPError NPN_PostURLNotify(NPP instance, const char* url, const char* target, uint32 len, const char* buf, NPBool file, void* notifyData)
84 return pluginViewForInstance(instance)->postURLNotify(url, target, len, buf, file, notifyData);
87 NPError NPN_PostURL(NPP instance, const char* url, const char* target, uint32 len, const char* buf, NPBool file)
89 return pluginViewForInstance(instance)->postURL(url, target, len, buf, file);
92 NPError NPN_NewStream(NPP instance, NPMIMEType type, const char* target, NPStream** stream)
94 return pluginViewForInstance(instance)->newStream(type, target, stream);
97 int32 NPN_Write(NPP instance, NPStream* stream, int32 len, void* buffer)
99 return pluginViewForInstance(instance)->write(stream, len, buffer);
102 NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPReason reason)
104 return pluginViewForInstance(instance)->destroyStream(stream, reason);
107 const char* NPN_UserAgent(NPP instance)
109 PluginView* view = pluginViewForInstance(instance);
111 if (!view)
112 return PluginView::userAgentStatic();
114 return view->userAgent();
117 void NPN_Status(NPP instance, const char* message)
119 pluginViewForInstance(instance)->status(message);
122 void NPN_InvalidateRect(NPP instance, NPRect* invalidRect)
124 pluginViewForInstance(instance)->invalidateRect(invalidRect);
127 void NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion)
129 pluginViewForInstance(instance)->invalidateRegion(invalidRegion);
132 void NPN_ForceRedraw(NPP instance)
134 pluginViewForInstance(instance)->forceRedraw();
137 NPError NPN_GetValue(NPP instance, NPNVariable variable, void* value)
139 PluginView* view = pluginViewForInstance(instance);
141 if (!view)
142 return PluginView::getValueStatic(variable, value);
144 return pluginViewForInstance(instance)->getValue(variable, value);
147 NPError NPN_SetValue(NPP instance, NPPVariable variable, void* value)
149 return pluginViewForInstance(instance)->setValue(variable, value);
152 void* NPN_GetJavaEnv()
154 // Unsupported
155 return 0;
158 void* NPN_GetJavaPeer(NPP instance)
160 // Unsupported
161 return 0;
164 void NPN_PushPopupsEnabledState(NPP instance, NPBool enabled)
166 pluginViewForInstance(instance)->pushPopupsEnabledState(enabled);
169 void NPN_PopPopupsEnabledState(NPP instance)
171 pluginViewForInstance(instance)->popPopupsEnabledState();
174 void NPN_PluginThreadAsyncCall(NPP instance, void (*func) (void *), void *userData)
176 PluginMainThreadScheduler::scheduler().scheduleCall(instance, func, userData);