15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* 25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. 35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without 55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions 65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * are met: 75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 1. Redistributions of source code must retain the above copyright 85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * notice, this list of conditions and the following disclaimer. 95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright 105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * notice, this list of conditions and the following disclaimer in the 115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * documentation and/or other materials provided with the distribution. 125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */ 255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "PluginObject.h" 275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "PluginTest.h" 295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include <cstdlib> 305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include <cstring> 315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include <string> 325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifdef XP_UNIX 345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include <X11/Xlib.h> 355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include <X11/Xutil.h> 365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif 375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#if !defined(NP_NO_CARBON) && defined(QD_HEADERS_ARE_PRIVATE) && QD_HEADERS_ARE_PRIVATE 395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)extern "C" void GlobalToLocal(Point*); 405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif 415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)using namespace std; 435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define CRASH() do { \ 455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *(int *)(uintptr_t)0xbbadbeef = 0; \ 465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) ((void(*)())0)(); /* More reliable, but doesn't say BBADBEEF */ \ 475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} while(false) 485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 49e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdochstatic bool getEntryPointsWasCalled = false; 50e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdochstatic bool initializeWasCalled = false; 51e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdochstatic NPClass* pluginObjectClass = 0; 525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#if defined(XP_WIN) 545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define STDCALL __stdcall 555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)static inline int strcasecmp(const char* s1, const char* s2) 575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return _stricmp(s1, s2); 595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#else 625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define STDCALL 635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif 645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)extern "C" { 665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)NPError STDCALL NP_GetEntryPoints(NPPluginFuncs *pluginFuncs); 675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// Entry points 705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)extern "C" 715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)NPError STDCALL NP_Initialize(NPNetscapeFuncs *browserFuncs 725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifdef XP_UNIX 735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) , NPPluginFuncs *pluginFuncs 745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif 755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) ) 765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 77e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch // Create a copy of the PluginObject NPClass that we can trash on shutdown. 78e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch pluginObjectClass = createPluginClass(); 79e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch 805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) initializeWasCalled = true; 815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#if defined(XP_WIN) 835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // Simulate Flash and QuickTime's behavior of crashing when NP_Initialize is called before NP_GetEntryPoints. 845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (!getEntryPointsWasCalled) 855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) CRASH(); 865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif 875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) browser = browserFuncs; 895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifdef XP_UNIX 915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return NP_GetEntryPoints(pluginFuncs); 925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#else 935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return NPERR_NO_ERROR; 945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif 955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)extern "C" 985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)NPError STDCALL NP_GetEntryPoints(NPPluginFuncs *pluginFuncs) 995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 1005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) getEntryPointsWasCalled = true; 1015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifdef XP_MACOSX 1035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // Simulate Silverlight's behavior of crashing when NP_GetEntryPoints is called before NP_Initialize. 1045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (!initializeWasCalled) 1055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) CRASH(); 1065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif 1075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginFunctions = pluginFuncs; 1095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginFuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR; 1115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginFuncs->size = sizeof(pluginFuncs); 1125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginFuncs->newp = NPP_New; 1135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginFuncs->destroy = NPP_Destroy; 1145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginFuncs->setwindow = NPP_SetWindow; 1155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginFuncs->newstream = NPP_NewStream; 1165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginFuncs->destroystream = NPP_DestroyStream; 1175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginFuncs->asfile = NPP_StreamAsFile; 1185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginFuncs->writeready = NPP_WriteReady; 1195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginFuncs->write = (NPP_WriteProcPtr)NPP_Write; 1205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginFuncs->print = NPP_Print; 1215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginFuncs->event = NPP_HandleEvent; 1225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginFuncs->urlnotify = NPP_URLNotify; 1235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginFuncs->getvalue = NPP_GetValue; 1245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginFuncs->setvalue = NPP_SetValue; 12502772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 1265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return NPERR_NO_ERROR; 1275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 1285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)extern "C" 1305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void STDCALL NP_Shutdown(void) 1315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 132e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch // Trash the PluginObject NPClass so that the process will deterministically 133e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch // crash if Blink tries to call into the plugin's NPObjects after unloading 134e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch // it, rather than relying on OS-specific DLL unload behaviour. 135e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch // Note that we leak the NPClass copy, to act as a guard for the lifetime of 136e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch // the process. 137e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch memset(pluginObjectClass, 0xf00dbeef, sizeof(NPClass)); 138e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch 1395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) PluginTest::NP_Shutdown(); 1405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 1415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)static void executeScript(const PluginObject* obj, const char* script); 1435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, char *argn[], char *argv[], NPSavedData *saved) 1455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 1465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifdef XP_MACOSX 1475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) NPEventModel eventModel; 14802772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 1495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // Always turn on the CG model 1505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) NPBool supportsCoreGraphics; 1515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (browser->getvalue(instance, NPNVsupportsCoreGraphicsBool, &supportsCoreGraphics) != NPERR_NO_ERROR) 1525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) supportsCoreGraphics = false; 15302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 1545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (!supportsCoreGraphics) 1555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return NPERR_INCOMPATIBLE_VERSION_ERROR; 1565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) NPDrawingModel drawingModelToUse = NPDrawingModelCoreGraphics; 1585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) NPBool supportsCoreAnimation; 1605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (browser->getvalue(instance, NPNVsupportsCoreAnimationBool, &supportsCoreAnimation) != NPERR_NO_ERROR) 1615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) supportsCoreAnimation = false; 1625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef NP_NO_CARBON 1645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) NPBool supportsCarbon = false; 1655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif 1665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) NPBool supportsCocoa = false; 1675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef NP_NO_CARBON 1695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // A browser that doesn't know about NPNVsupportsCarbonBool is one that only supports Carbon event model. 1705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (browser->getvalue(instance, NPNVsupportsCarbonBool, &supportsCarbon) != NPERR_NO_ERROR) 1715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) supportsCarbon = true; 1725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif 1735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (browser->getvalue(instance, NPNVsupportsCocoaBool, &supportsCocoa) != NPERR_NO_ERROR) 1755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) supportsCocoa = false; 1765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (supportsCocoa) { 1785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) eventModel = NPEventModelCocoa; 1795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef NP_NO_CARBON 1805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } else if (supportsCarbon) { 1815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) eventModel = NPEventModelCarbon; 1825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif 1835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } else { 1845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return NPERR_INCOMPATIBLE_VERSION_ERROR; 1855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 1865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) browser->setvalue(instance, NPPVpluginEventModel, (void *)eventModel); 1885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif // XP_MACOSX 1895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 190e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch PluginObject* obj = (PluginObject*)browser->createobject(instance, pluginObjectClass); 1915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) instance->pdata = obj; 1925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifdef XP_MACOSX 1945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) obj->eventModel = eventModel; 1955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) obj->coreAnimationLayer = 0; 1965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif // XP_MACOSX 1975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) string testIdentifier; 1995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) const char* onNewScript = 0; 20002772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 2015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) for (int i = 0; i < argc; i++) { 2025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (strcasecmp(argn[i], "test") == 0) 2035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) testIdentifier = argv[i]; 2045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (strcasecmp(argn[i], "onstreamload") == 0 && !obj->onStreamLoad) 2055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) obj->onStreamLoad = strdup(argv[i]); 2065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) else if (strcasecmp(argn[i], "onStreamDestroy") == 0 && !obj->onStreamDestroy) 2075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) obj->onStreamDestroy = strdup(argv[i]); 2085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) else if (strcasecmp(argn[i], "onURLNotify") == 0 && !obj->onURLNotify) 2095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) obj->onURLNotify = strdup(argv[i]); 2105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) else if (strcasecmp(argn[i], "src") == 0 && 2115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) strcasecmp(argv[i], "data:application/x-webkit-test-netscape,returnerrorfromnewstream") == 0) 2121fad5ca6c42d689812b66fc493992aa6d747a6fbBen Murdoch obj->returnErrorFromNewStream = true; 2135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) else if (strcasecmp(argn[i], "src") == 0 && 2145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) strcasecmp(argv[i], "data:application/x-webkit-test-netscape,alertwhenloaded") == 0) 2155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) executeScript(obj, "alert('Plugin Loaded!')"); 2165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) else if (strcasecmp(argn[i], "src") == 0 && 2175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) strcasecmp(argv[i], "data:application/x-webkit-test-netscape,logifloaded") == 0) { 2185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) for (int j = 0; j < argc; j++) { 2195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (strcasecmp(argn[j], "log") == 0) { 2205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) int length = 26 + strlen(argv[j]) + 1; 2215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) char* buffer = (char*) malloc(length); 2225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) snprintf(buffer, length, "xWebkitTestNetscapeLog('%s')", argv[j]); 2235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) executeScript(obj, buffer); 2245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) free(buffer); 2255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 2265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 2275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } else if (strcasecmp(argn[i], "onSetWindow") == 0 && !obj->onSetWindow) 2285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) obj->onSetWindow = strdup(argv[i]); 2295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) else if (strcasecmp(argn[i], "onNew") == 0 && !onNewScript) 2305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) onNewScript = argv[i]; 2315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) else if (strcasecmp(argn[i], "onPaintEvent") == 0 && !obj->onPaintEvent) 2325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) obj->onPaintEvent = strdup(argv[i]); 2335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) else if (strcasecmp(argn[i], "logfirstsetwindow") == 0) 2341fad5ca6c42d689812b66fc493992aa6d747a6fbBen Murdoch obj->logSetWindow = true; 2355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) else if (strcasecmp(argn[i], "testnpruntime") == 0) 2365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) testNPRuntime(instance); 2375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) else if (strcasecmp(argn[i], "logSrc") == 0) { 2385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) for (int i = 0; i < argc; i++) 2395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (strcasecmp(argn[i], "src") == 0) 2405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "src: %s", argv[i]); 2415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } else if (strcasecmp(argn[i], "cleardocumentduringnew") == 0) 2425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) executeScript(obj, "document.body.innerHTML = ''"); 2435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) else if (!strcasecmp(argn[i], "ondestroy")) 2445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) obj->onDestroy = strdup(argv[i]); 2455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) else if (strcasecmp(argn[i], "testwindowopen") == 0) 2461fad5ca6c42d689812b66fc493992aa6d747a6fbBen Murdoch obj->testWindowOpen = true; 2475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) else if (strcasecmp(argn[i], "drawingmodel") == 0) { 2485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifdef XP_MACOSX 2495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) const char* value = argv[i]; 2505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (strcasecmp(value, "coreanimation") == 0) { 2515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (supportsCoreAnimation) 2525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) drawingModelToUse = NPDrawingModelCoreAnimation; 2535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) else 2545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return NPERR_INCOMPATIBLE_VERSION_ERROR; 2555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } else if (strcasecmp(value, "coregraphics") == 0) { 2565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (supportsCoreGraphics) 2575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) drawingModelToUse = NPDrawingModelCoreGraphics; 2585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) else 2595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return NPERR_INCOMPATIBLE_VERSION_ERROR; 2605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } else 2615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return NPERR_INCOMPATIBLE_VERSION_ERROR; 2625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif 2635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } else if (strcasecmp(argn[i], "testGetURLOnDestroy") == 0) { 2645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#if defined(XP_WIN) 2655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // FIXME: When https://bugs.webkit.org/show_bug.cgi?id=41831 is fixed, this #ifdef can be removed. 2665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) obj->testGetURLOnDestroy = TRUE; 2675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif 2685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } else if (!strcasecmp(argn[i], "src") && strstr(argv[i], "plugin-document-has-focus.pl")) 2691fad5ca6c42d689812b66fc493992aa6d747a6fbBen Murdoch obj->testKeyboardFocusForPlugins = true; 2705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) else if (!strcasecmp(argn[i], "evaluatescript")) { 2715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) char* script = argv[i]; 2725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (script == strstr(script, "mouse::")) { 2735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) obj->mouseDownForEvaluateScript = true; 2745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) obj->evaluateScriptOnMouseDownOrKeyDown = strdup(script + sizeof("mouse::") - 1); 2755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } else if (script == strstr(script, "key::")) { 2765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) obj->evaluateScriptOnMouseDownOrKeyDown = strdup(script + sizeof("key::") - 1); 2775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 2785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // When testing evaluate script on mouse-down or key-down, allow event logging to handle events. 2795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->evaluateScriptOnMouseDownOrKeyDown) 2805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) obj->eventLogging = true; 2815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } else if (!strcasecmp(argn[i], "windowedPlugin")) { 2825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void* windowed = 0; 2835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (!strcasecmp(argv[i], "false") || !strcasecmp(argv[i], "0")) 2845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) windowed = 0; 2855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) else if (!strcasecmp(argv[i], "true") || !strcasecmp(argv[i], "1")) 2865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) windowed = reinterpret_cast<void*>(1); 2875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) else 2885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) assert(false); 2895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) browser->setvalue(instance, NPPVpluginWindowBool, windowed); 2905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 2915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 2925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 2935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifdef XP_MACOSX 2945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) browser->setvalue(instance, NPPVpluginDrawingModel, (void *)drawingModelToUse); 2955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (drawingModelToUse == NPDrawingModelCoreAnimation) 2965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) obj->coreAnimationLayer = createCoreAnimationLayer(); 2975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif 2985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 2995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) obj->pluginTest = PluginTest::create(instance, testIdentifier); 3005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (!obj->pluginTest) { 3025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "NPP_New: Could not find a test named \"%s\", maybe its .cpp file wasn't added to the build system?", testIdentifier.c_str()); 3035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return NPERR_GENERIC_ERROR; 3045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 3055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (onNewScript) 3075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) executeScript(obj, onNewScript); 3085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return obj->pluginTest->NPP_New(pluginType, mode, argc, argn, argv, saved); 3105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 3115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)NPError NPP_Destroy(NPP instance, NPSavedData **save) 3135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 3145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) PluginObject* obj = static_cast<PluginObject*>(instance->pdata); 315591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch 3165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj) { 3175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->testGetURLOnDestroy) 3185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) browser->geturlnotify(obj->npp, "about:blank", "", 0); 3195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->onDestroy) { 3215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) executeScript(obj, obj->onDestroy); 3225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) free(obj->onDestroy); 3235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 3245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->onStreamLoad) 3265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) free(obj->onStreamLoad); 3275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->onStreamDestroy) 3295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) free(obj->onStreamDestroy); 3305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->onURLNotify) 3325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) free(obj->onURLNotify); 3335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->onSetWindow) 3355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) free(obj->onSetWindow); 3365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->onPaintEvent) 3385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) free(obj->onPaintEvent); 33902772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 3405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->logDestroy) 3415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "NPP_Destroy"); 3425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifdef XP_MACOSX 3445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->coreAnimationLayer) 3455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) CFRelease(obj->coreAnimationLayer); 3465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif 3475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->pluginTest) 3495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) obj->pluginTest->NPP_Destroy(save); 3505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) browser->releaseobject(&obj->header); 3525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 3535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return NPERR_NO_ERROR; 3545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 3555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)NPError NPP_SetWindow(NPP instance, NPWindow *window) 3575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 3585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) PluginObject* obj = static_cast<PluginObject*>(instance->pdata); 3595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj) { 3615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) obj->lastWindow = *window; 3625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->logSetWindow) { 3645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "NPP_SetWindow: %d %d", (int)window->width, (int)window->height); 3651fad5ca6c42d689812b66fc493992aa6d747a6fbBen Murdoch obj->logSetWindow = false; 366926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) executeScript(obj, "testRunner.notifyDone();"); 3675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 3685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->onSetWindow) 3705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) executeScript(obj, obj->onSetWindow); 3715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->testWindowOpen) { 3735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) testWindowOpen(instance); 3741fad5ca6c42d689812b66fc493992aa6d747a6fbBen Murdoch obj->testWindowOpen = false; 3755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 3765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->testKeyboardFocusForPlugins) { 3785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) obj->eventLogging = true; 3795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) executeScript(obj, "eventSender.keyDown('A');"); 3805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 3815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 38202772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 3835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return obj->pluginTest->NPP_SetWindow(window); 3845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 3855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)static void executeScript(const PluginObject* obj, const char* script) 3875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 3885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) NPObject *windowScriptObject; 3895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) browser->getvalue(obj->npp, NPNVWindowNPObject, &windowScriptObject); 3905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) NPString npScript; 3925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) npScript.UTF8Characters = script; 3935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) npScript.UTF8Length = strlen(script); 3945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) NPVariant browserResult; 3965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) browser->evaluate(obj->npp, windowScriptObject, &npScript, &browserResult); 3975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) browser->releasevariantvalue(&browserResult); 3985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 3995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 4005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream *stream, NPBool seekable, uint16_t *stype) 4015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 4025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) PluginObject* obj = static_cast<PluginObject*>(instance->pdata); 4035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) obj->stream = stream; 4045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *stype = NP_NORMAL; 4055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 4065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->returnErrorFromNewStream) 4075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return NPERR_GENERIC_ERROR; 40802772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 4095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (browser->version >= NPVERS_HAS_RESPONSE_HEADERS) 4105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) notifyStream(obj, stream->url, stream->headers); 4115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 4125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->onStreamLoad) 4135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) executeScript(obj, obj->onStreamLoad); 4145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 4155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return obj->pluginTest->NPP_NewStream(type, stream, seekable, stype); 4165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 4175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 4185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)NPError NPP_DestroyStream(NPP instance, NPStream *stream, NPReason reason) 4195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 4205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) PluginObject* obj = (PluginObject*)instance->pdata; 4215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 4225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->onStreamDestroy) { 4235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) NPObject* windowObject = 0; 4245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) NPError error = browser->getvalue(instance, NPNVWindowNPObject, &windowObject); 42502772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 4265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (error == NPERR_NO_ERROR) { 4275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) NPVariant onStreamDestroyVariant; 4285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (browser->getproperty(instance, windowObject, browser->getstringidentifier(obj->onStreamDestroy), &onStreamDestroyVariant)) { 4295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (NPVARIANT_IS_OBJECT(onStreamDestroyVariant)) { 4305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) NPObject* onStreamDestroyFunction = NPVARIANT_TO_OBJECT(onStreamDestroyVariant); 4315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 4325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) NPVariant reasonVariant; 4335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) INT32_TO_NPVARIANT(reason, reasonVariant); 4345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 4355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) NPVariant result; 4365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) browser->invokeDefault(instance, onStreamDestroyFunction, &reasonVariant, 1, &result); 4375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) browser->releasevariantvalue(&result); 4385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 4395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) browser->releasevariantvalue(&onStreamDestroyVariant); 4405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 4415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) browser->releaseobject(windowObject); 4425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 4435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 4445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 4455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return obj->pluginTest->NPP_DestroyStream(stream, reason); 4465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 4475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 4485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)int32_t NPP_WriteReady(NPP instance, NPStream *stream) 4495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 4505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) PluginObject* obj = (PluginObject*)instance->pdata; 4515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return obj->pluginTest->NPP_WriteReady(stream); 4525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 4535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 4545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)int32_t NPP_Write(NPP instance, NPStream *stream, int32_t offset, int32_t len, void *buffer) 4555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 4565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) PluginObject* obj = (PluginObject*)instance->pdata; 4575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 4585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->returnNegativeOneFromWrite) 4595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return -1; 4605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 4615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return obj->pluginTest->NPP_Write(stream, offset, len, buffer); 4625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 4635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 4645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void NPP_StreamAsFile(NPP instance, NPStream *stream, const char *fname) 4655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 4665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 4675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 4685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void NPP_Print(NPP instance, NPPrint *platformPrint) 4695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 4705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 4715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 4725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifdef XP_MACOSX 4735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef NP_NO_CARBON 4745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)static int16_t handleEventCarbon(NPP instance, PluginObject* obj, EventRecord* event) 4755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 4765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) Point pt = { event->where.v, event->where.h }; 4775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 4785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) switch (event->what) { 4795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case nullEvent: 4805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // these are delivered non-deterministically, don't log. 4815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 4825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case mouseDown: 4835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) { 4845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#if __clang__ 4855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#pragma clang diagnostic push 4865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#pragma clang diagnostic ignored "-Wdeprecated-declarations" 4875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif 4885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) GlobalToLocal(&pt); 4895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#if __clang__ 4905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#pragma clang diagnostic pop 4915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif 4925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "mouseDown at (%d, %d)", pt.h, pt.v); 4935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 4945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->evaluateScriptOnMouseDownOrKeyDown && obj->mouseDownForEvaluateScript) 4955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) executeScript(obj, obj->evaluateScriptOnMouseDownOrKeyDown); 4965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 4975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case mouseUp: 4985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) { 4995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#if __clang__ 5005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#pragma clang diagnostic push 5015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#pragma clang diagnostic ignored "-Wdeprecated-declarations" 5025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif 5035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) GlobalToLocal(&pt); 5045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#if __clang__ 5055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#pragma clang diagnostic pop 5065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif 5075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "mouseUp at (%d, %d)", pt.h, pt.v); 5085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 5095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 5105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case keyDown: 5115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) 5125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "keyDown '%c'", (char)(event->message & 0xFF)); 5135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->evaluateScriptOnMouseDownOrKeyDown && !obj->mouseDownForEvaluateScript) 5145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) executeScript(obj, obj->evaluateScriptOnMouseDownOrKeyDown); 5155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 5165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case keyUp: 5175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) 5185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "keyUp '%c'", (char)(event->message & 0xFF)); 5195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->testKeyboardFocusForPlugins) { 5205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) obj->eventLogging = false; 5215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) obj->testKeyboardFocusForPlugins = FALSE; 5225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) executeScript(obj, "testRunner.notifyDone();"); 5235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 5245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 5255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case autoKey: 5265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) 5275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "autoKey '%c'", (char)(event->message & 0xFF)); 5285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 5295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case updateEvt: 5305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) 5315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "updateEvt"); 5325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 5335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case diskEvt: 5345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) 5355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "diskEvt"); 5365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 5375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case activateEvt: 5385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) 5395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "activateEvt"); 5405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 5415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case osEvt: 5425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (!obj->eventLogging) 5435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 5445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) printf("PLUGIN: osEvt - "); 5455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) switch ((event->message & 0xFF000000) >> 24) { 5465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case suspendResumeMessage: 5475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) printf("%s\n", (event->message & 0x1) ? "resume" : "suspend"); 5485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 5495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case mouseMovedMessage: 5505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) printf("mouseMoved\n"); 5515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 5525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) default: 5535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) printf("%08lX\n", event->message); 5545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 5555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 5565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case kHighLevelEvent: 5575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) 5585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "kHighLevelEvent"); 5595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 5605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // NPAPI events 5615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case NPEventType_GetFocusEvent: 5625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) 5635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "getFocusEvent"); 5645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 5655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case NPEventType_LoseFocusEvent: 5665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) 5675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "loseFocusEvent"); 5685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 5695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case NPEventType_AdjustCursorEvent: 5705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) 5715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "adjustCursorEvent"); 5725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 5735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) default: 5745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) 5755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "event %d", event->what); 5765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 57702772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 5785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return 0; 5795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 5805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif 5815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 5825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)static int16_t handleEventCocoa(NPP instance, PluginObject* obj, NPCocoaEvent* event) 5835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 5845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) switch (event->type) { 5855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case NPCocoaEventWindowFocusChanged: 58602772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 5875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case NPCocoaEventFocusChanged: 5885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) { 5895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (event->data.focus.hasFocus) 5905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "getFocusEvent"); 5915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) else 5925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "loseFocusEvent"); 5935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 5945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return 1; 5955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 5965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case NPCocoaEventDrawRect: { 5975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->onPaintEvent) 5985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) executeScript(obj, obj->onPaintEvent); 5995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return 1; 6005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 6015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 6025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case NPCocoaEventKeyDown: 6035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging && event->data.key.characters) 6045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "keyDown '%c'", CFStringGetCharacterAtIndex(reinterpret_cast<CFStringRef>(event->data.key.characters), 0)); 6055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->evaluateScriptOnMouseDownOrKeyDown && !obj->mouseDownForEvaluateScript) 6065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) executeScript(obj, obj->evaluateScriptOnMouseDownOrKeyDown); 6075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return 1; 6085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 6095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case NPCocoaEventKeyUp: 6105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging && event->data.key.characters) { 6115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "keyUp '%c'", CFStringGetCharacterAtIndex(reinterpret_cast<CFStringRef>(event->data.key.characters), 0)); 6125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->testKeyboardFocusForPlugins) { 6135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) obj->eventLogging = false; 6145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) obj->testKeyboardFocusForPlugins = FALSE; 6155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) executeScript(obj, "testRunner.notifyDone();"); 6165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 6175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 6185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return 1; 6195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 6205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case NPCocoaEventFlagsChanged: 6215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return 1; 6225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 6235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case NPCocoaEventMouseDown: 6245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) { 62502772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch pluginLog(instance, "mouseDown at (%d, %d)", 6265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) (int)event->data.mouse.pluginX, 6275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) (int)event->data.mouse.pluginY); 6285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 6295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->evaluateScriptOnMouseDownOrKeyDown && obj->mouseDownForEvaluateScript) 6305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) executeScript(obj, obj->evaluateScriptOnMouseDownOrKeyDown); 6315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return 1; 6325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case NPCocoaEventMouseUp: 6335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) { 63402772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch pluginLog(instance, "mouseUp at (%d, %d)", 6355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) (int)event->data.mouse.pluginX, 6365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) (int)event->data.mouse.pluginY); 6375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 6385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return 1; 63902772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 6405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case NPCocoaEventMouseMoved: 6415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case NPCocoaEventMouseEntered: 6425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case NPCocoaEventMouseExited: 6435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case NPCocoaEventMouseDragged: 6445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case NPCocoaEventScrollWheel: 6455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case NPCocoaEventTextInput: 6465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return 1; 6475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 64802772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 6495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return 0; 6505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 6515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 6525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif // XP_MACOSX 6535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 6545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifdef XP_UNIX 6555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 6565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)static char keyEventToChar(XKeyEvent* event) 6575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 6585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) char c = ' '; 6595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) XLookupString(event, &c, sizeof(c), 0, 0); 6605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return c; 6615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 6625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 6635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)static int16_t handleEventX11(NPP instance, PluginObject* obj, XEvent* event) 6645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 6655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) switch (event->type) { 6665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case ButtonPress: 6675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) 6685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "mouseDown at (%d, %d)", event->xbutton.x, event->xbutton.y); 6695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->evaluateScriptOnMouseDownOrKeyDown && obj->mouseDownForEvaluateScript) 6705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) executeScript(obj, obj->evaluateScriptOnMouseDownOrKeyDown); 6715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 6725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case ButtonRelease: 6735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) 6745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "mouseUp at (%d, %d)", event->xbutton.x, event->xbutton.y); 6755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 6765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case KeyPress: 6775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // FIXME: extract key code 6785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) 6795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "keyDown '%c'", keyEventToChar(&event->xkey)); 6805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->evaluateScriptOnMouseDownOrKeyDown && !obj->mouseDownForEvaluateScript) 6815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) executeScript(obj, obj->evaluateScriptOnMouseDownOrKeyDown); 6825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 6835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case KeyRelease: 6845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // FIXME: extract key code 6855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) 6865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "keyUp '%c'", keyEventToChar(&event->xkey)); 6875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->testKeyboardFocusForPlugins) { 6885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) obj->eventLogging = false; 6891fad5ca6c42d689812b66fc493992aa6d747a6fbBen Murdoch obj->testKeyboardFocusForPlugins = false; 6905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) executeScript(obj, "testRunner.notifyDone();"); 6915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 6925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 6935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case GraphicsExpose: 6945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) 6955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "updateEvt"); 6965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->onPaintEvent) 6975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) executeScript(obj, obj->onPaintEvent); 6985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 6995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // NPAPI events 7005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case FocusIn: 7015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) 7025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "getFocusEvent"); 7035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 7045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case FocusOut: 7055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) 7065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "loseFocusEvent"); 7075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 7085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case EnterNotify: 7095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case LeaveNotify: 7105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case MotionNotify: 7115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 7125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) default: 7135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) 7145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "event %d", event->type); 7155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 7165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 7175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) fflush(stdout); 7185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return 0; 7195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 7205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif // XP_UNIX 7215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 7225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifdef XP_WIN 7235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)static int16_t handleEventWin(NPP instance, PluginObject* obj, NPEvent* event) 7245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 7255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) switch (event->event) { 7265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case WM_PAINT: 7275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->onPaintEvent) 7285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) executeScript(obj, obj->onPaintEvent); 7295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 7305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case WM_KEYDOWN: 7315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) 7325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "keyDown '%c'", event->wParam); 7335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->evaluateScriptOnMouseDownOrKeyDown && !obj->mouseDownForEvaluateScript) 7345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) executeScript(obj, obj->evaluateScriptOnMouseDownOrKeyDown); 7355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 7365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case WM_CHAR: 7375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 7385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case WM_KEYUP: 7395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) 7405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "keyUp '%c'", event->wParam); 7415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->testKeyboardFocusForPlugins) { 7425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) obj->eventLogging = false; 7435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) obj->testKeyboardFocusForPlugins = FALSE; 7445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) executeScript(obj, "testRunner.notifyDone();"); 7455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 7465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 7475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case WM_LBUTTONDOWN: 7485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case WM_MBUTTONDOWN: 7495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case WM_RBUTTONDOWN: 7505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) 7515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "mouseDown at (%d, %d)", LOWORD(event->lParam), HIWORD(event->lParam)); 7525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->evaluateScriptOnMouseDownOrKeyDown && obj->mouseDownForEvaluateScript) 7535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) executeScript(obj, obj->evaluateScriptOnMouseDownOrKeyDown); 7545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 7555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case WM_LBUTTONUP: 7565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case WM_MBUTTONUP: 7575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case WM_RBUTTONUP: 7585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) 7595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "mouseUp at (%d, %d)", LOWORD(event->lParam), HIWORD(event->lParam)); 7605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 7615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case WM_SETFOCUS: 7625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) 7635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "getFocusEvent"); 7645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 7655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) case WM_KILLFOCUS: 7665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventLogging) 7675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) pluginLog(instance, "loseFocusEvent"); 7685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) break; 7695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 7705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return 0; 7715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 7725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif // XP_WIN 7735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 7745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)int16_t NPP_HandleEvent(NPP instance, void *event) 7755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 7765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) PluginObject* obj = static_cast<PluginObject*>(instance->pdata); 7775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 7785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->pluginTest->NPP_HandleEvent(event) == 1) 7795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return 1; 7805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 7815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifdef XP_MACOSX 7825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef NP_NO_CARBON 7835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->eventModel == NPEventModelCarbon) 7845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return handleEventCarbon(instance, obj, static_cast<EventRecord*>(event)); 7855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif 7865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 7875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) assert(obj->eventModel == NPEventModelCocoa); 7885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return handleEventCocoa(instance, obj, static_cast<NPCocoaEvent*>(event)); 7895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#elif defined(XP_UNIX) 7905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return handleEventX11(instance, obj, static_cast<XEvent*>(event)); 7915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#elif defined(XP_WIN) 7925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return handleEventWin(instance, obj, static_cast<NPEvent*>(event)); 7935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#else 7945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // FIXME: Implement for other platforms. 7955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return 0; 7965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif // XP_MACOSX 7975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 7985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 7995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)void NPP_URLNotify(NPP instance, const char *url, NPReason reason, void *notifyData) 8005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 8015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) PluginObject* obj = static_cast<PluginObject*>(instance->pdata); 8025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->pluginTest->NPP_URLNotify(url, reason, notifyData)) 8035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return; 8045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 8055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->onURLNotify) 8065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) executeScript(obj, obj->onURLNotify); 8075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 8085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) handleCallback(obj, url, reason, notifyData); 8095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 8105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 8115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value) 8125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 8135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifdef XP_UNIX 8145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (variable == NPPVpluginNameString) { 8155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *((char **)value) = const_cast<char*>("WebKit Test PlugIn"); 8165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return NPERR_NO_ERROR; 8175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 8185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (variable == NPPVpluginDescriptionString) { 8195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *((char **)value) = const_cast<char*>("Simple Netscape® plug-in that handles test content for WebKit"); 8205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return NPERR_NO_ERROR; 8215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 8225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (variable == NPPVpluginNeedsXEmbed) { 8231fad5ca6c42d689812b66fc493992aa6d747a6fbBen Murdoch *((NPBool *)value) = true; 8245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return NPERR_NO_ERROR; 8255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 8265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif 8275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 8285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (!instance) 8295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return NPERR_GENERIC_ERROR; 8305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) PluginObject* obj = static_cast<PluginObject*>(instance->pdata); 8315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 8325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // First, check if the PluginTest object supports getting this value. 8335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (obj->pluginTest->NPP_GetValue(variable, value) == NPERR_NO_ERROR) 8345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return NPERR_NO_ERROR; 8355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 8365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (variable == NPPVpluginScriptableNPObject) { 8375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void **v = (void **)value; 8385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // Return value is expected to be retained 8395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) browser->retainobject((NPObject *)obj); 8405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *v = obj; 8415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return NPERR_NO_ERROR; 8425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 84302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 8445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifdef XP_MACOSX 8455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (variable == NPPVpluginCoreAnimationLayer) { 8465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (!obj->coreAnimationLayer) 8475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return NPERR_GENERIC_ERROR; 84802772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 8495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void **v = (void **)value; 8505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *v = (void*)CFRetain(obj->coreAnimationLayer); 8515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return NPERR_NO_ERROR; 8525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 8535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif 8545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 8555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return NPERR_GENERIC_ERROR; 8565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 8575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 8585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value) 8595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 8605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) PluginObject* obj = static_cast<PluginObject*>(instance->pdata); 8615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return obj->pluginTest->NPP_SetValue(variable, value); 8625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 8635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 8645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifdef XP_UNIX 8655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)extern "C" 8665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)const char* NP_GetMIMEDescription(void) 8675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 8685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return "application/x-webkit-test-netscape:testnetscape:test netscape content;image/png:png:PNG image"; 8695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 8705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 8715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)extern "C" 8725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)NPError NP_GetValue(NPP instance, NPPVariable variable, void* value) 8735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){ 8745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return NPP_GetValue(instance, variable, value); 8755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 8765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif 877