aboutsummaryrefslogtreecommitdiffstats
path: root/embed
diff options
context:
space:
mode:
authorGustavo Noronha Silva <gns@gnome.org>2009-08-27 01:30:04 +0800
committerGustavo Noronha Silva <gns@gnome.org>2009-08-27 01:49:03 +0800
commit1d4cb08121bfadf263e8057d50e87833ef92c45b (patch)
treef1c60ade8f44351f26ec0eee5084425a1d2151db /embed
parente92add696ac0e460fc4e520a1201cfb38a67d6fb (diff)
downloadgsoc2013-epiphany-1d4cb08121bfadf263e8057d50e87833ef92c45b.tar
gsoc2013-epiphany-1d4cb08121bfadf263e8057d50e87833ef92c45b.tar.gz
gsoc2013-epiphany-1d4cb08121bfadf263e8057d50e87833ef92c45b.tar.bz2
gsoc2013-epiphany-1d4cb08121bfadf263e8057d50e87833ef92c45b.tar.lz
gsoc2013-epiphany-1d4cb08121bfadf263e8057d50e87833ef92c45b.tar.xz
gsoc2013-epiphany-1d4cb08121bfadf263e8057d50e87833ef92c45b.tar.zst
gsoc2013-epiphany-1d4cb08121bfadf263e8057d50e87833ef92c45b.zip
Reimplement search on the location bar
Use a regular expression and SoupURI to figure out if we should search the string that was typed, or load it as an URI. Bug #583795
Diffstat (limited to 'embed')
-rw-r--r--embed/ephy-web-view.c44
1 files changed, 43 insertions, 1 deletions
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 6bd0196cf..22f579a26 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -81,6 +81,9 @@ struct _EphyWebViewPrivate {
guint reload_scheduled_id;
guint reload_delay_ticks;
+ /* Regex to figure out if we're dealing with a wanna-be URI */
+ GRegex *non_search_regex;
+
GSList *hidden_popups;
GSList *shown_popups;
};
@@ -501,6 +504,11 @@ ephy_web_view_finalize (GObject *object)
priv->icon = NULL;
}
+ if (priv->non_search_regex != NULL) {
+ g_regex_unref (priv->non_search_regex);
+ priv->non_search_regex = NULL;
+ }
+
ephy_web_view_popups_manager_reset (EPHY_WEB_VIEW (object));
g_free (priv->address);
@@ -994,6 +1002,17 @@ ephy_web_view_init (EphyWebView *web_view)
priv->security_level = EPHY_WEB_VIEW_STATE_IS_UNKNOWN;
priv->monitor_directory = FALSE;
+ priv->non_search_regex = g_regex_new ("(^localhost$|"
+ "^[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]$|"
+ "^::[0-9a-f:]*$|" /* IPv6 literals */
+ "^[0-9a-f:]+:[0-9a-f:]*$|" /* IPv6 literals */
+ "^[^\\.[:space:]]+\\.[^\\.[:space:]]+.*$|" /* foo.bar... */
+ "^https?://[^/\\.[:space:]]+.*$|"
+ "^about:.*$|"
+ "^data:.*$|"
+ "^file:.*$)",
+ G_REGEX_OPTIMIZE, G_REGEX_MATCH_NOTEMPTY, NULL);
+
g_signal_connect_object (web_view, "ge_document_type",
G_CALLBACK (ge_document_type_cb),
web_view, (GConnectFlags)0);
@@ -1069,13 +1088,36 @@ 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);
- effective_url = ephy_embed_utils_normalize_address (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))
+ effective_url = g_strdup_printf (_("http://www.google.com/search?q=%s&ie=UTF-8&oe=UTF-8"), url);
+ else
+ effective_url = ephy_embed_utils_normalize_address (url);
+
webkit_web_view_open (WEBKIT_WEB_VIEW (view), effective_url);
+
+ if (soup_uri)
+ soup_uri_free (soup_uri);
+
g_free (effective_url);
}