webengine/osswebengine/WebKit/Plugins/npapi.m
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2  * Copyright (C) 2005 Apple Computer, Inc.  All rights reserved.
       
     3  *
       
     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  *
       
     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. 
       
    16  *
       
    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.
       
    27  */
       
    28 #ifndef __LP64__
       
    29 #import <WebKit/npapi.h>
       
    30 
       
    31 #import <WebKit/WebBaseNetscapePluginViewPrivate.h>
       
    32 #import <WebKit/WebKitLogging.h>
       
    33 
       
    34 WebBaseNetscapePluginView *pluginViewForInstance(NPP instance);
       
    35 
       
    36 // general plug-in to browser functions
       
    37 
       
    38 void* NPN_MemAlloc(uint32 size)
       
    39 {
       
    40     return malloc(size);
       
    41 }
       
    42 
       
    43 void NPN_MemFree(void* ptr)
       
    44 {
       
    45     free(ptr);
       
    46 }
       
    47 
       
    48 uint32 NPN_MemFlush(uint32 size)
       
    49 {
       
    50     LOG(Plugins, "NPN_MemFlush");
       
    51     return size;
       
    52 }
       
    53 
       
    54 void NPN_ReloadPlugins(NPBool reloadPages)
       
    55 {
       
    56     LOG(Plugins, "NPN_ReloadPlugins");
       
    57 }
       
    58 
       
    59 NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
       
    60 {
       
    61     LOG(Plugins, "NPN_RequestRead");
       
    62     return NPERR_GENERIC_ERROR;
       
    63 }
       
    64 
       
    65 // instance-specific functions
       
    66 // The plugin view is always the ndata of the instance. Sometimes, plug-ins will call an instance-specific function
       
    67 // with a NULL instance. To workaround this, call the last plug-in view that made a call to a plug-in.
       
    68 // Currently, the current plug-in view is only set before NPP_New in [WebBaseNetscapePluginView start].
       
    69 // This specifically works around Flash and Shockwave. When we call NPP_New, they call NPN_UserAgent with a NULL instance.
       
    70 WebBaseNetscapePluginView *pluginViewForInstance(NPP instance)
       
    71 {
       
    72     if (instance && instance->ndata)
       
    73         return (WebBaseNetscapePluginView *)instance->ndata;
       
    74     else
       
    75         return [WebBaseNetscapePluginView currentPluginView];
       
    76 }
       
    77 
       
    78 NPError NPN_GetURLNotify(NPP instance, const char* URL, const char* target, void* notifyData)
       
    79 {
       
    80     return [pluginViewForInstance(instance) getURLNotify:URL target:target notifyData:notifyData];
       
    81 }
       
    82 
       
    83 NPError NPN_GetURL(NPP instance, const char* URL, const char* target)
       
    84 {
       
    85     return [pluginViewForInstance(instance) getURL:URL target:target];
       
    86 }
       
    87 
       
    88 NPError NPN_PostURLNotify(NPP instance, const char* URL, const char* target, uint32 len, const char* buf, NPBool file, void* notifyData)
       
    89 {
       
    90     return [pluginViewForInstance(instance) postURLNotify:URL target:target len:len buf:buf file:file notifyData:notifyData];
       
    91 }
       
    92 
       
    93 NPError NPN_PostURL(NPP instance, const char* URL, const char* target, uint32 len, const char* buf, NPBool file)
       
    94 {
       
    95     return [pluginViewForInstance(instance) postURL:URL target:target len:len buf:buf file:file];
       
    96 }
       
    97 
       
    98 NPError NPN_NewStream(NPP instance, NPMIMEType type, const char* target, NPStream** stream)
       
    99 {
       
   100     return [pluginViewForInstance(instance) newStream:type target:target stream:stream];
       
   101 }
       
   102 
       
   103 int32 NPN_Write(NPP instance, NPStream* stream, int32 len, void* buffer)
       
   104 {
       
   105     return [pluginViewForInstance(instance) write:stream len:len buffer:buffer];
       
   106 }
       
   107 
       
   108 NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPReason reason)
       
   109 {
       
   110     return [pluginViewForInstance(instance) destroyStream:stream reason:reason];
       
   111 }
       
   112 
       
   113 const char* NPN_UserAgent(NPP instance)
       
   114 {
       
   115     return [pluginViewForInstance(instance) userAgent];
       
   116 }
       
   117 
       
   118 void NPN_Status(NPP instance, const char* message)
       
   119 {
       
   120     [pluginViewForInstance(instance) status:message];
       
   121 }
       
   122 
       
   123 void NPN_InvalidateRect(NPP instance, NPRect *invalidRect)
       
   124 {
       
   125     [pluginViewForInstance(instance) invalidateRect:invalidRect];
       
   126 }
       
   127 
       
   128 void NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion)
       
   129 {
       
   130     [pluginViewForInstance(instance) invalidateRegion:invalidRegion];
       
   131 }
       
   132 
       
   133 void NPN_ForceRedraw(NPP instance)
       
   134 {
       
   135     [pluginViewForInstance(instance) forceRedraw];
       
   136 }
       
   137 
       
   138 NPError NPN_GetValue(NPP instance, NPNVariable variable, void *value)
       
   139 {
       
   140     return [pluginViewForInstance(instance) getVariable:variable value:value];
       
   141 }
       
   142 
       
   143 NPError NPN_SetValue(NPP instance, NPPVariable variable, void *value)
       
   144 {
       
   145     return [pluginViewForInstance(instance) setVariable:variable value:value];
       
   146 }
       
   147 
       
   148 // Unsupported functions
       
   149 
       
   150 void* NPN_GetJavaEnv(void)
       
   151 {
       
   152     LOG(Plugins, "NPN_GetJavaEnv");
       
   153     return NULL;
       
   154 }
       
   155 
       
   156 void* NPN_GetJavaPeer(NPP instance)
       
   157 {
       
   158     LOG(Plugins, "NPN_GetJavaPeer");
       
   159     return NULL;
       
   160 }
       
   161 
       
   162 void
       
   163 NPN_PushPopupsEnabledState(NPP instance, NPBool enabled)
       
   164 {
       
   165 }
       
   166 
       
   167 void
       
   168 NPN_PopPopupsEnabledState(NPP instance)
       
   169 {
       
   170 }
       
   171 #endif