NPP_SetWindow can pass the wrong window's CGContextRef to a plugin. b=500130 r=josh sr=roc

This commit is contained in:
Steven Michaud 2009-07-14 10:09:18 -05:00
parent eed6512282
commit 68137e029c

View File

@ -810,12 +810,22 @@ void* nsChildView::GetNativeData(PRUint32 aDataType)
if ([mView isKindOfClass:[ChildView class]])
[(ChildView*)mView setIsPluginView:YES];
mPluginPort.cgPort.context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
NSWindow* window = [mView nativeWindow];
if (window) {
// [NSGraphicsContext currentContext] is supposed to "return the
// current graphics context of the current thread." But sometimes
// (when called while mView isn't focused for drawing) it returns a
// graphics context for the wrong window. [window graphicsContext]
// (which "provides the graphics context associated with the window
// for the current thread") seems always to return the "right"
// graphics context. See bug 500130.
mPluginPort.cgPort.context = (CGContextRef)
[[window graphicsContext] graphicsPort];
WindowRef topLevelWindow = (WindowRef)[window windowRef];
mPluginPort.cgPort.window = topLevelWindow;
} else {
mPluginPort.cgPort.context = nil;
mPluginPort.cgPort.window = nil;
}
retVal = (void*)&mPluginPort;