Esempio n. 1
0
bool PluginPackage::fetchInfo()
{
    DWORD versionInfoSize, zeroHandle;
    versionInfoSize = GetFileVersionInfoSizeW(m_path.charactersWithNullTermination(), &zeroHandle); 
    if (versionInfoSize == 0)
        return false;

    OwnArrayPtr<char> versionInfoData(new char[versionInfoSize]);

    if (!GetFileVersionInfoW(m_path.charactersWithNullTermination(), 0, versionInfoSize, versionInfoData.get()))
        return false;

    m_name = getVersionInfo(versionInfoData.get(), "ProductName");
    m_description = getVersionInfo(versionInfoData.get(), "FileDescription");
    if (m_name.isNull() || m_description.isNull())
        return false;

    VS_FIXEDFILEINFO* info;
    UINT infoSize;
    if (!VerQueryValue(versionInfoData.get(), TEXT("\\"), (LPVOID*) &info, &infoSize) || infoSize < sizeof(VS_FIXEDFILEINFO))
        return false;
    m_moduleVersion.leastSig = info->dwFileVersionLS;
    m_moduleVersion.mostSig = info->dwFileVersionMS;

    if (isPluginBlacklisted())
        return false;

    Vector<String> types;
    getVersionInfo(versionInfoData.get(), "MIMEType").split('|', types);
    Vector<String> extensionLists;
    getVersionInfo(versionInfoData.get(), "FileExtents").split('|', extensionLists);
    Vector<String> descriptions;
    getVersionInfo(versionInfoData.get(), "FileOpenName").split('|', descriptions);

    for (unsigned i = 0; i < types.size(); i++) {
        String type = types[i].lower();
        String description = i < descriptions.size() ? descriptions[i] : "";
        String extensionList = i < extensionLists.size() ? extensionLists[i] : "";

        Vector<String> extensionsVector;
        extensionList.split(',', extensionsVector);

        // Get rid of the extension list that may be at the end of the description string.
        int pos = description.find("(*");
        if (pos != -1) {
            // There might be a space that we need to get rid of.
            if (pos > 1 && description[pos - 1] == ' ')
                pos--;
            description = description.left(pos);
        }

        // Determine the quirks for the MIME types this plug-in supports
        determineQuirks(type);

        m_mimeToExtensions.add(type, extensionsVector);
        m_mimeToDescriptions.add(type, description);
    }

    return true;
}
Esempio n. 2
0
bool PluginPackage::fetchInfo()
{
    const char *errmsg;

    if (!load())
        return false;

    NPP_GetValueProcPtr getValue = 0;
    NP_GetMIMEDescriptionFuncPtr getMIMEDescription = 0;

    getValue = reinterpret_cast<NPP_GetValueProcPtr>(dlsym(m_module, "NP_GetValue"));
    if ((errmsg = dlerror())) {
        EINA_LOG_ERR("Could not get symbol NP_GetValue: %s", errmsg);
        return false;
    }

    getMIMEDescription = reinterpret_cast<NP_GetMIMEDescriptionFuncPtr>(dlsym(m_module, "NP_GetMIMEDescription"));
    if ((errmsg = dlerror())) {
        EINA_LOG_ERR("Could not get symbol NP_GetMIMEDescription: %s", errmsg);
        return false;
    }

    char* buffer = 0;
    NPError err = getValue(0, NPPVpluginNameString, static_cast<void*>(&buffer));
    if (err != NPERR_NO_ERROR)
        return false;
    m_name = buffer;

    buffer = 0;
    err = getValue(0, NPPVpluginDescriptionString, static_cast<void*>(&buffer));
    if (err != NPERR_NO_ERROR)
        return false;
    m_description = buffer;
    determineModuleVersionFromDescription();

    String description = getMIMEDescription();

    Vector<String> types;
    description.split(UChar(';'), false, types);

    for (size_t i = 0; i < types.size(); ++i) {
        Vector<String> mime;
        types[i].split(UChar(':'), true, mime);

        if (!mime.isEmpty() > 0) {
            Vector<String> exts;

            if (mime.size() > 1)
                mime[1].split(UChar(','), false, exts);

            determineQuirks(mime[0]);
            m_mimeToExtensions.add(mime[0], exts);

            if (mime.size() > 2)
                m_mimeToDescriptions.add(mime[0], mime[2]);
        }
    }

    return true;
}
bool PluginPackage::fetchInfo()
{
    if (!load())
        return false;

    NP_GetMIMEDescriptionFuncPtr NP_GetMIMEDescription = 0;
    NPP_GetValueProcPtr NPP_GetValue = 0;

    g_module_symbol(m_module, "NP_GetMIMEDescription", (void**)&NP_GetMIMEDescription);
    g_module_symbol(m_module, "NP_GetValue", (void**)&NPP_GetValue);

    if (!NP_GetMIMEDescription || !NPP_GetValue)
        return false;

    char* buffer = 0;
    NPError err = NPP_GetValue(0, NPPVpluginNameString, &buffer);
    if (err == NPERR_NO_ERROR)
        m_name = String::fromUTF8(buffer);

    buffer = 0;
    err = NPP_GetValue(0, NPPVpluginDescriptionString, &buffer);
    if (err == NPERR_NO_ERROR) {
        m_description = String::fromUTF8(buffer);
        determineModuleVersionFromDescription();
    }

    const gchar* types = NP_GetMIMEDescription();
    if (!types)
        return true;

    gchar** mimeDescs = g_strsplit(types, ";", -1);
    for (int i = 0; mimeDescs[i] && mimeDescs[i][0]; i++) {
        GOwnPtr<char> mime(g_utf8_strdown(mimeDescs[i], -1));
        gchar** mimeData = g_strsplit(mime.get(), ":", 3);
        if (g_strv_length(mimeData) < 3) {
            g_strfreev(mimeData);
            continue;
        }

        String description = String::fromUTF8(mimeData[2]);
        gchar** extensions = g_strsplit(mimeData[1], ",", -1);

        Vector<String> extVector;
        for (int j = 0; extensions[j]; j++)
            extVector.append(String::fromUTF8(extensions[j]));

        determineQuirks(mimeData[0]);
        m_mimeToExtensions.add(mimeData[0], extVector);
        m_mimeToDescriptions.add(mimeData[0], description);

        g_strfreev(extensions);
        g_strfreev(mimeData);
    }
    g_strfreev(mimeDescs);

    return true;
}
bool PluginPackage::fetchInfo()
{
    if (!load())
        return false;

    // FIXME: Find a better way to get around the fetchinfo load.
    // We are fetching the info. Technically we have not loaded the plugin. PluginView::Init will load the plugin so decrement the counter
    m_loadCount--;

    NP_GetMIMEDescriptionFuncPtr getDescription = (NP_GetMIMEDescriptionFuncPtr) dlsym(m_module, "NP_GetMIMEDescription");
    NPP_GetValueProcPtr getValue = (NPP_GetValueProcPtr) dlsym(m_module, "NP_GetValue");

    if (!getDescription || !getValue)
        return false;

    char* buf = 0;
    NPError err = getValue(0, NPPVpluginNameString, (void *) &buf);
    if (err != NPERR_NO_ERROR)
        return false;

    m_name = buf;

    err = getValue(0, NPPVpluginDescriptionString, (void *) &buf);
    if (err != NPERR_NO_ERROR)
        return false;

    m_description = buf;
    determineModuleVersionFromDescription();

    String s = getDescription();
    Vector<String> types;
    s.split(UChar(';'), false, types);
    for (unsigned i = 0; i < types.size(); ++i) {
        Vector<String> mime;
        types[i].split(UChar(':'), true, mime);
        if (mime.size() > 0) {
            Vector<String> extensions;
            if (mime.size() > 1)
                mime[1].split(UChar(','), false, extensions);
            determineQuirks(mime[0]);
            m_mimeToExtensions.add(mime[0], extensions);
            if (mime.size() > 2)
                m_mimeToDescriptions.add(mime[0], mime[2]);
        }
    }

    return true;
}
Esempio n. 5
0
bool PluginPackage::fetchInfo()
{
    // Load the library
    void *module = dlopen(g_locale_from_utf8(m_path.utf8().data(), m_path.length(), NULL, NULL, NULL), RTLD_LAZY);
    if (!module)
    {
        char *error = dlerror();
        return false;
    }

    NP_GetValueFuncPtr NP_GetValue = (NP_GetValueFuncPtr)dlsym(module, "NP_GetValue");
    NP_GetMIMEDescriptionFuncPtr NP_GetMIMEDescription = (NP_GetMIMEDescriptionFuncPtr)dlsym(module, "NP_GetMIMEDescription");

    char *str_name, *str_description;

    NP_GetValue(0, NPPVpluginNameString, (void*)(&str_name));
    m_name = String(str_name);
    NP_GetValue(0, NPPVpluginDescriptionString, (void*)(&str_description));
    m_description = String(str_description);

    if (m_name.isNull() || m_description.isNull()) {
        dlclose(module);
        return false;
    }

    String mimeCompleteString = String(NP_GetMIMEDescription());

    Vector<String> mimeEntries;
    mimeCompleteString.split(';', mimeEntries);
    for (unsigned i = 0; i < mimeEntries.size(); i++) {

        String mimeEntry = mimeEntries[i];
        Vector<String> mimeEntryParts;
        mimeEntry.split(':', mimeEntryParts);

        Vector<String> mimeExtensions;
        mimeEntryParts[1].split(',', mimeExtensions);
        m_mimeToExtensions.add(mimeEntryParts[0], mimeExtensions);
        m_mimeToDescriptions.add(mimeEntryParts[0], mimeEntryParts[2]);

        // Determine the quirks for the MIME types this plug-in supports
        determineQuirks(mimeEntryParts[0]);
    }

    dlclose(module);
    return true;
}
Esempio n. 6
0
bool PluginPackage::fetchInfo()
{
    if (!load())
        return false;

    NPP_GetValueProcPtr gv = (NPP_GetValueProcPtr)m_module->resolve("NP_GetValue");
    typedef char *(*NPP_GetMIMEDescriptionProcPtr)();
    NPP_GetMIMEDescriptionProcPtr gm =
        (NPP_GetMIMEDescriptionProcPtr)m_module->resolve("NP_GetMIMEDescription");
    if (!gm || !gv) {
        return false;
    }
    char *buf = 0;
    NPError err = gv(0, NPPVpluginNameString, (void *)&buf);
    if (err != NPERR_NO_ERROR) {
        return false;
    }
    m_name = buf;
    err = gv(0, NPPVpluginDescriptionString, (void *)&buf);
    if (err != NPERR_NO_ERROR) {
        return false;
    }
    m_description = buf;
    determineModuleVersionFromDescription();

    String s = gm();
    Vector<String> types;
    s.split(UChar(';'), false, types);
    for (int i = 0; i < types.size(); ++i) {
        Vector<String> mime;
        types[i].split(UChar(':'), true, mime); 
        if (mime.size() > 0) {
            Vector<String> exts;
            if (mime.size() > 1)
                mime[1].split(UChar(','), false, exts);
            determineQuirks(mime[0]);
            m_mimeToExtensions.add(mime[0], exts);
            if (mime.size() > 2)
                m_mimeToDescriptions.add(mime[0], mime[2]);
        }
    }

    return true;
}
Esempio n. 7
0
void PluginPackage::setMIMEDescription(const String& mimeDescription)
{
    m_fullMIMEDescription = mimeDescription;

    Vector<String> types;
    mimeDescription.split(UChar(';'), false, types);
    for (unsigned i = 0; i < types.size(); ++i) {
        Vector<String> mime;
        types[i].split(UChar(':'), true, mime);
        if (mime.size() > 0) {
            Vector<String> exts;
            if (mime.size() > 1)
                mime[1].split(UChar(','), false, exts);
            determineQuirks(mime[0]);
            m_mimeToExtensions.add(mime[0], exts);
            if (mime.size() > 2)
                m_mimeToDescriptions.add(mime[0], mime[2]);
        }
    }
}
bool NetscapePluginModule::load()
{
    if (m_isInitialized) {
        ASSERT(initializedNetscapePluginModules().find(this) != notFound);
        return true;
    }

    if (!tryLoad()) {
        unload();
        return false;
    }
    
    m_isInitialized = true;

    ASSERT(initializedNetscapePluginModules().find(this) == notFound);
    initializedNetscapePluginModules().append(this);

    determineQuirks();

    return true;
}
bool PluginPackage::fetchInfo()
{
    PLUGIN_LOG("Fetch Info Loading \"%s\"\n", m_path.utf8().data());

    // Open the library
    void *handle = dlopen(m_path.utf8().data(), RTLD_NOW);
    if(!handle) {
        PLUGIN_LOG("Couldn't load plugin library \"%s\": %s\n",
                   m_path.utf8().data(), dlerror());
        return false;
    }
    PLUGIN_LOG("Fetch Info Loaded %p\n", handle);
    
    // This object will call dlclose() and set m_module to NULL
    // when going out of scope.
    DynamicLibraryCloser dlCloser(&handle);
    
    // Get the three entry points we need for Linux Netscape Plug-ins
    NP_GetMIMEDescriptionFuncPtr NP_GetMIMEDescription;
    NPP_GetValueProcPtr NP_GetValue;
    if(!getEntryPoint(handle, "NP_GetMIMEDescription",
            (void **) &NP_GetMIMEDescription) ||
            !getEntryPoint(handle, "NP_GetValue", (void **) &NP_GetValue)) {
        // If any of those failed to resolve, fail the entire load
        return false;
    }
     
    // Get the plugin name and description using NP_GetValue
    const char *name;
    const char *description;
    if(NP_GetValue(NULL, NPPVpluginNameString, &name) != NPERR_NO_ERROR ||
            NP_GetValue(NULL, NPPVpluginDescriptionString, &description) !=
                NPERR_NO_ERROR) {
        PLUGIN_LOG("Couldn't get name/description using NP_GetValue\n");
        return false;
    }

    PLUGIN_LOG("Plugin name: \"%s\"\n", name);
    PLUGIN_LOG("Plugin description: \"%s\"\n", description);
    m_name = name;
    m_description = description;

    // fileName is just the trailing part of the path
    int last_slash = m_path.reverseFind('/');
    if(last_slash < 0)
        m_fileName = m_path;
    else
        m_fileName = m_path.substring(last_slash + 1);

    // Grab the MIME description. This is in the format, e.g:
    // application/x-somescriptformat:ssf:Some Script Format
    String mimeDescription(NP_GetMIMEDescription());
    PLUGIN_LOG("MIME description: \"%s\"\n", mimeDescription.utf8().data());
    // Clear out the current mappings.
    m_mimeToDescriptions.clear();
    m_mimeToExtensions.clear();    
    // Split the description into its component entries, separated by
    // semicolons.
    Vector<String> mimeEntries;
    mimeDescription.split(';', true, mimeEntries);
    // Iterate through the entries, adding them to the MIME mappings.
    for(Vector<String>::const_iterator it = mimeEntries.begin();
            it != mimeEntries.end(); ++it) {
        // Each part is split into 3 fields separated by colons
        // Field 1 is the MIME type (e.g "application/x-shockwave-flash").
        // Field 2 is a comma separated list of file extensions.
        // Field 3 is a human readable short description.
        const String &mimeEntry = *it;
        Vector<String> fields;
        mimeEntry.split(':', true, fields);
        if(fields.size() != 3) {
            PLUGIN_LOG("Bad MIME entry \"%s\"\n", mimeEntry.utf8().data());
            return false;
        }

        const String& mimeType = fields[0];
        Vector<String> extensions;
        fields[1].split(',', true, extensions);
        const String& description = fields[2];

        determineQuirks(mimeType);

        PLUGIN_LOG("mime_type: \"%s\"\n", mimeType.utf8().data());
        PLUGIN_LOG("extensions: \"%s\"\n", fields[1].utf8().data());
        PLUGIN_LOG("description: \"%s\"\n", description.utf8().data());
         
        // Map the mime type to the vector of extensions and the description
        if(!extensions.isEmpty())
            m_mimeToExtensions.set(mimeType, extensions);
        if(!description.isEmpty())
            m_mimeToDescriptions.set(mimeType, description);
    }

    PLUGIN_LOG("Fetch Info Loaded plugin details ok \"%s\"\n",
            m_path.utf8().data());

    // If this plugin needs to be kept in memory, unload the module now
    // and load it permanently.
    if (m_quirks.contains(PluginQuirkDontUnloadPlugin)) {
        dlCloser.ok();
        dlclose(handle);
        load();
    }
    
    // dlCloser will unload the plugin if required.
    return true;
}
Esempio n. 10
0
bool
PluginPackage::fetchInfo()
{
    if (!load())
        return false;

    WKCPluginInfo info = {0};
    if (!wkcPluginGetInfoPeer(m_module, &info))
        return false;

    CString cname = CString::newUninitialized(info.fNameLen, info.fName);
    CString cdesc = CString::newUninitialized(info.fDescriptionLen, info.fDescription);
    CString cmime = CString::newUninitialized(info.fMIMEDescriptionLen, info.fMIMEDescription);
    CString cexts = CString::newUninitialized(info.fExtensionLen, info.fExtension);
    CString ctypes = CString::newUninitialized(info.fFileOpenNameLen, info.fFileOpenName);

    if (!wkcPluginGetInfoPeer(m_module, &info))
        return false;

    m_name = info.fName;
    m_description = info.fDescription;
    determineModuleVersionFromDescription();

    String smimes = info.fMIMEDescription;
    Vector<String> mimes;

    if (info.fType==WKC_PLUGIN_TYPE_WIN) {
        String e = info.fExtension;
        String d = info.fFileOpenName;
        Vector<String> exts;
        Vector<String> descs;
        Vector<String> iexts;
        smimes.split('|', mimes);
        e.split('|', true, exts);
        d.split('|', true, descs);
        for (int i=0; i<mimes.size(); i++) {
            determineQuirks(mimes[0]);
            String v = i<descs.size() ? descs[i] : "";
            m_mimeToDescriptions.add(mimes[i], v);
            if (i<exts.size()) {
                exts[i].split(',', iexts);
            } else {
                iexts.clear();
            }
            m_mimeToExtensions.add(mimes[i], iexts);
        }
    } else {
        smimes.split(';', mimes);
        for (int i=0; i<mimes.size(); i++) {
            Vector<String> desc;
            Vector<String> exts;
            mimes[i].split(':', true, desc);
            if (desc.size()<3)
                continue;
            desc[1].split(',', exts);

            determineQuirks(desc[0]);
            m_mimeToDescriptions.add(desc[0], desc[2]);
            m_mimeToExtensions.add(desc[0], exts);
        }
    }

    return true;
}