diff options
Diffstat (limited to 'WebKit/mac/Plugins/WebNetscapePluginView.mm')
-rw-r--r-- | WebKit/mac/Plugins/WebNetscapePluginView.mm | 291 |
1 files changed, 74 insertions, 217 deletions
diff --git a/WebKit/mac/Plugins/WebNetscapePluginView.mm b/WebKit/mac/Plugins/WebNetscapePluginView.mm index a792e21..cef33a4 100644 --- a/WebKit/mac/Plugins/WebNetscapePluginView.mm +++ b/WebKit/mac/Plugins/WebNetscapePluginView.mm @@ -35,6 +35,7 @@ #import "WebFrameInternal.h" #import "WebFrameView.h" #import "WebGraphicsExtras.h" +#import "WebKitErrorsPrivate.h" #import "WebKitLogging.h" #import "WebKitNSStringExtras.h" #import "WebKitSystemInterface.h" @@ -59,19 +60,22 @@ #import <WebCore/Element.h> #import <WebCore/Frame.h> #import <WebCore/FrameLoader.h> -#import <WebCore/FrameTree.h> +#import <WebCore/FrameTree.h> +#import <WebCore/HTMLPlugInElement.h> #import <WebCore/Page.h> #import <WebCore/PluginMainThreadScheduler.h> #import <WebCore/ScriptController.h> #import <WebCore/SoftLinking.h> #import <WebCore/WebCoreObjCExtras.h> -#import <WebKit/nptextinput.h> +#import <WebCore/WebCoreURLResponse.h> #import <WebKit/DOMPrivate.h> #import <WebKit/WebUIDelegate.h> #import <runtime/InitializeThreading.h> #import <wtf/Assertions.h> #import <objc/objc-runtime.h> +using std::max; + #define LoginWindowDidSwitchFromUserNotification @"WebLoginWindowDidSwitchFromUserNotification" #define LoginWindowDidSwitchToUserNotification @"WebLoginWindowDidSwitchToUserNotification" @@ -91,6 +95,7 @@ static inline bool isDrawingModelQuickDraw(NPDrawingModel drawingModel) - (void)_destroyPlugin; - (NSBitmapImageRep *)_printedPluginBitmap; - (void)_redeliverStream; +- (BOOL)_shouldCancelSrcStream; @end static WebNetscapePluginView *currentPluginView = nil; @@ -489,6 +494,11 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr) #endif /* NP_NO_QUICKDRAW */ case NPDrawingModelCoreGraphics: { + if (![self canDraw]) { + portState = NULL; + break; + } + ASSERT([NSView focusView] == self); CGContextRef context = static_cast<CGContextRef>([[NSGraphicsContext currentContext] graphicsPort]); @@ -620,10 +630,6 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr) if (!page) return NO; - bool wasDeferring = page->defersLoading(); - if (!wasDeferring) - page->setDefersLoading(true); - // Can only send drawRect (updateEvt) to CoreGraphics plugins when actually drawing ASSERT((drawingModel != NPDrawingModelCoreGraphics) || !eventIsDrawRect || [NSView focusView] == self); @@ -667,9 +673,6 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr) free(portState); } - if (!wasDeferring) - page->setDefersLoading(false); - return acceptedEvent; } @@ -894,10 +897,18 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr) { // A plug-in can only update if it's (1) already been started (2) isn't stopped // and (3) is able to draw on-screen. To meet condition (3) the plug-in must not - // be hidden and be attached to a window. QuickDraw plug-ins are an important - // excpetion to rule (3) because they manually must be told when to stop writing + // be hidden and be attached to a window. There are two exceptions to this rule: + // + // Exception 1: QuickDraw plug-ins must be manually told when to stop writing // bits to the window backing store, thus to do so requires a new call to // NPP_SetWindow() with an empty NPWindow struct. + // + // Exception 2: CoreGraphics plug-ins expect to have their drawable area updated + // when they are moved to a background tab, via a NPP_SetWindow call. This is + // accomplished by allowing -saveAndSetNewPortStateForUpdate to "clip-out" the window's + // clipRect. Flash is curently an exception to this. See 6453738. + // + if (!_isStarted) return; @@ -907,9 +918,11 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr) #else if (drawingModel == NPDrawingModelQuickDraw) [self tellQuickTimeToChill]; - else if (drawingModel == NPDrawingModelCoreGraphics && ![self canDraw]) + else if (drawingModel == NPDrawingModelCoreGraphics && ![self canDraw] && _isFlash) { + // The Flash plug-in does not expect an NPP_SetWindow call from WebKit in this case. + // See Exception 2 above. return; - + } #endif // NP_NO_QUICKDRAW BOOL didLockFocus = [NSView focusView] != self && [self lockFocusIfCanDraw]; @@ -920,7 +933,9 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr) [self restorePortState:portState]; if (portState != (PortState)1) free(portState); - } + } else if (drawingModel == NPDrawingModelCoreGraphics) + [self setWindowIfNecessary]; + if (didLockFocus) [self unlockFocus]; } @@ -938,11 +953,7 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr) NPError npErr; ASSERT(!inSetWindow); - inSetWindow = YES; - - // A CoreGraphics plugin's window may only be set while the plugin is being updated - ASSERT((drawingModel != NPDrawingModelCoreGraphics) || [NSView focusView] == self); - + inSetWindow = YES; [self willCallPlugInFunction]; { JSC::JSLock::DropAllLocks dropAllLocks(false); @@ -961,8 +972,9 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr) #endif /* NP_NO_QUICKDRAW */ case NPDrawingModelCoreGraphics: - LOG(Plugins, "NPP_SetWindow (CoreGraphics): %d, window=%p, context=%p, window.x:%d window.y:%d window.width:%d window.height:%d", - npErr, nPort.cgPort.window, nPort.cgPort.context, (int)window.x, (int)window.y, (int)window.width, (int)window.height); + LOG(Plugins, "NPP_SetWindow (CoreGraphics): %d, window=%p, context=%p, window.x:%d window.y:%d window.width:%d window.height:%d window.clipRect size:%dx%d", + npErr, nPort.cgPort.window, nPort.cgPort.context, (int)window.x, (int)window.y, (int)window.width, (int)window.height, + window.clipRect.right - window.clipRect.left, window.clipRect.bottom - window.clipRect.top); break; case NPDrawingModelCoreAnimation: @@ -1056,19 +1068,7 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr) // Create the event handler _eventHandler.set(WebNetscapePluginEventHandler::create(self)); - - // Get the text input vtable - if (eventModel == NPEventModelCocoa) { - [self willCallPlugInFunction]; - { - JSC::JSLock::DropAllLocks dropAllLocks(false); - NPPluginTextInputFuncs *value = 0; - if (![_pluginPackage.get() pluginFuncs]->getvalue(plugin, NPPVpluginTextInputFuncs, &value) == NPERR_NO_ERROR && value) - textInputFuncs = value; - } - [self didCallPlugInFunction]; - } - + return YES; } @@ -1076,14 +1076,19 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr) - (void)setLayer:(CALayer *)newLayer { [super setLayer:newLayer]; - - if (_pluginLayer) + + if (_pluginLayer) { + _pluginLayer.get().autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable; [newLayer addSublayer:_pluginLayer.get()]; + } } #endif - (void)loadStream { + if ([self _shouldCancelSrcStream]) + return; + if (_loadManually) { [self _redeliverStream]; return; @@ -1136,8 +1141,6 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr) [_pluginPackage.get() close]; _eventHandler.clear(); - - textInputFuncs = 0; } - (NPEventModel)eventModel @@ -1150,7 +1153,7 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr) return plugin; } -- (void)setAttributeKeys:(NSArray *)keys andValues:(NSArray *)values; +- (void)setAttributeKeys:(NSArray *)keys andValues:(NSArray *)values { ASSERT([keys count] == [values count]); @@ -1203,9 +1206,9 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr) attributeKeys:(NSArray *)keys attributeValues:(NSArray *)values loadManually:(BOOL)loadManually - DOMElement:(DOMElement *)element + element:(PassRefPtr<WebCore::HTMLPlugInElement>)element { - self = [super initWithFrame:frame pluginPackage:pluginPackage URL:URL baseURL:baseURL MIMEType:MIME attributeKeys:keys attributeValues:values loadManually:loadManually DOMElement:element]; + self = [super initWithFrame:frame pluginPackage:pluginPackage URL:URL baseURL:baseURL MIMEType:MIME attributeKeys:keys attributeValues:values loadManually:loadManually element:element]; if (!self) return nil; @@ -1358,7 +1361,20 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr) return; if (!_manualStream->plugin()) { - + // Check if the load should be cancelled + if ([self _shouldCancelSrcStream]) { + NSURLResponse *response = [[self dataSource] response]; + + NSError *error = [[NSError alloc] _initWithPluginErrorCode:WebKitErrorPlugInWillHandleLoad + contentURL:[response URL] + pluginPageURL:nil + pluginName:nil // FIXME: Get this from somewhere + MIMEType:[response _webcore_MIMEType]]; + [[self dataSource] _documentLoader]->cancelMainResourceLoad(error); + [error release]; + return; + } + _manualStream->setRequestURL([[[self dataSource] request] URL]); _manualStream->setPlugin([self plugin]); ASSERT(_manualStream->plugin()); @@ -1392,160 +1408,11 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr) _manualStream->didFinishLoading(0); } -#pragma mark NSTextInput implementation - - (NSTextInputContext *)inputContext { -#ifndef NP_NO_CARBON - if (!_isStarted || eventModel == NPEventModelCarbon) - return nil; -#endif - - return [super inputContext]; -} - -- (BOOL)hasMarkedText -{ - ASSERT(eventModel == NPEventModelCocoa); - ASSERT(_isStarted); - - if (textInputFuncs && textInputFuncs->hasMarkedText) - return textInputFuncs->hasMarkedText(plugin); - - return NO; -} - -- (void)insertText:(id)aString -{ - ASSERT(eventModel == NPEventModelCocoa); - ASSERT(_isStarted); - - if (textInputFuncs && textInputFuncs->insertText) - textInputFuncs->insertText(plugin, aString); -} - -- (NSRange)markedRange -{ - ASSERT(eventModel == NPEventModelCocoa); - ASSERT(_isStarted); - - if (textInputFuncs && textInputFuncs->markedRange) - return textInputFuncs->markedRange(plugin); - - return NSMakeRange(NSNotFound, 0); -} - -- (NSRange)selectedRange -{ - ASSERT(eventModel == NPEventModelCocoa); - ASSERT(_isStarted); - - if (textInputFuncs && textInputFuncs->selectedRange) - return textInputFuncs->selectedRange(plugin); - - return NSMakeRange(NSNotFound, 0); -} - -- (void)setMarkedText:(id)aString selectedRange:(NSRange)selRange -{ - ASSERT(eventModel == NPEventModelCocoa); - ASSERT(_isStarted); - - if (textInputFuncs && textInputFuncs->setMarkedText) - textInputFuncs->setMarkedText(plugin, aString, selRange); -} - -- (void)unmarkText -{ - ASSERT(eventModel == NPEventModelCocoa); - ASSERT(_isStarted); - - if (textInputFuncs && textInputFuncs->unmarkText) - textInputFuncs->unmarkText(plugin); -} - -- (NSArray *)validAttributesForMarkedText -{ - ASSERT(eventModel == NPEventModelCocoa); - ASSERT(_isStarted); - - if (textInputFuncs && textInputFuncs->validAttributesForMarkedText) - return textInputFuncs->validAttributesForMarkedText(plugin); - - return [NSArray array]; -} - -- (NSAttributedString *)attributedSubstringFromRange:(NSRange)theRange -{ - ASSERT(eventModel == NPEventModelCocoa); - ASSERT(_isStarted); - - if (textInputFuncs && textInputFuncs->attributedSubstringFromRange) - return textInputFuncs->attributedSubstringFromRange(plugin, theRange); - return nil; } -- (NSUInteger)characterIndexForPoint:(NSPoint)thePoint -{ - ASSERT(eventModel == NPEventModelCocoa); - ASSERT(_isStarted); - - if (textInputFuncs && textInputFuncs->characterIndexForPoint) { - // Convert the point to window coordinates - NSPoint point = [[self window] convertScreenToBase:thePoint]; - - // And view coordinates - point = [self convertPoint:point fromView:nil]; - - return textInputFuncs->characterIndexForPoint(plugin, point); - } - - return NSNotFound; -} - -- (void)doCommandBySelector:(SEL)aSelector -{ - ASSERT(eventModel == NPEventModelCocoa); - ASSERT(_isStarted); - - if (textInputFuncs && textInputFuncs->doCommandBySelector) - textInputFuncs->doCommandBySelector(plugin, aSelector); -} - -- (NSRect)firstRectForCharacterRange:(NSRange)theRange -{ - ASSERT(eventModel == NPEventModelCocoa); - ASSERT(_isStarted); - - if (textInputFuncs && textInputFuncs->firstRectForCharacterRange) { - NSRect rect = textInputFuncs->firstRectForCharacterRange(plugin, theRange); - - // Convert the rect to window coordinates - rect = [self convertRect:rect toView:nil]; - - // Convert the rect location to screen coordinates - rect.origin = [[self window] convertBaseToScreen:rect.origin]; - - return rect; - } - - return NSZeroRect; -} - -// test for 10.4 because of <rdar://problem/4243463> -#ifdef BUILDING_ON_TIGER -- (long)conversationIdentifier -{ - return (long)self; -} -#else -- (NSInteger)conversationIdentifier -{ - return (NSInteger)self; -} -#endif - @end @implementation WebNetscapePluginView (WebNPPCallbacks) @@ -1945,11 +1812,6 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr) (float)invalidRect->right - invalidRect->left, (float)invalidRect->bottom - invalidRect->top)]; } --(BOOL)isOpaque -{ - return YES; -} - - (void)invalidateRegion:(NPRegion)invalidRegion { LOG(Plugins, "NPN_InvalidateRegion"); @@ -1986,18 +1848,6 @@ static inline void getNPRect(const NSRect& nr, NPRect& npr) [[self window] displayIfNeeded]; } -static NPBrowserTextInputFuncs *browserTextInputFuncs() -{ - static NPBrowserTextInputFuncs inputFuncs = { - 0, - sizeof(NPBrowserTextInputFuncs), - NPN_MarkedTextAbandoned, - NPN_MarkedTextSelectionChanged - }; - - return &inputFuncs; -} - - (NPError)getVariable:(NPNVariable)variable value:(void *)value { switch (variable) { @@ -2021,7 +1871,7 @@ static NPBrowserTextInputFuncs *browserTextInputFuncs() if (!_element) return NPERR_GENERIC_ERROR; - NPObject *plugInScriptObject = (NPObject *)[_element.get() _NPObject]; + NPObject *plugInScriptObject = _element->getNPObject(); // Return value is expected to be retained, as described here: <http://www.mozilla.org/projects/plugins/npruntime.html#browseraccess> if (plugInScriptObject) @@ -2082,14 +1932,7 @@ static NPBrowserTextInputFuncs *browserTextInputFuncs() *(NPBool *)value = TRUE; return NPERR_NO_ERROR; } - - case NPNVbrowserTextInputFuncs: - { - if (eventModel == NPEventModelCocoa) { - *(NPBrowserTextInputFuncs **)value = browserTextInputFuncs(); - return NPERR_NO_ERROR; - } - } + default: break; } @@ -2205,6 +2048,19 @@ static NPBrowserTextInputFuncs *browserTextInputFuncs() @implementation WebNetscapePluginView (Internal) +- (BOOL)_shouldCancelSrcStream +{ + ASSERT(_isStarted); + + // Check if we should cancel the load + NPBool cancelSrcStream = 0; + if ([_pluginPackage.get() pluginFuncs]->getvalue && + [_pluginPackage.get() pluginFuncs]->getvalue(plugin, NPPVpluginCancelSrcStream, &cancelSrcStream) == NPERR_NO_ERROR && cancelSrcStream) + return YES; + + return NO; +} + - (NPError)_createPlugin { plugin = (NPP)calloc(1, sizeof(NPP_t)); @@ -2217,6 +2073,7 @@ static NPBrowserTextInputFuncs *browserTextInputFuncs() PluginMainThreadScheduler::scheduler().registerPlugin(plugin); + _isFlash = [[[_pluginPackage.get() bundle] bundleIdentifier] isEqualToString:@"com.macromedia.Flash Player.plugin"]; _isSilverlight = [[[_pluginPackage.get() bundle] bundleIdentifier] isEqualToString:@"com.microsoft.SilverlightPlugin"]; [[self class] setCurrentPluginView:self]; |