📄 webplugindatabase.mm
字号:
/* * Copyright (C) 2005 Apple Computer, 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. * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 OR ITS 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 "WebPluginDatabase.h"#import "WebBaseNetscapePluginView.h"#import "WebBasePluginPackage.h"#import "WebDataSourcePrivate.h"#import "WebFrame.h"#import "WebFrameViewInternal.h"#import "WebHTMLRepresentation.h"#import "WebHTMLView.h"#import "WebHTMLView.h"#import "WebKitLogging.h"#import "WebNSFileManagerExtras.h"#import "WebNetscapePluginPackage.h"#import "WebPluginController.h"#import "WebPluginPackage.h"#import "WebViewPrivate.h"#import <WebKitSystemInterface.h>#import <wtf/Assertions.h>static void checkCandidate(WebBasePluginPackage **currentPlugin, WebBasePluginPackage **candidatePlugin);@interface WebPluginDatabase (Internal)+ (NSArray *)_defaultPlugInPaths;- (NSArray *)_plugInPaths;- (void)_addPlugin:(WebBasePluginPackage *)plugin;- (void)_removePlugin:(WebBasePluginPackage *)plugin;- (NSMutableSet *)_scanForNewPlugins;@end@implementation WebPluginDatabasestatic WebPluginDatabase *sharedDatabase = nil;+ (WebPluginDatabase *)sharedDatabase { if (!sharedDatabase) { sharedDatabase = [[WebPluginDatabase alloc] init]; [sharedDatabase setPlugInPaths:[self _defaultPlugInPaths]]; [sharedDatabase refresh]; } return sharedDatabase;}+ (void)closeSharedDatabase { [sharedDatabase close];}static void checkCandidate(WebBasePluginPackage **currentPlugin, WebBasePluginPackage **candidatePlugin){ if (!*currentPlugin) { *currentPlugin = *candidatePlugin; return; } if ([[[*currentPlugin bundle] bundleIdentifier] isEqualToString:[[*candidatePlugin bundle] bundleIdentifier]] && [*candidatePlugin versionNumber] > [*currentPlugin versionNumber]) *currentPlugin = *candidatePlugin;}- (WebBasePluginPackage *)pluginForKey:(NSString *)key withEnumeratorSelector:(SEL)enumeratorSelector{ WebBasePluginPackage *plugin = nil; WebBasePluginPackage *webPlugin = nil;#ifdef SUPPORT_CFM WebBasePluginPackage *CFMPlugin = nil;#endif WebBasePluginPackage *machoPlugin = nil; NSEnumerator *pluginEnumerator = [plugins objectEnumerator]; key = [key lowercaseString]; while ((plugin = [pluginEnumerator nextObject]) != nil) { if ([[[plugin performSelector:enumeratorSelector] allObjects] containsObject:key]) { if ([plugin isKindOfClass:[WebPluginPackage class]]) checkCandidate(&webPlugin, &plugin);#if ENABLE(NETSCAPE_PLUGIN_API) else if([plugin isKindOfClass:[WebNetscapePluginPackage class]]) { WebExecutableType executableType = [(WebNetscapePluginPackage *)plugin executableType];#ifdef SUPPORT_CFM if (executableType == WebCFMExecutableType) { checkCandidate(&CFMPlugin, &plugin); } else #endif // SUPPORT_CFM if (executableType == WebMachOExecutableType) { checkCandidate(&machoPlugin, &plugin); } else { ASSERT_NOT_REACHED(); } } else { ASSERT_NOT_REACHED(); }#endif } } // Allow other plug-ins to win over QT because if the user has installed a plug-in that can handle a type // that the QT plug-in can handle, they probably intended to override QT. if (webPlugin && ![webPlugin isQuickTimePlugIn]) return webPlugin; else if (machoPlugin && ![machoPlugin isQuickTimePlugIn]) return machoPlugin;#ifdef SUPPORT_CFM else if (CFMPlugin && ![CFMPlugin isQuickTimePlugIn]) return CFMPlugin;#endif // SUPPORT_CFM else if (webPlugin) return webPlugin; else if (machoPlugin) return machoPlugin;#ifdef SUPPORT_CFM else if (CFMPlugin) return CFMPlugin;#endif return nil;}- (WebBasePluginPackage *)pluginForMIMEType:(NSString *)MIMEType{ return [self pluginForKey:[MIMEType lowercaseString] withEnumeratorSelector:@selector(MIMETypeEnumerator)];}- (WebBasePluginPackage *)pluginForExtension:(NSString *)extension{ WebBasePluginPackage *plugin = [self pluginForKey:[extension lowercaseString] withEnumeratorSelector:@selector(extensionEnumerator)]; if (!plugin) { // If no plug-in was found from the extension, attempt to map from the extension to a MIME type // and find the a plug-in from the MIME type. This is done in case the plug-in has not fully specified // an extension <-> MIME type mapping. NSString *MIMEType = WKGetMIMETypeForExtension(extension); if ([MIMEType length] > 0) plugin = [self pluginForMIMEType:MIMEType]; } return plugin;}- (NSArray *)plugins{ return [plugins allValues];}static NSArray *additionalWebPlugInPaths;+ (void)setAdditionalWebPlugInPaths:(NSArray *)additionalPaths{ if (additionalPaths == additionalWebPlugInPaths) return; [additionalWebPlugInPaths release]; additionalWebPlugInPaths = [additionalPaths copy]; // One might be tempted to add additionalWebPlugInPaths to the global WebPluginDatabase here. // For backward compatibility with earlier versions of the +setAdditionalWebPlugInPaths: SPI, // we need to save a copy of the additional paths and not cause a refresh of the plugin DB // at this time. // See Radars 4608487 and 4609047.}- (void)setPlugInPaths:(NSArray *)newPaths{ if (plugInPaths == newPaths) return; [plugInPaths release]; plugInPaths = [newPaths copy];}- (void)close{ NSEnumerator *pluginEnumerator = [[self plugins] objectEnumerator]; WebBasePluginPackage *plugin; while ((plugin = [pluginEnumerator nextObject]) != nil) [self _removePlugin:plugin]; [plugins release]; plugins = nil;}- (id)init{ if (!(self = [super init])) return nil; registeredMIMETypes = [[NSMutableSet alloc] init]; pluginInstanceViews = [[NSMutableSet alloc] init]; return self;}- (void)dealloc{ [plugInPaths release]; [plugins release]; [registeredMIMETypes release]; [pluginInstanceViews release]; [super dealloc];}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -