gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash ChangeLog plugin/plugin.cpp


From: Benjamin Wolsey
Subject: [Gnash-commit] gnash ChangeLog plugin/plugin.cpp
Date: Mon, 17 Dec 2007 13:15:50 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Benjamin Wolsey <bwy>   07/12/17 13:15:50

Modified files:
        .              : ChangeLog 
        plugin         : plugin.cpp 

Log message:
                * plugin/plugin.cpp: change NPAPI error messages so as not to
                  annoy Opera users (doesn't make it work on Opera, 
unfortunately),
                  general code cleanup.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.5194&r2=1.5195
http://cvs.savannah.gnu.org/viewcvs/gnash/plugin/plugin.cpp?cvsroot=gnash&r1=1.88&r2=1.89

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.5194
retrieving revision 1.5195
diff -u -b -r1.5194 -r1.5195
--- ChangeLog   17 Dec 2007 12:32:53 -0000      1.5194
+++ ChangeLog   17 Dec 2007 13:15:48 -0000      1.5195
@@ -1,3 +1,9 @@
+2007-12-17 Benjamin Wolsey <address@hidden>
+
+       * plugin/plugin.cpp: change NPAPI error messages so as not to
+         annoy Opera users (doesn't make it work on Opera, unfortunately),
+         general code cleanup.
+
 2007-12-17 Sandro Santilli <address@hidden>
 
        * server/asobj/: Sound.{cpp,h}, SoundFfmpeg.{cpp,h},

Index: plugin/plugin.cpp
===================================================================
RCS file: /sources/gnash/gnash/plugin/plugin.cpp,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -b -r1.88 -r1.89
--- plugin/plugin.cpp   30 Nov 2007 12:55:54 -0000      1.88
+++ plugin/plugin.cpp   17 Dec 2007 13:15:49 -0000      1.89
@@ -15,7 +15,7 @@
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
-/* $Id: plugin.cpp,v 1.88 2007/11/30 12:55:54 strk Exp $ */
+/* $Id: plugin.cpp,v 1.89 2007/12/17 13:15:49 bwy Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -62,7 +62,6 @@
 #include <vector>
 #include <iostream>
 
-
 // Mozilla SDK headers
 #include "prinit.h"
 #include "prlock.h"
@@ -114,38 +113,64 @@
 NPError
 NS_PluginInitialize()
 {
+
+       /* Browser Functionality Checks */
+
     NPError err = NPERR_NO_ERROR;
     PRBool supportsXEmbed = PR_TRUE;
     NPNToolkitType toolkit;
 
-    // Make sure that the browser supports functionality we need
+       /* 
+       First, check for XEmbed support. The NPAPI Gnash plugin
+       only works with XEmbed, so tell the plugin API to fail if
+       XEmbed is not found.
+       */      
+       
     err = CallNPN_GetValueProc(NPNFuncs.getvalue, NULL,
                                NPNVSupportsXEmbedBool,
                                (void *)&supportsXEmbed);
 
-    if (err != NPERR_NO_ERROR || !supportsXEmbed) {
-       cout << "No xEmbed support in this Mozilla version!" << endl;
+
+       if (err != NPERR_NO_ERROR || !supportsXEmbed)
+       {
+               cout << "NPAPI ERROR: No xEmbed support in this browser!"
+                                                       << endl;
         return NPERR_INCOMPATIBLE_VERSION_ERROR;
-    } else {
-       cout << "xEmbed supported in this Mozilla version" << endl;
+       }
+       else
+       {
+               cout << "xEmbed supported in this browser" << endl;
     }
 
     err = CallNPN_GetValueProc(NPNFuncs.getvalue, NULL,
                                NPNVToolkit,
                                (void *)&toolkit);
 
-    if (err != NPERR_NO_ERROR || toolkit != NPNVGtk2) {
-       cout << "No GTK2 support in this Mozilla version! Have "
-            << (int)toolkit << endl;
+       /*
+       GTK2 support is currently also necessary. Fail if not
+       present.
+       */
+       if (err != NPERR_NO_ERROR || toolkit != NPNVGtk2)
+       {
+               cout << "NPAPI ERROR: No GTK2 support in this browser!"
+                       " Have version " << (int)toolkit << endl;
+
         return NPERR_INCOMPATIBLE_VERSION_ERROR;
-    } else {
-       cout << "Gtk2+ supported in this Mozilla version" << endl;
+       }
+       else
+       {
+               cout << "GTK2 supported in this browser" << endl;
     }
 
+       /*
+       Check for environment variables.
+       */
     char* opts = getenv("GNASH_OPTIONS");
     if ( opts )
     {
        cout << "GNASH_OPTIONS : " << opts << endl;
+               
+               // Should the plugin wait for gdb to be attached?
        if ( strstr(opts, "waitforgdb") )
        {
                waitforgdb = true;
@@ -153,6 +178,8 @@
 
     }
 
+       /* Success */
+
     plugInitialized = TRUE;
 
     return NPERR_NO_ERROR;
@@ -167,7 +194,8 @@
 void
 NS_PluginShutdown()
 {
-    if (!plugInitialized) {
+       if (!plugInitialized)
+       {
        cout << "Plugin already shut down" << endl;
        return;
     }
@@ -187,15 +215,19 @@
 {
     NPError err = NPERR_NO_ERROR;
 
-    switch (aVariable) {
+       switch (aVariable)
+       {
       case NPPVpluginNameString:
           *static_cast<char **> (aValue) = PLUGIN_NAME;
           break;
 
       // This becomes the description field you see below the opening
-      // text when you type about:plugins
+               // text when you type about:plugins and in
+               // navigator.plugins["Shockwave Flash"].description, used in
+               // many flash version detection scripts.
       case NPPVpluginDescriptionString:
-          *static_cast<const char **>(aValue) = getPluginDescription();
+                       *static_cast<const char **>(aValue) =
+                                               getPluginDescription();
           break;
 
       case NPPVpluginNeedsXEmbed:
@@ -205,8 +237,11 @@
          *static_cast<PRBool *>(aValue) = PR_FALSE;
 #endif
          break;
+
       case NPPVpluginTimerInterval:
+
       case NPPVpluginKeepLibraryInMemory:
+
       default:
           err = NPERR_INVALID_PARAM;
           break;
@@ -221,8 +256,7 @@
 nsPluginInstanceBase *
 NS_NewPluginInstance(nsPluginCreateData * aCreateDataStruct)
 {
-    if(!aCreateDataStruct)
-      return NULL;
+       if(!aCreateDataStruct) return NULL;
 
     return new nsPluginInstance(aCreateDataStruct);
 }
@@ -243,21 +277,25 @@
 
 /// \brief Constructor
 nsPluginInstance::nsPluginInstance(nsPluginCreateData* data)
-  : nsPluginInstanceBase(),
+       :
+       nsPluginInstanceBase(),
     _instance(data->instance),
     _window(0),
     _width(0),
     _height(0),
     _childpid(0)
 {
-       for (size_t i=0, n=data->argc; i<n; ++i) {
+       for (size_t i=0, n=data->argc; i<n; ++i)
+       {
                string name, val;
 
-               if (data->argn[i]) {
+               if (data->argn[i])
+               {
                        name = data->argn[i];
                }
 
-               if (data->argv[i]) {
+               if (data->argv[i])
+               {
                        val = data->argv[i];
                }
                //log_msg("PARAM: %s = %s", name.c_str(), val.c_str());
@@ -278,10 +316,13 @@
 NPBool
 nsPluginInstance::init(NPWindow* aWindow)
 {
-    if(!aWindow) {
+       if(!aWindow)
+       {
        cout <<  __PRETTY_FUNCTION__ << " ERROR: Window handle was bogus!" << 
endl;
         return FALSE;
-    } else {
+       }
+       else
+       {
        cout << "X origin: = " << aWindow->x 
             << ", Y Origin = " << aWindow->y
             << ", Width = " << aWindow->width
@@ -300,6 +341,7 @@
        sleep(5);
     }
 #endif
+
     return TRUE;
 }
 
@@ -311,7 +353,8 @@
 void
 nsPluginInstance::shut()
 {
-    if (_childpid > 0) {
+       if (_childpid > 0)
+       {
        // it seems that waiting after a SIGINT hangs firefox
        // IFF not run from the console (see bug#17082).
        // SIGTERM instead solves this problem
@@ -334,11 +377,14 @@
 NPError
 nsPluginInstance::SetWindow(NPWindow* aWindow)
 {
-    if(!aWindow) {
+       if(!aWindow)
+       {
        cout << __FUNCTION__ << ": ERROR: Window handle was bogus!" << endl;
         return NPERR_INVALID_PARAM;
 #if 0
-    } else {
+       }
+       else
+       {
        log_msg("%s: X origin = %d, Y Origin = %d, Width = %d,"
               " Height = %d, WindowID = %p, this = %p",
               __FUNCTION__,
@@ -399,7 +445,6 @@
 
     cout << __FUNCTION__ << ": The full URL is " << _swf_url << endl;
 
-
 #ifdef WRITE_FILE
     size_t start, end;
     string fname;
@@ -410,7 +455,9 @@
     cout << "The Flash movie name is: " << fname << endl;
 
     _filefd = open(fname.c_str(), O_CREAT | O_WRONLY, 
S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
-    if (_filefd < 0) {
+    
+       if (_filefd < 0)
+       {
         _filefd = open(fname.c_str(), O_TRUNC | O_WRONLY, 
S_IRUSR|S_IRGRP|S_IROTH);
     }
 #endif
@@ -431,19 +478,27 @@
       (void *)arg, stream->url);
 #endif
 
-    if (_streamfd != -1) {
-        if (close(_streamfd) == -1) {
+    if (_streamfd != -1)
+    {
+        if (close(_streamfd) == -1)
+        {
             perror(strerror(errno));
-        } else {
+        }
+        else
+        {
             _streamfd = -1;
         }
     }
 
 #ifdef WRITE_FILE
-    if (_filefd != -1) {
-        if (close(_filefd) == -1) {
+    if (_filefd != -1)
+    {
+        if (close(_filefd) == -1)
+        {
             perror(strerror(errno));
-        } else {
+        }
+        else
+        {
             _filefd = -1;
         }
     }
@@ -469,10 +524,12 @@
 nsPluginInstance::Write(NPStream * /* stream */, int32_t /* offset */, int32_t 
len,
                         void * buffer)
 {
+
 #if 0
     log_msg("Reading Stream %s, offset is %d, length = %d",
       stream->url, offset, len);
 #endif
+
 #ifdef WRITE_FILE
     write(_filefd, buffer, len);
 #endif
@@ -487,7 +544,9 @@
     if (!gnash_env) {
       procname = GNASHBINDIR;
       procname += "/gtk-gnash";
-    } else {
+       }
+       else
+       {
       procname = gnash_env;
     }
 
@@ -495,57 +554,71 @@
     if ( ! pageurl )
     {
        cout << "Could not get current page URL!" << endl;
-       //log_msg("UNIMPLEMENTED: current page url: %s", pageurl);
-       // invoke gnash with -U <current_page_url>
     }
 
     struct stat procstats;
 
     // See if the file actually exists, otherwise we can't spawn it
-    if (stat(procname.c_str(), &procstats) == -1) {
+       if (stat(procname.c_str(), &procstats) == -1)
+       {
        cout << "Invalid filename: " << procname << endl;
       return;
     }
 
-    int pipefd[2]; // 0 For reading, 1 for writing.
+       // 0 For reading, 1 for writing.
+       int pipefd[2];
 
     int ret = pipe(pipefd);
-    if (ret == -1) {
+       if (ret == -1)
+       {
       cout << "ERROR: pipe() failed: " << strerror(errno) << endl;
     }
 
     _streamfd = pipefd[1];
 
     _childpid = fork();
-    // childpid is -1, if the fork failed, so print out an error message
-    if (_childpid == -1) {
+
+       // If the fork failed, childpid is -1. So print out an error message.
+       if (_childpid == -1)
+       {
       cout << "ERROR: dup2() failed: " << strerror(errno) << endl;
       return;
     }
 
-    // childpid is a positive integer, if we are the parent, and
-    // fork() worked
-    if (_childpid > 0) {
-      ret = close (pipefd[0]); // we want to write, so close read-fd0
-      if (ret == -1) {
-        cout << "ERROR: close() failed: " << strerror(errno) << endl;
+       // If we are the parent and fork() worked, childpid is a positive 
integer.
+       if (_childpid > 0)
+       {
+
+               // we want to write, so close read-fd0
+               ret = close (pipefd[0]);
+       
+               if (ret == -1)
+               {
+                       cout << "ERROR: close() failed: " << strerror(errno)
+                                                               << endl;
       }
 
-      cout << "Forked sucessfully, child process PID is " << _childpid << endl;
+               cout << "Forked successfully, child process PID is " 
+                                                               << _childpid
+                                                               << endl;
 
       return;
     }
 
     // This is the child scope.
 
-    ret = close (pipefd[1]); // We want to read, so close write-fd1
-    if (ret == -1) {
+       // We want to read, so close write-fd1
+       ret = close (pipefd[1]); 
+       if (ret == -1)
+       {
       cout << "ERROR: close() failed: " << strerror(errno) << endl;
     }
 
     // close standard input and direct read-fd1 to standard input
     ret = dup2 (pipefd[0], fileno(stdin));
-    if (ret == -1) {
+       
+       if (ret == -1)
+       {
       cout << "ERROR: dup2() failed: " << strerror(errno) << endl;
     }
 
@@ -555,30 +628,41 @@
     // typical cases.  Rather than close all the thousands of possible file
     // descriptors, we start after stderr and keep closing higher numbers
     // until we encounter ten fd's in a row that
-    // aren't open.  This will tend to close most fd's in most programms.
+       // aren't open. This will tend to close most fd's in most programs.
     int numfailed = 0, closed = 0;
     int anfd = fileno(stderr)+1;
-    for ( ; numfailed < 10; anfd++) {
+       for ( ; numfailed < 10; anfd++)
+       {
        ret = close (anfd);
        if (ret < 0) numfailed++;
-       else         { numfailed = 0; closed++; }
+               else
+               {
+                       numfailed = 0;
+                       closed++;
+               }
     }
-    cout << "Closed " << closed << "files." <<endl;
 
-    // setup the command line
+       cout << "Closed " << closed << "files." << endl;
+
+       /*
+       Setup the command line for starting Gnash
+       */
 
+       // Prepare width, height and window ID variables
     const size_t buf_size = 30;
     char xid[buf_size], width[buf_size], height[buf_size];
     snprintf(xid, buf_size, "%ld", win);
     snprintf(width, buf_size, "%d", _width);
     snprintf(height, buf_size, "%d", _height);
 
-    // Write -P values 
+       // Prepare Actionscript variables (e.g. Flashvars).
     vector<string> paramvalues;
     paramvalues.reserve(_params.size());
-    for ( map<string,string>::const_iterator it=_params.begin(),
+
+       for (map<string,string>::const_iterator it=_params.begin(),
                itEnd=_params.end();
-               it != itEnd; ++it)
+               it != itEnd; ++it
+               )
     {
         const string& nam=it->first; 
         const string& val=it->second;
@@ -589,63 +673,95 @@
         paramvalues.push_back(param);
     }
 
-    // REMEMBER TO INCREMENT THE maxargc COUNT IF YOU
-    // ADD NEW ARGUMENTS 
+       /*
+       We pass the necessary arguments to the gnash executable for
+       it to run as a plugin. We do not specify rendering flags so
+       they can be set in gnashrc. Gnash defaults to -r3 anyway.
+       
+       REMEMBER TO INCREMENT THE maxargc COUNT IF YOU
+       ADD NEW ARGUMENTS
+       */ 
 
-    const size_t maxargc = 16 + paramvalues.size()*2;
+       const size_t maxargc = 16 + paramvalues.size() * 2;
     char **argv = new char *[maxargc];
 
     size_t argc = 0;
     argv[argc++] = const_cast<char*>( procname.c_str() );
-    // don't specify rendering flags, so that the rcfile
-    // will control that 
-    //argv[argc++] = "-r";
-    //argv[argc++] = "3";
-    argv[argc++] = "-v";
-    argv[argc++] = "-x";
+       
+       // Verbose
+       argv[argc++] = const_cast<char*>("-v");
+       
+       // X window ID (necessary for gnash to function as a plugin)
+       argv[argc++] = const_cast<char*>("-x");
     argv[argc++] = xid;
-    argv[argc++] = "-j";
+       
+       // Height and width
+       argv[argc++] = const_cast<char*>("-j");
     argv[argc++] = width;
-    argv[argc++] = "-k";
+       argv[argc++] = const_cast<char*>("-k");
     argv[argc++] = height;
-    argv[argc++] = "-u";
+       
+       argv[argc++] = const_cast<char*>("-u");
     argv[argc++] = const_cast<char*>( _swf_url.c_str() );
+
+       // Base URL is the page that the SWF is embedded in. It is 
+       // by Gnash for resolving relative URLs in the movie. If the
+       // embed tag "base" is specified, its value overrides the -U
+       // flag later (Player.cpp).
     if ( pageurl )
     {
-       argv[argc++] = "-U";
+               argv[argc++] = const_cast<char*> ("-U");
        argv[argc++] = const_cast<char*>( pageurl );
     }
 
+       // Variables for use by Actionscript.
     for ( size_t i=0, n=paramvalues.size(); i<n; ++i)
     {
-        argv[argc++] = "-P";
+               argv[argc++] = const_cast<char*>("-P");
         argv[argc++] = const_cast<char*>( paramvalues[i].c_str() );
     }
 
-    argv[argc++] = "-";
+       argv[argc++] = const_cast<char*>("-");
     argv[argc++] = 0;
 
     assert(argc <= maxargc);
 
-    // Start the desired executable and go away
+       /*
+       Start the desired executable and go away.
+       */
+       
     cout << "Starting process: ";
 
-    for (int i=0; argv[i] != 0; ++i) {
+       for (int i=0; argv[i] != 0; ++i)
+       {
       cout << argv[i] << " ";
     }
     cout << endl;
 
+       /*
+       For debugging the plugin (GNASH_OPTIONS=waitforgdb)
+       Block here until gdb is attached and sets waitforgdb to
+       false.
+       */
+
     if (waitforgdb) {
-       cout << endl << "  Attach GDB to PID " << getpid() << " to debug!" << 
endl;
-       cout << "  This thread will block until then!..." << endl;
-       cout << "  Once blocked here, you can set other breakpoints." << endl;
-       cout << "  do a \"set variable waitforgdb=false\" to continue" << endl 
<< endl;
-       while (waitforgdb) {
+
+               cout << endl << "  Attach GDB to PID " << getpid()
+                               << " to debug!" << endl;
+               cout << "  This thread will block until then!" << endl;
+               cout << "  Once blocked here, you can set other breakpoints."
+                               << endl;
+               cout << "  Do a \"set variable waitforgdb=$false\" to continue"
+                               << endl << endl;
+               
+               while (waitforgdb)
+               {
            sleep(1);
        }
     }
 
     execv(argv[0], argv);
+
     // if execv returns, an error has occurred.
     perror(strerror(errno));
 
@@ -667,10 +783,13 @@
         NPVariant vDoc;
         NPN_GetProperty(npp, window, sDocument, &vDoc);
         NPN_ReleaseObject(window);
-        if (!NPVARIANT_IS_OBJECT(vDoc)) {
+
+       if (!NPVARIANT_IS_OBJECT(vDoc))
+       {
            cout << "Can't get window object" << endl;
            return NULL;
        }
+       
         NPObject* npDoc = NPVARIANT_TO_OBJECT(vDoc);
 
         NPIdentifier sLocation = NPN_GetStringIdentifier("location");




reply via email to

[Prev in Thread] Current Thread [Next in Thread]