From 2aca0c21a8f140a6d3b6bddfa4aed1b31326b1cd Mon Sep 17 00:00:00 2001 From: Xan Lopez Date: Mon, 30 Nov 2009 14:12:12 +0200 Subject: ephy-web-view.c: fix auto-google search when using Ctrl-Enter Bug #603324 --- embed/ephy-web-view.c | 60 +++++++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 26 deletions(-) (limited to 'embed') diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c index 72c511221..4844bb1f8 100644 --- a/embed/ephy-web-view.c +++ b/embed/ephy-web-view.c @@ -1052,6 +1052,38 @@ ephy_web_view_new (void) return GTK_WIDGET (g_object_new (EPHY_TYPE_WEB_VIEW, NULL)); } +static char* +normalize_or_autosearch_url (EphyWebView *view, const char *url) +{ + char *effective_url; + SoupURI *soup_uri = NULL; + EphyWebViewPrivate *priv = view->priv; + + /* We use SoupURI as an indication of whether the value given in url + * is not something we want to search; we only do that, though, if + * the address has a web scheme, because SoupURI will consider any + * string: as a valid scheme, and we will end up prepending http:// + * to it */ + if (ephy_embed_utils_address_has_web_scheme (url)) + soup_uri = soup_uri_new (url); + + /* If the string doesn't look like an URI, let's search it; */ + if (soup_uri == NULL && + priv->non_search_regex && + !g_regex_match (priv->non_search_regex, url, 0, NULL)) { + char *query_param = soup_form_encode ("q", url, NULL); + /* + 2 here is getting rid of 'q=' */ + effective_url = g_strdup_printf (_("http://www.google.com/search?q=%s&ie=UTF-8&oe=UTF-8"), query_param + 2); + g_free (query_param); + } else + effective_url = ephy_embed_utils_normalize_address (url); + + if (soup_uri) + soup_uri_free (soup_uri); + + return effective_url; +} + /** * ephy_web_view_load_request: * @web_view: the #EphyWebView in which to load the request @@ -1071,7 +1103,7 @@ ephy_web_view_load_request (EphyWebView *web_view, g_return_if_fail (WEBKIT_IS_NETWORK_REQUEST(request)); url = webkit_network_request_get_uri (request); - effective_url = ephy_embed_utils_normalize_address (url); + effective_url = normalize_or_autosearch_url (web_view, url); webkit_network_request_set_uri (request, effective_url); g_free (effective_url); @@ -1090,42 +1122,18 @@ void ephy_web_view_load_url (EphyWebView *view, const char *url) { - EphyWebViewPrivate *priv; - SoupURI *soup_uri = NULL; char *effective_url; g_return_if_fail (EPHY_IS_WEB_VIEW (view)); g_return_if_fail (url); - priv = view->priv; - - /* We use SoupURI as an indication of whether the value given in url - * is not something we want to search; we only do that, though, if - * the address has a web scheme, because SoupURI will consider any - * string: as a valid scheme, and we will end up prepending http:// - * to it */ - if (ephy_embed_utils_address_has_web_scheme (url)) - soup_uri = soup_uri_new (url); - - /* If the string doesn't look like an URI, let's search it; */ - if (soup_uri == NULL && - priv->non_search_regex && - !g_regex_match (priv->non_search_regex, url, 0, NULL)) { - char *query_param = soup_form_encode ("q", url, NULL); - /* + 2 here is getting rid of 'q=' */ - effective_url = g_strdup_printf (_("http://www.google.com/search?q=%s&ie=UTF-8&oe=UTF-8"), query_param + 2); - g_free (query_param); - } else - effective_url = ephy_embed_utils_normalize_address (url); + effective_url = normalize_or_autosearch_url (view, url); if (g_str_has_prefix (effective_url, "javascript:")) webkit_web_view_execute_script (WEBKIT_WEB_VIEW (view), effective_url); else webkit_web_view_open (WEBKIT_WEB_VIEW (view), effective_url); - if (soup_uri) - soup_uri_free (soup_uri); - g_free (effective_url); } -- cgit v1.2.3