+2008-04-30 Anders Carlsson <andersca@apple.com>
+
+ Reviewed by Adam.
+
+ Add new Cocoa event model type declarations.
+
+ * bridge/npapi.h:
+
2008-04-30 Beth Dakin <bdakin@apple.com>
Reviewed by Sam Weinig.
#include <Events.h>
#endif
+#if defined(XP_MACOSX) && defined(__LP64__)
+#define NP_NO_QUICKDRAW
+#define NP_NO_CARBON
+#endif
+
#ifdef XP_MACOSX
- #include <Carbon/Carbon.h>
#include <ApplicationServices/ApplicationServices.h>
#include <OpenGL/OpenGL.h>
+#ifndef NP_NO_CARBON
+ #include <Carbon/Carbon.h>
+#endif
#endif
#ifdef XP_UNIX
#include <windows.h>
#endif
-#if defined(XP_MACOSX) && defined(__LP64__)
-#error 64-bit Netscape plug-ins are not supported on Mac OS X
-#endif
-
/*----------------------------------------------------------------------*/
/* Plugin Version Constants */
/*----------------------------------------------------------------------*/
#define NP_VERSION_MAJOR 0
-#define NP_VERSION_MINOR 18
+#define NP_VERSION_MINOR 20
NPPVformValue = 16, /* Not implemented in WebKit */
#ifdef XP_MACOSX
/* Used for negotiating drawing models */
- NPPVpluginDrawingModel = 1000
+ NPPVpluginDrawingModel = 1000,
+ /* Used for negotiating event models */
+ NPPVpluginEventModel = 1001,
#endif
} NPPVariable;
#endif
, NPNVsupportsCoreGraphicsBool = 2001 /* TRUE if the browser supports the CoreGraphics drawing model */
, NPNVsupportsOpenGLBool = 2002 /* TRUE if the browser supports the OpenGL drawing model (CGL on Mac) */
+
+ , NPNVpluginEventModel = 1001 /* The NPEventModel specified by the plugin */
+#ifndef NP_NO_CARBON
+ , NPNVsupportsCarbonBool = 2003 /* TRUE if the browser supports the Carbon event model */
+#endif
+ , NPNVsupportsCocoaBool = 2004 /* TRUE if the browser supports the Cocoa event model */
#endif /* XP_MACOSX */
} NPNVariable;
NPDrawingModelOpenGL = 2
} NPDrawingModel;
+/*
+ * The event model for a Mac OS X plugin. These are the possible values for the NPNVpluginEventModel variable.
+ */
+
+typedef enum {
+#ifndef NP_NO_CARBON
+ NPEventModelCarbon = 0,
+#endif
+ NPEventModelCocoa = 1,
+} NPEventModel;
+
+typedef enum {
+ NPCocoaEventDrawRect = 1,
+ NPCocoaEventMouseDown,
+ NPCocoaEventMouseUp,
+ NPCocoaEventMouseMoved,
+ NPCocoaEventMouseEntered,
+ NPCocoaEventMouseExited,
+ NPCocoaEventMouseDragged,
+ NPCocoaEventKeyDown,
+ NPCocoaEventKeyUp,
+ NPCocoaEventFlagsChanged,
+ NPCocoaEventFocusChanged,
+ NPCocoaEventWindowFocusChanged,
+ NPCocoaEventScrollWheel,
+} NPCocoaEventType;
+
+typedef struct _NPNSString NPNSString;
+typedef struct _NPNSWindow NPNSWindow;
+
+typedef struct _NPCocoaEvent {
+ NPCocoaEventType type;
+ union {
+ struct {
+ uint32 modifierFlags;
+ double pluginX;
+ double pluginY;
+ int32 buttonNumber;
+ int32 clickCount;
+ double deltaX;
+ double deltaY;
+ double deltaZ;
+ } mouse;
+ struct {
+ uint32 modifierFlags;
+ double pluginX;
+ double pluginY;
+ NPNSString *characters;
+ NPNSString *charactersIgnoringModifiers;
+ NPBool isARepeat;
+ uint16 keyCode;
+ } key;
+ struct {
+ double x;
+ double y;
+ double width;
+ double height;
+ } draw;
+ struct {
+ NPBool hasFocus;
+ } focus;
+ };
+} NPCocoaEvent;
+
#endif
typedef struct _NPWindow
} NPPrint;
#if defined(XP_MAC) || defined(XP_MACOSX)
+
+#ifndef NP_NO_CARBON
typedef EventRecord NPEvent;
+#endif
+
#elif defined(XP_WIN)
typedef struct _NPEvent
{
typedef struct NP_CGContext
{
CGContextRef context;
- WindowRef window;
+#ifdef NP_NO_CARBON
+ NPNSWindow *window;
+#else
+ void *window; // Can be either an NSWindow or a WindowRef depending on the event model
+#endif
} NP_CGContext;
/*
typedef struct NP_GLContext
{
CGLContextObj context;
- WindowRef window;
+#ifdef NP_NO_CARBON
+ NPNSWindow *window;
+#else
+ void *window; // Can be either an NSWindow or a WindowRef depending on the event model
+#endif
} NP_GLContext;
#endif /* XP_MACOSX */
#define NPVERS_HAS_RESPONSE_HEADERS 17
#define NPVERS_HAS_NPOBJECT_ENUM 18
#define NPVERS_HAS_PLUGIN_THREAD_ASYNC_CALL 19
+#define NPVERS_MACOSX_HAS_EVENT_MODELS 20
/*----------------------------------------------------------------------*/
/* Function Prototypes */
void NPN_PushPopupsEnabledState(NPP instance, NPBool enabled);
void NPN_PopPopupsEnabledState(NPP instance);
void NPN_PluginThreadAsyncCall(NPP instance, void (*func) (void *), void *userData);
+uint32_t NPN_ScheduleTimer(NPP instance, int32_t interval, NPBool repeat, void (*timerFunc)(NPP npp, uint32_t timerID));
+void NPN_UnscheduleTimer(NPP instance, uint32_t timerID);
#ifdef __cplusplus
} /* end extern "C" */
+2008-04-30 Anders Carlsson <andersca@apple.com>
+
+ Reviewed by Adam.
+
+ Add Cocoa event handler.
+
+ * WebKit.xcodeproj/project.pbxproj:
+
2008-04-29 Anders Carlsson <andersca@apple.com>
Reviewed by Adam.
1AEA66D50DC6B1FF003D12BF /* WebNetscapePluginEventHandler.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AEA66D30DC6B1FF003D12BF /* WebNetscapePluginEventHandler.mm */; };
1AEA66D80DC6B209003D12BF /* WebNetscapePluginEventHandlerCarbon.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AEA66D60DC6B209003D12BF /* WebNetscapePluginEventHandlerCarbon.h */; };
1AEA66D90DC6B209003D12BF /* WebNetscapePluginEventHandlerCarbon.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AEA66D70DC6B209003D12BF /* WebNetscapePluginEventHandlerCarbon.mm */; };
+ 1AEA6A500DC8CE2F003D12BF /* WebNetscapePluginEventHandlerCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = 1AEA6A4E0DC8CE2F003D12BF /* WebNetscapePluginEventHandlerCocoa.h */; };
+ 1AEA6A510DC8CE2F003D12BF /* WebNetscapePluginEventHandlerCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1AEA6A4F0DC8CE2F003D12BF /* WebNetscapePluginEventHandlerCocoa.mm */; };
1C0706630A431E01001078F6 /* WebScriptDebugServer.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C0706620A431E01001078F6 /* WebScriptDebugServer.h */; settings = {ATTRIBUTES = (Private, ); }; };
1C07073D0A433BD8001078F6 /* WebScriptDebugServer.m in Sources */ = {isa = PBXBuildFile; fileRef = 1C07073C0A433BD8001078F6 /* WebScriptDebugServer.m */; };
1C07079A0A433E22001078F6 /* WebScriptDebugServerPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C0707990A433E22001078F6 /* WebScriptDebugServerPrivate.h */; };
1AEA66D30DC6B1FF003D12BF /* WebNetscapePluginEventHandler.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebNetscapePluginEventHandler.mm; sourceTree = "<group>"; };
1AEA66D60DC6B209003D12BF /* WebNetscapePluginEventHandlerCarbon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebNetscapePluginEventHandlerCarbon.h; sourceTree = "<group>"; };
1AEA66D70DC6B209003D12BF /* WebNetscapePluginEventHandlerCarbon.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebNetscapePluginEventHandlerCarbon.mm; sourceTree = "<group>"; };
+ 1AEA6A4E0DC8CE2F003D12BF /* WebNetscapePluginEventHandlerCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebNetscapePluginEventHandlerCocoa.h; sourceTree = "<group>"; };
+ 1AEA6A4F0DC8CE2F003D12BF /* WebNetscapePluginEventHandlerCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebNetscapePluginEventHandlerCocoa.mm; sourceTree = "<group>"; };
1C0706620A431E01001078F6 /* WebScriptDebugServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebScriptDebugServer.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
1C07073C0A433BD8001078F6 /* WebScriptDebugServer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WebScriptDebugServer.m; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
1C0707990A433E22001078F6 /* WebScriptDebugServerPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebScriptDebugServerPrivate.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
1AEA66D30DC6B1FF003D12BF /* WebNetscapePluginEventHandler.mm */,
1AEA66D60DC6B209003D12BF /* WebNetscapePluginEventHandlerCarbon.h */,
1AEA66D70DC6B209003D12BF /* WebNetscapePluginEventHandlerCarbon.mm */,
+ 1AEA6A4E0DC8CE2F003D12BF /* WebNetscapePluginEventHandlerCocoa.h */,
+ 1AEA6A4F0DC8CE2F003D12BF /* WebNetscapePluginEventHandlerCocoa.mm */,
F5F7171E0288493C018635CA /* WebNetscapePluginPackage.h */,
F5F7171F0288493C018635CA /* WebNetscapePluginPackage.m */,
83402EFA035A58D100BE770A /* WebNetscapePluginStream.h */,
934C11670D8710BB00C32ABD /* WebDynamicScrollBarsViewInternal.h in Headers */,
1AEA66D40DC6B1FF003D12BF /* WebNetscapePluginEventHandler.h in Headers */,
1AEA66D80DC6B209003D12BF /* WebNetscapePluginEventHandlerCarbon.h in Headers */,
+ 1AEA6A500DC8CE2F003D12BF /* WebNetscapePluginEventHandlerCocoa.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
C0167BF90D7F5DD00028696E /* WebScriptDebugger.mm in Sources */,
1AEA66D50DC6B1FF003D12BF /* WebNetscapePluginEventHandler.mm in Sources */,
1AEA66D90DC6B209003D12BF /* WebNetscapePluginEventHandlerCarbon.mm in Sources */,
+ 1AEA6A510DC8CE2F003D12BF /* WebNetscapePluginEventHandlerCocoa.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
+2008-04-30 Anders Carlsson <andersca@apple.com>
+
+ Reviewed by Adam.
+
+ Add new Cocoa event model and the NPN_ScheduleTimer/NPN_UnscheduleTimer methods.
+
+ * Plugins/WebBaseNetscapePluginView.h:
+ * Plugins/WebBaseNetscapePluginView.mm:
+ (PluginTimer::PluginTimer):
+ (PluginTimer::start):
+ (PluginTimer::fired):
+ (-[WebBaseNetscapePluginView saveAndSetNewPortStateForUpdate:]):
+ (-[WebBaseNetscapePluginView stopTimers]):
+ (-[WebBaseNetscapePluginView restartTimers]):
+ (-[WebBaseNetscapePluginView scrollWheel:]):
+ (-[WebBaseNetscapePluginView flagsChanged:]):
+ (-[WebBaseNetscapePluginView start]):
+ (-[WebBaseNetscapePluginView eventModel]):
+ (-[WebBaseNetscapePluginView fini]):
+ (-[WebBaseNetscapePluginView getVariable:value:]):
+ (-[WebBaseNetscapePluginView setVariable:value:]):
+ (-[WebBaseNetscapePluginView scheduleTimerWithInterval:repeat:timerFunc:]):
+ (-[WebBaseNetscapePluginView unscheduleTimer:]):
+ * Plugins/WebBaseNetscapePluginViewInternal.h:
+ * Plugins/WebBaseNetscapePluginViewPrivate.h:
+ * Plugins/WebNetscapePluginEventHandler.h:
+ * Plugins/WebNetscapePluginEventHandler.mm:
+ (WebNetscapePluginEventHandler::create):
+ * Plugins/WebNetscapePluginEventHandlerCarbon.h:
+ * Plugins/WebNetscapePluginEventHandlerCarbon.mm:
+ (WebNetscapePluginEventHandlerCarbon::scrollWheel):
+ (WebNetscapePluginEventHandlerCarbon::flagsChanged):
+ (WebNetscapePluginEventHandlerCarbon::platformWindow):
+ * Plugins/WebNetscapePluginEventHandlerCocoa.h: Added.
+ (WebNetscapePluginEventHandlerCocoa::startTimers):
+ (WebNetscapePluginEventHandlerCocoa::stopTimers):
+ * Plugins/WebNetscapePluginEventHandlerCocoa.mm: Added.
+ (WebNetscapePluginEventHandlerCocoa::WebNetscapePluginEventHandlerCocoa):
+ (WebNetscapePluginEventHandlerCocoa::drawRect):
+ (WebNetscapePluginEventHandlerCocoa::mouseDown):
+ (WebNetscapePluginEventHandlerCocoa::mouseDragged):
+ (WebNetscapePluginEventHandlerCocoa::mouseEntered):
+ (WebNetscapePluginEventHandlerCocoa::mouseExited):
+ (WebNetscapePluginEventHandlerCocoa::mouseMoved):
+ (WebNetscapePluginEventHandlerCocoa::mouseUp):
+ (WebNetscapePluginEventHandlerCocoa::scrollWheel):
+ (WebNetscapePluginEventHandlerCocoa::sendMouseEvent):
+ (WebNetscapePluginEventHandlerCocoa::keyDown):
+ (WebNetscapePluginEventHandlerCocoa::keyUp):
+ (WebNetscapePluginEventHandlerCocoa::flagsChanged):
+ (WebNetscapePluginEventHandlerCocoa::sendKeyEvent):
+ (WebNetscapePluginEventHandlerCocoa::windowFocusChanged):
+ (WebNetscapePluginEventHandlerCocoa::focusChanged):
+ (WebNetscapePluginEventHandlerCocoa::platformWindow):
+ (WebNetscapePluginEventHandlerCocoa::sendEvent):
+ * Plugins/WebNetscapePluginPackage.m:
+ (-[WebNetscapePluginPackage load]):
+ * Plugins/npapi.m:
+ (NPN_ScheduleTimer):
+ (NPN_UnscheduleTimer):
+ * Plugins/npfunctions.h:
+
2008-04-30 Brady Eidson <beidson@apple.com>
Fix my WebPreferences revert check-in
#import <WebKit/npfunctions.h>
#import <WebKit/npapi.h>
#import <WebKit/WebBasePluginPackage.h>
+#import <wtf/HashMap.h>
@class DOMElement;
@class WebDataSource;
@class WebNetscapePluginStream;
@class WebView;
+class PluginTimer;
class WebNetscapePluginEventHandler;
typedef union PluginPort {
PluginPort nPort;
PluginPort lastSetPort;
NPDrawingModel drawingModel;
+ NPEventModel eventModel;
// These are only valid when drawingModel is NPDrawingModelOpenGL
AGLContext aglContext;
BOOL isTransparent;
BOOL isCompletelyObscured;
BOOL shouldStopSoon;
+
BOOL shouldFireTimers;
-
+ uint32_t currentTimerID;
+ HashMap<uint32_t, PluginTimer*>* timers;
+
unsigned pluginFunctionCallDepth;
DOMElement *element;
typedef struct OpaquePortState* PortState;
+static const double ThrottledTimerInterval = 0.25;
+
+class PluginTimer : public TimerBase {
+public:
+ typedef void (*TimerFunc)(NPP npp, uint32_t timerID);
+
+ PluginTimer(NPP npp, uint32_t timerID, uint32_t interval, NPBool repeat, TimerFunc timerFunc)
+ : m_npp(npp)
+ , m_timerID(timerID)
+ , m_interval(interval)
+ , m_repeat(repeat)
+ , m_timerFunc(timerFunc)
+ {
+ }
+
+ void start(bool throttle)
+ {
+ ASSERT(!isActive());
+
+ double timeInterval = throttle ? ThrottledTimerInterval : m_interval / 1000.0;
+ if (m_repeat)
+ startRepeating(timeInterval);
+ else
+ startOneShot(timeInterval);
+ }
+
+private:
+ virtual void fired()
+ {
+ m_timerFunc(m_npp, m_timerID);
+ if (!m_repeat)
+ delete this;
+ }
+
+ NPP m_npp;
+ uint32_t m_timerID;
+ uint32_t m_interval;
+ NPBool m_repeat;
+ TimerFunc m_timerFunc;
+};
+
#ifndef NP_NO_QUICKDRAW
// QuickDraw is not available in 64-bit
[self fixWindowPort];
#endif
- WindowRef windowRef = (WindowRef)[[self currentWindow] windowRef];
- ASSERT(windowRef);
-
// Use AppKit to convert view coordinates to NSWindow coordinates.
NSRect boundsInWindow = [self convertRect:[self bounds] toView:nil];
NSRect visibleRectInWindow = [self convertRect:[self visibleRect] toView:nil];
visibleRectInWindow.origin.y = borderViewHeight - NSMaxY(visibleRectInWindow);
#ifndef NP_NO_QUICKDRAW
+ WindowRef windowRef = (WindowRef)[[self currentWindow] windowRef];
+ ASSERT(windowRef);
+
// Look at the Carbon port to convert top-left-based window coordinates into top-left-based content coordinates.
if (drawingModel == NPDrawingModelQuickDraw) {
::Rect portBounds;
cgPortState->context = context;
// Update the plugin's window/context
- nPort.cgPort.window = windowRef;
+ nPort.cgPort.window = eventHandler->platformWindow([self currentWindow]);
nPort.cgPort.context = context;
window.window = &nPort.cgPort;
}
// Update the plugin's window/context
- nPort.aglPort.window = windowRef;
+ nPort.aglPort.window = eventHandler->platformWindow([self currentWindow]);;
nPort.aglPort.context = [self _cglContext];
window.window = &nPort.aglPort;
{
eventHandler->stopTimers();
shouldFireTimers = NO;
+
+ if (!timers)
+ return;
+
+ HashMap<uint32_t, PluginTimer*>::const_iterator end = timers->end();
+ for (HashMap<uint32_t, PluginTimer*>::const_iterator it = timers->begin(); it != end; ++it) {
+ PluginTimer* timer = it->second;
+ timer->stop();
+ }
}
- (void)restartTimers
// If the plugin is completely obscured (scrolled out of view, for example), then we will
// send null events at a reduced rate.
eventHandler->startTimers(isCompletelyObscured);
+
+ if (!timers)
+ return;
+
+ HashMap<uint32_t, PluginTimer*>::const_iterator end = timers->end();
+ for (HashMap<uint32_t, PluginTimer*>::const_iterator it = timers->begin(); it != end; ++it) {
+ PluginTimer* timer = it->second;
+ ASSERT(!timer->isActive());
+ timer->start(isCompletelyObscured);
+ }
}
- (BOOL)acceptsFirstResponder
eventHandler->mouseDragged(theEvent);
}
+- (void)scrollWheel:(NSEvent *)theEvent
+{
+ if (!eventHandler->scrollWheel(theEvent))
+ [super scrollWheel:theEvent];
+}
+
- (void)keyUp:(NSEvent *)theEvent
{
eventHandler->keyUp(theEvent);
eventHandler->keyDown(theEvent);
}
+- (void)flagsChanged:(NSEvent *)theEvent
+{
+ eventHandler->flagsChanged(theEvent);
+}
+
- (void)cut:(id)sender
{
eventHandler->keyDown([NSApp currentEvent]);
// Initialize drawingModel to an invalid value so that we can detect when the plugin does not specify a drawingModel
drawingModel = (NPDrawingModel)-1;
+ // Initialize eventModel to an invalid value so that we can detect when the plugin does not specify an event model.
+ eventModel = (NPEventModel)-1;
+
// Plug-ins are "windowed" by default. On MacOS, windowed plug-ins share the same window and graphics port as the main
// browser window. Windowless plug-ins are rendered off-screen, then copied into the main browser window.
window.type = NPWindowTypeWindow;
// Default to QuickDraw if the plugin did not specify a drawing model.
drawingModel = NPDrawingModelQuickDraw;
#else
- // QuickDraw is not available, so we can't default to it. We could default to CoreGraphics instead, but
- // if the plugin did not specify the CoreGraphics drawing model then it must be one of the old QuickDraw
- // plugins. Thus, the plugin is unsupported and should not be started. Destroy it here and bail out.
- LOG(Plugins, "Plugin only supports QuickDraw, but QuickDraw is unavailable: %@", pluginPackage);
- [self _destroyPlugin];
- [pluginPackage close];
- return NO;
+ // QuickDraw is not available, so we can't default to it. Instead, default to CoreGraphics.
+ drawingModel = NPDrawingModelCoreGraphics;
+#endif
+ }
+
+ if (eventModel == (NPEventModel)-1) {
+ // If the plug-in did not specify a drawing model we default to Carbon when it is available.
+#ifndef NP_NO_CARBON
+ eventModel = NPEventModelCarbon;
+#else
+ eventModel = NPEventModelCocoa;
#endif
}
+ if (eventModel == NPEventModelCocoa &&
+ drawingModel == NPDrawingModelQuickDraw) {
+ LOG(Plugins, "Plugin can't use use Cocoa event model with QuickDraw drawing model: %@", pluginPackage);
+ [self _destroyPlugin];
+ [pluginPackage close];
+
+ return NO;
+ }
+
// Create the event handler
eventHandler = WebNetscapePluginEventHandler::create(self);
return isStarted;
}
+- (NPEventModel)eventModel
+{
+ return eventModel;
+}
+
- (WebDataSource *)dataSource
{
WebFrame *webFrame = kit(core(element)->document()->frame());
free(cValues);
ASSERT(!eventHandler);
+
+ if (timers) {
+ deleteAllValues(*timers);
+ delete timers;
+ }
}
- (void)disconnectStream:(WebBaseNetscapePluginStream*)stream
return NPERR_NO_ERROR;
}
+ case NPNVpluginEventModel:
+ {
+ *(NPEventModel *)value = eventModel;
+ return NPERR_NO_ERROR;
+ }
+
+#ifndef NP_NO_CARBON
+ case NPNVsupportsCarbonBool:
+ {
+ *(NPBool *)value = TRUE;
+ return NPERR_NO_ERROR;
+ }
+#endif /* NP_NO_CARBON */
+
+ case NPNVsupportsCocoaBool:
+ {
+ *(NPBool *)value = TRUE;
+ return NPERR_NO_ERROR;
+ }
+
default:
break;
}
}
}
+ case NPPVpluginEventModel:
+ {
+ // Can only set event model inside NPP_New()
+ if (self != [[self class] currentPluginView])
+ return NPERR_GENERIC_ERROR;
+
+ // Check for valid, supported event model
+ NPEventModel newEventModel = (NPEventModel)(uintptr_t)value;
+ switch (newEventModel) {
+ // Supported event models:
+#ifndef NP_NO_CARBON
+ case NPEventModelCarbon:
+#endif
+ case NPEventModelCocoa:
+ eventModel = newEventModel;
+ return NPERR_NO_ERROR;
+
+ // Unsupported (or unknown) event models:
+ default:
+ LOG(Plugins, "Plugin %@ uses unsupported event model: %d", pluginPackage, eventModel);
+ return NPERR_GENERIC_ERROR;
+ }
+ }
+
default:
return NPERR_GENERIC_ERROR;
}
}
+- (uint32_t)scheduleTimerWithInterval:(uint32_t)interval repeat:(NPBool)repeat timerFunc:(void (*)(NPP npp, uint32_t timerID))timerFunc
+{
+ if (!timerFunc)
+ return 0;
+
+ if (!timers)
+ timers = new HashMap<uint32_t, PluginTimer*>;
+
+ uint32_t timerID = ++currentTimerID;
+
+ PluginTimer* timer = new PluginTimer(plugin, timerID, interval, repeat, timerFunc);
+ timers->set(timerID, timer);
+
+ if (shouldFireTimers)
+ timer->start(isCompletelyObscured);
+
+ return 0;
+}
+
+- (void)unscheduleTimer:(uint32_t)timerID
+{
+ if (!timers)
+ return;
+
+ if (PluginTimer* timer = timers->take(timerID))
+ delete timer;
+}
+
@end
@implementation WebPluginRequest
@interface WebBaseNetscapePluginView (WebInternal)
- (BOOL)sendEvent:(void*)event isDrawRect:(BOOL)eventIsDrawRect;
+- (NPEventModel)eventModel;
@end
#endif
- (void)forceRedraw;
- (NPError)getVariable:(NPNVariable)variable value:(void *)value;
- (NPError)setVariable:(NPPVariable)variable value:(void *)value;
+- (uint32_t)scheduleTimerWithInterval:(uint32_t)interval repeat:(NPBool)repeat timerFunc:(void (*)(NPP npp, uint32_t timerID))timerFunc;
+- (void)unscheduleTimer:(uint32_t)timerID;
@end
#endif
virtual void mouseExited(NSEvent*) = 0;
virtual void mouseMoved(NSEvent*) = 0;
virtual void mouseUp(NSEvent*) = 0;
+ virtual bool scrollWheel(NSEvent*) = 0;
virtual void keyDown(NSEvent*) = 0;
virtual void keyUp(NSEvent*) = 0;
+ virtual void flagsChanged(NSEvent*) = 0;
+
virtual void focusChanged(bool hasFocus) = 0;
virtual void windowFocusChanged(bool hasFocus) = 0;
- virtual void startTimers(bool throttleTimers) = 0;
- virtual void stopTimers() = 0;
+ virtual void startTimers(bool throttleTimers) { }
+ virtual void stopTimers() { }
+
+ // Returns the platform specific window used in NPP_SetWindow
+ virtual void* platformWindow(NSWindow*) = 0;
bool currentEventIsUserGesture() const { return m_currentEventIsUserGesture; }
protected:
#import "WebNetscapePluginEventHandler.h"
+#import <wtf/Assertions.h>
+#import "WebBaseNetscapePluginViewInternal.h"
#import "WebNetscapePluginEventHandlerCarbon.h"
+#import "WebNetscapePluginEventHandlerCocoa.h"
WebNetscapePluginEventHandler* WebNetscapePluginEventHandler::create(WebBaseNetscapePluginView* pluginView)
{
- return new WebNetscapePluginEventHandlerCarbon(pluginView);
+ switch ([pluginView eventModel]) {
+ case NPEventModelCarbon:
+ return new WebNetscapePluginEventHandlerCarbon(pluginView);
+ case NPEventModelCocoa:
+ return new WebNetscapePluginEventHandlerCocoa(pluginView);
+ default:
+ ASSERT_NOT_REACHED();
+ return 0;
+ }
}
#endif // ENABLE(NETSCAPE_PLUGIN_API)
virtual void mouseExited(NSEvent*);
virtual void mouseMoved(NSEvent*);
virtual void mouseUp(NSEvent*);
+ virtual bool scrollWheel(NSEvent*);
virtual void keyDown(NSEvent*);
virtual void keyUp(NSEvent*);
+ virtual void flagsChanged(NSEvent*);
virtual void windowFocusChanged(bool hasFocus);
virtual void focusChanged(bool hasFocus);
virtual void startTimers(bool throttleTimers);
virtual void stopTimers();
+ virtual void* platformWindow(NSWindow*);
+
private:
void sendNullEvent();
LOG(PluginEvents, "NPP_HandleEvent(mouseUp): %d pt.v=%d, pt.h=%d", acceptedEvent, event.where.v, event.where.h);
}
+bool WebNetscapePluginEventHandlerCarbon::scrollWheel(NSEvent* theEvent)
+{
+ return false;
+}
+
void WebNetscapePluginEventHandlerCarbon::mouseEntered(NSEvent* theEvent)
{
EventRecord event;
}
}
+void WebNetscapePluginEventHandlerCarbon::flagsChanged(NSEvent*)
+{
+}
+
void WebNetscapePluginEventHandlerCarbon::focusChanged(bool hasFocus)
{
EventRecord event;
m_nullEventTimer = 0;
}
+void* WebNetscapePluginEventHandlerCarbon::platformWindow(NSWindow* window)
+{
+ return [window windowRef];
+}
+
bool WebNetscapePluginEventHandlerCarbon::sendEvent(EventRecord* event)
{
// If at any point the user clicks or presses a key from within a plugin, set the
--- /dev/null
+/*
+ * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebNetscapePluginEventHandlerCocoa_h
+#define WebNetscapePluginEventHandlerCocoa_h
+
+#include <WebKit/npapi.h>
+#include "WebNetscapePluginEventHandler.h"
+
+class WebNetscapePluginEventHandlerCocoa : public WebNetscapePluginEventHandler {
+public:
+ WebNetscapePluginEventHandlerCocoa(WebBaseNetscapePluginView*);
+
+ virtual void drawRect(const NSRect&);
+
+ virtual void mouseDown(NSEvent*);
+ virtual void mouseDragged(NSEvent*);
+ virtual void mouseEntered(NSEvent*);
+ virtual void mouseExited(NSEvent*);
+ virtual void mouseMoved(NSEvent*);
+ virtual void mouseUp(NSEvent*);
+ virtual bool scrollWheel(NSEvent*);
+
+ virtual void keyDown(NSEvent*);
+ virtual void keyUp(NSEvent*);
+ virtual void flagsChanged(NSEvent*);
+
+ virtual void windowFocusChanged(bool hasFocus);
+ virtual void focusChanged(bool hasFocus);
+
+ virtual void* platformWindow(NSWindow*);
+private:
+ bool sendMouseEvent(NSEvent*, NPCocoaEventType);
+ void sendKeyEvent(NSEvent*, NPCocoaEventType);
+ bool sendEvent(NPCocoaEvent*);
+};
+
+#endif //WebNetscapePluginEventHandlerCocoa_h
+
+
--- /dev/null
+/*
+ * Copyright (C) 2008 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "WebNetscapePluginEventHandlerCocoa.h"
+
+#import "WebBaseNetscapePluginViewInternal.h"
+
+WebNetscapePluginEventHandlerCocoa::WebNetscapePluginEventHandlerCocoa(WebBaseNetscapePluginView* pluginView)
+ : WebNetscapePluginEventHandler(pluginView)
+{
+}
+
+void WebNetscapePluginEventHandlerCocoa::drawRect(const NSRect& rect)
+{
+ NPCocoaEvent event;
+
+ event.type = NPCocoaEventDrawRect;
+ event.draw.x = rect.origin.x;
+ event.draw.y = rect.origin.y;
+ event.draw.width = rect.size.width;
+ event.draw.height = rect.size.height;
+
+ sendEvent(&event);
+}
+
+void WebNetscapePluginEventHandlerCocoa::mouseDown(NSEvent *event)
+{
+ sendMouseEvent(event, NPCocoaEventMouseDown);
+}
+
+void WebNetscapePluginEventHandlerCocoa::mouseDragged(NSEvent *event)
+{
+ sendMouseEvent(event, NPCocoaEventMouseDragged);
+}
+
+void WebNetscapePluginEventHandlerCocoa::mouseEntered(NSEvent *event)
+{
+ sendMouseEvent(event, NPCocoaEventMouseEntered);
+}
+
+void WebNetscapePluginEventHandlerCocoa::mouseExited(NSEvent *event)
+{
+ sendMouseEvent(event, NPCocoaEventMouseExited);
+}
+
+void WebNetscapePluginEventHandlerCocoa::mouseMoved(NSEvent *event)
+{
+ sendMouseEvent(event, NPCocoaEventMouseMoved);
+}
+
+void WebNetscapePluginEventHandlerCocoa::mouseUp(NSEvent *event)
+{
+ sendMouseEvent(event, NPCocoaEventMouseUp);
+}
+
+bool WebNetscapePluginEventHandlerCocoa::scrollWheel(NSEvent* event)
+{
+ return sendMouseEvent(event, NPCocoaEventScrollWheel);
+}
+
+bool WebNetscapePluginEventHandlerCocoa::sendMouseEvent(NSEvent *nsEvent, NPCocoaEventType type)
+{
+ NPCocoaEvent event;
+
+ NSPoint point = [m_pluginView convertPoint:[nsEvent locationInWindow] fromView:nil];
+
+ event.type = type;
+ event.mouse.modifierFlags = [nsEvent modifierFlags];
+ event.mouse.buttonNumber = [nsEvent buttonNumber];
+ event.mouse.pluginX = point.x;
+ event.mouse.pluginY = point.y;
+ event.mouse.deltaX = [nsEvent deltaX];
+ event.mouse.deltaY = [nsEvent deltaY];
+ event.mouse.deltaZ = [nsEvent deltaZ];
+
+ return sendEvent(&event);
+}
+
+void WebNetscapePluginEventHandlerCocoa::keyDown(NSEvent *event)
+{
+ sendKeyEvent(event, NPCocoaEventKeyDown);
+}
+
+void WebNetscapePluginEventHandlerCocoa::keyUp(NSEvent *event)
+{
+ sendKeyEvent(event, NPCocoaEventKeyUp);
+}
+
+void WebNetscapePluginEventHandlerCocoa::flagsChanged(NSEvent *event)
+{
+ sendKeyEvent(event, NPCocoaEventFlagsChanged);
+}
+
+void WebNetscapePluginEventHandlerCocoa::sendKeyEvent(NSEvent* nsEvent, NPCocoaEventType type)
+{
+ NPCocoaEvent event;
+
+ NSPoint point = [m_pluginView convertPoint:[nsEvent locationInWindow] fromView:nil];
+
+ event.type = type;
+ event.key.modifierFlags = [nsEvent modifierFlags];
+ event.key.pluginX = point.x;
+ event.key.pluginY = point.y;
+ event.key.keyCode = [nsEvent keyCode];
+ event.key.isARepeat = [nsEvent isARepeat];
+ event.key.characters = (NPNSString *)[nsEvent characters];
+ event.key.charactersIgnoringModifiers = (NPNSString *)[nsEvent charactersIgnoringModifiers];
+
+ sendEvent(&event);
+}
+
+void WebNetscapePluginEventHandlerCocoa::windowFocusChanged(bool hasFocus)
+{
+ NPCocoaEvent event;
+
+ event.type = NPCocoaEventWindowFocusChanged;
+ event.focus.hasFocus = hasFocus;
+
+ sendEvent(&event);
+}
+
+void WebNetscapePluginEventHandlerCocoa::focusChanged(bool hasFocus)
+{
+ NPCocoaEvent event;
+
+ event.type = NPCocoaEventFocusChanged;
+ event.focus.hasFocus = hasFocus;
+
+ sendEvent(&event);
+}
+
+void* WebNetscapePluginEventHandlerCocoa::platformWindow(NSWindow* window)
+{
+ return window;
+}
+
+bool WebNetscapePluginEventHandlerCocoa::sendEvent(NPCocoaEvent* event)
+{
+ switch (event->type) {
+ case NPCocoaEventMouseDown:
+ case NPCocoaEventMouseUp:
+ case NPCocoaEventMouseDragged:
+ case NPCocoaEventKeyDown:
+ case NPCocoaEventKeyUp:
+ case NPCocoaEventFlagsChanged:
+ case NPCocoaEventScrollWheel:
+ m_currentEventIsUserGesture = true;
+ break;
+ default:
+ m_currentEventIsUserGesture = false;
+ }
+
+ bool result = [m_pluginView sendEvent:event isDrawRect:event->type == NPCocoaEventDrawRect];
+
+ m_currentEventIsUserGesture = false;
+ return result;
+}
browserFuncs.getJavaPeer = (NPN_GetJavaPeerProcPtr)tVectorForFunctionPointer((FunctionPointer)NPN_GetJavaPeer);
browserFuncs.pushpopupsenabledstate = (NPN_PushPopupsEnabledStateProcPtr)tVectorForFunctionPointer((FunctionPointer)NPN_PushPopupsEnabledState);
browserFuncs.poppopupsenabledstate = (NPN_PopPopupsEnabledStateProcPtr)tVectorForFunctionPointer((FunctionPointer)NPN_PopPopupsEnabledState);
-
+ browserFuncs.scheduletimer = (NPN_ScheduleTimerProcPtr)tVectorForFunctionPointer((FunctionPointer)NPN_ScheduleTimer);
+ browserFuncs.unscheduletimer = (NPN_UnscheduleTimerProcPtr)tVectorForFunctionPointer((FunctionPointer)NPN_UnscheduleTimer);
+
browserFuncs.releasevariantvalue = (NPN_ReleaseVariantValueProcPtr)tVectorForFunctionPointer((FunctionPointer)_NPN_ReleaseVariantValue);
browserFuncs.getstringidentifier = (NPN_GetStringIdentifierProcPtr)tVectorForFunctionPointer((FunctionPointer)_NPN_GetStringIdentifier);
browserFuncs.getstringidentifiers = (NPN_GetStringIdentifiersProcPtr)tVectorForFunctionPointer((FunctionPointer)_NPN_GetStringIdentifiers);
browserFuncs.getJavaPeer = NPN_GetJavaPeer;
browserFuncs.pushpopupsenabledstate = NPN_PushPopupsEnabledState;
browserFuncs.poppopupsenabledstate = NPN_PopPopupsEnabledState;
+ browserFuncs.scheduletimer = NPN_ScheduleTimer;
+ browserFuncs.unscheduletimer = NPN_UnscheduleTimer;
browserFuncs.releasevariantvalue = _NPN_ReleaseVariantValue;
browserFuncs.getstringidentifier = _NPN_GetStringIdentifier;
NPN_PopPopupsEnabledState(NPP instance)
{
}
+
+uint32_t NPN_ScheduleTimer(NPP instance, int32_t interval, NPBool repeat, void (*timerFunc)(NPP npp, uint32_t timerID))
+{
+ return [pluginViewForInstance(instance) scheduleTimerWithInterval:interval repeat:repeat timerFunc:timerFunc];
+}
+
+void NPN_UnscheduleTimer(NPP instance, uint32_t timerID)
+{
+ [pluginViewForInstance(instance) unscheduleTimer:timerID];
+}
+
#endif
typedef void (*NPN_PushPopupsEnabledStateProcPtr)(NPP instance, NPBool enabled);
typedef void (*NPN_PopPopupsEnabledStateProcPtr)(NPP instance);
typedef void (*NPN_PluginThreadAsyncCallProcPtr)(NPP npp, void (*func)(void *), void *userData);
-typedef bool (*NPN_ConstructProcPtr)(NPP npp, NPObject* obj, const NPVariant *args, uint32_t argCount, NPVariant *result);
-
+typedef uint32_t (*NPN_ScheduleTimerProcPtr)(NPP npp, int32_t interval, NPBool repeat, void (*timerFunc)(NPP npp, uint32_t timerID));
+typedef void (*NPN_UnscheduleTimerProcPtr)(NPP npp, uint32_t timerID);
+
typedef void (*NPN_ReleaseVariantValueProcPtr) (NPVariant *variant);
typedef NPIdentifier (*NPN_GetStringIdentifierProcPtr) (const NPUTF8 *name);
typedef bool (*NPN_RemovePropertyProcPtr) (NPP npp, NPObject *obj, NPIdentifier propertyName);
typedef void (*NPN_SetExceptionProcPtr) (NPObject *obj, const NPUTF8 *message);
typedef bool (*NPN_EnumerateProcPtr) (NPP npp, NPObject *npobj, NPIdentifier **identifier, uint32_t *count);
+typedef bool (*NPN_ConstructProcPtr)(NPP npp, NPObject* obj, const NPVariant *args, uint32_t argCount, NPVariant *result);
typedef NPError (*NPP_NewProcPtr)(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved);
typedef NPError (*NPP_DestroyProcPtr)(NPP instance, NPSavedData** save);
NPN_EnumerateProcPtr enumerate;
NPN_PluginThreadAsyncCallProcPtr pluginthreadasynccall;
NPN_ConstructProcPtr construct;
+ NPN_ScheduleTimerProcPtr scheduletimer;
+ NPN_UnscheduleTimerProcPtr unscheduletimer;
} NPNetscapeFuncs;
typedef struct _NPPluginFuncs {