Browse Source

Phew, finally managed to get flash to load.

Girish Ramakrishnan 9 years ago
parent
commit
6cfc898fbe
2 changed files with 117 additions and 25 deletions
  1. 117 25
      main.cpp
  2. BIN
      test.swf

+ 117 - 25
main.cpp

@@ -41,8 +41,11 @@ struct Plugin {
     Plugin() {
         memset(&funcs, 0, sizeof(NPPluginFuncs));
         funcs.size = sizeof(NPPluginFuncs);
+
+        memset(&stream, 0, sizeof(NPStream));
     }
     NPPluginFuncs funcs;
+    NPStream stream;
 };
 
 struct InstanceData {
@@ -68,6 +71,9 @@ NPError NPN_GetValueImpl(NPP instance, NPNVariable variable, void *r_value)
     case NPNVToolkit:
         *(NPNToolkitType *)r_value = NPNVGtk2; // ouch, that hurts
         break;
+    case NPNVSupportsWindowless:
+        *(NPBool *)r_value = TRUE;
+        break;
     default:
         qDebug() << "NotImplemented: Value of " << variable;
         return NPERR_GENERIC_ERROR;
@@ -128,6 +134,59 @@ void NPN_ForceRedrawImpl(NPP instance)
     qDebug() << "Force redraw : NPN_ForceRedraw";
 }
 
+NPError NPN_GetURLImpl(NPP instance, const char* url, const char* target)
+{
+    qDebug() << "Not implemented : NPN_GetURL" << url << target;
+    return NPERR_GENERIC_ERROR;
+}
+
+NPError NPN_GetURLNotifyImpl(NPP    instance,
+                             const  char* url, 
+                             const  char* target,
+                             void*   notifyData)
+{
+    qDebug() << "Not implemented : NPN_GetURLNotifyImpl" << url << target;
+    return NPERR_GENERIC_ERROR;
+}
+
+
+NPError NPN_PostURLImpl(NPP instance, const char *url,
+                        const char *target, uint32 len,
+                        const char *buf, NPBool file)
+{
+    qDebug() << "Not implemented : NPN_PostURL" << url << target;
+    return NPERR_GENERIC_ERROR;
+}
+ 
+NPError NPN_NewStreamImpl(NPP instance, NPMIMEType  type, const char* target, NPStream**  stream)
+{
+    qDebug() << "Not implemented : NPN_NewStream";
+    return NPERR_GENERIC_ERROR;
+}
+ 
+int32 NPN_WriteImpl(NPP instance, NPStream* stream, int32 len, void *buf)
+{
+    qDebug() << "Not implemented : NPN_Write";
+    return NPERR_GENERIC_ERROR;
+}
+ 
+NPError NPN_RequestReadImpl(NPStream *stream, NPByteRange* rangeList)
+{
+    qDebug() << "Not implemented : NPN_RequestRead";
+    return NPERR_GENERIC_ERROR;
+}
+
+NPError NPN_DestroyStreamImpl(NPP instance, NPStream* stream, NPError reason)
+{
+    qDebug() << "Not implemented : NPN_DestroyStream";
+    return NPERR_GENERIC_ERROR;
+}
+
+void NPN_StatusImpl(NPP instance, const char* message)
+{
+    qDebug() << "Set the status to " << message;
+}
+
 static const char* mozillaUserAgent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0";
 
 const char* NPN_UserAgentImpl(NPP instance)
@@ -137,10 +196,12 @@ const char* NPN_UserAgentImpl(NPP instance)
 
 class X11EmbedContainer : public QX11EmbedContainer
 {
+    Q_OBJECT
 public:
     X11EmbedContainer(Plugin *plugin, NPP instance, QWidget *parent = 0) 
         : QX11EmbedContainer(parent), m_plugin(plugin), m_instance(instance)
     {
+        connect(this, SIGNAL(clientIsEmbedded()), this, SLOT(startStream()));
     }
 
     void setSizeHint(const QSize &sh)
@@ -180,6 +241,38 @@ protected:
         }
     }
 
+private slots:
+    void startStream()
+    {
+        uint16 stype = NP_NORMAL;
+        qDebug() << "Starting a new stream";
+        QFile file("test.swf");
+        file.open(QFile::ReadOnly);
+        const QByteArray ba = file.readAll();
+        const char *data = ba.data();
+
+        m_plugin->stream.url = "test.swf";
+        m_plugin->stream.end = ba.size();
+        m_plugin->stream.lastmodified = 0;
+
+        NPError err = m_plugin->funcs.newstream(m_instance, PLUGIN_MIMETYPE, &m_plugin->stream, false, &stype);
+        if (err != NPERR_NO_ERROR) {
+            qDebug() << "Error creating stream!!";
+            return;
+        }
+
+        int32 offset = 0;
+
+        while (offset < ba.length()) {
+            int32 canWrite = m_plugin->funcs.writeready(m_instance, &m_plugin->stream);
+            int consumed = m_plugin->funcs.write(m_instance, &m_plugin->stream, offset, qMin(canWrite, ba.length()-offset), (void *) &data[offset]);
+            if (consumed == -1) {
+                qDebug() << "Error when writing";
+                return;
+            }
+            offset += consumed;
+        }
+    }
 private:
     QSize m_sh;
     Plugin *m_plugin;
@@ -315,41 +408,38 @@ int main(int argc, char *argv[])
     qDebug() << "Loading plugin supporting mime type " << NP_GetMIMEDescriptionPtr();
 
     NPNetscapeFuncs nsTable;
-    memset(&nsTable, 0, sizeof(nsTable));
+    memset(&nsTable, 0x0, sizeof(nsTable));
     nsTable.size = sizeof(NPNetscapeFuncs);
-    nsTable.version = NP_VERSION_MAJOR << 8;
+    nsTable.version = NP_VERSION_MINOR;
 
-/*
     nsTable.geturl = NPN_GetURLImpl;
     nsTable.posturl = NPN_PostURLImpl;
-    nsTable.requestread = NPN_RequestRead;
-    nsTable.newstream = NPN_NewStream;
-    nsTable.write = NPN_Write;
-    nsTable.destroystream = NPN_DestroyStream;
-    nsTable.status = NPN_Status;
-*/
+
+    nsTable.requestread = NPN_RequestReadImpl;
+    nsTable.newstream = NPN_NewStreamImpl;
+    nsTable.write = NPN_WriteImpl;
+    nsTable.destroystream = NPN_DestroyStreamImpl;
+    nsTable.status = NPN_StatusImpl;
     nsTable.uagent = NPN_UserAgentImpl;
 
     nsTable.memalloc = NPN_MemAllocImpl;
     nsTable.memfree = NPN_MemFreeImpl;
-/*
-    nsTable.memflush = NPN_MemFlush;
-    nsTable.reloadplugins = NPN_ReloadPlugins;
-    nsTable.geturlnotify = NPN_GetURLNotify;
-    nsTable.posturlnotify = NPN_PostURLNotify;
-*/
+    nsTable.memflush = 0;
+    nsTable.reloadplugins = 0;
+    nsTable.geturlnotify = NPN_GetURLNotifyImpl;
+    nsTable.posturlnotify = 0;
+
     nsTable.getvalue = NPN_GetValueImpl;
     nsTable.setvalue = NPN_SetValueImpl;
     nsTable.invalidaterect = NPN_InvalidateRectImpl;
     nsTable.invalidateregion = NPN_InvalidateRegionImpl;
     nsTable.forceredraw = NPN_ForceRedrawImpl;
-/*
-    nsTable.getJavaEnv = NPN_GetJavaEnv;
-    nsTable.getJavaPeer = NPN_GetJavaPeer;
-    nsTable.pushpopupsenabledstate = NPN_PushPopupsEnabledState;
-    nsTable.poppopupsenabledstate = NPN_PopPopupsEnabledState;
-    nsTable.pluginthreadasynccall = NPN_PluginThreadAsyncCall;
-*/
+
+    nsTable.getJavaEnv = 0; 
+    nsTable.getJavaPeer = 0; 
+    nsTable.pushpopupsenabledstate = 0;
+    nsTable.poppopupsenabledstate = 0;
+    //nsTable.pluginthreadasynccall = 0;
 
     // initialize
     Plugin plugin;
@@ -365,9 +455,9 @@ int main(int argc, char *argv[])
     InstanceData instanceData;
     instance.ndata = &instanceData;
 
-    char *keys[] =  { "wmode" };
-    char *values[] = { "transparent" };
-    int16 count = app.arguments().contains("-windowless") ? sizeof(keys)/sizeof(const char *) : 0;
+    char *keys[] =  { "url", "type", "wmode" };
+    char *values[] = { "test.swf", PLUGIN_MIMETYPE, "transparent" };
+    int16 count = sizeof(keys)/sizeof(const char *) - !app.arguments().contains("-windowless");
     error = plugin.funcs.newp(PLUGIN_MIMETYPE, &instance, NP_EMBED, count, keys, values, 0 /* saved */);
     if (error != NPERR_NO_ERROR) {
         qDebug() << "Failed to create new instance" << error;
@@ -420,3 +510,5 @@ int main(int argc, char *argv[])
     return 0;
 }
 
+#include "main.moc"
+

BIN
test.swf