$OpenBSD: patch-plugin_npapi_plugin_cpp,v 1.3 2010/11/07 18:58:24 dcoppa Exp $

Use window.document.baseURI rather than
window.document.location.href. The former
honours <base> tags, fixing bug #31497
(aka easy come, easy go)

--- plugin/npapi/plugin.cpp.orig	Mon Aug 16 11:46:55 2010
+++ plugin/npapi/plugin.cpp	Fri Nov  5 21:15:29 2010
@@ -1218,6 +1218,13 @@ nsPluginInstance::startProc()
 std::string
 nsPluginInstance::getCurrentPageURL() const
 {
+    // Return:
+    //  window.document.baseURI
+    //
+    // Was (bogus):
+    //  window.document.location.href
+    //
+
     NPP npp = _instance;
 
     NPIdentifier sDocument = NPN_GetStringIdentifier("document");
@@ -1230,20 +1237,21 @@ nsPluginInstance::getCurrentPageURL() const
     NPN_ReleaseObject(window);
 
     if (!NPVARIANT_IS_OBJECT(vDoc)) {
-        gnash::log_error("Can't get window object");
-        return NULL;
+        gnash::log_error("Can't get window.document object");
+        return std::string();
     }
     
     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)) {
-        gnash::log_error("Can't get window.location object");
-        return NULL;
+        gnash::log_error("Can't get window.document.location object");
+        return std::string();
     }
 
     NPObject* npLoc = NPVARIANT_TO_OBJECT(vLoc);
@@ -1254,8 +1262,19 @@ nsPluginInstance::getCurrentPageURL() const
     NPN_ReleaseObject(npLoc);
 
     if (!NPVARIANT_IS_STRING(vProp)) {
-        gnash::log_error("Can't get window.location.href object");
-        return NULL;
+        gnash::log_error("Can't get window.document.location.href string");
+        return std::string();
+    }
+*/
+
+    NPIdentifier sProperty = NPN_GetStringIdentifier("baseURI");
+    NPVariant vProp;
+    NPN_GetProperty(npp, npDoc, sProperty, &vProp);
+    NPN_ReleaseObject(npDoc);
+
+    if (!NPVARIANT_IS_STRING(vProp)) {
+        gnash::log_error("Can't get window.document.baseURI string");
+        return std::string();
     }
 
     const NPString& propValue = NPVARIANT_TO_STRING(vProp);
