📄 webnetscapepluginview.mm
字号:
Vector<RefPtr<WebNetscapePluginStream> > streamsCopy; copyToVector(streams, streamsCopy); for (size_t i = 0; i < streamsCopy.size(); i++) streamsCopy[i]->stop(); [[_pendingFrameLoads.get() allKeys] makeObjectsPerformSelector:@selector(_setInternalLoadDelegate:) withObject:nil]; [NSObject cancelPreviousPerformRequestsWithTarget:self]; // Setting the window type to 0 ensures that NPP_SetWindow will be called if the plug-in is restarted. lastSetWindow.type = (NPWindowType)0; #ifndef BUILDING_ON_TIGER _pluginLayer = 0;#endif [self _destroyPlugin]; [_pluginPackage.get() close]; _eventHandler.clear(); textInputFuncs = 0;}- (NPEventModel)eventModel{ return eventModel;}- (NPP)plugin{ return plugin;}- (void)setAttributeKeys:(NSArray *)keys andValues:(NSArray *)values{ ASSERT([keys count] == [values count]); // Convert the attributes to 2 C string arrays. // These arrays are passed to NPP_New, but the strings need to be // modifiable and live the entire life of the plugin. // The Java plug-in requires the first argument to be the base URL if ([_MIMEType.get() isEqualToString:@"application/x-java-applet"]) { cAttributes = (char **)malloc(([keys count] + 1) * sizeof(char *)); cValues = (char **)malloc(([values count] + 1) * sizeof(char *)); cAttributes[0] = strdup("DOCBASE"); cValues[0] = strdup([_baseURL.get() _web_URLCString]); argsCount++; } else { cAttributes = (char **)malloc([keys count] * sizeof(char *)); cValues = (char **)malloc([values count] * sizeof(char *)); } BOOL isWMP = [[[_pluginPackage.get() bundle] bundleIdentifier] isEqualToString:@"com.microsoft.WMP.defaultplugin"]; unsigned i; unsigned count = [keys count]; for (i = 0; i < count; i++) { NSString *key = [keys objectAtIndex:i]; NSString *value = [values objectAtIndex:i]; if ([key _webkit_isCaseInsensitiveEqualToString:@"height"]) { specifiedHeight = [value intValue]; } else if ([key _webkit_isCaseInsensitiveEqualToString:@"width"]) { specifiedWidth = [value intValue]; } // Avoid Window Media Player crash when these attributes are present. if (isWMP && ([key _webkit_isCaseInsensitiveEqualToString:@"SAMIStyle"] || [key _webkit_isCaseInsensitiveEqualToString:@"SAMILang"])) { continue; } cAttributes[argsCount] = strdup([key UTF8String]); cValues[argsCount] = strdup([value UTF8String]); LOG(Plugins, "%@ = %@", key, value); argsCount++; }}#pragma mark NSVIEW- (id)initWithFrame:(NSRect)frame pluginPackage:(WebNetscapePluginPackage *)pluginPackage URL:(NSURL *)URL baseURL:(NSURL *)baseURL MIMEType:(NSString *)MIME attributeKeys:(NSArray *)keys attributeValues:(NSArray *)values loadManually:(BOOL)loadManually element:(PassRefPtr<WebCore::HTMLPlugInElement>)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; _pendingFrameLoads.adoptNS([[NSMutableDictionary alloc] init]); // load the plug-in if it is not already loaded if (![pluginPackage load]) { [self release]; return nil; } return self;}- (id)initWithFrame:(NSRect)frame{ ASSERT_NOT_REACHED(); return nil;}- (void)fini{#ifndef NP_NO_QUICKDRAW if (offscreenGWorld) DisposeGWorld(offscreenGWorld);#endif for (unsigned i = 0; i < argsCount; i++) { free(cAttributes[i]); free(cValues[i]); } free(cAttributes); free(cValues); ASSERT(!_eventHandler); if (timers) { deleteAllValues(*timers); delete timers; } }- (void)disconnectStream:(WebNetscapePluginStream*)stream{ streams.remove(stream);}- (void)dealloc{ ASSERT(!_isStarted); ASSERT(!plugin); [self fini]; [super dealloc];}- (void)finalize{ ASSERT_MAIN_THREAD(); ASSERT(!_isStarted); [self fini]; [super finalize];}- (void)drawRect:(NSRect)rect{ if (drawingModel == NPDrawingModelCoreAnimation) return; if (!_isStarted) return; if ([NSGraphicsContext currentContextDrawingToScreen]) [self sendDrawRectEvent:rect]; else { NSBitmapImageRep *printedPluginBitmap = [self _printedPluginBitmap]; if (printedPluginBitmap) { // Flip the bitmap before drawing because the QuickDraw port is flipped relative // to this view. CGContextRef cgContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort]; CGContextSaveGState(cgContext); NSRect bounds = [self bounds]; CGContextTranslateCTM(cgContext, 0.0f, NSHeight(bounds)); CGContextScaleCTM(cgContext, 1.0f, -1.0f); [printedPluginBitmap drawInRect:bounds]; CGContextRestoreGState(cgContext); } }}- (NPObject *)createPluginScriptableObject{ if (![_pluginPackage.get() pluginFuncs]->getvalue || !_isStarted) return NULL; NPObject *value = NULL; NPError error; [self willCallPlugInFunction]; { JSC::JSLock::DropAllLocks dropAllLocks(false); error = [_pluginPackage.get() pluginFuncs]->getvalue(plugin, NPPVpluginScriptableNPObject, &value); } [self didCallPlugInFunction]; if (error != NPERR_NO_ERROR) return NULL; return value;}- (void)willCallPlugInFunction{ ASSERT(plugin); // Could try to prevent infinite recursion here, but it's probably not worth the effort. pluginFunctionCallDepth++;}- (void)didCallPlugInFunction{ ASSERT(pluginFunctionCallDepth > 0); pluginFunctionCallDepth--; // If -stop was called while we were calling into a plug-in function, and we're no longer // inside a plug-in function, stop now. if (pluginFunctionCallDepth == 0 && shouldStopSoon) { shouldStopSoon = NO; [self stop]; }}-(void)pluginView:(NSView *)pluginView receivedResponse:(NSURLResponse *)response{ ASSERT(_loadManually); ASSERT(!_manualStream); _manualStream = WebNetscapePluginStream::create(core([self webFrame])->loader());}- (void)pluginView:(NSView *)pluginView receivedData:(NSData *)data{ ASSERT(_loadManually); ASSERT(_manualStream); _dataLengthReceived += [data length]; if (!_isStarted) 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 MIMEType]]; [[self dataSource] _documentLoader]->cancelMainResourceLoad(error); [error release]; return; } _manualStream->setRequestURL([[[self dataSource] request] URL]); _manualStream->setPlugin([self plugin]); ASSERT(_manualStream->plugin()); _manualStream->startStreamWithResponse([[self dataSource] response]); } if (_manualStream->plugin()) _manualStream->didReceiveData(0, static_cast<const char *>([data bytes]), [data length]);}- (void)pluginView:(NSView *)pluginView receivedError:(NSError *)error{ ASSERT(_loadManually); _error = error; if (!_isStarted) { return; } _manualStream->destroyStreamWithError(error);}- (void)pluginViewFinishedLoading:(NSView *)pluginView { ASSERT(_loadManually); ASSERT(_manualStream); if (_isStarted) _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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -