[epiphany/gnome-2-28] ephy-web-view.c: fix auto-google search when using Ctrl-Enter



commit c140548c90a76c3dcc3297e920b25ebf94eb56ef
Author: Xan Lopez <xan gnome org>
Date:   Mon Nov 30 14:12:12 2009 +0200

    ephy-web-view.c: fix auto-google search when using Ctrl-Enter
    
    Bug #603324

 embed/ephy-web-view.c |   60 +++++++++++++++++++++++++++---------------------
 1 files changed, 34 insertions(+), 26 deletions(-)
---
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 084d7bc..11ac048 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -1066,6 +1066,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
@@ -1085,7 +1117,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);
 
@@ -1104,42 +1136,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);
 }
 



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