[epiphany] embed-utils: Move ephy_web_view_normalize_or_autosearch_url to embed-utils
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] embed-utils: Move ephy_web_view_normalize_or_autosearch_url to embed-utils
- Date: Mon, 3 Mar 2014 13:35:25 +0000 (UTC)
commit bbfc8866769bc04c36f9476d7c63ec5b5fca84d6
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Mon Feb 24 18:49:07 2014 +0100
embed-utils: Move ephy_web_view_normalize_or_autosearch_url to embed-utils
And use it only for actually typed (or pasted) text.
https://bugzilla.gnome.org/show_bug.cgi?id=725081
embed/ephy-embed-private.h | 3 -
embed/ephy-embed-utils.c | 26 ++++++++++++
embed/ephy-embed-utils.h | 1 +
embed/ephy-web-view.c | 87 +--------------------------------------
src/ephy-location-controller.c | 31 +++++++++++++-
src/ephy-notebook.c | 6 ++-
tests/ephy-web-view-test.c | 3 +-
7 files changed, 65 insertions(+), 92 deletions(-)
---
diff --git a/embed/ephy-embed-private.h b/embed/ephy-embed-private.h
index d023efb..5500b82 100644
--- a/embed/ephy-embed-private.h
+++ b/embed/ephy-embed-private.h
@@ -61,9 +61,6 @@ void ephy_web_view_load_homepage (EphyWebView
char * ephy_web_view_create_web_application (EphyWebView *view,
const char *title,
GdkPixbuf *icon);
-char* ephy_web_view_normalize_or_autosearch_url (EphyWebView *view,
- const char *url);
-
EphyFrecentStore *ephy_embed_shell_get_frecent_store (EphyEmbedShell *shell);
G_END_DECLS
diff --git a/embed/ephy-embed-utils.c b/embed/ephy-embed-utils.c
index 94ce596..cd39780 100644
--- a/embed/ephy-embed-utils.c
+++ b/embed/ephy-embed-utils.c
@@ -26,6 +26,7 @@
#include "ephy-about-handler.h"
#include "ephy-embed-private.h"
+#include "ephy-settings.h"
#include "ephy-string.h"
#include <string.h>
@@ -226,6 +227,31 @@ ephy_embed_utils_normalize_address (const char *address)
return effective_address ? effective_address : g_strdup (address);
}
+char *
+ephy_embed_utils_normalize_or_autosearch_address (const char *address)
+{
+ char *query_param, *url_search;
+ char *effective_address;
+
+ if (ephy_embed_utils_address_is_valid (address))
+ return ephy_embed_utils_normalize_address (address);
+
+ url_search = g_settings_get_string (EPHY_SETTINGS_MAIN,
+ EPHY_PREFS_KEYWORD_SEARCH_URL);
+ if (url_search == NULL || url_search[0] == '\0') {
+ g_free (url_search);
+ url_search = g_strdup (_("http://duckduckgo.com/?q=%s&t=epiphany"));
+ }
+
+ query_param = soup_form_encode ("q", address, NULL);
+ /* + 2 here is getting rid of 'q=' */
+ effective_address = g_strdup_printf (url_search, query_param + 2);
+ g_free (query_param);
+ g_free (url_search);
+
+ return effective_address;
+}
+
gboolean
ephy_embed_utils_url_is_empty (const char *location)
{
diff --git a/embed/ephy-embed-utils.h b/embed/ephy-embed-utils.h
index 2cb6a7e..c5d0342 100644
--- a/embed/ephy-embed-utils.h
+++ b/embed/ephy-embed-utils.h
@@ -42,6 +42,7 @@ gboolean ephy_embed_utils_address_has_web_scheme (const char *add
gboolean ephy_embed_utils_address_is_existing_absolute_filename (const char *address);
gboolean ephy_embed_utils_address_is_valid (const char *address);
char* ephy_embed_utils_normalize_address (const char *address);
+char * ephy_embed_utils_normalize_or_autosearch_address (const char *address);
gboolean ephy_embed_utils_url_is_empty (const char *location);
gboolean ephy_embed_utils_is_no_show_address (const char *address);
void ephy_embed_utils_shutdown (void);
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index f8228b9..5b7e780 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -2030,48 +2030,6 @@ ephy_web_view_new_with_related_view (WebKitWebView *related_view)
}
/**
- * ephy_web_view_normalize_or_autosearch_url:
- * @view: an %EphyWebView
- * @url: a URI
- *
- * Returns a normalized representation of @url, or an autosearch
- * string for it when necessary.
- *
- * Returns: the normalized @url or autosearch string.
- **/
-char*
-ephy_web_view_normalize_or_autosearch_url (EphyWebView *view, const char *url)
-{
- char *effective_url;
-
- g_return_val_if_fail (EPHY_IS_WEB_VIEW (view), NULL);
- g_return_val_if_fail (url, NULL);
-
- /* If the string doesn't look like an URI, let's search it; */
- if (!ephy_embed_utils_address_is_valid (url)) {
- char *query_param, *url_search;
-
- url_search = g_settings_get_string (EPHY_SETTINGS_MAIN,
- EPHY_PREFS_KEYWORD_SEARCH_URL);
-
- if (url_search == NULL || url_search[0] == '\0') {
- g_free (url_search);
-
- url_search = g_strdup (_("http://duckduckgo.com/?q=%s&t=epiphany"));
- }
-
- query_param = soup_form_encode ("q", url, NULL);
- /* + 2 here is getting rid of 'q=' */
- effective_url = g_strdup_printf (url_search, query_param + 2);
- g_free (query_param);
- g_free (url_search);
- } else
- effective_url = ephy_embed_utils_normalize_address (url);
-
- return effective_url;
-}
-
-/**
* ephy_web_view_load_request:
* @view: the #EphyWebView in which to load the request
* @request: the #WebKitNetworkRequest to be loaded
@@ -2089,7 +2047,7 @@ ephy_web_view_load_request (EphyWebView *view,
g_return_if_fail (WEBKIT_IS_URI_REQUEST (request));
url = webkit_uri_request_get_uri (request);
- effective_url = ephy_web_view_normalize_or_autosearch_url (view, url);
+ effective_url = ephy_embed_utils_normalize_address (url);
webkit_uri_request_set_uri (request, effective_url);
g_free (effective_url);
@@ -2155,47 +2113,8 @@ ephy_web_view_load_url (EphyWebView *view,
g_return_if_fail (EPHY_IS_WEB_VIEW (view));
g_return_if_fail (url);
- effective_url = ephy_web_view_normalize_or_autosearch_url (view, url);
-
- /* After normalization there are still some cases that are
- * impossible to tell apart. One example is <URI>:<PORT> and <NON
- * WEB SCHEME>:<DATA>. To fix this, let's do a HEAD request to the
- * effective URI prefxed with http://; if we get OK Status the URI
- * exists, and we'll go ahead, otherwise we'll try to launch a
- * proper handler through gtk_show_uri. We only do this in
- * ephy_web_view_load_url, since this case is only relevant for URIs
- * typed in the location entry, which uses this method to do the
- * load. */
- if (!ephy_embed_utils_address_has_web_scheme (effective_url)) {
-#if 0
- /* TODO: WebKit2, Network features */
- SoupMessage *message;
- SoupSession *session;
- char *temp_url;
- HEADAttemptData *data;
-
- temp_url = g_strconcat ("http://", effective_url, NULL);
-
- session = webkit_get_default_session ();
- message = soup_message_new (SOUP_METHOD_HEAD,
- temp_url);
-
- if (message) {
- data = g_slice_new (HEADAttemptData);
- data->view = view;
- data->original_uri = g_strdup (effective_url);
- soup_session_queue_message (session, message,
- effective_url_head_cb, data);
- } else {
- /* If we cannot even create a message fallback to the effective
- * url, the gtk_show_uri code will make another attempt in
- * EphyWindow's policy code. */
- webkit_web_view_load_uri (WEBKIT_WEB_VIEW (view), effective_url);
- }
-
- g_free (temp_url);
-#endif
- } else if (g_str_has_prefix (effective_url, "javascript:")) {
+ effective_url = ephy_embed_utils_normalize_address (url);
+ if (g_str_has_prefix (effective_url, "javascript:")) {
char *decoded_url;
decoded_url = soup_uri_decode (effective_url);
diff --git a/src/ephy-location-controller.c b/src/ephy-location-controller.c
index eaf7868..883ade5 100644
--- a/src/ephy-location-controller.c
+++ b/src/ephy-location-controller.c
@@ -176,11 +176,15 @@ entry_drag_data_received_cb (GtkWidget *widget,
}
g_strfreev (uris);
} else if (gtk_selection_data_get_target (selection_data) == text_type) {
+ char *address;
+
gtk_entry_set_text (entry, (const gchar *)sel_data);
+ address = ephy_embed_utils_normalize_or_autosearch_address ((const gchar *)sel_data);
ephy_link_open (EPHY_LINK (controller),
- (const gchar *)sel_data,
+ address,
NULL,
ephy_link_flags_from_current_event ());
+ g_free (address);
}
}
@@ -191,6 +195,7 @@ entry_activate_cb (GtkEntry *entry,
EphyBookmarks *bookmarks;
const char *content;
char *address;
+ char *effective_address;
EphyLocationControllerPrivate *priv;
priv = controller->priv;
@@ -209,10 +214,30 @@ entry_activate_cb (GtkEntry *entry,
address = ephy_bookmarks_resolve_address (bookmarks, content, NULL);
g_return_if_fail (address != NULL);
- ephy_link_open (EPHY_LINK (controller), g_strstrip (address), NULL,
+ effective_address = ephy_embed_utils_normalize_or_autosearch_address (g_strstrip (address));
+ g_free (address);
+#if 0
+ if (!ephy_embed_utils_address_has_web_scheme (effective_address))
+ {
+ /* After normalization there are still some cases that are
+ * impossible to tell apart. One example is <URI>:<PORT> and <NON
+ * WEB SCHEME>:<DATA>. To fix this, let's do a HEAD request to the
+ * effective URI prefxed with http://; if we get OK Status the URI
+ * exists, and we'll go ahead, otherwise we'll try to launch a
+ * proper handler through gtk_show_uri. We only do this in
+ * ephy_web_view_load_url, since this case is only relevant for URIs
+ * typed in the location entry, which uses this method to do the
+ * load. */
+ /* TODO: however, this is not really possible, because normalize_or_autosearch_address
+ * prepends http:// for anything that doesn't look like a URL.
+ */
+ }
+#endif
+
+ ephy_link_open (EPHY_LINK (controller), effective_address, NULL,
ephy_link_flags_from_current_event () | EPHY_LINK_TYPED);
- g_free (address);
+ g_free (effective_address);
}
static void
diff --git a/src/ephy-notebook.c b/src/ephy-notebook.c
index 0760f33..67073cf 100644
--- a/src/ephy-notebook.c
+++ b/src/ephy-notebook.c
@@ -368,8 +368,12 @@ notebook_drag_data_received_cb (GtkWidget* widget,
text = (char *) gtk_selection_data_get_text (selection_data);
if (text != NULL) {
- ephy_link_open (EPHY_LINK (notebook), text, embed,
+ char *address;
+
+ address = ephy_embed_utils_normalize_or_autosearch_address (text);
+ ephy_link_open (EPHY_LINK (notebook), address, embed,
embed ? 0 : EPHY_LINK_NEW_TAB);
+ g_free (address);
g_free (text);
}
}
diff --git a/tests/ephy-web-view-test.c b/tests/ephy-web-view-test.c
index b078583..3156125 100644
--- a/tests/ephy-web-view-test.c
+++ b/tests/ephy-web-view-test.c
@@ -26,6 +26,7 @@
#include "ephy-debug.h"
#include "ephy-embed-prefs.h"
#include "ephy-embed-private.h"
+#include "ephy-embed-utils.h"
#include "ephy-file-helpers.h"
#include "ephy-history-service.h"
#include "ephy-private.h"
@@ -283,7 +284,7 @@ verify_normalize_or_autosearch_urls (EphyWebView *view,
url = test[i].url;
- result = ephy_web_view_normalize_or_autosearch_url (view, url);
+ result = ephy_embed_utils_normalize_or_autosearch_address (url);
g_assert_cmpstr (result, ==, test[i].expected);
g_free (result);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]