extern "C" NPError NP_GetValue(void*, NPPVariable aVariable, void *aValue) { NPError err = NPERR_NO_ERROR; static QByteArray name = qtNPFactory()->pluginName().toLocal8Bit(); static QByteArray descr = qtNPFactory()->pluginDescription().toLocal8Bit(); switch (aVariable) { case NPPVpluginNameString: *static_cast<const char **> (aValue) = name.constData(); break; case NPPVpluginDescriptionString: *static_cast<const char **>(aValue) = descr.constData(); break; case NPPVpluginNeedsXEmbed: *static_cast<int*>(aValue) = true; break; case NPPVpluginTimerInterval: case NPPVpluginKeepLibraryInMemory: default: err = NPERR_INVALID_PARAM; break; } return err; }
// Instance state information about the plugin. extern "C" char * NP_GetMIMEDescription(void) { static QByteArray mime = qtNPFactory()->mimeTypes().join(";").toLocal8Bit() + "::" + qtNPFactory()->pluginName().toLocal8Bit(); return (char *)mime.constData(); }
extern "C" NPError NPP_SetWindow(NPP instance, NPWindow* window) { if (!instance) return NPERR_INVALID_INSTANCE_ERROR; QtNPInstance* This = (QtNPInstance*) instance->pdata; extern void qtns_setGeometry(QtNPInstance*, const QRect &, const QRect &); const QRect clipRect(window->clipRect.left, window->clipRect.top, window->clipRect.right - window->clipRect.left, window->clipRect.bottom - window->clipRect.top); if (window) This->geometry = QRect(window->x, window->y, window->width, window->height); // take a shortcut if all that was changed is the geometry if (qobject_cast<QWidget*>(This->qt.object) && window && This->window == (QtNPInstance::Widget)window->window) { qtns_setGeometry(This, This->geometry, clipRect); return NPERR_NO_ERROR; } delete This->qt.object; This->qt.object = 0; extern void qtns_destroy(QtNPInstance *This); qtns_destroy(This); if (!window) { This->window = 0; return NPERR_NO_ERROR; } This->window = (QtNPInstance::Widget)window->window; #ifdef Q_WS_X11 //This->display = ((NPSetWindowCallbackStruct *)window->ws_info)->display; #endif extern void qtns_initialize(QtNPInstance*); qtns_initialize(This); next_pi = This; This->qt.object = qtNPFactory()->createObject(This->mimetype); next_pi = 0; if (!This->qt.object) return NPERR_NO_ERROR; if (!This->htmlID.isEmpty()) This->qt.object->setObjectName(QLatin1String(This->htmlID)); This->filter = new QtSignalForwarder(This); QStatusBar *statusbar = qFindChild<QStatusBar*>(This->qt.object); if (statusbar) { int statusSignal = statusbar->metaObject()->indexOfSignal("messageChanged(QString)"); if (statusSignal != -1) { QMetaObject::connect(statusbar, statusSignal, This->filter, -1); statusbar->hide(); } } const QMetaObject *mo = This->qt.object->metaObject(); for (int p = 0; p < mo->propertyCount(); ++p) { const QMetaProperty property = mo->property(p); QByteArray name(property.name()); QVariant value = This->parameters.value(name.toLower()); if (value.isValid()) property.write(This->qt.object, value); } for (int methodIndex = 0; methodIndex < mo->methodCount(); ++methodIndex) { const QMetaMethod method = mo->method(methodIndex); if (method.methodType() == QMetaMethod::Signal) QMetaObject::connect(This->qt.object, methodIndex, This->filter, methodIndex); } if (This->pendingStream) { This->pendingStream->finish(This->bindable); This->pendingStream = 0; } if (!qobject_cast<QWidget*>(This->qt.object)) return NPERR_NO_ERROR; extern void qtns_embed(QtNPInstance*); qtns_embed(This); QEvent e(QEvent::EmbeddingControl); QApplication::sendEvent(This->qt.widget, &e); if (!This->qt.widget->testAttribute(Qt::WA_PaintOnScreen)) This->qt.widget->setAutoFillBackground(true); This->qt.widget->raise(); qtns_setGeometry(This, This->geometry, clipRect); This->qt.widget->show(); return NPERR_NO_ERROR; }
// Plugin functions extern "C" NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value) { if (!instance || !instance->pdata) return NPERR_INVALID_INSTANCE_ERROR; QtNPInstance* This = (QtNPInstance*) instance->pdata; switch (variable) { case NPPVpluginNameString: { static QByteArray name = qtNPFactory()->pluginName().toLocal8Bit(); *(const char**)value = name.constData(); } break; case NPPVpluginDescriptionString: { static QByteArray description = qtNPFactory()->pluginDescription().toLocal8Bit(); *(const char**)value = description.constData(); } break; #ifdef Q_WS_X11 case NPPVpluginNeedsXEmbed: *(int*)value = true; // PRBool = int break; #endif case NPPVpluginScriptableNPObject: { NPObject *object = NPN_CreateObject(instance, new NPClass(This)); *(NPObject**)value = object; } break; case NPPVformValue: { QObject *object = This->qt.object; const QMetaObject *metaObject = object->metaObject(); int defaultIndex = metaObject->indexOfClassInfo("DefaultProperty"); if (defaultIndex == -1) return NPERR_GENERIC_ERROR; QByteArray defaultProperty = metaObject->classInfo(defaultIndex).value(); if (defaultProperty.isEmpty()) return NPERR_GENERIC_ERROR; QVariant defaultValue = object->property(defaultProperty); if (!defaultValue.isValid()) return NPERR_GENERIC_ERROR; defaultProperty = defaultValue.toString().toUtf8(); int size = defaultProperty.size(); char *utf8 = (char*)NPN_MemAlloc(size + 1); memcpy(utf8, defaultProperty.constData(), size); utf8[size] = 0; // null-terminator *(void**)value = utf8; } break; default: return NPERR_GENERIC_ERROR; } return NPERR_NO_ERROR; }