summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Garcia Campos <cgarcia@igalia.com>2015-04-10 12:25:24 +0200
committerCarlos Garcia Campos <carlosgc@gnome.org>2015-04-10 12:47:28 +0200
commit597740cc356db222be25cdce6d8415090eba0860 (patch)
treeba89e83ae2602e0ceb5f5e83dc97e2cab8bd0dad
parent316b36ddd86562550f2e86a271fece9f316514cc (diff)
downloadyelp-597740cc356db222be25cdce6d8415090eba0860.tar.gz
web-extension: Fix external resources of ghelp documents
ghelp uris can start with the document name or with a slash and point directly to a xternal resource like an image. However, we were assuming the uris always started with the document name, so for uris not including it, we were removing the first element of the path, typically the images/figures directory. We could check first if the uri starts with the document uri, to remove the document uri prefix from the path or only the scheme.
-rw-r--r--libyelp/web-extension/yelp-web-extension.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/libyelp/web-extension/yelp-web-extension.c b/libyelp/web-extension/yelp-web-extension.c
index 701cfbc2..1d66a63b 100644
--- a/libyelp/web-extension/yelp-web-extension.c
+++ b/libyelp/web-extension/yelp-web-extension.c
@@ -30,10 +30,10 @@
static YelpUri *current_uri;
static gchar *
-get_resource_path (gchar *uri, YelpUri *document_uri)
+get_resource_path (gchar *uri, YelpUri *current_uri)
{
+ gchar *doc_uri;
gchar *resource = NULL;
- gchar *resource_path = 0;
if (!g_str_has_prefix (uri, "ghelp") &&
!g_str_has_prefix (uri, "gnome-help") &&
@@ -41,16 +41,30 @@ get_resource_path (gchar *uri, YelpUri *document_uri)
return NULL;
}
- resource = strstr (uri, "/");
- if (resource) {
- resource[0] = '\0';
- resource++;
+ doc_uri = yelp_uri_get_document_uri (current_uri);
+ if (g_str_has_prefix (uri, doc_uri)) {
+ /* If the uri starts with the document uri,
+ * simply remove the document uri to get the
+ * resource path.
+ */
+ uri[strlen (doc_uri)] = '\0';
+ resource = uri + strlen (doc_uri) + 1;
+ } else {
+ /* If the uri doesn't contain the document uri,
+ * the full path is the resource path.
+ */
+ resource = strstr (uri, ":");
+ if (resource) {
+ resource[0] = '\0';
+ resource++;
+ }
}
+ g_free (doc_uri);
if (resource && resource[0] != '\0')
- resource_path = yelp_uri_locate_file_uri (document_uri, resource);
+ return yelp_uri_locate_file_uri (current_uri, resource);
- return resource_path;
+ return NULL;
}
static gboolean
@@ -59,24 +73,20 @@ web_page_send_request (WebKitWebPage *web_page,
WebKitURIResponse *redirected_response,
gpointer user_data)
{
- const gchar *wk_uri = webkit_uri_request_get_uri (request);
- gchar *yelp_uri, *current_uri_canonical, *file_path;
+ const gchar *resource_uri = webkit_uri_request_get_uri (request);
+ gchar *yelp_uri, *file_path;
if (!current_uri)
return FALSE;
- yelp_uri = build_yelp_uri (wk_uri);
- current_uri_canonical = yelp_uri_get_canonical_uri (current_uri);
-
+ yelp_uri = build_yelp_uri (resource_uri);
file_path = get_resource_path (yelp_uri, current_uri);
-
if (file_path) {
webkit_uri_request_set_uri (request, file_path);
g_free (file_path);
}
-
g_free (yelp_uri);
- g_free (current_uri_canonical);
+
return FALSE;
}