NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value) { return NP_GetValue(NULL, variable, value); // FIXME: put in plugin? //MaleoWidgetPlugin * pPlugin = static_cast<MaleoWidgetPlugin *>(instance->pdata); //return pPlugin->getValuevariable, value); }
static NPError cloud_spy_plugin_get_value (NPP instance, NPPVariable variable, void * value) { (void) instance; if (NP_GetValue (NULL, variable, value) == NPERR_NO_ERROR) return NPERR_NO_ERROR; switch (variable) { case NPPVpluginScriptableNPObject: { NPObject * obj; G_LOCK (cloud_spy_plugin); obj = static_cast<NPObject *> (g_hash_table_lookup (cloud_spy_plugin_roots, instance)); if (obj == NULL) { obj = cloud_spy_nsfuncs->createobject (instance, static_cast<NPClass *> (cloud_spy_object_type_get_np_class (CLOUD_SPY_TYPE_ROOT))); g_hash_table_insert (cloud_spy_plugin_roots, instance, obj); } cloud_spy_nsfuncs->retainobject (obj); G_UNLOCK (cloud_spy_plugin); *(static_cast<NPObject **> (value)) = obj; break; } default: return NPERR_INVALID_PARAM; } return NPERR_NO_ERROR; }
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; }
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; }