Changeset 86097 in webkit


Ignore:
Timestamp:
May 9, 2011 3:49:41 PM (13 years ago)
Author:
andersca@apple.com
Message:

2011-05-09 Anders Carlsson <andersca@apple.com>

Reviewed by Sam Weinig.

Create a plug-in's MIME types preferences plist if it doesn't exist.
https://bugs.webkit.org/show_bug.cgi?id=57204
<rdar://problem/9195048>

Spawn a plug-in process and let it create the plist. For now, we'll do this on the
main thread since it's a rare one-time computation and we have an API function,
WKFrameCanShowMIMEType, which would have to block anyway.

  • PluginProcess/mac/PluginProcessMainMac.mm: (WebKit::PluginProcessMain): If -createPluginMIMETypesPreferences is one of the command line argument keys, the plug-in path will be the argument value. Call NetscapePluginModule::createPluginMIMETypesPreferences to create the preferences file and then exit.
  • Shared/Plugins/Netscape/mac/NetscapePluginModuleMac.mm: (WebKit::contentsOfPropertyListAtURL): Move code to read a property list out into a helper function.

(WebKit::getMIMETypesFromPluginBundle):
If there's no property list file, try to create one.

(WebKit::NetscapePluginModule::createPluginMIMETypesPreferences):
Load the plug-in, find the BP_CreatePluginMIMETypesPreferences and call it.

  • UIProcess/Plugins/mac/PluginProcessProxyMac.mm: (WebKit::PluginProcessProxy::createPropertyListFile): Spawn a plug-in process and pass the -createPluginMIMETypesPreferences flag to it and then wait for it to exit.
