[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/trunk r10397: Indentation and line break c
From: |
Benjamin Wolsey |
Subject: |
[Gnash-commit] /srv/bzr/gnash/trunk r10397: Indentation and line break changes. |
Date: |
Mon, 08 Dec 2008 12:41:01 +0100 |
User-agent: |
Bazaar (1.5) |
------------------------------------------------------------
revno: 10397
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Mon 2008-12-08 12:41:01 +0100
message:
Indentation and line break changes.
Reduce VM-version-based initialization in Global.cpp.
Some minor changes to plugin that reduce segfaults with xulrunner-1.9
(not xpcom).
modified:
libcore/asobj/ClassHierarchy.cpp
libcore/asobj/Global.cpp
libcore/asobj/Object.cpp
libcore/asobj/Selection_as.cpp
libcore/asobj/Selection_as.h
plugin/plugin.cpp
plugin/plugin.h
------------------------------------------------------------
revno: 10396.1.1
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Mon 2008-12-08 10:16:52 +0100
message:
Line breaks and remove some obsolete code.
modified:
plugin/plugin.cpp
plugin/plugin.h
------------------------------------------------------------
revno: 10396.1.2
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Mon 2008-12-08 10:26:27 +0100
message:
Set some member variables to 0 after they are finished with, which seems
to reduce segfaults with xulrunner-1.9.
modified:
plugin/plugin.cpp
------------------------------------------------------------
revno: 10396.1.3
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Mon 2008-12-08 11:21:43 +0100
message:
GIOFunc should signal whether to remove the g_source, not remove it
itself.
modified:
plugin/plugin.cpp
------------------------------------------------------------
revno: 10396.1.4
committer: Benjamin Wolsey <address@hidden>
branch nick: work
timestamp: Mon 2008-12-08 12:11:44 +0100
message:
Add Selection natives. Register all natives regardless of VM version.
modified:
libcore/asobj/ClassHierarchy.cpp
libcore/asobj/Global.cpp
libcore/asobj/Object.cpp
libcore/asobj/Selection_as.cpp
libcore/asobj/Selection_as.h
=== modified file 'libcore/asobj/ClassHierarchy.cpp'
--- a/libcore/asobj/ClassHierarchy.cpp 2008-12-08 08:30:13 +0000
+++ b/libcore/asobj/ClassHierarchy.cpp 2008-12-08 11:11:44 +0000
@@ -308,11 +308,14 @@
{ contextmenu_class_init, NSV::CLASS_CONTEXT_MENU, NSV::CLASS_OBJECT,
NSV::NS_FLASH_UI, 7 },
{ moviecliploader_class_init, NSV::CLASS_MOVIE_CLIP_LOADER,
NSV::CLASS_OBJECT, NS_GLOBAL, 7 },
{ Error_class_init, NSV::CLASS_ERROR, NSV::CLASS_OBJECT, NS_GLOBAL, 5 },
- { Accessibility_class_init, NSV::CLASS_ACCESSIBILITY,
NSV::CLASS_OBJECT, NS_GLOBAL, 5 }
-// These classes are all implicitly constructed; that is, it is not necessary
for
-// the class name to be used to construct the class, so they must always be
available.
+ { Accessibility_class_init, NSV::CLASS_ACCESSIBILITY,
NSV::CLASS_OBJECT,
+ NS_GLOBAL, 5 }
+// These classes are all implicitly constructed; that is, it is not
+// necessary for the class name to be used to construct the class, so
+// they must always be available.
// { object_class_init, NSV::CLASS_OBJECT, 0, NS_GLOBAL, 5 }
-// { function_class_init, NSV::CLASS_FUNCTION, NSV::CLASS_OBJECT,
NS_GLOBAL, 6 }
+// { function_class_init, NSV::CLASS_FUNCTION, NSV::CLASS_OBJECT,
+// NS_GLOBAL, 6 }
// { array_class_init, NSV::CLASS_ARRAY, NSV::CLASS_OBJECT, NS_GLOBAL, 5 }
// { string_class_init, NSV::CLASS_STRING, NSV::CLASS_OBJECT, NS_GLOBAL, 5
}
=== modified file 'libcore/asobj/Global.cpp'
--- a/libcore/asobj/Global.cpp 2008-12-08 08:30:13 +0000
+++ b/libcore/asobj/Global.cpp 2008-12-08 11:11:44 +0000
@@ -38,6 +38,7 @@
#include "Global.h"
#include "String_as.h"
#include "Key_as.h"
+#include "Selection_as.h"
//#include "LoadVars_as.h"
//#include "LocalConnection.h"
#include "Microphone.h"
@@ -108,23 +109,16 @@
static as_value as_global_asconstructor(const fn_call& /*fn*/);
static as_value as_global_updateAfterEvent(const fn_call& /*fn*/);
+namespace {
+ void registerNatives(as_object& global);
+}
+
Global::Global(VM& vm, ClassHierarchy *ch)
:
as_object()
{
- //-------------------------------------------------
- // Unclassified - TODO: move to appropriate section
- //
- // WARNING: this approach seems to be bogus, in
- // that the proprietary player seems to
- // always provide all the core classes it
- // supports, reguardless of target SWF version.
- // The only difference seems to be in actual
- // usability of them. For example some will
- // be available [ typeof(Name) == 'function' ]
- // but not instanciatable.
- //-------------------------------------------------
+ registerNatives(*this);
// No idea why, but it seems there's a NULL _global.o
// defined at player startup...
@@ -134,24 +128,17 @@
as_value nullVal; nullVal.set_null();
init_member("o", nullVal, as_prop_flags::dontEnum);
- // ASNew was dropped as a builtin function but exists
- // as ASnative.
- vm.registerNative(as_global_assetpropflags, 1, 0);
- vm.registerNative(as_global_asnew, 2, 0);
- vm.registerNative(as_global_assetnative, 4, 0);
- vm.registerNative(as_global_assetnativeaccessor, 4, 1);
- vm.registerNative(as_global_updateAfterEvent, 9, 0);
- vm.registerNative(timer_setinterval, 250, 0);
- vm.registerNative(timer_clearinterval, 250, 1);
-
// _global functions.
+ // These functions are only available in SWF6+, but this is just
+ // because SWF5 or lower did not have a "_global"
+ // reference at all.
init_member("ASnative", new builtin_function(as_global_asnative));
init_member("ASconstructor", new
builtin_function(as_global_asconstructor));
-
init_member("ASSetPropFlags", vm.getNative(1, 0));
init_member("ASSetNative", vm.getNative(4, 0));
init_member("ASSetNativeAccessor", vm.getNative(4, 1));
init_member("updateAfterEvent", vm.getNative(9, 0));
+ init_member("trace", vm.getNative(100, 4));
// Defined in timers.h
init_member("setInterval", vm.getNative(250, 0));
@@ -170,30 +157,16 @@
ch->massDeclare(version);
- /// Version-based initialization.
- //
- /// ASnative functions must always be available. Gnash
- /// loads classes on first use, so all ASnative functions
- /// must be registered separately on startup.
- //
- /// TODO: which ASnative functions are available for which
- /// VM version?
- /// TODO: establish when classes should be available (see
- /// note above).
-
- function_class_init(*this); // flagged for sole SWF6+ visibility
- object_class_init(*this); // flagged for sole SWF5+ visibility
- string_class_init(*this); // should be SWF5+ only
- array_class_init(*this); // should be only for SWF5+
-
- registerDateNative(*this);
-
- XMLNode_as::registerNative(*this);
-
- // LoadableObject has natives shared between LoadVars and XML, so
- // should be registered first.
- LoadableObject::registerNative(*this);
- XML_as::registerNative(*this);
+ object_class_init(*this);
+ string_class_init(*this);
+ array_class_init(*this);
+
+ /// SWF6 visibility:
+ function_class_init(*this);
+
+ // SWF8 visibility:
+ flash_package_init(*this);
+
switch (version)
{
@@ -205,7 +178,6 @@
case 7:
case 6:
- flash_package_init(*this); // will hide unless swf8 (by prop flags)
ch->getGlobalNs()->stubPrototype(NSV::CLASS_FUNCTION);
ch->getGlobalNs()->getClass(NSV::CLASS_FUNCTION)->setDeclared();
@@ -217,14 +189,8 @@
ch->getGlobalNs()->getClass(NSV::CLASS_ARRAY)->setDeclared();
ch->getGlobalNs()->stubPrototype(NSV::CLASS_STRING);
ch->getGlobalNs()->getClass(NSV::CLASS_STRING)->setDeclared();
-
- vm.registerNative(as_global_escape, 100, 0);
- vm.registerNative(as_global_unescape, 100, 1);
- vm.registerNative(as_global_parseint, 100, 2);
- vm.registerNative(as_global_parsefloat, 100, 3);
- vm.registerNative(as_global_isNaN, 200, 18);
- vm.registerNative(as_global_isfinite, 200, 19);
-
+ // This is surely not correct, but they are not available
+ // in SWF4
init_member("escape", vm.getNative(100, 0));
init_member("unescape", vm.getNative(100, 1));
init_member("parseInt", vm.getNative(100, 2));
@@ -232,25 +198,11 @@
init_member("isNaN", vm.getNative(200, 18));
init_member("isFinite", vm.getNative(200, 19));
- // NaN and Infinity should only be in _global since SWF6,
- // but this is just because SWF5 or lower did not have a "_global"
- // reference at all, most likely.
init_member("NaN", as_value(NaN));
- init_member("Infinity",
as_value(std::numeric_limits<double>::infinity()));
-
- registerColorNative(*this);
- registerTextFormatNative(*this);
- registerMouseNative(*this);
-
+ init_member("Infinity", as_value(
+ std::numeric_limits<double>::infinity()));
+
case 4:
-
- registerMathNative(*this);
- registerSystemNative(*this);
- registerStageNative(*this);
-
- vm.registerNative(as_global_trace, 100, 4);
- init_member("trace", vm.getNative(100, 4));
-
case 3:
case 2:
case 1:
@@ -686,6 +638,48 @@
}
+namespace {
+
+void
+registerNatives(as_object& global)
+{
+
+ VM& vm = global.getVM();
+
+ // ASNew was dropped as a builtin function but exists
+ // as ASnative.
+ vm.registerNative(as_global_assetpropflags, 1, 0);
+ vm.registerNative(as_global_asnew, 2, 0);
+ vm.registerNative(as_global_assetnative, 4, 0);
+ vm.registerNative(as_global_assetnativeaccessor, 4, 1);
+ vm.registerNative(as_global_updateAfterEvent, 9, 0);
+ vm.registerNative(as_global_escape, 100, 0);
+ vm.registerNative(as_global_unescape, 100, 1);
+ vm.registerNative(as_global_parseint, 100, 2);
+ vm.registerNative(as_global_parsefloat, 100, 3);
+ vm.registerNative(as_global_trace, 100, 4);
+ vm.registerNative(as_global_isNaN, 200, 18);
+ vm.registerNative(as_global_isfinite, 200, 19);
+ vm.registerNative(timer_setinterval, 250, 0);
+ vm.registerNative(timer_clearinterval, 250, 1);
+
+ registerSelectionNative(global);
+ registerDateNative(global);
+ registerColorNative(global);
+ registerTextFormatNative(global);
+ registerMouseNative(global);
+ registerMathNative(global);
+ registerSystemNative(global);
+ registerStageNative(global);
+
+ // LoadableObject has natives shared between LoadVars and XML, so
+ // should be registered first.
+ LoadableObject::registerNative(global);
+ XML_as::registerNative(global);
+ XMLNode_as::registerNative(global);
+
+}
+
#ifdef USE_EXTENSIONS
//-----------------------
@@ -713,4 +707,6 @@
#endif
+} // anonymous namespace
} // namespace gnash
+
=== modified file 'libcore/asobj/Object.cpp'
--- a/libcore/asobj/Object.cpp 2008-11-20 15:22:13 +0000
+++ b/libcore/asobj/Object.cpp 2008-12-08 11:11:44 +0000
@@ -183,7 +183,7 @@
}
// Register _global.Object (should only be visible in SWF5 up)
- int flags = as_prop_flags::dontEnum; // |as_prop_flags::onlySWF5Up;
+ int flags = as_prop_flags::dontEnum;
global.init_member("Object", cl.get(), flags);
}
=== modified file 'libcore/asobj/Selection_as.cpp'
--- a/libcore/asobj/Selection_as.cpp 2008-12-05 12:37:17 +0000
+++ b/libcore/asobj/Selection_as.cpp 2008-12-08 11:11:44 +0000
@@ -39,12 +39,12 @@
namespace gnash {
namespace {
- as_value selection_getbeginindex(const fn_call& fn);
- as_value selection_getcaretindex(const fn_call& fn);
- as_value selection_getendindex(const fn_call& fn);
- as_value selection_getfocus(const fn_call& fn);
- as_value selection_setfocus(const fn_call& fn);
- as_value selection_setselection(const fn_call& fn);
+ as_value selection_getBeginIndex(const fn_call& fn);
+ as_value selection_getCaretIndex(const fn_call& fn);
+ as_value selection_getEndIndex(const fn_call& fn);
+ as_value selection_getFocus(const fn_call& fn);
+ as_value selection_setFocus(const fn_call& fn);
+ as_value selection_setSelection(const fn_call& fn);
as_object* getSelectionInterface();
void attachSelectionInterface(as_object& o);
@@ -64,27 +64,37 @@
}
+void
+registerSelectionNative(as_object& global)
+{
+ VM& vm = global.getVM();
+
+ vm.registerNative(selection_getBeginIndex, 600, 0);
+ vm.registerNative(selection_getEndIndex, 600, 1);
+ vm.registerNative(selection_getCaretIndex, 600, 2);
+ vm.registerNative(selection_getFocus, 600, 3);
+ vm.registerNative(selection_setFocus, 600, 4);
+ vm.registerNative(selection_setSelection, 600, 5);
+}
+
namespace {
void
attachSelectionInterface(as_object& o)
{
+ VM& vm = o.getVM();
+
const int flags = as_prop_flags::dontEnum |
as_prop_flags::dontDelete |
as_prop_flags::readOnly;
- o.init_member("getBeginIndex",
- new builtin_function(selection_getbeginindex), flags);
- o.init_member("getCaretIndex",
- new builtin_function(selection_getcaretindex), flags);
- o.init_member("getEndIndex",
- new builtin_function(selection_getendindex), flags);
- o.init_member("getFocus",
- new builtin_function(selection_getfocus), flags);
- o.init_member("setFocus", new builtin_function(selection_setfocus),
flags);
- o.init_member("setSelection",
- new builtin_function(selection_setselection), flags);
+ o.init_member("getBeginIndex", vm.getNative(600, 0), flags);
+ o.init_member("getEndIndex", vm.getNative(600, 1), flags);
+ o.init_member("getCaretIndex", vm.getNative(600, 2), flags);
+ o.init_member("getFocus", vm.getNative(600, 3), flags);
+ o.init_member("setFocus", vm.getNative(600, 4), flags);
+ o.init_member("setSelection", vm.getNative(600, 5), flags);
/// Handles addListener, removeListener, and _listeners.
AsBroadcaster::initialize(o);
@@ -104,7 +114,7 @@
}
as_value
-selection_getbeginindex(const fn_call& fn)
+selection_getBeginIndex(const fn_call& fn)
{
boost::intrusive_ptr<as_object> ptr = ensureType<as_object>(fn.this_ptr);
@@ -126,7 +136,7 @@
/// base class, with a default implementation returning -1. We would still
/// have to check for no-focus events here, though.
as_value
-selection_getcaretindex(const fn_call& fn)
+selection_getCaretIndex(const fn_call& fn)
{
boost::intrusive_ptr<as_object> ptr = ensureType<as_object>(fn.this_ptr);
@@ -142,7 +152,7 @@
as_value
-selection_getendindex(const fn_call& fn)
+selection_getEndIndex(const fn_call& fn)
{
boost::intrusive_ptr<as_object> ptr = ensureType<as_object>(fn.this_ptr);
@@ -159,7 +169,7 @@
/// Returns null when there is no focus, otherwise the target of the
/// character.
as_value
-selection_getfocus(const fn_call& fn)
+selection_getFocus(const fn_call& fn)
{
boost::intrusive_ptr<as_object> ptr = ensureType<as_object>(fn.this_ptr);
@@ -194,7 +204,7 @@
// single argument can be a character or a full target path, otherwise it's
// a no-op and returns false.
as_value
-selection_setfocus(const fn_call& fn)
+selection_setFocus(const fn_call& fn)
{
boost::intrusive_ptr<as_object> ptr = ensureType<as_object>(fn.this_ptr);
@@ -241,7 +251,7 @@
as_value
-selection_setselection(const fn_call& fn)
+selection_setSelection(const fn_call& fn)
{
boost::intrusive_ptr<as_object> ptr = ensureType<as_object>(fn.this_ptr);
=== modified file 'libcore/asobj/Selection_as.h'
--- a/libcore/asobj/Selection_as.h 2008-12-05 07:35:49 +0000
+++ b/libcore/asobj/Selection_as.h 2008-12-08 11:11:44 +0000
@@ -16,10 +16,8 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
-#ifndef __GNASH_ASOBJ_SELECTION_H__
-#define __GNASH_ASOBJ_SELECTION_H__
-
-#include <memory> // for auto_ptr
+#ifndef GNASH_ASOBJ_SELECTION_H
+#define GNASH_ASOBJ_SELECTION_H
namespace gnash {
@@ -28,11 +26,10 @@
/// Initialize the global Selection class
void selection_class_init(as_object& global);
-/// Return a Selection instance (in case the core lib needs it)
-//std::auto_ptr<as_object> init_selection_instance();
+/// Register native selection methods
+void registerSelectionNative(as_object& global);
} // end of gnash namespace
-// __GNASH_ASOBJ_SELECTION_H__
#endif
=== modified file 'plugin/plugin.cpp'
--- a/plugin/plugin.cpp 2008-11-21 15:15:25 +0000
+++ b/plugin/plugin.cpp 2008-12-08 10:21:43 +0000
@@ -25,7 +25,7 @@
#define MIME_TYPES_HANDLED "application/x-shockwave-flash"
// The name must be this value to get flash movies that check the
// plugin version to load.
-#define PLUGIN_NAME "Shockwave Flash"
+#define PLUGIN_NAME "Shockwave Flash"
#define MIME_TYPES_DESCRIPTION MIME_TYPES_HANDLED":swf:"PLUGIN_NAME
// Some javascript plugin detectors use the description
@@ -33,7 +33,7 @@
// form (major version).(minor version) r(revision).
// e.g. "8.0 r99."
#define FLASH_VERSION DEFAULT_FLASH_MAJOR_VERSION"."\
- DEFAULT_FLASH_MINOR_VERSION" r"DEFAULT_FLASH_REV_NUMBER"."
+ DEFAULT_FLASH_MINOR_VERSION" r"DEFAULT_FLASH_REV_NUMBER"."
#define PLUGIN_DESCRIPTION \
"Shockwave Flash "FLASH_VERSION" Gnash "VERSION", the GNU SWF Player. \
@@ -56,7 +56,7 @@
#define GNASH_PLUGIN_DEBUG 1
#include <sys/param.h>
-#include "plugin.h" //Fixes Warning on redef of MIN/MAX
+#include "plugin.h"
#include <csignal>
#include "GnashSystemIOHeaders.h"
#include <cstdio>
@@ -96,8 +96,6 @@
# include <nsStringAPI.h>
#endif // HAVE_XPCOM
-using namespace std;
-
extern NPNetscapeFuncs NPNFuncs;
NPBool plugInitialized = FALSE;
@@ -130,7 +128,7 @@
char*
NPP_GetMIMEDescription(void)
{
- return const_cast<char *>(MIME_TYPES_DESCRIPTION);
+ return const_cast<char *>(MIME_TYPES_DESCRIPTION);
}
//
@@ -146,174 +144,174 @@
NPError
NS_PluginInitialize()
{
- if ( plugInitialized )
- {
+ if ( plugInitialized )
+ {
#if GNASH_PLUGIN_DEBUG > 1
- cout << "NS_PluginInitialize called, but ignored (we already
initialized)" << endl;
+ std::cout << "NS_PluginInitialize called, but ignored (we already
initialized)" << std::endl;
#endif
- return NPERR_NO_ERROR;
- }
+ return NPERR_NO_ERROR;
+ }
#if GNASH_PLUGIN_DEBUG > 1
- cout << "NS_PluginInitialize call
---------------------------------------------------" << endl;
+ std::cout << "NS_PluginInitialize call
---------------------------------------------------" << std::endl;
#endif
#ifdef HAVE_XPCOM
- if(!cookieManager) {
- nsIServiceManager *serviceManager = nsnull;
- NPError err;
- err = CallNPN_GetValueProc (NPNFuncs.getvalue,
- NULL, NPNVserviceManager,
- reinterpret_cast<void *>
- (reinterpret_cast<void
**>(&serviceManager)));
+ if(!cookieManager) {
+ nsIServiceManager *serviceManager = nsnull;
+ NPError err;
+ err = CallNPN_GetValueProc (NPNFuncs.getvalue,
+ NULL, NPNVserviceManager,
+ reinterpret_cast<void *>
+ (reinterpret_cast<void
**>(&serviceManager)));
- if (err != NPERR_NO_ERROR || !serviceManager) {
-#ifdef GNASH_PLUGIN_DEBUG
- cout << "[XPCOM] Failed to get the service manager" <<
endl;
-#endif
- return NPERR_GENERIC_ERROR;
- }
- nsresult rv;
- rv = serviceManager->GetServiceByContractID
(NS_COOKIEMANAGER_CONTRACTID,
- NS_GET_IID
(nsICookieManager),
-
reinterpret_cast<void **>(&cookieManager));
- if (NS_FAILED (rv) || !cookieManager) {
-#ifdef GNASH_PLUGIN_DEBUG
- cout << "[XPCOM] Failed to get CookieManager" << endl;
-#endif
- return NPERR_GENERIC_ERROR;
- }
+ if (err != NPERR_NO_ERROR || !serviceManager) {
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout << "[XPCOM] Failed to get the service manager" <<
std::endl;
+#endif
+ return NPERR_GENERIC_ERROR;
+ }
+ nsresult rv;
+ rv = serviceManager->GetServiceByContractID
(NS_COOKIEMANAGER_CONTRACTID,
+ NS_GET_IID (nsICookieManager),
+ reinterpret_cast<void **>(&cookieManager));
+ if (NS_FAILED (rv) || !cookieManager) {
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout << "[XPCOM] Failed to get CookieManager" << std::endl;
+#endif
+ return NPERR_GENERIC_ERROR;
+ }
#if GNASH_PLUGIN_DEBUG > 1
- cout << "[XPCOM] - CookieManager retrieved." << endl;
+ std::cout << "[XPCOM] - CookieManager retrieved." << std::endl;
#endif
- }
+ }
#endif // HAVE_XPCOM
- /* Browser Functionality Checks */
-
- NPError err = NPERR_NO_ERROR;
- PRBool supportsXEmbed = PR_TRUE;
- NPNToolkitType toolkit;
-
- /*
- 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)
- {
-#ifdef GNASH_PLUGIN_DEBUG
- cout << "NPAPI ERROR: No xEmbed support in this browser!"
- << endl;
-#endif
- return NPERR_INCOMPATIBLE_VERSION_ERROR;
- }
- else
- {
-#if GNASH_PLUGIN_DEBUG > 1
- cout << "xEmbed supported in this browser" << endl;
-#endif
- }
-
- err = CallNPN_GetValueProc(NPNFuncs.getvalue, NULL,
- NPNVToolkit,
- (void *)&toolkit);
-
- /*
- GTK2 support is currently also necessary. Fail if not
- present.
- */
- if (err != NPERR_NO_ERROR || toolkit != NPNVGtk2)
- {
-#ifdef GNASH_PLUGIN_DEBUG
- cout << "NPAPI ERROR: No GTK2 support in this browser!"
- " Have version " << (int)toolkit << endl;
-#endif
-
- return NPERR_INCOMPATIBLE_VERSION_ERROR;
- }
- else
- {
-#if GNASH_PLUGIN_DEBUG > 1
- cout << "GTK2 supported in this browser" << endl;
-#endif
- }
-
- /*
- Check for environment variables.
- */
- char* opts = std::getenv("GNASH_OPTIONS");
- if (opts != NULL)
- {
-#if GNASH_PLUGIN_DEBUG > 1
- cout << "GNASH_OPTIONS : " << opts << endl;
-#endif
-
- // Should the plugin wait for gdb to be attached?
- if ( strstr(opts, "waitforgdb") )
- {
- waitforgdb = true;
- }
-
- // Should the plugin write a script to invoke
- // the standalone player for debugging ?
- if ( strstr(opts, "writelauncher") )
- {
- createSaLauncher = true;
- }
-
- }
-
- // Append SYSCONFDIR/gnashpluginrc and ~/.gnashpluginrc to GNASHRC
- do {
- // TODO: extract content in a set, add to set
- // and serialize back (to avoid duplicates)
-
- std::string newGnashRc;
- char *gnashrc = std::getenv("GNASHRC");
- if ( gnashrc )
- {
- newGnashRc.assign(gnashrc);
- newGnashRc.append(":");
- }
-
- newGnashRc.append(SYSCONFDIR);
- newGnashRc.append("/gnashpluginrc");
-
- char *home = std::getenv("HOME");
- if ( home )
- {
- newGnashRc.append(":");
- newGnashRc.append(home);
- newGnashRc.append("/.gnashpluginrc");
- }
- else
- {
- cout << "WARNING: NPAPI plugin could not find user home
dir" << endl;
- }
-
- if ( setenv("GNASHRC", newGnashRc.c_str(), 1) )
- {
- cout << "WARNING: NPAPI plugin could not append to the
GNASHRC env variable" << endl;
- }
-#if GNASH_PLUGIN_DEBUG > 1
- else cout << "NOTE: NPAPI plugin set GNASHRC to " << newGnashRc
<< endl;
-#endif
-
- } while (0);
-
-
- /* Success */
-
- plugInitialized = TRUE;
-
- return NPERR_NO_ERROR;
+ /* Browser Functionality Checks */
+
+ NPError err = NPERR_NO_ERROR;
+ PRBool supportsXEmbed = PR_TRUE;
+ NPNToolkitType toolkit;
+
+ /*
+ 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)
+ {
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout << "NPAPI ERROR: No xEmbed support in this browser!"
+ << std::endl;
+#endif
+ return NPERR_INCOMPATIBLE_VERSION_ERROR;
+ }
+ else
+ {
+#if GNASH_PLUGIN_DEBUG > 1
+ std::cout << "xEmbed supported in this browser" << std::endl;
+#endif
+ }
+
+ err = CallNPN_GetValueProc(NPNFuncs.getvalue, NULL,
+ NPNVToolkit,
+ (void *)&toolkit);
+
+ /*
+ GTK2 support is currently also necessary. Fail if not
+ present.
+ */
+ if (err != NPERR_NO_ERROR || toolkit != NPNVGtk2)
+ {
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout << "NPAPI ERROR: No GTK2 support in this browser!"
+ " Have version " << (int)toolkit << std::endl;
+#endif
+
+ return NPERR_INCOMPATIBLE_VERSION_ERROR;
+ }
+ else
+ {
+#if GNASH_PLUGIN_DEBUG > 1
+ std::cout << "GTK2 supported in this browser" << std::endl;
+#endif
+ }
+
+ /*
+ Check for environment variables.
+ */
+ char* opts = std::getenv("GNASH_OPTIONS");
+ if (opts != NULL)
+ {
+#if GNASH_PLUGIN_DEBUG > 1
+ std::cout << "GNASH_OPTIONS : " << opts << std::endl;
+#endif
+
+ // Should the plugin wait for gdb to be attached?
+ if ( strstr(opts, "waitforgdb") )
+ {
+ waitforgdb = true;
+ }
+
+ // Should the plugin write a script to invoke
+ // the standalone player for debugging ?
+ if ( strstr(opts, "writelauncher") )
+ {
+ createSaLauncher = true;
+ }
+
+ }
+
+ // Append SYSCONFDIR/gnashpluginrc and ~/.gnashpluginrc to GNASHRC
+ do {
+ // TODO: extract content in a set, add to set
+ // and serialize back (to avoid duplicates)
+
+ std::string newGnashRc;
+ char *gnashrc = std::getenv("GNASHRC");
+ if ( gnashrc )
+ {
+ newGnashRc.assign(gnashrc);
+ newGnashRc.append(":");
+ }
+
+ newGnashRc.append(SYSCONFDIR);
+ newGnashRc.append("/gnashpluginrc");
+
+ char *home = std::getenv("HOME");
+ if ( home )
+ {
+ newGnashRc.append(":");
+ newGnashRc.append(home);
+ newGnashRc.append("/.gnashpluginrc");
+ }
+ else
+ {
+ std::cout << "WARNING: NPAPI plugin could not find user home dir"
<< std::endl;
+ }
+
+ if ( setenv("GNASHRC", newGnashRc.c_str(), 1) )
+ {
+ std::cout << "WARNING: NPAPI plugin could not append to the
GNASHRC env variable" << std::endl;
+ }
+#if GNASH_PLUGIN_DEBUG > 1
+ else std::cout << "NOTE: NPAPI plugin set GNASHRC to " << newGnashRc
<< std::endl;
+#endif
+
+ } while (0);
+
+
+ /* Success */
+
+ plugInitialized = TRUE;
+
+ return NPERR_NO_ERROR;
}
/// \brief Shutdown the plugin
@@ -326,15 +324,15 @@
NS_PluginShutdown()
{
#if 0
- if (!plugInitialized)
- {
+ if (!plugInitialized)
+ {
#if GNASH_PLUGIN_DEBUG > 1
- cout << "Plugin already shut down" << endl;
+ std::cout << "Plugin already shut down" << std::endl;
#endif
- return;
- }
+ return;
+ }
- plugInitialized = FALSE;
+ plugInitialized = FALSE;
#endif
}
@@ -348,40 +346,40 @@
NPError
NS_PluginGetValue(NPPVariable aVariable, void *aValue)
{
- NPError err = NPERR_NO_ERROR;
-
- switch (aVariable)
- {
- case NPPVpluginNameString:
- *static_cast<const char **> (aValue) = PLUGIN_NAME;
- break;
-
- // This becomes the description field you see below the opening
- // 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();
- break;
-
- case NPPVpluginNeedsXEmbed:
+ NPError err = NPERR_NO_ERROR;
+
+ switch (aVariable)
+ {
+ case NPPVpluginNameString:
+ *static_cast<const char **> (aValue) = PLUGIN_NAME;
+ break;
+
+ // This becomes the description field you see below the opening
+ // 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();
+ break;
+
+ case NPPVpluginNeedsXEmbed:
#ifdef HAVE_GTK2
- *static_cast<PRBool *>(aValue) = PR_TRUE;
+ *static_cast<PRBool *>(aValue) = PR_TRUE;
#else
- *static_cast<PRBool *>(aValue) = PR_FALSE;
+ *static_cast<PRBool *>(aValue) = PR_FALSE;
#endif
- break;
-
- case NPPVpluginTimerInterval:
-
- case NPPVpluginKeepLibraryInMemory:
-
- default:
- err = NPERR_INVALID_PARAM;
- break;
- }
- return err;
+ break;
+
+ case NPPVpluginTimerInterval:
+
+ case NPPVpluginKeepLibraryInMemory:
+
+ default:
+ err = NPERR_INVALID_PARAM;
+ break;
+ }
+ return err;
}
/// \brief construct our plugin instance object
@@ -391,9 +389,9 @@
nsPluginInstanceBase *
NS_NewPluginInstance(nsPluginCreateData * aCreateDataStruct)
{
- if(!aCreateDataStruct) return NULL;
+ if(!aCreateDataStruct) return NULL;
- return new nsPluginInstance(aCreateDataStruct);
+ return new nsPluginInstance(aCreateDataStruct);
}
/// \brief destroy our plugin instance object
@@ -401,9 +399,9 @@
/// This destroys our instantiated object via a C++ function used by the
/// browser.
void
-NS_DestroyPluginInstance(nsPluginInstanceBase * aPlugin)
+NS_DestroyPluginInstance(nsPluginInstanceBase* aPlugin)
{
- delete static_cast<nsPluginInstance *> (aPlugin);
+ delete static_cast<nsPluginInstance *> (aPlugin);
}
//
@@ -412,40 +410,40 @@
/// \brief Constructor
nsPluginInstance::nsPluginInstance(nsPluginCreateData* data)
- :
- nsPluginInstanceBase(),
- _instance(data->instance),
- _window(0),
- _width(0),
- _height(0),
- _streamfd(-1),
- _ichan(0),
- _ichanWatchId(0),
- _childpid(0),
- _filefd(-1),
- _name()
+ :
+ nsPluginInstanceBase(),
+ _instance(data->instance),
+ _window(0),
+ _width(0),
+ _height(0),
+ _streamfd(-1),
+ _ichan(0),
+ _ichanWatchId(0),
+ _childpid(0),
+ _filefd(-1),
+ _name()
{
- for (size_t i=0, n=data->argc; i<n; ++i)
- {
- string name, val;
-
- if (data->argn[i])
- {
- name = data->argn[i];
- }
-
- if (data->argv[i])
- {
- val = data->argv[i];
- }
-
- if ( ! strcasecmp(name.c_str(), "name") )
- {
- _name = val;
- }
-
- _params[name] = val;
- }
+ for (size_t i=0, n=data->argc; i<n; ++i)
+ {
+ string name, val;
+
+ if (data->argn[i])
+ {
+ name = data->argn[i];
+ }
+
+ if (data->argv[i])
+ {
+ val = data->argv[i];
+ }
+
+ if ( ! strcasecmp(name.c_str(), "name") )
+ {
+ _name = val;
+ }
+
+ _params[name] = val;
+ }
}
@@ -453,26 +451,30 @@
nsPluginInstance::~nsPluginInstance()
{
#if GNASH_PLUGIN_DEBUG > 1
- cout << "plugin instance destruction" << endl;
+ std::cout << "plugin instance destruction" << std::endl;
#endif
- if ( _ichan )
- {
+ if (_ichan)
+ {
#if GNASH_PLUGIN_DEBUG > 1
- cout << "shutting down input chan " << _ichan << endl;
+ std::cout << "shutting down input chan " << _ichan << std::endl;
#endif
- GError *error = NULL;
- g_io_channel_shutdown (_ichan, TRUE, &error);
- g_io_channel_unref (_ichan);
- }
- if ( _ichanWatchId )
- {
- g_source_remove(_ichanWatchId);
- }
+ GError *error = NULL;
+ g_io_channel_shutdown (_ichan, TRUE, &error);
+ g_io_channel_unref (_ichan);
+ _ichan = 0;
+ }
+
+ if ( _ichanWatchId )
+ {
+ g_source_remove(_ichanWatchId);
+ _ichanWatchId = 0;
+ }
// TODO: unlink the cookie jar
if ( ! _cookieFile.empty() ) {
#ifdef GNASH_PLUGIN_DEBUG
- cout << " ~nsPluginInstance: file " << _cookieFile << " should be
unlinked!" << endl;
+ std::cout << " ~nsPluginInstance: file " << _cookieFile
+ << " should be unlinked!" << std::endl;
#endif
}
}
@@ -485,37 +487,27 @@
NPBool
nsPluginInstance::init(NPWindow* aWindow)
{
- if(!aWindow)
- {
+ if(!aWindow)
+ {
#ifdef GNASH_PLUGIN_DEBUG
- cout << __PRETTY_FUNCTION__ << " ERROR: Window handle was
bogus!" << endl;
+ std::cout << __PRETTY_FUNCTION__ << " ERROR: Window handle was bogus!"
+ << std::endl;
#endif
- return FALSE;
- }
- else
- {
+ return FALSE;
+ }
+ else
+ {
#if GNASH_PLUGIN_DEBUG > 1
- cout << "X origin: = " << aWindow->x
- << ", Y Origin = " << aWindow->y
- << ", Width = " << aWindow->width
- << ", Height = " << aWindow->height
- << ", WindowID = " << aWindow->window
- << ", this = " << static_cast<void*>(this) << endl;
+ std::cout << "X origin: = " << aWindow->x
+ << ", Y Origin = " << aWindow->y
+ << ", Width = " << aWindow->width
+ << ", Height = " << aWindow->height
+ << ", WindowID = " << aWindow->window
+ << ", this = " << static_cast<void*>(this) << std::endl;
#endif
- }
-
-#if 0
- // Only for developers. Make the plugin block here so we can
- // attach GDB to it.
-
- bool gdb = true;
- while (gdb) {
- cout << "Waiting for GDB for pid " << getpid() << endl;
- sleep(5);
}
-#endif
- return TRUE;
+ return TRUE;
}
/// \brief Shutdown an instantiated object
@@ -527,23 +519,23 @@
nsPluginInstance::shut()
{
#if GNASH_PLUGIN_DEBUG > 1
- cout << "Gnash plugin shutting down" << endl;
+ std::cout << "Gnash plugin shutting down" << std::endl;
#endif
- 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
- kill(_childpid, SIGTERM);
- int status;
- waitpid(_childpid, &status, 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
+ kill(_childpid, SIGTERM);
+ int status;
+ waitpid(_childpid, &status, 0);
#if GNASH_PLUGIN_DEBUG > 1
- cout << "Child process exited with status " << status << endl;
+ std::cout << "Child process exited with status " << status <<
std::endl;
#endif
- }
+ }
- _childpid = 0;
+ _childpid = 0;
}
/// \brief Set the window to be used to render in
@@ -556,37 +548,38 @@
NPError
nsPluginInstance::SetWindow(NPWindow* aWindow)
{
- if(!aWindow)
- {
+ if(!aWindow)
+ {
#ifdef GNASH_PLUGIN_DEBUG
- cout << __FUNCTION__ << ": ERROR: Window handle was bogus!" <<
endl;
+ std::cout << __FUNCTION__ << ": ERROR: Window handle was bogus!"
+ << std::endl;
#endif
- return NPERR_INVALID_PARAM;
+ return NPERR_INVALID_PARAM;
#if 0
- }
- else
- {
- log_debug("%s: X origin = %d, Y Origin = %d, Width = %d,"
- " Height = %d, WindowID = %p, this = %p",
- __FUNCTION__,
- aWindow->x, aWindow->y, aWindow->width, aWindow->height,
- aWindow->window, this);
+ }
+ else
+ {
+ log_debug("%s: X origin = %d, Y Origin = %d, Width = %d,"
+ " Height = %d, WindowID = %p, this = %p",
+ __FUNCTION__,
+ aWindow->x, aWindow->y, aWindow->width, aWindow->height,
+ aWindow->window, this);
#endif
- }
-
- _width = aWindow->width;
- _height = aWindow->height;
-
- _window = reinterpret_cast<Window> (aWindow->window);
-
- return NPERR_NO_ERROR;
+ }
+
+ _width = aWindow->width;
+ _height = aWindow->height;
+
+ _window = reinterpret_cast<Window> (aWindow->window);
+
+ return NPERR_NO_ERROR;
}
NPError
nsPluginInstance::GetValue(NPPVariable aVariable, void *aValue)
{
- return NS_PluginGetValue(aVariable, aValue) ;
+ return NS_PluginGetValue(aVariable, aValue);
}
/// \brief Write a status message
@@ -596,16 +589,16 @@
NPError
nsPluginInstance::WriteStatus(char *msg) const
{
- NPN_Status(_instance, msg);
- cout << msg << endl;
+ NPN_Status(_instance, msg);
+ std::cout << msg << std::endl;
- return NPERR_NO_ERROR;
+ return NPERR_NO_ERROR;
}
NPError
nsPluginInstance::WriteStatus(std::string msg) const
{
- return WriteStatus( const_cast<char*>(msg.c_str()) );
+ return WriteStatus(const_cast<char*>(msg.c_str()));
}
/// \brief Open a new data stream
@@ -619,50 +612,48 @@
/// So this is where we parse the URL to get all the options passed in
/// when invoking the plugin.
NPError
-nsPluginInstance::NewStream(NPMIMEType /* type */, NPStream * stream,
- NPBool /* seekable */, uint16_t * /* stype */)
+nsPluginInstance::NewStream(NPMIMEType /*type*/, NPStream* stream,
+ NPBool /*seekable*/, uint16_t* /*stype*/)
{
- _swf_url = stream->url;
+ _swf_url = stream->url;
#if GNASH_PLUGIN_DEBUG > 1
- cout << __FUNCTION__ << ": The full URL is " << _swf_url << endl;
+ std::cout << __FUNCTION__ << ": The full URL is " << _swf_url << std::endl;
#endif
#ifdef WRITE_FILE
- size_t start, end;
- string fname;
- end = _swf_url.find(".swf", 0) + 4;
- start = _swf_url.rfind("/", end) + 1;
- fname = "/tmp/";
- fname += _swf_url.substr(start, end - start);
+ size_t start, end;
+ string fname;
+ end = _swf_url.find(".swf", 0) + 4;
+ start = _swf_url.rfind("/", end) + 1;
+ fname = "/tmp/";
+ fname += _swf_url.substr(start, end - start);
#if GNASH_PLUGIN_DEBUG > 1
- cout << "The Flash movie name is: " << fname << endl;
-#endif
-
- _filefd = open(fname.c_str(), O_CREAT | O_WRONLY,
S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
-
- if (_filefd < 0)
- {
- _filefd = open(fname.c_str(), O_TRUNC | O_WRONLY,
S_IRUSR|S_IRGRP|S_IROTH);
- }
-#endif
-
- startProc(_window);
-
- return NPERR_NO_ERROR;
+ std::cout << "The Flash movie name is: " << fname << std::endl;
+#endif
+
+ _filefd = open(fname.c_str(),
+ O_CREAT | O_WRONLY
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
+
+ if (_filefd < 0)
+ {
+ _filefd = open(fname.c_str(),
+ O_TRUNC | O_WRONLY,
+ S_IRUSR | S_IRGRP | S_IROTH);
+ }
+#endif
+
+ startProc(_window);
+
+ return NPERR_NO_ERROR;
}
/// \brief Destroy the data stream we've been reading.
NPError
-nsPluginInstance::DestroyStream(NPStream * /* stream */, NPError /* reason */)
+nsPluginInstance::DestroyStream(NPStream* /*stream*/, NPError /*reason*/)
{
-#if 0
- nsPluginInstance *arg = (nsPluginInstance *)this;
- log_debug("%s: this = %p, URL is %s", __PRETTY_FUNCTION__,
- (void *)arg, stream->url);
-#endif
-
if (_streamfd != -1)
{
if (close(_streamfd) == -1)
@@ -694,219 +685,224 @@
/// \brief Return how many bytes we can read into the buffer
int32_t
-nsPluginInstance::WriteReady(NPStream * /* stream */ )
+nsPluginInstance::WriteReady(NPStream* /* stream */ )
{
#if GNASH_PLUGIN_DEBUG > 1
- //cout << "Stream for " << stream->url << " is ready" << endl;
+ //std::cout << "Stream for " << stream->url << " is ready" << std::endl;
#endif
- if ( _streamfd != -1 ) return 1024;
- else return 0;
+ if ( _streamfd != -1 ) return 1024;
+ else return 0;
}
/// \brief Read the data stream from Mozilla/Firefox
///
/// For now we read the bytes and write them to a disk file.
int32_t
-nsPluginInstance::Write(NPStream * /* stream */, int32_t /* offset */, int32_t
len,
- void * buffer)
+nsPluginInstance::Write(NPStream* /*stream*/, int32_t /*offset*/, int32_t len,
+ void* buffer)
{
-
-#if 0
- log_debug("Reading Stream %s, offset is %d, length = %d",
- stream->url, offset, len);
-#endif
-
#ifdef WRITE_FILE
- write(_filefd, buffer, len);
+ write(_filefd, buffer, len);
#endif
- return write(_streamfd, buffer, len);
+ return write(_streamfd, buffer, len);
}
bool
-nsPluginInstance::handlePlayerRequestsWrapper(GIOChannel* iochan, GIOCondition
cond, nsPluginInstance* plugin)
+nsPluginInstance::handlePlayerRequestsWrapper(GIOChannel* iochan,
+ GIOCondition cond, nsPluginInstance* plugin)
{
- return plugin->handlePlayerRequests(iochan, cond);
+ return plugin->handlePlayerRequests(iochan, cond);
}
bool
nsPluginInstance::handlePlayerRequests(GIOChannel* iochan, GIOCondition cond)
{
- if ( cond & G_IO_HUP )
- {
-#if GNASH_PLUGIN_DEBUG > 1
- cout << "Player request channel hang up" << endl;
-#endif
- g_source_remove(_ichanWatchId);
- return false;
- }
-
- assert(cond & G_IO_IN);
-
-#if GNASH_PLUGIN_DEBUG > 1
- int inputfd = g_io_channel_unix_get_fd(iochan);
- cout << "Checking player requests on fd " << inputfd << endl;
-#endif
-
- do
- {
- GError* error=NULL;
- gchar* request;
- gsize requestSize=0;
- GIOStatus status = g_io_channel_read_line(iochan, &request,
&requestSize, NULL, &error);
- switch ( status )
- {
- case G_IO_STATUS_ERROR:
-#ifdef GNASH_PLUGIN_DEBUG
- cout << "Error reading request line: " <<
error->message << endl;
-#endif
- g_error_free(error);
- return false;
- case G_IO_STATUS_EOF:
-#ifdef GNASH_PLUGIN_DEBUG
- cout << "EOF (error:" << error << ")" << endl;
-#endif
- return false;
- case G_IO_STATUS_AGAIN:
-#ifdef GNASH_PLUGIN_DEBUG
- cout << "Read again (error:" << error << ")" <<
endl;
-#endif
- break;
- case G_IO_STATUS_NORMAL:
- // process request
-#if GNASH_PLUGIN_DEBUG > 1
- cout << "Normal read: " << request << "
(error:" << error << ")" << endl;
-#endif
- break;
- default:
-#ifdef GNASH_PLUGIN_DEBUG
- cout << "Abnormal status " << status << "
(error:" << error << ")" << endl;
-#endif
- return false;
-
- }
-
- // process request..
- processPlayerRequest(request, requestSize);
- g_free(request);
-
- } while (g_io_channel_get_buffer_condition(iochan) & G_IO_IN);
-
- return true;
+ if ( cond & G_IO_HUP )
+ {
+#if GNASH_PLUGIN_DEBUG > 1
+ std::cout << "Player request channel hang up" << std::endl;
+#endif
+ // false signals that the source should be removed.
+ return false;
+ }
+
+ assert(cond & G_IO_IN);
+
+#if GNASH_PLUGIN_DEBUG > 1
+ int inputfd = g_io_channel_unix_get_fd(iochan);
+ std::cout << "Checking player requests on fd " << inputfd << std::endl;
+#endif
+
+ do
+ {
+ GError* error=NULL;
+ gchar* request;
+ gsize requestSize=0;
+ GIOStatus status = g_io_channel_read_line(iochan, &request,
+ &requestSize, NULL, &error);
+
+ switch ( status )
+ {
+ case G_IO_STATUS_ERROR:
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout << "Error reading request line: " << error->message
+ << std::endl;
+#endif
+ g_error_free(error);
+ return false;
+ case G_IO_STATUS_EOF:
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout << "EOF (error:" << error << ")" << std::endl;
+#endif
+ return false;
+ case G_IO_STATUS_AGAIN:
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout << "Read again (error:" << error << ")" << std::endl;
+#endif
+ break;
+ case G_IO_STATUS_NORMAL:
+ // process request
+#if GNASH_PLUGIN_DEBUG > 1
+ std::cout << "Normal read: " << request << " (error:"
+ << error << ")" << std::endl;
+#endif
+ break;
+ default:
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout << "Abnormal status " << status << " (error:"
+ << error << ")" << std::endl;
+#endif
+ return false;
+
+ }
+
+ // process request..
+ processPlayerRequest(request, requestSize);
+ g_free(request);
+
+ } while (g_io_channel_get_buffer_condition(iochan) & G_IO_IN);
+
+ return true;
}
bool
nsPluginInstance::processPlayerRequest(gchar* buf, gsize linelen)
{
- if ( linelen < 4 )
- {
-#ifdef GNASH_PLUGIN_DEBUG
- cout << "Invalid player request (too short): " << buf << endl;
-#endif
- return false;
- }
-
- if ( ! strncmp(buf, "GET ", 4) )
- {
- char* target = buf + 4;
- if ( ! *target )
- {
-#ifdef GNASH_PLUGIN_DEBUG
- cout << "No target found after GET request" << endl;
-#endif
- return false;
- }
- char* url = target;
- while (*url && *url != ':') ++url;
- if ( *url )
- {
- *url='\0';
- ++url;
- }
- else
- {
-#ifdef GNASH_PLUGIN_DEBUG
- cout << "No colon found after GETURL target string" <<
endl;
-#endif
- return false;
- }
-
-#if GNASH_PLUGIN_DEBUG > 1
- cout << "Asked to get URL '" << url << "' in target '" <<
target << "'" << endl;
-#endif
- NPN_GetURL(_instance, url, target);
- return true;
-
- }
- else if ( ! strncmp(buf, "INVOKE ", 7) )
- {
- char* command = buf + 7;
- if ( ! *command ) {
-#ifdef GNASH_PLUGIN_DEBUG
- cout << "No command found after INVOKE request" << endl;
-#endif
- return false;
- }
- char* arg = command;
- while (*arg && *arg != ':') ++arg;
- if ( *arg ) {
- *arg='\0';
- ++arg;
- } else {
-#ifdef GNASH_PLUGIN_DEBUG
- cout << "No colon found after INVOKE command string" <<
endl;
-#endif
- return false;
- }
-
- std::string name = _name;
-
- std::stringstream jsurl;
- jsurl << "javascript:" << name << "_DoFSCommand('" << command
<< "','" << arg <<"')";
-
- // TODO: check if _self is a good target for this
- static const char* tgt = "_self";
-
-#if GNASH_PLUGIN_DEBUG > 1
- cout << "Calling NPN_GetURL(" << jsurl.str() << ", '" << tgt <<
"');" << endl;
-#endif
- NPN_GetURL(_instance, jsurl.str().c_str(), tgt);
- return true;
- }
+ if ( linelen < 4 )
+ {
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout << "Invalid player request (too short): " << buf <<
std::endl;
+#endif
+ return false;
+ }
+
+ if ( ! strncmp(buf, "GET ", 4) )
+ {
+ char* target = buf + 4;
+ if ( ! *target )
+ {
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout << "No target found after GET request" << std::endl;
+#endif
+ return false;
+ }
+ char* url = target;
+ while (*url && *url != ':') ++url;
+ if ( *url )
+ {
+ *url='\0';
+ ++url;
+ }
+ else
+ {
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout << "No colon found after GETURL target string"
+ << std::endl;
+#endif
+ return false;
+ }
+
+#if GNASH_PLUGIN_DEBUG > 1
+ std::cout << "Asked to get URL '" << url << "' in target '"
+ << target << "'" << std::endl;
+#endif
+ NPN_GetURL(_instance, url, target);
+ return true;
+
+ }
+ else if ( ! strncmp(buf, "INVOKE ", 7) )
+ {
+ char* command = buf + 7;
+ if ( ! *command ) {
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout << "No command found after INVOKE request" << std::endl;
+#endif
+ return false;
+ }
+ char* arg = command;
+ while (*arg && *arg != ':') ++arg;
+ if ( *arg ) {
+ *arg='\0';
+ ++arg;
+ } else {
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout << "No colon found after INVOKE command string"
+ << std::endl;
+#endif
+ return false;
+ }
+
+ std::string name = _name;
+
+ std::stringstream jsurl;
+ jsurl << "javascript:" << name << "_DoFSCommand('" << command << "','"
<< arg <<"')";
+
+ // TODO: check if _self is a good target for this
+ static const char* tgt = "_self";
+
+#if GNASH_PLUGIN_DEBUG > 1
+ std::cout << "Calling NPN_GetURL(" << jsurl.str() << ", '" << tgt <<
"');" << std::endl;
+#endif
+ NPN_GetURL(_instance, jsurl.str().c_str(), tgt);
+ return true;
+ }
else if ( ! strncmp(buf, "POST ", 5))
{
char* target = buf + 5;
if (! *target) return false;
-
+
char* postdata = target;
while (*postdata && *postdata != ':') ++postdata;
- if ( *postdata )
- {
- *postdata='\0';
- ++postdata;
- }
- else
- {
+ if ( *postdata )
+ {
+ *postdata='\0';
+ ++postdata;
+ }
+ else
+ {
#ifdef GNASH_PLUGIN_DEBUG
- cout << "No colon found after getURL postdata string"
<< endl;
+ std::cout << "No colon found after getURL postdata string"
+ << std::endl;
#endif
- return false;
- }
-
+ return false;
+ }
+
char* url = postdata;
while (*url && *url != '$') ++url;
- if (*url)
- {
- *url='\0';
- ++url;
- }
- else
- {
+ if (*url)
+ {
+ *url='\0';
+ ++url;
+ }
+ else
+ {
#ifdef GNASH_PLUGIN_DEBUG
- cout << "No $ character found after getURL target
string" << endl;
+ std::cout << "No $ character found after getURL target string"
+ << std::endl;
#endif
- return false;
- }
+ return false;
+ }
NPN_PostURL(_instance, url, target, std::strlen(postdata),
@@ -914,76 +910,89 @@
return true;
}
- else
- {
+ else
+ {
#ifdef GNASH_PLUGIN_DEBUG
- cout << "Unknown player request: '" << buf << "'" << endl;
+ std::cout << "Unknown player request: '" << buf << "'" << std::endl;
#endif
- return false;
- }
+ return false;
+ }
}
#ifdef GNASH_XPI_PLUGIN
static int
getHome(string& gnashpath)
{
- nsresult rv;
-
- // this is probably a good place to get the service manager
- // note that Mozilla will add reference, so do not forget to release
- nsISupports * sm = NULL;
-
- // Get service manager
-#if GNASH_PLUGIN_DEBUG > 1
- cout << "Getting Path" << NPN_GetValue(NULL, NPNVserviceManager, &sm)
<< "\n";
-#endif
-
- // Mozilla returns nsIServiceManager so we can use it directly;
- // doing QI on nsISupports here can still be more appropriate in
- // case something is changed in the future so we don't need to
- // do casting of any sort.
-
- // valid service manager
- if(!sm) return -1;
-
- nsIServiceManager * gServiceManager = NULL;
- rv = sm->QueryInterface(NS_GET_IID(nsIServiceManager),
(void**)&gServiceManager);
-
- nsIFile *file = NULL;
- nsIInstallLocation * installLocation = NULL;
- nsIExtensionManager * nsExtensionService = NULL;
-
- // Gets extension service
- rv =
gServiceManager->GetServiceByContractID("@mozilla.org/extensions/manager;1",
NS_GET_IID(nsIExtensionManager), (void **)&nsExtensionService);
-#if GNASH_PLUGIN_DEBUG > 1
- cout << "gSM" << rv << " " << (nsExtensionService == NULL) << "\n";
-#endif
- if (!nsExtensionService) return -2;
-
- // Gets install location object
- rv =
nsExtensionService->GetInstallLocation(NS_LITERAL_STRING("{2b70f2b1-fc72-4734-bb81-4eb2a7713e49}"),
(nsIInstallLocation**)&installLocation);
-#if GNASH_PLUGIN_DEBUG > 1
- cout << "nES" << rv << " " << (installLocation == NULL) << "\n";
-#endif
- if (!installLocation) return -3;
-
- // Gets information on file in the extension - here, "address@hidden"
is the ID of the plugin. install.rdf is a file stored in the plugin
- rv =
installLocation->GetItemFile(NS_LITERAL_STRING("{2b70f2b1-fc72-4734-bb81-4eb2a7713e49}"),
NS_LITERAL_STRING("plugins/gnash"), (nsIFile**)&file);
-#if GNASH_PLUGIN_DEBUG > 1
- cout << "iL" << rv << " " << (file == NULL) << "\n";
-#endif
- if (!file) return -4;
-
- // We get the path (stored as unicode in nsName)
- nsString sName;
- file->GetPath(sName);
-
- //const NPString& propValue =
NS_LossyConvertUTF16toASCII(sName);
- gnashpath = ToNewCString(NS_LossyConvertUTF16toASCII(sName));
-#if GNASH_PLUGIN_DEBUG > 1
- cout << "Path" << gnashpath << "\n";
-#endif
- return 0;
+ nsresult rv;
+
+ // this is probably a good place to get the service manager
+ // note that Mozilla will add reference, so do not forget to release
+ nsISupports * sm = NULL;
+
+ // Get service manager
+#if GNASH_PLUGIN_DEBUG > 1
+ std::cout << "Getting Path" << NPN_GetValue(NULL, NPNVserviceManager, &sm)
+ << std::endl;
+#endif
+
+ // Mozilla returns nsIServiceManager so we can use it directly;
+ // doing QI on nsISupports here can still be more appropriate in
+ // case something is changed in the future so we don't need to
+ // do casting of any sort.
+
+ // valid service manager
+ if (!sm) return -1;
+
+ nsIServiceManager * gServiceManager = NULL;
+ rv = sm->QueryInterface(NS_GET_IID(nsIServiceManager),
+ (void**)&gServiceManager);
+
+ nsIFile *file = NULL;
+ nsIInstallLocation * installLocation = NULL;
+ nsIExtensionManager * nsExtensionService = NULL;
+
+ // Gets extension service
+ rv = gServiceManager->GetServiceByContractID(
+ "@mozilla.org/extensions/manager;1",
+ NS_GET_IID(nsIExtensionManager), (void **)&nsExtensionService);
+
+#if GNASH_PLUGIN_DEBUG > 1
+ std::cout << "gSM" << rv << " " << (nsExtensionService == NULL) << "\n";
+#endif
+
+ if (!nsExtensionService) return -2;
+
+ // Gets install location object
+ rv = nsExtensionService->GetInstallLocation(
+ NS_LITERAL_STRING("{2b70f2b1-fc72-4734-bb81-4eb2a7713e49}"),
+ (nsIInstallLocation**)&installLocation);
+
+#if GNASH_PLUGIN_DEBUG > 1
+ std::cout << "nES" << rv << " " << (installLocation == NULL) << "\n";
+#endif
+
+ if (!installLocation) return -3;
+
+ // Gets information on file in the extension - here,
+ // "address@hidden" is the ID of the plugin. install.rdf
+ // is a file stored in the plugin
+ rv = installLocation->GetItemFile(
+ NS_LITERAL_STRING("{2b70f2b1-fc72-4734-bb81-4eb2a7713e49}"),
+ NS_LITERAL_STRING("plugins/gnash"), (nsIFile**)&file);
+#if GNASH_PLUGIN_DEBUG > 1
+ std::cout << "iL" << rv << " " << (file == NULL) << "\n";
+#endif
+ if (!file) return -4;
+
+ // We get the path (stored as unicode in nsName)
+ nsString sName;
+ file->GetPath(sName);
+
+ gnashpath = ToNewCString(NS_LossyConvertUTF16toASCII(sName));
+#if GNASH_PLUGIN_DEBUG > 1
+ std::cout << "Path" << gnashpath << "\n";
+#endif
+ return 0;
}
#endif // GNASH_XPI_PLUGIN
@@ -992,7 +1001,8 @@
{
if ( ! _cookieFile.empty() ) {
#ifdef GNASH_PLUGIN_DEBUG
- cout << " dumpCookies: file " << _cookieFile << " should be
unlinked!" << endl;
+ std::cout << " dumpCookies: file " << _cookieFile
+ << " should be unlinked!" << std::endl;
#endif
}
_cookieFile.clear();
@@ -1001,126 +1011,129 @@
//#ifdef HAVE_XPCOM
#if 0
#if GNASH_PLUGIN_DEBUG > 1
- cout << "[XPCOM] trying to dump cookies" << endl;
-#endif
-
- nsCOMPtr<nsISimpleEnumerator> cookie_e;
- nsresult rv = cookieManager->GetEnumerator(getter_AddRefs(cookie_e));
-
- //char *cookiefile = NULL;
-
- if(NS_SUCCEEDED(rv)) {
- PRBool res = FALSE;
- ofstream fout;
- mode_t oldmask = umask(0077);
- char tmpnamebuf[L_tmpnam];
- while(!res) {
- const char *tmpname = tmpnam(tmpnamebuf);
- fout.open(tmpname, ios::out | ios::trunc);
- if(!fout.is_open()) {
-#ifdef GNASH_PLUGIN_DEBUG
- cout << "[XPCOM] cookie file not opened!!" <<
endl;
-#endif
- continue;
- } else {
-#if GNASH_PLUGIN_DEBUG > 1
- cout << "[XPCOM] opened cookie store: " <<
tmpname << endl;
-#endif
- }
- res = TRUE;
- _cookieFile = tmpname; // assign ?
- }
- umask(oldmask);
-
- res = TRUE;
- int c = 0;
- while(NS_SUCCEEDED(cookie_e->HasMoreElements(&res)) && res ) {
- nsCOMPtr<nsICookie> cookie;
- cookie_e->GetNext(getter_AddRefs(cookie));
- if(!cookie)
- continue;
-
- nsCString host;
- if(NS_FAILED(cookie->GetHost(host))) {
-#ifdef GNASH_PLUGIN_DEBUG
- cout << "[XPCOM] cookie without host ... ommitting"
<< endl;
-#endif
- continue;
- }
- nsCString path;
- if(NS_FAILED(cookie->GetPath(path))) {
-#ifdef GNASH_PLUGIN_DEBUG
- cout << "[XPCOM] cookie without path ... ommitting"
<< endl;
-#endif
- continue;
- }
- PRBool isSecure;
- if(NS_FAILED(cookie->GetIsSecure(&isSecure))) {
-#ifdef GNASH_PLUGIN_DEBUG
- cout << "[XPCOM] cookie without isSecure ...
ommitting" << endl;
-#endif
- continue;
- }
- PRUint64 expires;
- if(NS_FAILED(cookie->GetExpires(&expires))) {
-#ifdef GNASH_PLUGIN_DEBUG
- cout << "[XPCOM] cookie without expires ...
ommitting" << endl;
-#endif
- continue;
- }
- nsCString name;
- if(NS_FAILED(cookie->GetName(name))) {
-#ifdef GNASH_PLUGIN_DEBUG
- cout << "[XPCOM] cookie without name ... ommitting"
<< endl;
-#endif
- continue;
- }
- nsCString value;
- if(NS_FAILED(cookie->GetValue(value))) {
-#ifdef GNASH_PLUGIN_DEBUG
- cout << "[XPCOM] cookie without value ... ommitting"
<< endl;
-#endif
- continue;
- }
-
- char *hostChar = ToNewCString (host);
- char *pathChar = ToNewCString (path);
- char *nameChar = ToNewCString (name);
- char *valueChar = ToNewCString (value);
-
- /*
- cout << "[XPCOM] have cookie line:" << endl
- << " "
- << hostChar << "\t"
- << pathChar << "\t"
- << isSecure << "\t"
- << expires << "\t"
- << nameChar << "\t"
- << valueChar << endl;
- */
-
- fout << hostChar << "\t"
- << pathChar << "\t"
- << isSecure << "\t"
- << expires << "\t"
- << nameChar << "\t"
- << valueChar << endl;
-
- g_free(hostChar);
- g_free(pathChar);
- g_free(nameChar);
- g_free(valueChar);
- c++;
- }
- fout.close();
-#if GNASH_PLUGIN_DEBUG > 1
- cout << "[XPCOM] dump finished (" << c << " cookies in total)"
<< endl;
-#endif
- } else {
-#if GNASH_PLUGIN_DEBUG > 1
- cout << "[XPCOM] WARNING: Cookie feature disabled" << endl;
-#endif
- }
+ std::cout << "[XPCOM] trying to dump cookies" << std::endl;
+#endif
+
+ nsCOMPtr<nsISimpleEnumerator> cookie_e;
+ nsresult rv = cookieManager->GetEnumerator(getter_AddRefs(cookie_e));
+
+ //char *cookiefile = NULL;
+
+ if(NS_SUCCEEDED(rv)) {
+ PRBool res = FALSE;
+ ofstream fout;
+ mode_t oldmask = umask(0077);
+ char tmpnamebuf[L_tmpnam];
+ while(!res) {
+ const char *tmpname = tmpnam(tmpnamebuf);
+ fout.open(tmpname, ios::out | ios::trunc);
+ if(!fout.is_open()) {
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout << "[XPCOM] cookie file not opened!!" << std::endl;
+#endif
+ continue;
+ } else {
+#if GNASH_PLUGIN_DEBUG > 1
+ std::cout << "[XPCOM] opened cookie store: " << tmpname <<
std::endl;
+#endif
+ }
+ res = TRUE;
+ _cookieFile = tmpname; // assign ?
+ }
+ umask(oldmask);
+
+ res = TRUE;
+ int c = 0;
+ while(NS_SUCCEEDED(cookie_e->HasMoreElements(&res)) && res ) {
+ nsCOMPtr<nsICookie> cookie;
+ cookie_e->GetNext(getter_AddRefs(cookie));
+ if(!cookie)
+ continue;
+
+ nsCString host;
+ if(NS_FAILED(cookie->GetHost(host))) {
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout << "[XPCOM] cookie without host ... ommitting" <<
std::endl;
+#endif
+ continue;
+ }
+ nsCString path;
+ if(NS_FAILED(cookie->GetPath(path))) {
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout << "[XPCOM] cookie without path ... ommitting" <<
std::endl;
+#endif
+ continue;
+ }
+ PRBool isSecure;
+ if(NS_FAILED(cookie->GetIsSecure(&isSecure))) {
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout << "[XPCOM] cookie without isSecure ... ommitting" <<
std::endl;
+#endif
+ continue;
+ }
+ PRUint64 expires;
+ if(NS_FAILED(cookie->GetExpires(&expires))) {
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout << "[XPCOM] cookie without expires ... ommitting" <<
std::endl;
+#endif
+ continue;
+ }
+ nsCString name;
+ if(NS_FAILED(cookie->GetName(name))) {
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout << "[XPCOM] cookie without name ... ommitting" <<
std::endl;
+#endif
+ continue;
+ }
+ nsCString value;
+ if(NS_FAILED(cookie->GetValue(value))) {
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout << "[XPCOM] cookie without value ... ommitting"
+ << std::endl;
+#endif
+ continue;
+ }
+
+ char *hostChar = ToNewCString (host);
+ char *pathChar = ToNewCString (path);
+ char *nameChar = ToNewCString (name);
+ char *valueChar = ToNewCString (value);
+
+ /*
+ std::cout << "[XPCOM] have cookie line:" << std::endl
+ << " "
+ << hostChar << "\t"
+ << pathChar << "\t"
+ << isSecure << "\t"
+ << expires << "\t"
+ << nameChar << "\t"
+ << valueChar << std::endl;
+ */
+
+ fout << hostChar << "\t"
+ << pathChar << "\t"
+ << isSecure << "\t"
+ << expires << "\t"
+ << nameChar << "\t"
+ << valueChar << std::endl;
+
+ g_free(hostChar);
+ g_free(pathChar);
+ g_free(nameChar);
+ g_free(valueChar);
+ c++;
+ }
+ fout.close();
+#if GNASH_PLUGIN_DEBUG > 1
+ std::cout << "[XPCOM] dump finished (" << c << " cookies in total)"
+ << std::endl;
+#endif
+ }
+ else {
+#if GNASH_PLUGIN_DEBUG > 1
+ std::cout << "[XPCOM] WARNING: Cookie feature disabled" << std::endl;
+#endif
+ }
#endif // HAVE_XPCOM
}
@@ -1128,415 +1141,420 @@
void
nsPluginInstance::startProc(Window win)
{
- string procname;
- char *gnash_env = std::getenv("GNASH_PLAYER");
+ string procname;
+ char *gnash_env = std::getenv("GNASH_PLAYER");
#ifdef GNASH_XPI_PLUGIN
- if (getHome(procname) >= 0)
- ;
- else
+ if (getHome(procname) >= 0)
+ ;
+ else
#endif // def GNASH_XPI_PLUGIN
- if (gnash_env == NULL) {
- procname = GNASHBINDIR;
- procname += "/gtk-gnash";
- }
- else
- {
- procname = gnash_env;
- }
-
- const char* pageurl = getCurrentPageURL();
- if (!pageurl)
- {
-#ifdef GNASH_PLUGIN_DEBUG
- cout << "Could not get current page URL!" << endl;
-#endif
- }
-
- struct stat procstats;
-
- // See if the file actually exists, otherwise we can't spawn it
- if (stat(procname.c_str(), &procstats) == -1)
- {
-#ifdef GNASH_PLUGIN_DEBUG
- cout << "Invalid path to standalone executable: " << procname
<< endl;
-#endif
- return;
- }
+ if (gnash_env == NULL) {
+ procname = GNASHBINDIR;
+ procname += "/gtk-gnash";
+ }
+ else
+ {
+ procname = gnash_env;
+ }
+
+ const char* pageurl = getCurrentPageURL();
+ if (!pageurl)
+ {
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout << "Could not get current page URL!" << std::endl;
+#endif
+ }
+
+ struct stat procstats;
+
+ // See if the file actually exists, otherwise we can't spawn it
+ if (stat(procname.c_str(), &procstats) == -1)
+ {
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout << "Invalid path to standalone executable: " <<
+ procname << std::endl;
+#endif
+ return;
+ }
dumpCookies();
- // 0 For reading, 1 for writing.
- int p2c_pipe[2];
- int c2p_pipe[2];
-
- int ret = pipe(p2c_pipe);
- if (ret == -1)
- {
-#ifdef GNASH_PLUGIN_DEBUG
- cout << "ERROR: parent to child pipe() failed: " <<
strerror(errno) << endl;
-#endif
- }
- _streamfd = p2c_pipe[1];
-
- ret = pipe(c2p_pipe);
- if (ret == -1)
- {
-#ifdef GNASH_PLUGIN_DEBUG
- cout << "ERROR: child to parent pipe() failed: " <<
strerror(errno) << endl;
-#endif
- }
-
-
- /*
- 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], hostfd[buf_size];
- snprintf(xid, buf_size, "%ld", win);
- snprintf(width, buf_size, "%d", _width);
- snprintf(height, buf_size, "%d", _height);
- snprintf(hostfd, buf_size, "%d", c2p_pipe[1]);
-
- // Prepare Actionscript variables (e.g. Flashvars).
- vector<string> paramvalues;
- paramvalues.reserve(_params.size());
-
- for (map<string,string>::const_iterator it = _params.begin(),
- itEnd = _params.end();
- it != itEnd; ++it
- )
- {
- const string& nam = it->first;
- const string& val = it->second;
-
- string param = nam;
- param += string("=");
- param += val;
- paramvalues.push_back(param);
- }
-
- /*
- 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 = 18 + paramvalues.size() * 2;
- const char **argv = new const char *[maxargc];
-
-#ifdef CREATE_STANDALONE_GNASH_LAUNCHER
-
- ofstream saLauncher;
-
- if ( createSaLauncher )
- {
- std::stringstream ss;
- static int debugno = 0;
- debugno = (debugno + 1) % 10;
- ss << "/tmp/gnash-debug-" << debugno << ".sh";
- saLauncher.open(ss.str().c_str(), ios::out | ios::trunc);
- }
-
- if ( saLauncher )
- {
- saLauncher << "#!/bin/sh" << endl
- << procname << " ";
- }
-#endif // CREATE_STANDALONE_GNASH_LAUNCHER
-
- size_t argc = 0;
- argv[argc++] = procname.c_str();
-
- // Don't force verbosity, use configuration for that
- //argv[argc++] = "-v";
-
- // X window ID (necessary for gnash to function as a plugin)
- argv[argc++] = "-x";
- argv[argc++] = xid;
-
- // Height and width
- argv[argc++] = "-j";
- argv[argc++] = width;
- argv[argc++] = "-k";
- argv[argc++] = height;
-
-#ifdef CREATE_STANDALONE_GNASH_LAUNCHER
- // we don't need this, do we ?
- if ( saLauncher ) saLauncher << "-j " << width << " -k " << height << "
";
-#endif // CREATE_STANDALONE_GNASH_LAUNCHER
-
- // Url of the root movie
- argv[argc++] = "-u";
- argv[argc++] = _swf_url.c_str();
-
- // Host FD
- argv[argc++] = "-F";
- argv[argc++] = hostfd;
-
- // 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++] = pageurl;
-#ifdef CREATE_STANDALONE_GNASH_LAUNCHER
- if ( saLauncher ) saLauncher << "-U '" << pageurl << "' ";
-#endif // CREATE_STANDALONE_GNASH_LAUNCHER
- }
-
- // Variables for use by Actionscript.
- for ( size_t i = 0, n = paramvalues.size(); i < n; ++i)
- {
- argv[argc++] = "-P";
- argv[argc++] = paramvalues[i].c_str();
-#ifdef CREATE_STANDALONE_GNASH_LAUNCHER
- if ( saLauncher ) saLauncher << "-P '" << paramvalues[i] << "'
";
-#endif // CREATE_STANDALONE_GNASH_LAUNCHER
- }
-
- argv[argc++] = "-";
- argv[argc++] = 0;
-#ifdef CREATE_STANDALONE_GNASH_LAUNCHER
- if ( saLauncher ) saLauncher << _swf_url << " ";
-#endif // CREATE_STANDALONE_GNASH_LAUNCHER
-
- assert(argc <= maxargc);
-
-#ifdef CREATE_STANDALONE_GNASH_LAUNCHER
- if ( saLauncher )
- {
- // allow caller to pass any additional argument
- saLauncher << "$@"
- << endl;
- saLauncher.close();
- }
-#endif // CREATE_STANDALONE_GNASH_LAUNCHER
-
- /*
- Argument List prepared, now fork(), close file descriptors and execv()
- */
-
- _childpid = fork();
-
- // If the fork failed, childpid is -1. So print out an error message.
- if (_childpid == -1)
- {
-#ifdef GNASH_PLUGIN_DEBUG
- cout << "ERROR: dup2() failed: " << strerror(errno) << endl;
-#endif
- return;
- }
-
- // If we are the parent and fork() worked, childpid is a positive
integer.
- if (_childpid > 0)
- {
- delete[] argv;//don't need the argument list
-
- // we want to write to p2c pipe, so close read-fd0
- ret = close (p2c_pipe[0]);
- if (ret == -1)
- {
-// this is not really a fatal error...
-#ifdef GNASH_PLUGIN_DEBUG
- cout << "ERROR: p2c_pipe[0] close() failed: " <<
strerror(errno)
- << endl;
-#endif
- }
-
- // we want to read from c2p pipe, so close read-fd1
- ret = close (c2p_pipe[1]);
- if (ret == -1)
- {
-// this is not really a fatal error...
-#ifdef GNASH_PLUGIN_DEBUG
- cout << "ERROR: c2p_pipe[1] close() failed: " <<
strerror(errno)
- << endl;
-#endif
- }
-
+ // 0 For reading, 1 for writing.
+ int p2c_pipe[2];
+ int c2p_pipe[2];
+
+ int ret = pipe(p2c_pipe);
+ if (ret == -1)
+ {
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout << "ERROR: parent to child pipe() failed: " <<
+ std::strerror(errno) << std::endl;
+#endif
+ }
+ _streamfd = p2c_pipe[1];
+
+ ret = pipe(c2p_pipe);
+ if (ret == -1)
+ {
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout << "ERROR: child to parent pipe() failed: " <<
+ std::strerror(errno) << std::endl;
+#endif
+ }
+
+ /*
+ 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], hostfd[buf_size];
+ snprintf(xid, buf_size, "%ld", win);
+ snprintf(width, buf_size, "%d", _width);
+ snprintf(height, buf_size, "%d", _height);
+ snprintf(hostfd, buf_size, "%d", c2p_pipe[1]);
+
+ // Prepare Actionscript variables (e.g. Flashvars).
+ vector<string> paramvalues;
+ paramvalues.reserve(_params.size());
+
+ for (map<string,string>::const_iterator it = _params.begin(),
+ itEnd = _params.end(); it != itEnd; ++it) {
+ const string& nam = it->first;
+ const string& val = it->second;
+
+ string param = nam;
+ param += string("=");
+ param += val;
+ paramvalues.push_back(param);
+ }
+
+ /*
+ 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 = 18 + paramvalues.size() * 2;
+ const char **argv = new const char *[maxargc];
+
+#ifdef CREATE_STANDALONE_GNASH_LAUNCHER
+ ofstream saLauncher;
+
+ if ( createSaLauncher )
+ {
+ std::stringstream ss;
+ static int debugno = 0;
+ debugno = (debugno + 1) % 10;
+ ss << "/tmp/gnash-debug-" << debugno << ".sh";
+ saLauncher.open(ss.str().c_str(), ios::out | ios::trunc);
+ }
+
+ if ( saLauncher )
+ {
+ saLauncher << "#!/bin/sh" << std::endl
+ << procname << " ";
+ }
+#endif
+
+ size_t argc = 0;
+ argv[argc++] = procname.c_str();
+
+ // Don't force verbosity, use configuration for that
+ //argv[argc++] = "-v";
+
+ // X window ID (necessary for gnash to function as a plugin)
+ argv[argc++] = "-x";
+ argv[argc++] = xid;
+
+ // Height and width
+ argv[argc++] = "-j";
+ argv[argc++] = width;
+ argv[argc++] = "-k";
+ argv[argc++] = height;
+
+#ifdef CREATE_STANDALONE_GNASH_LAUNCHER
+ // we don't need this, do we ?
+ if ( saLauncher ) saLauncher << "-j " << width << " -k " << height << " ";
+#endif
+
+ // Url of the root movie
+ argv[argc++] = "-u";
+ argv[argc++] = _swf_url.c_str();
+
+ // Host FD
+ argv[argc++] = "-F";
+ argv[argc++] = hostfd;
+
+ // 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++] = pageurl;
+#ifdef CREATE_STANDALONE_GNASH_LAUNCHER
+ if ( saLauncher ) saLauncher << "-U '" << pageurl << "' ";
+#endif
+ }
+
+ // Variables for use by Actionscript.
+ for ( size_t i = 0, n = paramvalues.size(); i < n; ++i)
+ {
+ argv[argc++] = "-P";
+ argv[argc++] = paramvalues[i].c_str();
+#ifdef CREATE_STANDALONE_GNASH_LAUNCHER
+ if ( saLauncher ) saLauncher << "-P '" << paramvalues[i] << "' ";
+#endif
+ }
+
+ argv[argc++] = "-";
+ argv[argc++] = 0;
+#ifdef CREATE_STANDALONE_GNASH_LAUNCHER
+ if ( saLauncher ) saLauncher << _swf_url << " ";
+#endif
+
+ assert(argc <= maxargc);
+
+#ifdef CREATE_STANDALONE_GNASH_LAUNCHER
+ if ( saLauncher )
+ {
+ // allow caller to pass any additional argument
+ saLauncher << "$@"
+ << std::endl;
+ saLauncher.close();
+ }
+#endif
+
+ /*
+ Argument List prepared, now fork(), close file descriptors and execv()
+ */
+
+ _childpid = fork();
+
+ // If the fork failed, childpid is -1. So print out an error message.
+ if (_childpid == -1)
+ {
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout << "ERROR: dup2() failed: " << strerror(errno) << std::endl;
+#endif
+ return;
+ }
+
+ // If we are the parent and fork() worked, childpid is a positive integer.
+ if (_childpid > 0)
+ {
+ delete[] argv;//don't need the argument list
+
+ // we want to write to p2c pipe, so close read-fd0
+ ret = close (p2c_pipe[0]);
+ if (ret == -1)
+ {
+// this is not really a fatal error...
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout << "ERROR: p2c_pipe[0] close() failed: " <<
strerror(errno)
+ << std::endl;
+#endif
+ }
+
+ // we want to read from c2p pipe, so close read-fd1
+ ret = close (c2p_pipe[1]);
+ if (ret == -1)
+ {
+// this is not really a fatal error...
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout << "ERROR: c2p_pipe[1] close() failed: " <<
strerror(errno)
+ << std::endl;
+#endif
+ }
+
#if GNASH_PLUGIN_DEBUG > 1
- cout << "Forked successfully, child process PID is "
- << _childpid
- << endl;
+ std::cout << "Forked successfully, child process PID is "
+ << _childpid
+ << std::endl;
#endif
- _ichan = g_io_channel_unix_new(c2p_pipe[0]);
- g_io_channel_set_close_on_unref(_ichan, true);
- _ichanWatchId = g_io_add_watch(_ichan,
(GIOCondition)(G_IO_IN|G_IO_HUP), (GIOFunc)handlePlayerRequestsWrapper, this);
-
- return;
- }
-
- // This is the child scope.
- //FF3 uses jemalloc and it has problems after the fork(), do NOT
- //use memory functions (malloc()/free()/new/delete) after the fork()
- //in the child thread process
-
- // We want to read parent to child, so close write-fd1
- ret = close (p2c_pipe[1]);
- if (ret == -1)
- {
+ _ichan = g_io_channel_unix_new(c2p_pipe[0]);
+ g_io_channel_set_close_on_unref(_ichan, true);
+ _ichanWatchId = g_io_add_watch(_ichan,
+ (GIOCondition)(G_IO_IN|G_IO_HUP),
+ (GIOFunc)handlePlayerRequestsWrapper, this);
+
+ return;
+ }
+
+ // This is the child scope.
+ //FF3 uses jemalloc and it has problems after the fork(), do NOT
+ //use memory functions (malloc()/free()/new/delete) after the fork()
+ //in the child thread process
+
+ // We want to read parent to child, so close write-fd1
+ ret = close (p2c_pipe[1]);
+ if (ret == -1)
+ {
// not really a fatal error
#ifdef GNASH_PLUGIN_DEBUG
- cout << "ERROR: close() failed: " << strerror(errno) << endl;
+ std::cout << "ERROR: close() failed: " << strerror(errno) << std::endl;
#endif
- }
+ }
- // close standard input and direct read-fd1 to standard input
- ret = dup2 (p2c_pipe[0], fileno(stdin));
-
- if (ret == -1)
- {
+ // close standard input and direct read-fd1 to standard input
+ ret = dup2 (p2c_pipe[0], fileno(stdin));
+
+ if (ret == -1)
+ {
#ifdef GNASH_PLUGIN_DEBUG
- cout << "ERROR: dup2() failed: " << strerror(errno) << endl;
-#endif
- }
-
- // Close all of the browser's file descriptors that we just
- // inherited (including p2c_pipe[0] that we just dup'd to fd 0).
- // Experiments show seventy or eighty file descriptors open in
- // 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 programs.
- int numfailed = 0, closed = 0;
- int anfd = fileno(stderr)+1;
- for ( ; numfailed < 10; anfd++)
- {
- if ( anfd == c2p_pipe[1] ) continue; // don't close this
- if ( anfd == c2p_pipe[0] ) continue; // don't close this either
(correct?)
- ret = close (anfd);
- if (ret < 0) numfailed++;
- else
- {
- numfailed = 0;
- closed++;
- }
- }
-
-#if GNASH_PLUGIN_DEBUG > 1
- cout << "Closed " << closed << " files." << endl;
-#endif
-
-
- /*
- Start the desired executable and go away.
- */
-
-
-#if GNASH_PLUGIN_DEBUG > 1
- cout << "Starting process: ";
- for (int i = 0; argv[i] != 0; ++i)
- {
- cout << argv[i] << " ";
- }
- cout << endl;
-#endif
-
- /*
- 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)
- {
- sleep(1);
- }
- }
-
- execv(argv[0], const_cast<char**>(argv));
-
- // if execv returns, an error has occurred.
- perror("executing standalone gnash");
-
- //could actually cause a deadlock due to jemalloc and we
- //are exiting now anyways
- //delete[] argv;
-
- exit (-1);
+ std::cout << "ERROR: dup2() failed: " << strerror(errno) << std::endl;
+#endif
+ }
+
+ // Close all of the browser's file descriptors that we just
+ // inherited (including p2c_pipe[0] that we just dup'd to fd 0).
+ // Experiments show seventy or eighty file descriptors open in
+ // 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 programs.
+ int numfailed = 0, closed = 0;
+ int anfd = fileno(stderr)+1;
+ for ( ; numfailed < 10; anfd++)
+ {
+ if ( anfd == c2p_pipe[1] ) continue; // don't close this
+ if ( anfd == c2p_pipe[0] ) continue; // don't close this either
(correct?)
+ ret = close (anfd);
+ if (ret < 0) numfailed++;
+ else
+ {
+ numfailed = 0;
+ closed++;
+ }
+ }
+
+#if GNASH_PLUGIN_DEBUG > 1
+ std::cout << "Closed " << closed << " files." << std::endl;
+#endif
+
+
+ /*
+ Start the desired executable and go away.
+ */
+
+
+#if GNASH_PLUGIN_DEBUG > 1
+ std::cout << "Starting process: ";
+ for (int i = 0; argv[i] != 0; ++i)
+ {
+ std::cout << argv[i] << " ";
+ }
+ std::cout << std::endl;
+#endif
+
+ /*
+ For debugging the plugin (GNASH_OPTIONS=waitforgdb)
+ Block here until gdb is attached and sets waitforgdb to
+ false.
+ */
+
+ if (waitforgdb) {
+
+ std::cout << std::endl << " Attach GDB to PID " << getpid()
+ << " to debug!" << std::endl;
+ std::cout << " This thread will block until then!" << std::endl;
+ std::cout << " Once blocked here, you can set other breakpoints."
+ << std::endl;
+ std::cout << " Do a \"set variable waitforgdb=$false\" to continue"
+ << std::endl << std::endl;
+
+ while (waitforgdb)
+ {
+ sleep(1);
+ }
+ }
+
+ execv(argv[0], const_cast<char**>(argv));
+
+ // if execv returns, an error has occurred.
+ perror("executing standalone gnash");
+
+ //could actually cause a deadlock due to jemalloc and we
+ //are exiting now anyways
+ //delete[] argv;
+
+ exit (-1);
}
const char*
nsPluginInstance::getCurrentPageURL() const
{
- NPP npp = _instance;
-
- NPIdentifier sDocument = NPN_GetStringIdentifier("document");
-
- NPObject *window;
- NPN_GetValue(npp, NPNVWindowNPObject, &window);
-
- NPVariant vDoc;
- NPN_GetProperty(npp, window, sDocument, &vDoc);
- NPN_ReleaseObject(window);
-
- if (!NPVARIANT_IS_OBJECT(vDoc))
- {
-#ifdef GNASH_PLUGIN_DEBUG
- cout << "Can't get window object" << endl;
-#endif
- return NULL;
- }
-
- NPObject* npDoc = NPVARIANT_TO_OBJECT(vDoc);
-
- NPIdentifier sLocation = NPN_GetStringIdentifier("location");
- NPVariant vLoc;
- NPN_GetProperty(npp, npDoc, sLocation, &vLoc);
- NPN_ReleaseObject(npDoc);
- if (!NPVARIANT_IS_OBJECT(vLoc))
- {
-#ifdef GNASH_PLUGIN_DEBUG
- cout <<"Can't get window.location object" << endl;
-#endif
- return NULL;
- }
- NPObject* npLoc = NPVARIANT_TO_OBJECT(vLoc);
-
- NPIdentifier sProperty = NPN_GetStringIdentifier("href");
- NPVariant vProp;
- NPN_GetProperty(npp, npLoc, sProperty, &vProp);
- NPN_ReleaseObject(npLoc);
- if (!NPVARIANT_IS_STRING(vProp))
- {
-#ifdef GNASH_PLUGIN_DEBUG
- cout << "Can't get window.location.href object" << endl;
-#endif
- return NULL;
- }
- const NPString& propValue = NPVARIANT_TO_STRING(vProp);
-
- return propValue.utf8characters; // const char *
+ NPP npp = _instance;
+
+ NPIdentifier sDocument = NPN_GetStringIdentifier("document");
+
+ NPObject *window;
+ NPN_GetValue(npp, NPNVWindowNPObject, &window);
+
+ NPVariant vDoc;
+ NPN_GetProperty(npp, window, sDocument, &vDoc);
+ NPN_ReleaseObject(window);
+
+ if (!NPVARIANT_IS_OBJECT(vDoc))
+ {
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout << "Can't get window object" << std::endl;
+#endif
+ return NULL;
+ }
+
+ NPObject* npDoc = NPVARIANT_TO_OBJECT(vDoc);
+
+ NPIdentifier sLocation = NPN_GetStringIdentifier("location");
+ NPVariant vLoc;
+ NPN_GetProperty(npp, npDoc, sLocation, &vLoc);
+ NPN_ReleaseObject(npDoc);
+
+ if (!NPVARIANT_IS_OBJECT(vLoc))
+ {
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout <<"Can't get window.location object" << std::endl;
+#endif
+ return NULL;
+ }
+
+ NPObject* npLoc = NPVARIANT_TO_OBJECT(vLoc);
+
+ NPIdentifier sProperty = NPN_GetStringIdentifier("href");
+ NPVariant vProp;
+ NPN_GetProperty(npp, npLoc, sProperty, &vProp);
+ NPN_ReleaseObject(npLoc);
+
+ if (!NPVARIANT_IS_STRING(vProp))
+ {
+#ifdef GNASH_PLUGIN_DEBUG
+ std::cout << "Can't get window.location.href object" << std::endl;
+#endif
+ return NULL;
+ }
+
+ const NPString& propValue = NPVARIANT_TO_STRING(vProp);
+
+ return propValue.utf8characters; // const char *
}
-static const char* getPluginDescription()
+static const char*
+getPluginDescription()
{
- static const char* desc = NULL;
- if (!desc)
- {
- desc = std::getenv("GNASH_PLUGIN_DESCRIPTION");
- if (desc == NULL) desc = PLUGIN_DESCRIPTION;
- }
- return desc;
+ static const char* desc = NULL;
+ if (!desc)
+ {
+ desc = std::getenv("GNASH_PLUGIN_DESCRIPTION");
+ if (desc == NULL) desc = PLUGIN_DESCRIPTION;
+ }
+ return desc;
}
// Local Variables:
=== modified file 'plugin/plugin.h'
--- a/plugin/plugin.h 2008-11-25 15:23:03 +0000
+++ b/plugin/plugin.h 2008-12-08 09:16:52 +0000
@@ -63,7 +63,7 @@
// We are required to implement these three methods.
NPBool init(NPWindow *aWindow);
- NPBool isInitialized() {return plugInitialized;}
+ NPBool isInitialized() { return plugInitialized; }
void shut();
NPError GetValue(NPPVariable variable, void *value);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] /srv/bzr/gnash/trunk r10397: Indentation and line break changes.,
Benjamin Wolsey <=