[epiphany/wip/exalm/newtab-dark: 1/2] Stop using about:blank for new tabs
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/exalm/newtab-dark: 1/2] Stop using about:blank for new tabs
- Date: Wed, 24 Nov 2021 08:42:37 +0000 (UTC)
commit c2621f7178c3e1b6f176e6e75d71e059ca845085
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Wed Nov 24 02:15:46 2021 +0500
Stop using about:blank for new tabs
about:blank is still white even when the app is using dark style.
Go with the same approach as Safari and introduce a new page for new tab
instead: about:newtab. As a bonus, we can give it a proper title instead
of "blank page".
Fixes https://gitlab.gnome.org/GNOME/epiphany/-/issues/1555
embed/ephy-about-handler.c | 19 +++++++++++++++++++
embed/ephy-embed-shell.c | 4 +++-
embed/ephy-embed-utils.c | 6 ++++++
embed/ephy-embed-utils.h | 1 +
embed/ephy-web-view.c | 10 ++++++++++
embed/ephy-web-view.h | 1 +
src/ephy-action-bar-start.c | 2 +-
src/ephy-desktop-utils.c | 2 ++
src/ephy-session.c | 3 ++-
src/ephy-window.c | 8 ++++++--
src/preferences/prefs-general-page.c | 6 +++---
src/window-commands.c | 2 +-
12 files changed, 55 insertions(+), 9 deletions(-)
---
diff --git a/embed/ephy-about-handler.c b/embed/ephy-about-handler.c
index 43d91adaa..d502b845d 100644
--- a/embed/ephy-about-handler.c
+++ b/embed/ephy-about-handler.c
@@ -440,6 +440,23 @@ out:
g_object_unref (request);
}
+static gboolean
+ephy_about_handler_handle_newtab (EphyAboutHandler *handler,
+ WebKitURISchemeRequest *request)
+{
+ char *data;
+
+ data = g_strdup_printf ("<html><head><title>%s</title>"
+ "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
+ "</head><body style=\"color-scheme: light dark;\">"
+ "</body></html>",
+ _(NEW_TAB_PAGE_TITLE));
+
+ ephy_about_handler_finish_request (request, data, -1);
+
+ return TRUE;
+}
+
EphyHistoryQuery *
ephy_history_query_new_for_overview (void)
{
@@ -543,6 +560,8 @@ ephy_about_handler_handle_request (EphyAboutHandler *handler,
handled = ephy_about_handler_handle_epiphany (handler, request);
else if (!g_strcmp0 (path, "applications") && !ephy_is_running_inside_flatpak ())
handled = ephy_about_handler_handle_applications (handler, request);
+ else if (!g_strcmp0 (path, "newtab"))
+ handled = ephy_about_handler_handle_newtab (handler, request);
else if (!g_strcmp0 (path, "overview"))
handled = ephy_about_handler_handle_html_overview (handler, request);
else if (!g_strcmp0 (path, "incognito"))
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index 0d3002b80..abfa0d7d8 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -156,7 +156,9 @@ tabs_catalog_get_tabs_info (EphyTabsCatalog *catalog)
for (GList *t = tabs; t && t->data; t = t->next) {
title = ephy_embed_get_title (t->data);
- if (!g_strcmp0 (title, _(BLANK_PAGE_TITLE)) || !g_strcmp0 (title, _(OVERVIEW_PAGE_TITLE)))
+ if (!g_strcmp0 (title, _(BLANK_PAGE_TITLE)) ||
+ !g_strcmp0 (title, _(NEW_TAB_PAGE_TITLE)) ||
+ !g_strcmp0 (title, _(OVERVIEW_PAGE_TITLE)))
continue;
url = ephy_web_view_get_display_address (ephy_embed_get_web_view (t->data));
diff --git a/embed/ephy-embed-utils.c b/embed/ephy-embed-utils.c
index e6cc8dd79..8621f136a 100644
--- a/embed/ephy-embed-utils.c
+++ b/embed/ephy-embed-utils.c
@@ -375,6 +375,7 @@ ephy_embed_utils_url_is_empty (const char *location)
return (location == NULL ||
location[0] == '\0' ||
strcmp (location, "about:blank") == 0 ||
+ strcmp (location, "ephy-about:newtab") == 0 ||
strcmp (location, "ephy-about:overview") == 0 ||
strcmp (location, "ephy-about:incognito") == 0);
}
@@ -383,6 +384,7 @@ ephy_embed_utils_url_is_empty (const char *location)
* window's location entry. */
static const char *do_not_show_address[] = {
"about:blank",
+ "ephy-about:newtab",
"ephy-about:incognito",
"ephy-about:overview",
NULL
@@ -416,6 +418,10 @@ ephy_embed_utils_get_title_from_address (const char *address)
!strcmp (address, "about:overview"))
return g_strdup (_(OVERVIEW_PAGE_TITLE));
+ if (!strcmp (address, EPHY_ABOUT_SCHEME ":newtab") ||
+ !strcmp (address, "about:newtab"))
+ return g_strdup (_(NEW_TAB_PAGE_TITLE));
+
return ephy_string_get_host_name (address);
}
diff --git a/embed/ephy-embed-utils.h b/embed/ephy-embed-utils.h
index 1385b8b56..613024956 100644
--- a/embed/ephy-embed-utils.h
+++ b/embed/ephy-embed-utils.h
@@ -30,6 +30,7 @@ G_BEGIN_DECLS
#define BLANK_PAGE_TITLE N_("Blank page") /* Title for the blank page */
#define OVERVIEW_PAGE_TITLE N_("Most Visited") /* Title for the overview page */
+#define NEW_TAB_PAGE_TITLE N_("New Tab") /* Title for the new tab page */
#define EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED(embed) (WEBKIT_WEB_VIEW (ephy_embed_get_web_view (embed)))
#define EPHY_GET_EMBED_FROM_EPHY_WEB_VIEW(view) (EPHY_EMBED (gtk_widget_get_parent (gtk_widget_get_parent
((GTK_WIDGET (view))))))
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index b40c05157..2f964ccf5 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -2956,6 +2956,16 @@ ephy_web_view_is_overview (EphyWebView *view)
!strcmp (view->address, "about:overview"));
}
+gboolean
+ephy_web_view_is_newtab (EphyWebView *view)
+{
+ if (!view->address)
+ return FALSE;
+
+ return (!strcmp (view->address, EPHY_ABOUT_SCHEME ":newtab") ||
+ !strcmp (view->address, "about:newtab"));
+}
+
/**
* ephy_web_view_get_address:
* @view: an #EphyWebView
diff --git a/embed/ephy-web-view.h b/embed/ephy-web-view.h
index 8cf7019db..5e45cb861 100644
--- a/embed/ephy-web-view.h
+++ b/embed/ephy-web-view.h
@@ -105,6 +105,7 @@ gboolean ephy_web_view_get_should_bypass_safe_browsing (EphyWebView
void ephy_web_view_set_should_bypass_safe_browsing (EphyWebView *view,
gboolean
bypass_safe_browsing);
gboolean ephy_web_view_get_is_blank (EphyWebView *view);
+gboolean ephy_web_view_is_newtab (EphyWebView *view);
gboolean ephy_web_view_is_overview (EphyWebView *view);
void ephy_web_view_has_modified_forms (EphyWebView *view,
GCancellable *cancellable,
diff --git a/src/ephy-action-bar-start.c b/src/ephy-action-bar-start.c
index 2cb1955d9..feac717fe 100644
--- a/src/ephy-action-bar-start.c
+++ b/src/ephy-action-bar-start.c
@@ -475,7 +475,7 @@ homepage_url_changed (GSettings *settings,
setting = g_settings_get_string (settings, key);
if (setting && setting[0])
- show_button = g_strcmp0 (setting, "about:blank") != 0;
+ show_button = g_strcmp0 (setting, "about:newtab") != 0;
else
show_button = is_desktop_pantheon ();
diff --git a/src/ephy-desktop-utils.c b/src/ephy-desktop-utils.c
index 5f52bb784..732f72ac2 100644
--- a/src/ephy-desktop-utils.c
+++ b/src/ephy-desktop-utils.c
@@ -62,6 +62,8 @@ ephy_get_fallback_favicon_name (const char *uri,
if (uri) {
if (g_str_has_prefix (uri, "ephy-about:overview") || g_str_has_prefix (uri, "about:overview"))
return type == EPHY_FAVICON_TYPE_SHOW_MISSING_PLACEHOLDER ? "view-grid-symbolic" : NULL;
+ else if (g_str_has_prefix (uri, "ephy-about:newtab") || g_str_has_prefix (uri, "about:newtab"))
+ return NULL;
else if (g_str_has_prefix (uri, "ephy-about:") || g_str_has_prefix (uri, "about:"))
return "web-browser-symbolic";
}
diff --git a/src/ephy-session.c b/src/ephy-session.c
index 815498e98..af2df8f3c 100644
--- a/src/ephy-session.c
+++ b/src/ephy-session.c
@@ -300,7 +300,8 @@ ephy_session_tab_closed (EphySession *session,
wk_view = WEBKIT_WEB_VIEW (view);
if (!webkit_web_view_can_go_back (wk_view) && !webkit_web_view_can_go_forward (wk_view) &&
- (ephy_web_view_get_is_blank (view) || ephy_web_view_is_overview (view))) {
+ (ephy_web_view_get_is_blank (view) || ephy_web_view_is_newtab (view) ||
+ ephy_web_view_is_overview (view))) {
return;
}
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 8df7833dc..6f8ac95b8 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -2806,7 +2806,9 @@ ephy_window_close_tab (EphyWindow *window,
if (keep_window_open && ephy_tab_view_get_n_pages (window->tab_view) == 1) {
EphyWebView *view = ephy_embed_get_web_view (tab);
- if (ephy_web_view_get_is_blank (view) || ephy_web_view_is_overview (view))
+ if (ephy_web_view_get_is_blank (view) ||
+ ephy_web_view_is_newtab (view) ||
+ ephy_web_view_is_overview (view))
return;
ephy_link_open (EPHY_LINK (window), NULL, NULL, EPHY_LINK_NEW_TAB);
@@ -2987,7 +2989,9 @@ ephy_window_update_entry_focus (EphyWindow *window,
const char *address = NULL;
address = ephy_web_view_get_address (view);
- if (!ephy_embed_utils_is_no_show_address (address) && !ephy_web_view_is_overview (view))
+ if (!ephy_embed_utils_is_no_show_address (address) &&
+ !ephy_web_view_is_newtab (view) &&
+ !ephy_web_view_is_overview (view))
return;
title_widget = GTK_WIDGET (ephy_header_bar_get_title_widget (EPHY_HEADER_BAR (window->header_bar)));
diff --git a/src/preferences/prefs-general-page.c b/src/preferences/prefs-general-page.c
index b17241edc..4bae44c72 100644
--- a/src/preferences/prefs-general-page.c
+++ b/src/preferences/prefs-general-page.c
@@ -960,7 +960,7 @@ blank_homepage_get_mapping (GValue *value,
const char *setting;
setting = g_variant_get_string (variant, NULL);
- if (g_strcmp0 (setting, "about:blank") == 0)
+ if (g_strcmp0 (setting, "about:newtab") == 0)
g_value_set_boolean (value, TRUE);
return TRUE;
@@ -978,7 +978,7 @@ blank_homepage_set_mapping (const GValue *value,
gtk_entry_set_text (GTK_ENTRY (general_page->custom_homepage_entry), "");
- return g_variant_new_string ("about:blank");
+ return g_variant_new_string ("about:newtab");
}
static gboolean
@@ -989,7 +989,7 @@ custom_homepage_get_mapping (GValue *value,
const char *setting;
setting = g_variant_get_string (variant, NULL);
- if (setting && setting[0] != '\0' && g_strcmp0 (setting, "about:blank") != 0)
+ if (setting && setting[0] != '\0' && g_strcmp0 (setting, "about:newtab") != 0)
g_value_set_boolean (value, TRUE);
return TRUE;
}
diff --git a/src/window-commands.c b/src/window-commands.c
index 8744ae10f..a6bc16b6b 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -1309,7 +1309,7 @@ window_cmd_new_tab (GSimpleAction *action,
char *url;
url = g_settings_get_string (EPHY_SETTINGS_MAIN, EPHY_PREFS_HOMEPAGE_URL);
- if (g_strcmp0 (url, "about:blank") != 0) {
+ if (g_strcmp0 (url, "about:newtab") != 0) {
g_free (url);
url = NULL;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]