Location:
trunk/Source/WebKit2
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r86089 r86097  
     12011-05-09  Anders Carlsson  <andersca@apple.com>
     2
     3        Reviewed by Sam Weinig.
     4
     5        Create a plug-in's MIME types preferences plist if it doesn't exist.
     6        https://bugs.webkit.org/show_bug.cgi?id=57204
     7        <rdar://problem/9195048>
     8
     9        Spawn a plug-in process and let it create the plist. For now, we'll do this on the
     10        main thread since it's a rare one-time computation and we have an API function,
     11        WKFrameCanShowMIMEType, which would have to block anyway.
     12
     13        * PluginProcess/mac/PluginProcessMainMac.mm:
     14        (WebKit::PluginProcessMain):
     15        If -createPluginMIMETypesPreferences is one of the command line argument keys,
     16        the plug-in path will be the argument value. Call NetscapePluginModule::createPluginMIMETypesPreferences
     17        to create the preferences file and then exit.
     18
     19        * Shared/Plugins/Netscape/mac/NetscapePluginModuleMac.mm:
     20        (WebKit::contentsOfPropertyListAtURL):
     21        Move code to read a property list out into a helper function.
     22
     23        (WebKit::getMIMETypesFromPluginBundle):
     24        If there's no property list file, try to create one.
     25
     26        (WebKit::NetscapePluginModule::createPluginMIMETypesPreferences):
     27        Load the plug-in, find the BP_CreatePluginMIMETypesPreferences and call it.
     28
     29        * UIProcess/Plugins/mac/PluginProcessProxyMac.mm:
     30        (WebKit::PluginProcessProxy::createPropertyListFile):
     31        Spawn a plug-in process and pass the -createPluginMIMETypesPreferences flag to it and then wait
     32        for it to exit.
     33
    1342011-05-09  Anders Carlsson  <andersca@apple.com>
    235
  • trunk/Source/WebKit2/PluginProcess/mac/PluginProcessMainMac.mm

    r80014 r86097  
    3030
    3131#import "CommandLine.h"
     32#import "NetscapePluginModule.h"
    3233#import "PluginProcess.h"
    3334#import "RunLoop.h"
     
    5455    // by any child processes that the plug-in may launch.
    5556    unsetenv("DYLD_INSERT_LIBRARIES");
     57
     58    // Check if we're being spawned to write a MIME type preferences file.
     59    String pluginPath = commandLine["createPluginMIMETypesPreferences"];
     60    if (!pluginPath.isEmpty()) {
     61        JSC::initializeThreading();
     62        WTF::initializeMainThread();
     63
     64        if (!NetscapePluginModule::createPluginMIMETypesPreferences(pluginPath))
     65            return EXIT_FAILURE;
     66
     67        return EXIT_SUCCESS;
     68    }
    5669
    5770    String serviceName = commandLine["servicename"];
  • trunk/Source/WebKit2/Shared/Plugins/Netscape/NetscapePluginModule.h

    r84638 r86097  
    6262    Module* module() const { return m_module.get(); }
    6363
     64#if PLUGIN_ARCHITECTURE(MAC)
     65    static bool createPluginMIMETypesPreferences(const String& pluginPath);
     66#endif
     67
    6468private:
    6569    explicit NetscapePluginModule(const String& pluginPath);
  • trunk/Source/WebKit2/Shared/Plugins/Netscape/mac/NetscapePluginModuleMac.mm

    r86076 r86097  
    2727#import "NetscapePluginModule.h"
    2828
     29#import "PluginProcessProxy.h"
    2930#import <WebCore/WebCoreNSStringExtras.h>
    3031#import <wtf/HashSet.h>
     32
    3133
    3234using namespace WebCore;
     
    8789    return false;
    8890}
    89    
    90 static RetainPtr<CFDictionaryRef> getMIMETypesFromPluginBundle(CFBundleRef bundle)
     91
     92static RetainPtr<CFDictionaryRef> contentsOfPropertyListAtURL(CFURLRef propertyListURL)
     93{
     94    CFDataRef propertyListData;
     95    CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, propertyListURL, &propertyListData, 0, 0, 0);
     96    if (!propertyListData)
     97        return 0;
     98
     99    RetainPtr<CFPropertyListRef> propertyList(AdoptCF, CFPropertyListCreateWithData(kCFAllocatorDefault, propertyListData, kCFPropertyListImmutable, 0, 0));
     100    CFRelease(propertyListData);
     101
     102    if (!propertyList)
     103        return 0;
     104
     105    if (CFGetTypeID(propertyList.get()) != CFDictionaryGetTypeID())
     106        return 0;
     107
     108    return RetainPtr<CFDictionaryRef>(AdoptCF, static_cast<CFDictionaryRef>(propertyList.leakRef()));
     109}
     110
     111static RetainPtr<CFDictionaryRef> getMIMETypesFromPluginBundle(CFBundleRef bundle, const PluginInfoStore::Plugin& plugin)
    91112{
    92113    CFStringRef propertyListFilename = static_cast<CFStringRef>(CFBundleGetValueForInfoDictionaryKey(bundle, CFSTR("WebPluginMIMETypesFilename")));
     
    95116        RetainPtr<CFURLRef> propertyListURL(AdoptCF, CFURLCreateWithFileSystemPath(kCFAllocatorDefault, propertyListPath.get(), kCFURLPOSIXPathStyle, FALSE));
    96117
    97         CFDataRef propertyListData;
    98         CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, propertyListURL.get(), &propertyListData, 0, 0, 0);
    99         RetainPtr<CFPropertyListRef> propertyList(AdoptCF, CFPropertyListCreateWithData(kCFAllocatorDefault, propertyListData, kCFPropertyListImmutable, 0, 0));
    100         if (propertyListData)
    101             CFRelease(propertyListData);
    102        
    103         // FIXME: Have the plug-in create the MIME types property list if it doesn't exist.
    104         // https://bugs.webkit.org/show_bug.cgi?id=57204
    105         if (!propertyList || CFGetTypeID(propertyList.get()) != CFDictionaryGetTypeID())
     118        RetainPtr<CFDictionaryRef> propertyList = contentsOfPropertyListAtURL(propertyListURL.get());
     119
     120#if ENABLE(PLUGIN_PROCESS)
     121        if (!propertyList && PluginProcessProxy::createPropertyListFile(plugin))
     122            propertyList = contentsOfPropertyListAtURL(propertyListURL.get());
     123#endif
     124
     125        if (!propertyList)
    106126            return 0;
    107127       
    108         return static_cast<CFDictionaryRef>(CFDictionaryGetValue(static_cast<CFDictionaryRef>(propertyList.get()), CFSTR("WebPluginMIMETypes")));
     128        return static_cast<CFDictionaryRef>(CFDictionaryGetValue(propertyList.get(), CFSTR("WebPluginMIMETypes")));
    109129    }
    110130   
     
    114134static bool getPluginInfoFromPropertyLists(CFBundleRef bundle, PluginInfoStore::Plugin& plugin)
    115135{
    116     RetainPtr<CFDictionaryRef> mimeTypes = getMIMETypesFromPluginBundle(bundle);
     136    RetainPtr<CFDictionaryRef> mimeTypes = getMIMETypesFromPluginBundle(bundle, plugin);
    117137    if (!mimeTypes || CFGetTypeID(mimeTypes.get()) != CFDictionaryGetTypeID())
    118138        return false;
     
    363383}
    364384
     385bool NetscapePluginModule::createPluginMIMETypesPreferences(const String& pluginPath)
     386{
     387    RetainPtr<CFStringRef> bundlePath(AdoptCF, pluginPath.createCFString());
     388    RetainPtr<CFURLRef> bundleURL(AdoptCF, CFURLCreateWithFileSystemPath(kCFAllocatorDefault, bundlePath.get(), kCFURLPOSIXPathStyle, false));
     389   
     390    // Try to initialize the bundle.
     391    RetainPtr<CFBundleRef> bundle(AdoptCF, CFBundleCreate(kCFAllocatorDefault, bundleURL.get()));
     392    if (!bundle)
     393        return false;
     394
     395    if (!CFBundleLoadExecutable(bundle.get()))
     396        return false;
     397
     398    void (*createPluginMIMETypesPreferences)(void) = reinterpret_cast<void (*)(void)>(CFBundleGetFunctionPointerForName(bundle.get(), CFSTR("BP_CreatePluginMIMETypesPreferences")));
     399    if (!createPluginMIMETypesPreferences)
     400        return false;
     401   
     402    createPluginMIMETypesPreferences();
     403    return true;
     404}
     405
    365406void NetscapePluginModule::determineQuirks()
    366407{
  • trunk/Source/WebKit2/UIProcess/Plugins/PluginProcessProxy.h

    r84302 r86097  
    5555class PluginProcessProxy : CoreIPC::Connection::Client, ProcessLauncher::Client {
    5656public:
    57 #if PLATFORM(MAC)
    58     static bool pluginNeedsExecutableHeap(const PluginInfoStore::Plugin&);
    59 #endif
    6057    static PassOwnPtr<PluginProcessProxy> create(PluginProcessManager*, const PluginInfoStore::Plugin&);
    6158    ~PluginProcessProxy();
     
    7572    // Terminates the plug-in process.
    7673    void terminate();
     74
     75#if PLATFORM(MAC)
     76    // Returns whether the plug-in needs the heap to be marked executable.
     77    static bool pluginNeedsExecutableHeap(const PluginInfoStore::Plugin&);
     78
     79    // Creates a property list in ~/Library/Preferences that contains all the MIME types supported by the plug-in.
     80    static bool createPropertyListFile(const PluginInfoStore::Plugin&);
     81#endif
    7782
    7883private:
  • trunk/Source/WebKit2/UIProcess/Plugins/mac/PluginProcessProxyMac.mm

    r83109 r86097  
    2929#if ENABLE(PLUGIN_PROCESS)
    3030
     31#import "EnvironmentVariables.h"
    3132#import "PluginProcessCreationParameters.h"
    3233#import "WebKitSystemInterface.h"
     34#import <WebCore/FileSystem.h>
     35#import <spawn.h>
     36#import <wtf/text/CString.h>
    3337
    3438@interface WKPlaceholderModalWindow : NSWindow
     
    4650@end
    4751
     52using namespace WebCore;
     53
    4854namespace WebKit {
    4955   
     
    5763        return false;
    5864   
     65    return true;
     66}
     67
     68bool PluginProcessProxy::createPropertyListFile(const PluginInfoStore::Plugin& plugin)
     69{
     70    NSBundle *webKit2Bundle = [NSBundle bundleWithIdentifier:@"com.apple.WebKit2"];
     71    NSString *frameworksPath = [[webKit2Bundle bundlePath] stringByDeletingLastPathComponent];
     72    const char* frameworkExecutablePath = [[webKit2Bundle executablePath] fileSystemRepresentation];
     73   
     74    NSString *processPath = [webKit2Bundle pathForAuxiliaryExecutable:@"PluginProcess.app"];
     75    NSString *processAppExecutablePath = [[NSBundle bundleWithPath:processPath] executablePath];
     76
     77    CString pluginPathString = fileSystemRepresentation(plugin.path);
     78
     79    posix_spawnattr_t attr;
     80    posix_spawnattr_init(&attr);
     81
     82    cpu_type_t cpuTypes[] = { plugin.pluginArchitecture };   
     83    size_t outCount = 0;
     84    posix_spawnattr_setbinpref_np(&attr, 1, cpuTypes, &outCount);
     85
     86    EnvironmentVariables environmentVariables;
     87   
     88    // To make engineering builds work, if the path is outside of /System set up
     89    // DYLD_FRAMEWORK_PATH to pick up other frameworks, but don't do it for the
     90    // production configuration because it involves extra file system access.
     91    if (![frameworksPath hasPrefix:@"/System/"])
     92        environmentVariables.appendValue("DYLD_FRAMEWORK_PATH", [frameworksPath fileSystemRepresentation], ':');
     93
     94    const char* args[] = { [processAppExecutablePath fileSystemRepresentation], frameworkExecutablePath, "-type", "pluginprocess", "-createPluginMIMETypesPreferences", pluginPathString.data(), 0 };
     95
     96    pid_t pid;
     97    int result = posix_spawn(&pid, args[0], 0, &attr, const_cast<char* const*>(args), environmentVariables.environmentPointer());
     98    posix_spawnattr_destroy(&attr);
     99
     100    if (result < 0)
     101        return false;
     102    int status;
     103    if (waitpid(pid, &status, 0) < 0)
     104        return false;
     105
     106    if (!WIFEXITED(status))
     107        return false;
     108
     109    if (WEXITSTATUS(status) != EXIT_SUCCESS)
     110        return false;
     111
    59112    return true;
    60113}
Note: See TracChangeset for help on using the changeset viewer.