webengine/osswebengine/WebKitTools/DumpRenderTree/TestNetscapePlugIn.subproj/main.c
changeset 0 dd21522fd290
child 36 0ed94ceaa377
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     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.
       
     7  
       
     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.
       
    20  
       
    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.
       
    25  
       
    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.
       
    32  */
       
    33 
       
    34 #import "PluginObject.h"
       
    35 
       
    36 // Mach-o entry points
       
    37 NPError NP_Initialize(NPNetscapeFuncs *browserFuncs);
       
    38 NPError NP_GetEntryPoints(NPPluginFuncs *pluginFuncs);
       
    39 void NP_Shutdown(void);
       
    40 
       
    41 // Mach-o entry points
       
    42 NPError NP_Initialize(NPNetscapeFuncs *browserFuncs)
       
    43 {
       
    44     browser = browserFuncs;
       
    45     return NPERR_NO_ERROR;
       
    46 }
       
    47 
       
    48 NPError NP_GetEntryPoints(NPPluginFuncs *pluginFuncs)
       
    49 {
       
    50     pluginFuncs->version = 11;
       
    51     pluginFuncs->size = sizeof(pluginFuncs);
       
    52     pluginFuncs->newp = NPP_New;
       
    53     pluginFuncs->destroy = NPP_Destroy;
       
    54     pluginFuncs->setwindow = NPP_SetWindow;
       
    55     pluginFuncs->newstream = NPP_NewStream;
       
    56     pluginFuncs->destroystream = NPP_DestroyStream;
       
    57     pluginFuncs->asfile = NPP_StreamAsFile;
       
    58     pluginFuncs->writeready = NPP_WriteReady;
       
    59     pluginFuncs->write = (NPP_WriteProcPtr)NPP_Write;
       
    60     pluginFuncs->print = NPP_Print;
       
    61     pluginFuncs->event = NPP_HandleEvent;
       
    62     pluginFuncs->urlnotify = NPP_URLNotify;
       
    63     pluginFuncs->getvalue = NPP_GetValue;
       
    64     pluginFuncs->setvalue = NPP_SetValue;
       
    65     
       
    66     return NPERR_NO_ERROR;
       
    67 }
       
    68 
       
    69 void NP_Shutdown(void)
       
    70 {
       
    71 }
       
    72 
       
    73 NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char *argn[], char *argv[], NPSavedData *saved)
       
    74 {
       
    75     if (browser->version >= 14) {
       
    76         PluginObject* obj = (PluginObject*)browser->createobject(instance, getPluginClass());
       
    77     
       
    78         obj->onStreamLoad = NULL;
       
    79         
       
    80         for (uint i = 0; i < argc; i++) {
       
    81             if (strcasecmp(argn[i], "onstreamload") == 0 && !obj->onStreamLoad)
       
    82                 obj->onStreamLoad = strdup(argv[i]);
       
    83             else if (strcasecmp(argn[i], "src") == 0 &&
       
    84                      strcasecmp(argv[i], "data:application/x-webkit-test-netscape,returnerrorfromnewstream") == 0)
       
    85                 obj->returnErrorFromNewStream = TRUE;
       
    86             else if (strcasecmp(argn[i], "logfirstsetwindow") == 0)
       
    87                 obj->logSetWindow = TRUE;
       
    88         }
       
    89         
       
    90         instance->pdata = obj;
       
    91     }
       
    92     
       
    93     return NPERR_NO_ERROR;
       
    94 }
       
    95 
       
    96 NPError NPP_Destroy(NPP instance, NPSavedData **save)
       
    97 {
       
    98     PluginObject *obj = instance->pdata;
       
    99     if (obj) {
       
   100         if (obj->onStreamLoad)
       
   101             free(obj->onStreamLoad);
       
   102         
       
   103         if (obj->logDestroy)
       
   104             printf("PLUGIN: NPP_Destroy\n");
       
   105 
       
   106         browser->releaseobject(&obj->header);
       
   107     }
       
   108     return NPERR_NO_ERROR;
       
   109 }
       
   110 
       
   111 NPError NPP_SetWindow(NPP instance, NPWindow *window)
       
   112 {
       
   113     PluginObject *obj = instance->pdata;
       
   114 
       
   115     if (obj) {
       
   116         if (obj->logSetWindow) {
       
   117             printf("PLUGIN: NPP_SetWindow: %d %d\n", (int)window->width, (int)window->height);
       
   118             obj->logSetWindow = false;
       
   119         }
       
   120     }
       
   121     
       
   122     return NPERR_NO_ERROR;
       
   123 }
       
   124 
       
   125 NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream *stream, NPBool seekable, uint16 *stype)
       
   126 {
       
   127     PluginObject* obj = instance->pdata;
       
   128     obj->stream = stream;
       
   129     *stype = NP_ASFILEONLY;
       
   130 
       
   131     if (obj->returnErrorFromNewStream)
       
   132         return NPERR_GENERIC_ERROR;
       
   133     
       
   134     if (browser->version >= NPVERS_HAS_RESPONSE_HEADERS)
       
   135         notifyStream(obj, stream->url, stream->headers);
       
   136 
       
   137     if (obj->onStreamLoad) {
       
   138         NPObject *windowScriptObject;
       
   139         browser->getvalue(obj->npp, NPNVWindowNPObject, &windowScriptObject);
       
   140                 
       
   141         NPString script;
       
   142         script.UTF8Characters = obj->onStreamLoad;
       
   143         script.UTF8Length = strlen(obj->onStreamLoad);
       
   144         
       
   145         NPVariant browserResult;
       
   146         browser->evaluate(obj->npp, windowScriptObject, &script, &browserResult);
       
   147         browser->releasevariantvalue(&browserResult);
       
   148     }
       
   149     
       
   150     return NPERR_NO_ERROR;
       
   151 }
       
   152 
       
   153 NPError NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason)
       
   154 {
       
   155     return NPERR_NO_ERROR;
       
   156 }
       
   157 
       
   158 int32 NPP_WriteReady(NPP instance, NPStream *stream)
       
   159 {
       
   160     return 0;
       
   161 }
       
   162 
       
   163 int32 NPP_Write(NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer)
       
   164 {
       
   165     return 0;
       
   166 }
       
   167 
       
   168 void NPP_StreamAsFile(NPP instance, NPStream *stream, const char *fname)
       
   169 {
       
   170 }
       
   171 
       
   172 void NPP_Print(NPP instance, NPPrint *platformPrint)
       
   173 {
       
   174 }
       
   175 
       
   176 int16 NPP_HandleEvent(NPP instance, void *event)
       
   177 {
       
   178     PluginObject *obj = instance->pdata;
       
   179     if (!obj->eventLogging)
       
   180         return 0;
       
   181     
       
   182     EventRecord *evt = event;
       
   183     Point pt = { evt->where.v, evt->where.h };
       
   184     switch (evt->what) {
       
   185         case nullEvent:
       
   186             // these are delivered non-deterministically, don't log.
       
   187             break;
       
   188         case mouseDown:
       
   189             GlobalToLocal(&pt);
       
   190             printf("PLUGIN: mouseDown at (%d, %d)\n", pt.h, pt.v);
       
   191             break;
       
   192         case mouseUp:
       
   193             GlobalToLocal(&pt);
       
   194             printf("PLUGIN: mouseUp at (%d, %d)\n", pt.h, pt.v);
       
   195             break;
       
   196         case keyDown:
       
   197             printf("PLUGIN: keyDown '%c'\n", (char)(evt->message & 0xFF));
       
   198             break;
       
   199         case keyUp:
       
   200             printf("PLUGIN: keyUp '%c'\n", (char)(evt->message & 0xFF));
       
   201             break;
       
   202         case autoKey:
       
   203             printf("PLUGIN: autoKey '%c'\n", (char)(evt->message & 0xFF));
       
   204             break;
       
   205         case updateEvt:
       
   206             printf("PLUGIN: updateEvt\n");
       
   207             break;
       
   208         case diskEvt:
       
   209             printf("PLUGIN: diskEvt\n");
       
   210             break;
       
   211         case activateEvt:
       
   212             printf("PLUGIN: activateEvt\n");
       
   213             break;
       
   214         case osEvt:
       
   215             printf("PLUGIN: osEvt - ");
       
   216             switch ((evt->message & 0xFF000000) >> 24) {
       
   217                 case suspendResumeMessage:
       
   218                     printf("%s\n", (evt->message & 0x1) ? "resume" : "suspend");
       
   219                     break;
       
   220                 case mouseMovedMessage:
       
   221                     printf("mouseMoved\n");
       
   222                     break;
       
   223                 default:
       
   224                     printf("%08lX\n", evt->message);
       
   225             }
       
   226             break;
       
   227         case kHighLevelEvent:
       
   228             printf("PLUGIN: kHighLevelEvent\n");
       
   229             break;
       
   230         // NPAPI events
       
   231         case getFocusEvent:
       
   232             printf("PLUGIN: getFocusEvent\n");
       
   233             break;
       
   234         case loseFocusEvent:
       
   235             printf("PLUGIN: loseFocusEvent\n");
       
   236             break;
       
   237         case adjustCursorEvent:
       
   238             printf("PLUGIN: adjustCursorEvent\n");
       
   239             break;
       
   240         default:
       
   241             printf("PLUGIN: event %d\n", evt->what);
       
   242     }
       
   243     
       
   244     return 0;
       
   245 }
       
   246 
       
   247 void NPP_URLNotify(NPP instance, const char *url, NPReason reason, void *notifyData)
       
   248 {
       
   249     PluginObject *obj = instance->pdata;
       
   250         
       
   251     handleCallback(obj, url, reason, notifyData);
       
   252 }
       
   253 
       
   254 NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value)
       
   255 {
       
   256     if (variable == NPPVpluginScriptableNPObject) {
       
   257         void **v = (void **)value;
       
   258         PluginObject *obj = instance->pdata;
       
   259         // Return value is expected to be retained
       
   260         browser->retainobject((NPObject *)obj);
       
   261         *v = obj;
       
   262         return NPERR_NO_ERROR;
       
   263     }
       
   264     return NPERR_GENERIC_ERROR;
       
   265 }
       
   266 
       
   267 NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value)
       
   268 {
       
   269     return NPERR_GENERIC_ERROR;
       
   270 }