Changeset 61594 in webkit


Ignore:
Timestamp:
Jun 21, 2010 5:33:34 PM (14 years ago)
Author:
andersca@apple.com
Message:

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

Reviewed by Sam Weinig.

Support reading plug-in info from Carbon resources
https://bugs.webkit.org/show_bug.cgi?id=40959

  • UIProcess/Plugins/mac/PluginInfoStoreMac.mm: (WebKit::ResourceMap::ResourceMap): (WebKit::ResourceMap::~ResourceMap): (WebKit::ResourceMap::isValid): (WebKit::getStringListResource): (WebKit::getPluginInfoFromCarbonResources): (WebKit::PluginInfoStore::getPluginInfo):
Location:
trunk/WebKit2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit2/ChangeLog

    r61593 r61594  
     12010-06-21  Anders Carlsson  <andersca@apple.com>
     2
     3        Reviewed by Sam Weinig.
     4
     5        Support reading plug-in info from Carbon resources
     6        https://bugs.webkit.org/show_bug.cgi?id=40959
     7
     8        * UIProcess/Plugins/mac/PluginInfoStoreMac.mm:
     9        (WebKit::ResourceMap::ResourceMap):
     10        (WebKit::ResourceMap::~ResourceMap):
     11        (WebKit::ResourceMap::isValid):
     12        (WebKit::getStringListResource):
     13        (WebKit::getPluginInfoFromCarbonResources):
     14        (WebKit::PluginInfoStore::getPluginInfo):
     15
    1162010-06-21  Anders Carlsson  <andersca@apple.com>
    217
  • trunk/WebKit2/UIProcess/Plugins/mac/PluginInfoStoreMac.mm

    r61593 r61594  
    2626#include "PluginInfoStore.h"
    2727
     28#include <WebCore/WebCoreNSStringExtras.h>
    2829#include <wtf/HashSet.h>
    2930#include <wtf/RetainPtr.h>
     
    175176}
    176177
     178class ResourceMap {
     179public:
     180    explicit ResourceMap(CFBundleRef bundle)
     181        : m_bundle(bundle)
     182        , m_currentResourceFile(CurResFile())
     183        , m_bundleResourceMap(CFBundleOpenBundleResourceMap(m_bundle))
     184    {
     185        UseResFile(m_bundleResourceMap);
     186    }
     187
     188    ~ResourceMap()
     189    {
     190        // Close the resource map.
     191        CFBundleCloseBundleResourceMap(m_bundle, m_bundleResourceMap);
     192       
     193        // And restore the old resource.
     194        UseResFile(m_currentResourceFile);
     195    }
     196
     197    bool isValid() const { return m_bundleResourceMap != -1; }
     198
     199private:
     200    CFBundleRef m_bundle;
     201    ResFileRefNum m_currentResourceFile;
     202    ResFileRefNum m_bundleResourceMap;
     203};
     204
     205static bool getStringListResource(ResID resourceID, Vector<String>& stringList) {
     206    Handle stringListHandle = Get1Resource('STR#', resourceID);
     207    if (!stringListHandle || !*stringListHandle)
     208        return false;
     209
     210    // Get the string list size.
     211    Size stringListSize = GetHandleSize(stringListHandle);
     212    if (stringListSize < static_cast<Size>(sizeof(UInt16)))
     213        return false;
     214 
     215    CFStringEncoding stringEncoding = stringEncodingForResource(stringListHandle);
     216
     217    unsigned char* ptr = reinterpret_cast<unsigned char*>(*stringListHandle);
     218    unsigned char* end = ptr + stringListSize;
     219   
     220    // Get the number of strings in the string list.
     221    UInt16 numStrings = *reinterpret_cast<UInt16*>(ptr);
     222    ptr += sizeof(UInt16);
     223                 
     224    for (UInt16 i = 0; i < numStrings; ++i) {
     225        // We're past the end of the string, bail.
     226        if (ptr >= end)
     227            return false;
     228
     229        // Get the string length.
     230        unsigned char stringLength = *ptr++;
     231
     232        RetainPtr<CFStringRef> cfString(AdoptCF, CFStringCreateWithBytesNoCopy(kCFAllocatorDefault, ptr, stringLength, stringEncoding, false, kCFAllocatorNull));
     233        if (!cfString.get())
     234            return false;
     235
     236        stringList.append(cfString.get());
     237        ptr += stringLength;
     238    }
     239
     240    if (ptr != end)
     241        return false;
     242
     243    return true;
     244}
     245
     246static const ResID PluginNameOrDescriptionStringNumber = 126;
     247static const ResID MIMEDescriptionStringNumber = 127;
     248static const ResID MIMEListStringStringNumber = 128;
     249
     250static bool getPluginInfoFromCarbonResources(CFBundleRef bundle, PluginInfo& pluginInfo)
     251{
     252    ResourceMap resourceMap(bundle);
     253    if (!resourceMap.isValid())
     254        return false;
     255
     256    // Get the name and description string list.
     257    Vector<String> nameAndDescription;
     258    if (!getStringListResource(PluginNameOrDescriptionStringNumber, nameAndDescription))
     259        return false;
     260
     261    // Get the MIME types and extensions string list. This list needs to be a multiple of two.
     262    Vector<String> mimeTypesAndExtensions;
     263    if (!getStringListResource(MIMEListStringStringNumber, mimeTypesAndExtensions))
     264        return false;
     265
     266    if (mimeTypesAndExtensions.size() % 2)
     267        return false;
     268
     269    size_t numMimeTypes = mimeTypesAndExtensions.size() / 2;
     270   
     271    // Now get the MIME type descriptions string list. This string list needs to be the same length as the number of MIME types.
     272    Vector<String> mimeTypeDescriptions;
     273    if (!getStringListResource(MIMEDescriptionStringNumber, mimeTypeDescriptions))
     274        return false;
     275
     276    if (mimeTypeDescriptions.size() != numMimeTypes)
     277        return false;
     278
     279    // Add all MIME types.
     280    for (size_t i = 0; i < mimeTypesAndExtensions.size() / 2; ++i) {
     281        MimeClassInfo mimeClassInfo;
     282       
     283        const String& mimeType = mimeTypesAndExtensions[i * 2];
     284        const String& description = mimeTypeDescriptions[i];
     285       
     286        mimeClassInfo.type = mimeType.lower();
     287        mimeClassInfo.desc = description;
     288       
     289        Vector<String> extensions;
     290        mimeTypesAndExtensions[i * 2 + 1].split(',', extensions);
     291       
     292        for (size_t i = 0; i < extensions.size(); ++i)
     293            mimeClassInfo.extensions.append(extensions[i].lower());
     294
     295        pluginInfo.mimes.append(mimeClassInfo);
     296    }
     297
     298    // Set the name and description if they exist.
     299    if (nameAndDescription.size() > 0)
     300        pluginInfo.name = nameAndDescription[0];
     301    if (nameAndDescription.size() > 1)
     302        pluginInfo.desc = nameAndDescription[1];
     303
     304    return true;
     305}
     306
    177307bool PluginInfoStore::getPluginInfo(const WebCore::String& pluginPath, Plugin& plugin)
    178308{
     
    197327
    198328    // Check that there's valid info for this plug-in.
    199     if (!getPluginInfoFromPropertyLists(bundle.get(), plugin.info))
     329    if (!getPluginInfoFromPropertyLists(bundle.get(), plugin.info) &&
     330        !getPluginInfoFromCarbonResources(bundle.get(), plugin.info))
    200331        return false;
    201332
Note: See TracChangeset for help on using the changeset viewer.