[epiphany] Hide navigation buttons if webapp supports apple-mobile-web-app-capable
- From: Jan-Michael Brummer <jbrummer src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] Hide navigation buttons if webapp supports apple-mobile-web-app-capable
- Date: Tue, 10 Mar 2020 20:32:25 +0000 (UTC)
commit 91f81b1c292c003d53c15137fa129abac5ab1e26
Author: Jan-Michael Brummer <jan brummer tabos org>
Date: Fri Feb 28 22:01:48 2020 +0100
Hide navigation buttons if webapp supports apple-mobile-web-app-capable
Fixes: https://gitlab.gnome.org/GNOME/epiphany/issues/212
data/org.gnome.epiphany.gschema.xml | 19 +++++----
embed/ephy-web-view.c | 53 ++++++++++++++++++++++++
embed/ephy-web-view.h | 7 ++++
embed/web-process-extension/resources/js/ephy.js | 14 +++++++
lib/ephy-prefs.h | 1 +
lib/ephy-web-app-utils.c | 25 ++++++++---
lib/ephy-web-app-utils.h | 9 +++-
src/ephy-header-bar.c | 8 ++++
src/window-commands.c | 25 ++++++++++-
tests/ephy-web-app-utils-test.c | 2 +-
10 files changed, 146 insertions(+), 17 deletions(-)
---
diff --git a/data/org.gnome.epiphany.gschema.xml b/data/org.gnome.epiphany.gschema.xml
index c272268c6..948e3c141 100644
--- a/data/org.gnome.epiphany.gschema.xml
+++ b/data/org.gnome.epiphany.gschema.xml
@@ -231,13 +231,18 @@
<description>Whether to present a directory chooser dialog for every
download.</description>
</key>
</schema>
- <schema id="org.gnome.Epiphany.webapp">
- <key type="as" name="additional-urls">
- <default>[]</default>
- <summary>Web application additional URLs</summary>
- <description>The list of URLs that should be opened by the web
application</description>
- </key>
- </schema>
+ <schema id="org.gnome.Epiphany.webapp">
+ <key type="as" name="additional-urls">
+ <default>[]</default>
+ <summary>Web application additional URLs</summary>
+ <description>The list of URLs that should be opened by the web
application</description>
+ </key>
+ <key type="b" name="mobile-capable">
+ <default>false</default>
+ <summary>WebApp is mobile capable</summary>
+ <description>Whether to show buttons for navigation.</description>
+ </key>
+ </schema>
<schema id="org.gnome.Epiphany.state">
<key type="s" name="download-dir">
<default>'Downloads'</default>
diff --git a/embed/ephy-web-view.c b/embed/ephy-web-view.c
index 841baab17..8493f09eb 100644
--- a/embed/ephy-web-view.c
+++ b/embed/ephy-web-view.c
@@ -3077,6 +3077,59 @@ ephy_web_view_get_web_app_title_finish (EphyWebView *view,
return g_task_propagate_pointer (G_TASK (result), error);
}
+static void
+get_web_app_mobile_capable_cb (WebKitWebView *view,
+ GAsyncResult *result,
+ GTask *task)
+{
+ WebKitJavascriptResult *js_result;
+ GError *error = NULL;
+
+ js_result = webkit_web_view_run_javascript_in_world_finish (view, result, &error);
+ if (js_result) {
+ JSCValue *js_value;
+ gboolean retval = FALSE;
+
+ js_value = webkit_javascript_result_get_js_value (js_result);
+ retval = jsc_value_to_boolean (js_value);
+
+ g_task_return_boolean (task, retval);
+ webkit_javascript_result_unref (js_result);
+ } else
+ g_task_return_error (task, error);
+
+ g_object_unref (task);
+}
+
+void
+ephy_web_view_get_web_app_mobile_capable (EphyWebView *view,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GTask *task;
+
+ g_assert (EPHY_IS_WEB_VIEW (view));
+
+ task = g_task_new (view, cancellable, callback, user_data);
+ webkit_web_view_run_javascript_in_world (WEBKIT_WEB_VIEW (view),
+ "Ephy.getAppleMobileWebAppCapable();",
+ ephy_embed_shell_get_guid (ephy_embed_shell_get_default ()),
+ cancellable,
+ (GAsyncReadyCallback)get_web_app_mobile_capable_cb,
+ task);
+}
+
+gboolean
+ephy_web_view_get_web_app_mobile_capable_finish (EphyWebView *view,
+ GAsyncResult *result,
+ GError **error)
+{
+ g_assert (g_task_is_valid (result, view));
+
+ return g_task_propagate_boolean (G_TASK (result), error);
+}
+
/**
* ephy_web_view_get_security_level:
* @view: an #EphyWebView
diff --git a/embed/ephy-web-view.h b/embed/ephy-web-view.h
index 21a4defc9..4bc2516a1 100644
--- a/embed/ephy-web-view.h
+++ b/embed/ephy-web-view.h
@@ -143,6 +143,13 @@ void ephy_web_view_get_web_app_title (EphyWebView
char *ephy_web_view_get_web_app_title_finish (EphyWebView *view,
GAsyncResult *result,
GError **error);
+void ephy_web_view_get_web_app_mobile_capable (EphyWebView *view,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean ephy_web_view_get_web_app_mobile_capable_finish (EphyWebView *view,
+ GAsyncResult *result,
+ GError **error);
void ephy_web_view_set_visit_type (EphyWebView *view,
EphyHistoryPageVisitType visit_type);
diff --git a/embed/web-process-extension/resources/js/ephy.js
b/embed/web-process-extension/resources/js/ephy.js
index b487528ad..a4ec51e5e 100644
--- a/embed/web-process-extension/resources/js/ephy.js
+++ b/embed/web-process-extension/resources/js/ephy.js
@@ -2,6 +2,20 @@
var Ephy = {};
+Ephy.getAppleMobileWebAppCapable = function()
+{
+ let metas = document.getElementsByTagName('meta');
+
+ for (let i = 0; i < metas.length; i++) {
+ let meta = metas[i];
+
+ if (meta.name == 'apple-mobile-web-app-capable' && meta.getAttribute('content') == 'yes')
+ return true;
+ }
+
+ return false;
+}
+
Ephy.getWebAppTitle = function()
{
let metas = document.getElementsByTagName('meta');
diff --git a/lib/ephy-prefs.h b/lib/ephy-prefs.h
index f7479584f..c0b651f22 100644
--- a/lib/ephy-prefs.h
+++ b/lib/ephy-prefs.h
@@ -197,6 +197,7 @@ static const char * const ephy_prefs_web_schema[] = {
#define EPHY_PREFS_WEB_APP_SCHEMA "org.gnome.Epiphany.webapp"
#define EPHY_PREFS_WEB_APP_ADDITIONAL_URLS "additional-urls"
+#define EPHY_PREFS_WEB_APP_MOBILE_CAPABLE "mobile-capable"
static struct {
const char *schema;
diff --git a/lib/ephy-web-app-utils.c b/lib/ephy-web-app-utils.c
index cc00a2ba1..18f165a03 100644
--- a/lib/ephy-web-app-utils.c
+++ b/lib/ephy-web-app-utils.c
@@ -363,16 +363,18 @@ create_desktop_file (const char *id,
* @address: the address of the new web application
* @name: the name for the new web application
* @icon: the icon for the new web application
+ * @options: the options for the new web application
*
* Creates a new Web Application for @address.
*
* Returns: (transfer-full): the path to the desktop file representing the new application
**/
char *
-ephy_web_application_create (const char *id,
- const char *address,
- const char *name,
- GdkPixbuf *icon)
+ephy_web_application_create (const char *id,
+ const char *address,
+ const char *name,
+ GdkPixbuf *icon,
+ EphyWebApplicationOptions options)
{
g_autofree char *app_file = NULL;
g_autofree char *profile_dir = NULL;
@@ -408,7 +410,7 @@ ephy_web_application_create (const char *id,
/* Create the deskop file. */
desktop_file_path = create_desktop_file (id, name, address, profile_dir, icon);
if (desktop_file_path)
- ephy_web_application_initialize_settings (profile_dir);
+ ephy_web_application_initialize_settings (profile_dir, options);
return g_steal_pointer (&desktop_file_path);
}
@@ -712,7 +714,8 @@ ephy_web_application_exists (const char *id)
}
void
-ephy_web_application_initialize_settings (const char *profile_directory)
+ephy_web_application_initialize_settings (const char *profile_directory,
+ EphyWebApplicationOptions options)
{
GSettings *settings;
GSettings *web_app_settings;
@@ -753,6 +756,16 @@ ephy_web_application_initialize_settings (const char *profile_directory)
g_object_unref (settings);
g_object_unref (web_app_settings);
+
+ if (options & EPHY_WEB_APPLICATION_MOBILE_CAPABLE) {
+ path = g_build_path ("/", "/org/gnome/epiphany/web-apps/", name, "webapp/", NULL);
+ web_app_settings = g_settings_new_with_path (EPHY_PREFS_WEB_APP_SCHEMA, path);
+ g_free (path);
+
+ g_settings_set_boolean (web_app_settings, EPHY_PREFS_WEB_APP_MOBILE_CAPABLE, TRUE);
+ g_object_unref (web_app_settings);
+ }
+
g_free (name);
}
diff --git a/lib/ephy-web-app-utils.h b/lib/ephy-web-app-utils.h
index 1d436858c..b51fdaf41 100644
--- a/lib/ephy-web-app-utils.h
+++ b/lib/ephy-web-app-utils.h
@@ -35,13 +35,18 @@ typedef struct {
char install_date[128];
} EphyWebApplication;
+typedef enum {
+ EPHY_WEB_APPLICATION_NONE,
+ EPHY_WEB_APPLICATION_MOBILE_CAPABLE,
+} EphyWebApplicationOptions;
+
#define EPHY_WEB_APP_ICON_NAME "app-icon.png"
char *ephy_web_application_get_app_id_from_name (const char *name);
const char *ephy_web_application_get_program_name_from_profile_directory (const char *profile_dir);
-char *ephy_web_application_create (const char *id, const char *address, const char *name,
GdkPixbuf *icon);
+char *ephy_web_application_create (const char *id, const char *address, const char *name,
GdkPixbuf *icon, EphyWebApplicationOptions options);
char *ephy_web_application_ensure_for_app_info (GAppInfo *app_info);
@@ -65,7 +70,7 @@ GList *ephy_web_application_get_legacy_application_list (void);
void ephy_web_application_free_application_list (GList *list);
-void ephy_web_application_initialize_settings (const char *profile_directory);
+void ephy_web_application_initialize_settings (const char *profile_directory,
EphyWebApplicationOptions options);
gboolean ephy_web_application_is_uri_allowed (const char *uri);
diff --git a/src/ephy-header-bar.c b/src/ephy-header-bar.c
index 12849de44..a5e3d8e46 100644
--- a/src/ephy-header-bar.c
+++ b/src/ephy-header-bar.c
@@ -26,9 +26,11 @@
#include "ephy-add-bookmark-popover.h"
#include "ephy-desktop-utils.h"
#include "ephy-embed-utils.h"
+#include "ephy-file-helpers.h"
#include "ephy-flatpak-utils.h"
#include "ephy-location-entry.h"
#include "ephy-notebook.h"
+#include "ephy-settings.h"
#include "ephy-shell.h"
#include "ephy-title-box.h"
#include "ephy-title-widget.h"
@@ -362,6 +364,12 @@ ephy_header_bar_constructed (GObject *object)
gtk_size_group_add_widget (downloads_size_group,
ephy_action_bar_end_get_downloads_revealer (header_bar->action_bar_end));
g_object_unref (downloads_size_group);
+
+ if (ephy_profile_dir_is_web_application ()) {
+ GtkWidget *navigation_box = ephy_action_bar_start_get_navigation_box (header_bar->action_bar_start);
+
+ g_settings_bind (EPHY_SETTINGS_WEB_APP, EPHY_PREFS_WEB_APP_MOBILE_CAPABLE, navigation_box, "visible",
G_SETTINGS_BIND_DEFAULT | G_SETTINGS_BIND_INVERT_BOOLEAN);
+ }
}
static void
diff --git a/src/window-commands.c b/src/window-commands.c
index 501724ed3..7ac98934a 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -1013,6 +1013,7 @@ typedef struct {
char *icon_href;
GdkRGBA icon_rgba;
GCancellable *cancellable;
+ gboolean mobile_capable;
} EphyApplicationDialogData;
static void
@@ -1345,6 +1346,26 @@ fill_default_application_title (EphyApplicationDialogData *data)
ephy_web_view_get_web_app_title (data->view, data->cancellable, fill_default_application_title_cb, data);
}
+static void
+fill_mobile_capable_cb (GObject *source,
+ GAsyncResult *async_result,
+ gpointer user_data)
+{
+ g_autoptr (GError) error = NULL;
+ EphyApplicationDialogData *data = user_data;
+ gboolean capable;
+
+ capable = ephy_web_view_get_web_app_mobile_capable_finish (EPHY_WEB_VIEW (source), async_result, &error);
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ data->mobile_capable = capable;
+}
+
+static void
+fill_mobile_capable (EphyApplicationDialogData *data)
+{
+ ephy_web_view_get_web_app_mobile_capable (data->view, data->cancellable, fill_mobile_capable_cb, data);
+}
+
static void
notify_launch_cb (NotifyNotification *notification,
char *action,
@@ -1452,7 +1473,8 @@ dialog_save_as_application_response_cb (GtkDialog *dialog,
desktop_file = ephy_web_application_create (app_id,
webkit_web_view_get_uri (WEBKIT_WEB_VIEW (data->view)),
app_name,
- gtk_image_get_pixbuf (GTK_IMAGE (data->image)));
+ gtk_image_get_pixbuf (GTK_IMAGE (data->image)),
+ data->mobile_capable);
if (desktop_file)
message = g_strdup_printf (_("The application ā%sā is ready to be used"),
@@ -1571,6 +1593,7 @@ window_cmd_save_as_application (GSimpleAction *action,
fill_default_application_image (data);
fill_default_application_title (data);
+ fill_mobile_capable (data);
gtk_widget_show_all (dialog);
diff --git a/tests/ephy-web-app-utils-test.c b/tests/ephy-web-app-utils-test.c
index b0389303a..75b0642c9 100644
--- a/tests/ephy-web-app-utils-test.c
+++ b/tests/ephy-web-app-utils-test.c
@@ -68,7 +68,7 @@ test_web_app_lifetime (void)
/* Test creation */
id = ephy_web_application_get_app_id_from_name (test.name);
- desktop_file = ephy_web_application_create (id, test.url, test.name, NULL);
+ desktop_file = ephy_web_application_create (id, test.url, test.name, NULL, EPHY_WEB_APPLICATION_NONE);
g_assert_true (g_str_has_prefix (desktop_file, ephy_profile_dir ()));
g_assert_true (g_file_test (desktop_file, G_FILE_TEST_EXISTS));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]