totem r5758 - in branches/gnome-2-24: . browser-plugin



Author: hadess
Date: Wed Oct  8 16:43:53 2008
New Revision: 5758
URL: http://svn.gnome.org/viewvc/totem?rev=5758&view=rev

Log:
2008-10-08  Bastien Nocera  <hadess hadess net>

	* browser-plugin/totem-plugin-viewer.c (relative_uri_remove_query),
	(resolve_uri):
	* browser-plugin/totemPlugin.cpp:
	* browser-plugin/totemPlugin.h: Backport fixes from #555417



Modified:
   branches/gnome-2-24/ChangeLog
   branches/gnome-2-24/browser-plugin/totem-plugin-viewer.c
   branches/gnome-2-24/browser-plugin/totemPlugin.cpp
   branches/gnome-2-24/browser-plugin/totemPlugin.h

Modified: branches/gnome-2-24/browser-plugin/totem-plugin-viewer.c
==============================================================================
--- branches/gnome-2-24/browser-plugin/totem-plugin-viewer.c	(original)
+++ branches/gnome-2-24/browser-plugin/totem-plugin-viewer.c	Wed Oct  8 16:43:53 2008
@@ -663,45 +663,85 @@
 }
 
 static char *
+relative_uri_remove_query (const char *uri, char **query)
+{
+	char *qmark;
+
+	/* Look for '?' */
+	qmark = strrchr (uri, '?');
+	if (qmark == NULL)
+		return NULL;
+
+	*query = g_strdup (qmark);
+	return g_strndup (uri, qmark - uri);
+}
+
+static char *
 resolve_uri (const char *base_uri,
-             const char *relative_uri)
+	     const char *relative_uri)
 {
-  char *uri, *scheme;
-  GFile *base_gfile, *base_parent_gfile, *resolved_gfile;
+	char *uri, *scheme, *query, *new_relative_uri;
+	GFile *base_gfile, *base_parent_gfile, *resolved_gfile;
+
+	if (!relative_uri)
+		return g_strdup (base_uri);
 
-  if (!relative_uri)
-    return g_strdup (base_uri);
+	if (!base_uri)
+		return g_strdup (relative_uri);
 
-  if (!base_uri)
-    return g_strdup (relative_uri);
-
-  /* If |relative_uri| has a scheme, it's a full URI, just return it */
-  scheme = g_uri_parse_scheme (relative_uri);
-  if (scheme) {
-    g_free (scheme);
-    return g_strdup (relative_uri);
-  }
-
-  base_gfile = g_file_new_for_uri (base_uri);
-  base_parent_gfile = g_file_get_parent (base_gfile);
-  if (!base_parent_gfile) {
-    g_print ("Base URI %s has no parent!\n", base_uri);
-    g_object_unref (base_gfile);
-    return NULL;
-  }
-  g_object_unref (base_gfile);
-
-  resolved_gfile = g_file_resolve_relative_path (base_parent_gfile, relative_uri);
-  g_object_unref (base_parent_gfile);
-  if (!resolved_gfile) {
-    g_warning ("Failed to resolve relative URI '%s' against base '%s'\n", relative_uri, base_uri);
-    return NULL;
-  }
+	/* If |relative_uri| has a scheme, it's a full URI, just return it */
+	scheme = g_uri_parse_scheme (relative_uri);
+	if (scheme) {
+		g_free (scheme);
+		return g_strdup (relative_uri);
+	}
 
-  uri = g_file_get_uri (resolved_gfile);
-  g_object_unref (resolved_gfile);
+	base_gfile = g_file_new_for_uri (base_uri);
+	base_parent_gfile = g_file_get_parent (base_gfile);
+	if (!base_parent_gfile) {
+		g_print ("Base URI %s has no parent!\n", base_uri);
+		g_object_unref (base_gfile);
+		return NULL;
+	}
+	g_object_unref (base_gfile);
 
-  return uri;
+	query = NULL;
+	new_relative_uri = relative_uri_remove_query (relative_uri, &query);
+
+	if (new_relative_uri) {
+		char *tmpuri;
+
+		resolved_gfile = g_file_resolve_relative_path (base_parent_gfile, new_relative_uri);
+		g_object_unref (base_parent_gfile);
+		if (!resolved_gfile) {
+			g_warning ("Failed to resolve relative URI '%s' against base '%s'\n", relative_uri, base_uri);
+			g_free (new_relative_uri);
+			g_free (query);
+			return NULL;
+		}
+
+		tmpuri = g_file_get_uri (resolved_gfile);
+		g_object_unref (resolved_gfile);
+		uri = g_strdup_printf ("%s%s", tmpuri, query);
+
+		g_free (tmpuri);
+		g_free (new_relative_uri);
+		g_free (query);
+
+		return uri;
+	} else {
+		resolved_gfile = g_file_resolve_relative_path (base_parent_gfile, relative_uri);
+		g_object_unref (base_parent_gfile);
+		if (!resolved_gfile) {
+			g_warning ("Failed to resolve relative URI '%s' against base '%s'\n", relative_uri, base_uri);
+			return NULL;
+		}
+
+		uri = g_file_get_uri (resolved_gfile);
+		g_object_unref (resolved_gfile);
+
+		return uri;
+	}
 }
 
 static void

Modified: branches/gnome-2-24/browser-plugin/totemPlugin.cpp
==============================================================================
--- branches/gnome-2-24/browser-plugin/totemPlugin.cpp	(original)
+++ branches/gnome-2-24/browser-plugin/totemPlugin.cpp	Wed Oct  8 16:43:53 2008
@@ -959,6 +959,8 @@
 void
 totemPlugin::RequestStream (bool aForceViewer)
 {
+	D ("Stream requested (force viewer: %d)", aForceViewer);
+
 //        assert (mViewerReady);
         if (!mViewerReady)
           return;//FIXMEchpe
@@ -1022,7 +1024,7 @@
 	/* If the URL is supported and the caller isn't asking us to make
 	 * the viewer open the stream, we call OpenStream, and
 	 * otherwise OpenURI. */
-	if (!aForceViewer && IsSchemeSupported (requestURI)) {
+	if (!aForceViewer && IsSchemeSupported (requestURI, baseURI)) {
 		/* This will fail for the 2nd stream, but we shouldn't
 		 * ever come to using it for the 2nd stream... */
 
@@ -1397,14 +1399,17 @@
 }
 
 bool
-totemPlugin::IsSchemeSupported (const char *aURI)
+totemPlugin::IsSchemeSupported (const char *aURI, const char *aBaseURI)
 {
   if (!aURI)
     return false;
 
   char *scheme = g_uri_parse_scheme (aURI);
-  if (!scheme)
-    return false;
+  if (!scheme) {
+    scheme = g_uri_parse_scheme (aBaseURI);
+    if (!scheme)
+      return false;
+  }
 
   bool isSupported = false;
   if (g_ascii_strcasecmp (scheme, "http") == 0 ||

Modified: branches/gnome-2-24/browser-plugin/totemPlugin.h
==============================================================================
--- branches/gnome-2-24/browser-plugin/totemPlugin.h	(original)
+++ branches/gnome-2-24/browser-plugin/totemPlugin.h	Wed Oct  8 16:43:53 2008
@@ -160,7 +160,7 @@
 
     bool IsMimeTypeSupported (const char *aMimeType,
                               const char *aURL);
-    bool IsSchemeSupported (const char *aURI);
+    bool IsSchemeSupported (const char *aURI, const char *aBaseURI);
     void SetRealMimeType (const char *aMimeType);
     bool ParseBoolean (const char *key,
                        const char *value,



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