Commit a9f64e93 authored by cblu's avatar cblu

Fixed: 3079134 - Throttle plug-ins while in background

        * Plugins.subproj/WebBaseNetscapePluginView.h:
        * Plugins.subproj/WebBaseNetscapePluginView.m:
        (-[WebBaseNetscapePluginView sendNullEvent]): new
        (-[WebBaseNetscapePluginView stopNullEvents]): stops timer
        (-[WebBaseNetscapePluginView restartNullEvents]): stops timer if there is one, and starts a new one based on window activation state
        (-[WebBaseNetscapePluginView start]): call restartNullEvents
        (-[WebBaseNetscapePluginView stop]): call stopNullEvents
        (-[WebBaseNetscapePluginView windowBecameKey:]): call restartNullEvents
        (-[WebBaseNetscapePluginView windowResignedKey:]): call restartNullEvents
        (-[WebBaseNetscapePluginView windowDidMiniaturize:]): call stopNullEvents
        (-[WebBaseNetscapePluginView windowDidDeminiaturize:]): call restartNullEvents
        * Plugins.subproj/WebNetscapePluginNullEventSender.h: Removed. No need for another class, use a timer.
        * Plugins.subproj/WebNetscapePluginNullEventSender.m: Removed. No need for another class, use a timer.
        * WebKit.pbproj/project.pbxproj:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@2797 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 7d0b05a1
2002-11-20 Chris Blumenberg <cblu@apple.com>
Fixed: 3079134 - Throttle plug-ins while in background
* Plugins.subproj/WebBaseNetscapePluginView.h:
* Plugins.subproj/WebBaseNetscapePluginView.m:
(-[WebBaseNetscapePluginView sendNullEvent]): new
(-[WebBaseNetscapePluginView stopNullEvents]): stops timer
(-[WebBaseNetscapePluginView restartNullEvents]): stops timer if there is one, and starts a new one based on window activation state
(-[WebBaseNetscapePluginView start]): call restartNullEvents
(-[WebBaseNetscapePluginView stop]): call stopNullEvents
(-[WebBaseNetscapePluginView windowBecameKey:]): call restartNullEvents
(-[WebBaseNetscapePluginView windowResignedKey:]): call restartNullEvents
(-[WebBaseNetscapePluginView windowDidMiniaturize:]): call stopNullEvents
(-[WebBaseNetscapePluginView windowDidDeminiaturize:]): call restartNullEvents
* Plugins.subproj/WebNetscapePluginNullEventSender.h: Removed. No need for another class, use a timer.
* Plugins.subproj/WebNetscapePluginNullEventSender.m: Removed. No need for another class, use a timer.
* WebKit.pbproj/project.pbxproj:
2002-11-20 Richard Williamson <rjw@apple.com>
Fixed 3107007. Letter-spacing is causing width to be miscalculated.
......
2002-11-20 Chris Blumenberg <cblu@apple.com>
Fixed: 3079134 - Throttle plug-ins while in background
* Plugins.subproj/WebBaseNetscapePluginView.h:
* Plugins.subproj/WebBaseNetscapePluginView.m:
(-[WebBaseNetscapePluginView sendNullEvent]): new
(-[WebBaseNetscapePluginView stopNullEvents]): stops timer
(-[WebBaseNetscapePluginView restartNullEvents]): stops timer if there is one, and starts a new one based on window activation state
(-[WebBaseNetscapePluginView start]): call restartNullEvents
(-[WebBaseNetscapePluginView stop]): call stopNullEvents
(-[WebBaseNetscapePluginView windowBecameKey:]): call restartNullEvents
(-[WebBaseNetscapePluginView windowResignedKey:]): call restartNullEvents
(-[WebBaseNetscapePluginView windowDidMiniaturize:]): call stopNullEvents
(-[WebBaseNetscapePluginView windowDidDeminiaturize:]): call restartNullEvents
* Plugins.subproj/WebNetscapePluginNullEventSender.h: Removed. No need for another class, use a timer.
* Plugins.subproj/WebNetscapePluginNullEventSender.m: Removed. No need for another class, use a timer.
* WebKit.pbproj/project.pbxproj:
2002-11-20 Richard Williamson <rjw@apple.com>
Fixed 3107007. Letter-spacing is causing width to be miscalculated.
......
......@@ -16,8 +16,6 @@
@interface WebBaseNetscapePluginView : NSView
{
WebNetscapePluginNullEventSender *eventSender;
WebNetscapePluginPackage *plugin;
int mode;
......@@ -40,6 +38,7 @@
NSTrackingRectTag trackingTag;
NSMutableArray *streams;
NSMutableDictionary *streamNotifications;
NSTimer *nullEventTimer;
NPP_NewProcPtr NPP_New;
NPP_DestroyProcPtr NPP_Destroy;
......
......@@ -11,7 +11,6 @@
#import <WebKit/WebFramePrivate.h>
#import <WebKit/WebKitLogging.h>
#import <WebKit/WebNetscapePluginStream.h>
#import <WebKit/WebNetscapePluginNullEventSender.h>
#import <WebKit/WebNullPluginView.h>
#import <WebKit/WebNSViewExtras.h>
#import <WebKit/WebNetscapePluginPackage.h>
......@@ -24,9 +23,12 @@
#import <WebFoundation/WebNSURLExtras.h>
#import <AppKit/NSEvent_Private.h>
#import <Carbon/Carbon.h>
// FIXME: Why .01? Why not 0? Why not a larger number?
#define NullEventIntervalActive 0.1
#define NullEventIntervalNotActive 0.25
@implementation WebBaseNetscapePluginView
#pragma mark EVENTS
......@@ -156,6 +158,50 @@ - (BOOL)sendUpdateEvent
return acceptedEvent;
}
-(void)sendNullEvent
{
EventRecord event;
[self getCarbonEvent:&event];
// plug-in should not react to cursor position when not active.
// FIXME: How does passing a v and h of 0 prevent it from reacting to the cursor position?
if (![_window isKeyWindow]) {
event.where.v = 0;
event.where.h = 0;
}
[self sendEvent:&event];
}
- (void)stopNullEvents
{
[nullEventTimer invalidate];
[nullEventTimer release];
nullEventTimer = nil;
}
- (void)restartNullEvents
{
if(nullEventTimer){
[self stopNullEvents];
}
NSTimeInterval interval;
if ([_window isKeyWindow]) {
interval = NullEventIntervalActive;
}else{
interval = NullEventIntervalNotActive;
}
nullEventTimer = [[NSTimer scheduledTimerWithTimeInterval:interval
target:self
selector:@selector(sendNullEvent)
userInfo:nil
repeats:YES] retain];
}
- (BOOL)acceptsFirstResponder
{
return YES;
......@@ -429,11 +475,10 @@ -(void)start
LOG(Plugins, "NPP_New: %d", npErr);
// Create a WindowRef is one doesn't already exist
[[self window] windowRef];
[_window windowRef];
[self setWindow];
NSWindow *theWindow = [self window];
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
NSView *view;
for (view = self; view; view = [view superview]) {
......@@ -443,26 +488,26 @@ -(void)start
name:NSViewBoundsDidChangeNotification object:view];
}
[notificationCenter addObserver:self selector:@selector(windowWillClose:)
name:NSWindowWillCloseNotification object:theWindow];
name:NSWindowWillCloseNotification object:_window];
[notificationCenter addObserver:self selector:@selector(windowBecameKey:)
name:NSWindowDidBecomeKeyNotification object:theWindow];
name:NSWindowDidBecomeKeyNotification object:_window];
[notificationCenter addObserver:self selector:@selector(windowResignedKey:)
name:NSWindowDidResignKeyNotification object:theWindow];
name:NSWindowDidResignKeyNotification object:_window];
[notificationCenter addObserver:self selector:@selector(defaultsHaveChanged:)
name:NSUserDefaultsDidChangeNotification object:nil];
[notificationCenter addObserver:self selector:@selector(windowDidMiniaturize:)
name:NSWindowDidMiniaturizeNotification object:theWindow];
name:NSWindowDidMiniaturizeNotification object:_window];
[notificationCenter addObserver:self selector:@selector(windowDidDeminiaturize:)
name:NSWindowDidDeminiaturizeNotification object:theWindow];
name:NSWindowDidDeminiaturizeNotification object:_window];
if ([theWindow isKeyWindow]) {
if ([_window isKeyWindow]) {
[self sendActivateEvent:YES];
}
eventSender = [[WebNetscapePluginNullEventSender alloc] initWithPluginView:self];
if (![theWindow isMiniaturized]) {
[eventSender sendNullEvents];
if (![_window isMiniaturized]) {
[self restartNullEvents];
}
[self resetTrackingRect];
}
......@@ -480,8 +525,7 @@ - (void)stop
[streams makeObjectsPerformSelector:@selector(stop)];
// Stop the null events
[eventSender stop];
[eventSender release];
[self stopNullEvents];
// Set cursor back to arrow cursor
[[NSCursor arrowCursor] set];
......@@ -691,22 +735,24 @@ -(void)windowBecameKey:(NSNotification *)notification
{
[self sendActivateEvent:YES];
[self sendUpdateEvent];
[self restartNullEvents];
}
-(void)windowResignedKey:(NSNotification *)notification
{
[self sendActivateEvent:NO];
[self sendUpdateEvent];
[self restartNullEvents];
}
-(void)windowDidMiniaturize:(NSNotification *)notification
{
[eventSender stop];
[self stopNullEvents];
}
-(void)windowDidDeminiaturize:(NSNotification *)notification
{
[eventSender sendNullEvents];
[self restartNullEvents];
}
- (void)defaultsHaveChanged:(NSNotification *)notification
......
/*
WebNetscapePluginNullEventSender.h
Copyright 2002, Apple, Inc. All rights reserved.
*/
#import <Foundation/Foundation.h>
@class WebBaseNetscapePluginView;
@interface WebNetscapePluginNullEventSender : NSObject
{
WebBaseNetscapePluginView *view;
}
-(id)initWithPluginView:(WebBaseNetscapePluginView *)pluginView;
-(void)sendNullEvents;
-(void)stop;
@end
/*
WebNetscapePluginNullEventSender.m
Copyright 2002, Apple, Inc. All rights reserved.
*/
#import <WebKit/WebBaseNetscapePluginView.h>
#import <WebKit/WebKitLogging.h>
#import <WebKit/WebNetscapePluginNullEventSender.h>
#import <WebFoundation/WebAssertions.h>
#import <Carbon/Carbon.h>
@implementation WebNetscapePluginNullEventSender
-(id)initWithPluginView:(WebBaseNetscapePluginView *)pluginView
{
[super init];
view = [pluginView retain];
return self;
}
-(void)dealloc
{
[view release];
[super dealloc];
}
-(void)sendNullEvents
{
EventRecord event;
[WebBaseNetscapePluginView getCarbonEvent:&event];
// plug-in should not react to cursor position when not active.
// FIXME: How does passing a v and h of 0 prevent it from reacting to the cursor position?
if (![[view window] isKeyWindow]) {
event.where.v = 0;
event.where.h = 0;
}
[view sendEvent:&event];
//LOG(Plugins, "NPP_HandleEvent(nullEvent): %d when: %u %d", acceptedEvent, (unsigned)event.when, shouldStop);
// FIXME: Why .01? Why not 0? Why not a larger number?
[self performSelector:@selector(sendNullEvents) withObject:nil afterDelay:.01];
}
-(void)stop
{
LOG(Plugins, "Stopping null events");
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(sendNullEvents) object:nil];
}
@end
......@@ -237,7 +237,6 @@
931A72D303265920008635CE,
657D8FA2036669BC00FA1ED0,
657D8FA3036669D800FA1ED0,
F5A672BB0263866E01000102,
F5F717240288493C018635CA,
657D8FA4036669DD00FA1ED0,
657D8FA5036669E300FA1ED0,
......@@ -342,7 +341,6 @@
F5AEBB3E024A527601C1A526,
F59EAE420253C8DE018635CA,
F5883BE3025E5E9D01000102,
F5A672BC0263866E01000102,
F5A672BE0263866E01000102,
F5065223027F557E01C1A526,
F5065225027F557E01C1A526,
......@@ -1766,8 +1764,6 @@
84D4BFFC0348EF9D00CA2ACA,
84D4BFF70348EF7600CA2ACA,
84D4BFF80348EF7600CA2ACA,
F5A672B70263866E01000102,
F5A672B80263866E01000102,
F5F7171E0288493C018635CA,
F5F7171F0288493C018635CA,
83402EF6035A588900BE770A,
......@@ -3045,18 +3041,6 @@
settings = {
};
};
F5A672B70263866E01000102 = {
fileEncoding = 4;
isa = PBXFileReference;
path = WebNetscapePluginNullEventSender.h;
refType = 4;
};
F5A672B80263866E01000102 = {
fileEncoding = 4;
isa = PBXFileReference;
path = WebNetscapePluginNullEventSender.m;
refType = 4;
};
F5A672B90263866E01000102 = {
fileEncoding = 4;
isa = PBXFileReference;
......@@ -3069,18 +3053,6 @@
path = WebBaseNetscapePluginStream.m;
refType = 4;
};
F5A672BB0263866E01000102 = {
fileRef = F5A672B70263866E01000102;
isa = PBXBuildFile;
settings = {
};
};
F5A672BC0263866E01000102 = {
fileRef = F5A672B80263866E01000102;
isa = PBXBuildFile;
settings = {
};
};
F5A672BD0263866E01000102 = {
fileRef = F5A672B90263866E01000102;
isa = PBXBuildFile;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment