Skip to content

Commit

Permalink
2010-06-20 Anders Carlsson <andersca@apple.com>
Browse files Browse the repository at this point in the history
        Reviewed by Dan Bernstein.

        Move the NSBundle ivar to WebPluginPackage
        https://bugs.webkit.org/show_bug.cgi?id=40894

        * Plugins/WebBasePluginPackage.h:
        * Plugins/WebBasePluginPackage.mm:
        (-[WebBasePluginPackage initWithPath:]):
        (-[WebBasePluginPackage _objectForInfoDictionaryKey:]):
        (-[WebBasePluginPackage getPluginInfoFromPLists]):
        (-[WebBasePluginPackage load]):
        (-[WebBasePluginPackage dealloc]):
        * Plugins/WebNetscapePluginPackage.mm:
        (-[WebNetscapePluginPackage _initWithPath:]):
        * Plugins/WebPluginPackage.h:
        * Plugins/WebPluginPackage.mm:
        (-[WebPluginPackage initWithPath:]):
        (-[WebPluginPackage dealloc]):
        (-[WebPluginPackage viewFactory]):
        (-[WebPluginPackage load]):


Canonical link: https://commits.webkit.org/52529@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@61519 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Anders Carlsson committed Jun 21, 2010
1 parent d1b1d51 commit 266134e
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 29 deletions.
23 changes: 23 additions & 0 deletions WebKit/mac/ChangeLog
@@ -1,3 +1,26 @@
2010-06-20 Anders Carlsson <andersca@apple.com>

Reviewed by Dan Bernstein.

Move the NSBundle ivar to WebPluginPackage
https://bugs.webkit.org/show_bug.cgi?id=40894

* Plugins/WebBasePluginPackage.h:
* Plugins/WebBasePluginPackage.mm:
(-[WebBasePluginPackage initWithPath:]):
(-[WebBasePluginPackage _objectForInfoDictionaryKey:]):
(-[WebBasePluginPackage getPluginInfoFromPLists]):
(-[WebBasePluginPackage load]):
(-[WebBasePluginPackage dealloc]):
* Plugins/WebNetscapePluginPackage.mm:
(-[WebNetscapePluginPackage _initWithPath:]):
* Plugins/WebPluginPackage.h:
* Plugins/WebPluginPackage.mm:
(-[WebPluginPackage initWithPath:]):
(-[WebPluginPackage dealloc]):
(-[WebPluginPackage viewFactory]):
(-[WebPluginPackage load]):

2010-06-20 Anders Carlsson <andersca@apple.com>

Reviewed by Sam Weinig.
Expand Down
1 change: 0 additions & 1 deletion WebKit/mac/Plugins/WebBasePluginPackage.h
Expand Up @@ -60,7 +60,6 @@ typedef void (*BP_CreatePluginMIMETypesPreferencesFuncPtr)(void);
WebCore::String path;
WebCore::String pluginDescription;

NSBundle *bundle;
CFBundleRef cfBundle;

NSDictionary *MIMEToDescription;
Expand Down
33 changes: 18 additions & 15 deletions WebKit/mac/Plugins/WebBasePluginPackage.mm
Expand Up @@ -124,15 +124,15 @@ - (id)initWithPath:(NSString *)pluginPath
return nil;

path = pathByResolvingSymlinksAndAliases(pluginPath);
bundle = [[NSBundle alloc] initWithPath:path];
cfBundle = CFBundleCreate(kCFAllocatorDefault, (CFURLRef)[NSURL fileURLWithPath:path]);

#ifndef __ppc__
// 32-bit PowerPC is the only platform where non-bundled CFM plugins are supported
if (!bundle) {
if (!cfBundle) {
[self release];
return nil;
}
#endif
cfBundle = CFBundleCreate(NULL, (CFURLRef)[NSURL fileURLWithPath:path]);
extensionToMIME = [[NSMutableDictionary alloc] init];

return self;
Expand Down Expand Up @@ -167,13 +167,22 @@ - (NSDictionary *)pListForPath:(NSString *)pListPath createFile:(BOOL)createFile
return pList;
}

- (id)_objectForInfoDictionaryKey:(NSString *)key
{
CFDictionaryRef bundleInfoDictionary = CFBundleGetInfoDictionary(cfBundle);
if (!bundleInfoDictionary)
return nil;

return (id)CFDictionaryGetValue(bundleInfoDictionary, key);
}

- (BOOL)getPluginInfoFromPLists
{
if (!bundle)
if (!cfBundle)
return NO;

NSDictionary *MIMETypes = nil;
NSString *pListFilename = [bundle objectForInfoDictionaryKey:WebPluginMIMETypesFilenameKey];
NSString *pListFilename = [self _objectForInfoDictionaryKey:WebPluginMIMETypesFilenameKey];

// Check if the MIME types are claimed in a plist in the user's preferences directory.
if (pListFilename) {
Expand All @@ -191,7 +200,7 @@ - (BOOL)getPluginInfoFromPLists
}

if (!MIMETypes) {
MIMETypes = [bundle objectForInfoDictionaryKey:WebPluginMIMETypesKey];
MIMETypes = [self _objectForInfoDictionaryKey:WebPluginMIMETypesKey];
if (!MIMETypes)
return NO;
}
Expand Down Expand Up @@ -231,12 +240,12 @@ - (BOOL)getPluginInfoFromPLists

NSString *filename = [self filename];

NSString *theName = [bundle objectForInfoDictionaryKey:WebPluginNameKey];
NSString *theName = [self _objectForInfoDictionaryKey:WebPluginNameKey];
if (!theName)
theName = filename;
name = theName;

description = [bundle objectForInfoDictionaryKey:WebPluginDescriptionKey];
description = [self _objectForInfoDictionaryKey:WebPluginDescriptionKey];
if (!description)
description = filename;
pluginDescription = description;
Expand All @@ -246,7 +255,7 @@ - (BOOL)getPluginInfoFromPLists

- (BOOL)load
{
if (bundle && !BP_CreatePluginMIMETypesPreferences)
if (cfBundle && !BP_CreatePluginMIMETypesPreferences)
BP_CreatePluginMIMETypesPreferences = (BP_CreatePluginMIMETypesPreferencesFuncPtr)CFBundleGetFunctionPointerForName(cfBundle, CFSTR("BP_CreatePluginMIMETypesPreferences"));

return YES;
Expand All @@ -261,7 +270,6 @@ - (void)dealloc
[MIMEToExtensions release];
[extensionToMIME release];

[bundle release];
if (cfBundle)
CFRelease(cfBundle);

Expand Down Expand Up @@ -330,11 +338,6 @@ - (NSArray *)extensionsForMIMEType:(NSString *)MIMEType
return [MIMEToExtensions objectForKey:MIMEType];
}

- (NSBundle *)bundle
{
return bundle;
}

- (void)setMIMEToDescriptionDictionary:(NSDictionary *)MIMEToDescriptionDictionary
{
[MIMEToDescription release];
Expand Down
16 changes: 10 additions & 6 deletions WebKit/mac/Plugins/WebNetscapePluginPackage.mm
Expand Up @@ -35,6 +35,7 @@
#import "WebNSObjectExtras.h"
#import "WebNetscapeDeprecatedFunctions.h"
#import <WebCore/npruntime_impl.h>
#import <wtf/RetainPtr.h>

#if USE(PLUGIN_HOST_PROCESS)
#import "NetscapePluginHostManager.h"
Expand Down Expand Up @@ -208,7 +209,7 @@ - (BOOL)_initWithPath:(NSString *)pluginPath

OSType type = 0;

if (bundle) {
if (cfBundle) {
// Bundle
CFBundleGetPackageInfo(cfBundle, &type, NULL);
#ifdef SUPPORT_CFM
Expand All @@ -230,8 +231,11 @@ - (BOOL)_initWithPath:(NSString *)pluginPath
return NO;

// Check if the executable is Mach-O or CFM.
if (bundle) {
NSFileHandle *executableFile = [NSFileHandle fileHandleForReadingAtPath:[bundle executablePath]];
if (cfBundle) {
RetainPtr<CFURLRef> executableURL(AdoptCF, CFBundleCopyExecutableURL(cfBundle));
if (!executableURL)
return NO;
NSFileHandle *executableFile = [NSFileHandle fileHandleForReadingAtPath:[(NSURL *)executableURL.get() path]];
NSData *data = [executableFile readDataOfLength:512];
[executableFile closeFile];
// Check the length of the data before calling memcmp. We think this fixes 3782543.
Expand All @@ -246,11 +250,11 @@ - (BOOL)_initWithPath:(NSString *)pluginPath
#endif

#if USE(PLUGIN_HOST_PROCESS)
NSArray *archs = [bundle executableArchitectures];
RetainPtr<CFArrayRef> archs(AdoptCF, CFBundleCopyExecutableArchitectures(cfBundle));

if ([archs containsObject:[NSNumber numberWithInteger:NSBundleExecutableArchitectureX86_64]])
if ([(NSArray *)archs.get() containsObject:[NSNumber numberWithInteger:NSBundleExecutableArchitectureX86_64]])
pluginHostArchitecture = CPU_TYPE_X86_64;
else if ([archs containsObject:[NSNumber numberWithInteger:NSBundleExecutableArchitectureI386]])
else if ([(NSArray *)archs.get() containsObject:[NSNumber numberWithInteger:NSBundleExecutableArchitectureI386]])
pluginHostArchitecture = CPU_TYPE_X86;
else
return NO;
Expand Down
4 changes: 3 additions & 1 deletion WebKit/mac/Plugins/WebPluginPackage.h
Expand Up @@ -32,7 +32,9 @@

@protocol WebPluginViewFactory;

@interface WebPluginPackage : WebBasePluginPackage
@interface WebPluginPackage : WebBasePluginPackage {
NSBundle *nsBundle;
}

- (Class)viewFactory;

Expand Down
21 changes: 15 additions & 6 deletions WebKit/mac/Plugins/WebPluginPackage.mm
Expand Up @@ -40,12 +40,14 @@

@implementation WebPluginPackage

- initWithPath:(NSString *)pluginPath
- (id)initWithPath:(NSString *)pluginPath
{
if (!(self = [super initWithPath:pluginPath]))
return nil;

if (bundle == nil) {
nsBundle = [[NSBundle alloc] initWithPath:path];

if (!nsBundle) {
[self release];
return nil;
}
Expand All @@ -59,7 +61,7 @@ @implementation WebPluginPackage
}
}

NSFileHandle *executableFile = [NSFileHandle fileHandleForReadingAtPath:[bundle executablePath]];
NSFileHandle *executableFile = [NSFileHandle fileHandleForReadingAtPath:[nsBundle executablePath]];
NSData *data = [executableFile readDataOfLength:512];
[executableFile closeFile];
if (![self isNativeLibraryData:data]) {
Expand All @@ -75,9 +77,16 @@ @implementation WebPluginPackage
return self;
}

- (void)dealloc
{
[nsBundle release];

[super dealloc];
}

- (Class)viewFactory
{
return [bundle principalClass];
return [nsBundle principalClass];
}

- (BOOL)load
Expand All @@ -87,8 +96,8 @@ - (BOOL)load
#endif

// Load the bundle
if (![bundle isLoaded]) {
if (![bundle load])
if (![nsBundle isLoaded]) {
if (![nsBundle load])
return NO;
}

Expand Down

0 comments on commit 266134e

Please sign in to comment.