[epiphany] Add window.browser.tabs.reload
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] Add window.browser.tabs.reload
- Date: Wed, 22 Jun 2022 21:55:01 +0000 (UTC)
commit 2f7438ebe163c8e0fae9e26023018aa76e5ac838
Author: Jan-Michael Brummer <jan brummer tabos org>
Date: Thu Jun 16 07:17:15 2022 +0200
Add window.browser.tabs.reload
Part-of: <https://gitlab.gnome.org/GNOME/epiphany/-/merge_requests/1146>
.../resources/js/webextensions.js | 2 ++
src/webextension/api/tabs.c | 34 +++++++++++++++++++++-
2 files changed, 35 insertions(+), 1 deletion(-)
---
diff --git a/embed/web-process-extension/resources/js/webextensions.js
b/embed/web-process-extension/resources/js/webextensions.js
index c230a8b20..df2790151 100644
--- a/embed/web-process-extension/resources/js/webextensions.js
+++ b/embed/web-process-extension/resources/js/webextensions.js
@@ -30,6 +30,7 @@ window.browser.tabs = {
update: function (...args) { return ephy_message ('tabs.update', args); },
getZoom: function (...args) { return ephy_message ('tabs.getZoom', args); },
setZoom: function (...args) { return ephy_message ('tabs.setZoom', args); },
+ reload: function (...args) { return ephy_message ('tabs.reload', args); },
onActivated: new EphyEventListener (),
onAttached: new EphyEventListener (),
onCreated: new EphyEventListener (),
@@ -151,3 +152,4 @@ window.browser.downloads = {
onErased: new EphyEventListener (),
onChanged: new EphyEventListener (),
};
+
diff --git a/src/webextension/api/tabs.c b/src/webextension/api/tabs.c
index 1f1ef3d30..4427f9d73 100644
--- a/src/webextension/api/tabs.c
+++ b/src/webextension/api/tabs.c
@@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
- * Copyright © 2019-2020 Jan-Michael Brummer <jan brummer tabos org>
+ * Copyright © 2019-2022 Jan-Michael Brummer <jan brummer tabos org>
*
* This file is part of Epiphany.
*
@@ -797,6 +797,37 @@ tabs_handler_get_zoom (EphyWebExtension *self,
return g_strdup_printf ("%f", webkit_web_view_get_zoom_level (target_web_view));
}
+static char *
+tabs_handler_reload (EphyWebExtension *self,
+ char *name,
+ JSCValue *args,
+ WebKitWebView *web_view,
+ GError **error)
+{
+ EphyShell *shell = ephy_shell_get_default ();
+ g_autoptr (JSCValue) tab_id_value = NULL;
+ WebKitWebView *target_web_view;
+ int tab_id = -1;
+
+ tab_id_value = jsc_value_object_get_property_at_index (args, 0);
+ if (jsc_value_is_number (tab_id_value))
+ tab_id = jsc_value_to_int32 (tab_id_value);
+
+ if (tab_id >= 0)
+ target_web_view = get_web_view_for_tab_id (shell, tab_id, NULL);
+ else
+ target_web_view = WEBKIT_WEB_VIEW (ephy_shell_get_active_web_view (shell));
+
+ if (!target_web_view) {
+ g_set_error (error, WEB_EXTENSION_ERROR, WEB_EXTENSION_ERROR_INVALID_ARGUMENT, "tabs.reload(): Failed to
find tabId %d.", tab_id);
+ return NULL;
+ }
+
+ webkit_web_view_reload (WEBKIT_WEB_VIEW (target_web_view));
+
+ return NULL;
+}
+
static EphyWebExtensionSyncApiHandler tabs_sync_handlers[] = {
{"create", tabs_handler_create},
{"query", tabs_handler_query},
@@ -807,6 +838,7 @@ static EphyWebExtensionSyncApiHandler tabs_sync_handlers[] = {
{"getZoom", tabs_handler_get_zoom},
{"setZoom", tabs_handler_set_zoom},
{"update", tabs_handler_update},
+ {"reload", tabs_handler_reload},
};
static EphyWebExtensionAsyncApiHandler tab_async_handlers[] = {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]