diff options
author | Marcos ChavarrÃa Teijeiro <chavarria1991@gmail.com> | 2014-11-12 10:28:42 +0100 |
---|---|---|
committer | David King <amigadave@amigadave.com> | 2015-06-22 13:32:35 +0100 |
commit | 901b4fb82e007e9d93deb3f1e13cc36d5b2bf37b (patch) | |
tree | 2007392a342967c526c412dfb5b5a97175883de7 /libyelp/yelp-view.c | |
parent | 7a2f5fc0ab4709d82de7748080dfe920407b763d (diff) | |
download | yelp-901b4fb82e007e9d93deb3f1e13cc36d5b2bf37b.tar.gz |
yelp-view: Implement web extension to load resources
I have split the libyelp library into two parts in order to avoid linking the webextension against libyelp. So now we have a libyelpuri with the yelp-uri, yelp-build-uri and their dependecies and the old libyelp with the remaining files. I have modified the yelp-build-uri logic to not have to use yelp-document because it implies to have to add to the new library most of libyelp classes.
Diffstat (limited to 'libyelp/yelp-view.c')
-rw-r--r-- | libyelp/yelp-view.c | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/libyelp/yelp-view.c b/libyelp/yelp-view.c index cb2b5bc3..293823ab 100644 --- a/libyelp/yelp-view.c +++ b/libyelp/yelp-view.c @@ -1927,11 +1927,43 @@ view_clear_load (YelpView *view) } } +static gchar* +fix_docbook_uri (YelpUri *docbook_uri, YelpDocument* document) +{ + SoupURI *soup_uri; + gchar *retval, *canonical; + + canonical = yelp_uri_get_canonical_uri (docbook_uri); + soup_uri = soup_uri_new (canonical); + g_free (canonical); + + /* We don't have actual page and frag IDs for DocBook. We just map IDs + of block elements. The result is that we get xref:someid#someid. + If someid is really the page ID, we just drop the frag reference. + Otherwise, normal page views scroll past the link trail. + */ + if (soup_uri->fragment && YELP_IS_DOCBOOK_DOCUMENT (document)) { + gchar *page_id = yelp_uri_get_page_id (docbook_uri); + gchar *real_id = yelp_document_get_page_id (document, page_id); + + if (g_str_equal (real_id, soup_uri->fragment)) + soup_uri_set_fragment (soup_uri, NULL); + + g_free (real_id); + g_free (page_id); + } + + retval = soup_uri_to_string (soup_uri, FALSE); + soup_uri_free (soup_uri); + + return retval; +} + static void view_load_page (YelpView *view) { YelpViewPrivate *priv = GET_PRIV (view); - gchar *uri_str; + gchar *uri_str, *tmp_uri; g_return_if_fail (priv->cancellable == NULL); @@ -1956,7 +1988,17 @@ view_load_page (YelpView *view) return; } - uri_str = build_network_uri (priv->uri, priv->document); + uri_str = yelp_uri_get_canonical_uri (priv->uri); + + if (YELP_IS_DOCBOOK_DOCUMENT (priv->document)){ + tmp_uri = uri_str; + uri_str = fix_docbook_uri (priv->uri, priv->document); + g_free (tmp_uri); + } + + tmp_uri = uri_str; + uri_str = build_network_uri (uri_str); + g_free (tmp_uri); g_signal_handler_block (view, priv->navigation_requested); webkit_web_view_load_uri (WEBKIT_WEB_VIEW (view), uri_str); |