summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJan-Michael Brummer <jan.brummer@tabos.org>2019-05-02 09:53:25 +0200
committerJan-Michael Brummer <jan.brummer@tabos.org>2021-01-17 13:55:36 +0100
commit5410fec78bc699b593d327e6a98b105f6cef7cd5 (patch)
tree7e7f379bc6e9677d0ea8015c5c97996d9d49f920 /lib
parentda8757af88925c803be2201784a6821410150608 (diff)
downloadepiphany-5410fec78bc699b593d327e6a98b105f6cef7cd5.tar.gz
Add initial WebExtension support
Diffstat (limited to 'lib')
-rw-r--r--lib/ephy-file-helpers.c50
-rw-r--r--lib/ephy-file-helpers.h3
-rw-r--r--lib/ephy-prefs.h3
-rw-r--r--lib/ephy-string.c29
-rw-r--r--lib/ephy-string.h2
-rw-r--r--lib/widgets/ephy-location-entry.c67
-rw-r--r--lib/widgets/ephy-location-entry.h4
7 files changed, 116 insertions, 42 deletions
diff --git a/lib/ephy-file-helpers.c b/lib/ephy-file-helpers.c
index 8cd382afd..8bc2a494d 100644
--- a/lib/ephy-file-helpers.c
+++ b/lib/ephy-file-helpers.c
@@ -854,3 +854,53 @@ ephy_open_incognito_window (const char *uri)
g_free (command);
}
+
+void
+ephy_copy_directory (const char *source,
+ const char *target)
+{
+ g_autoptr (GError) error = NULL;
+ GFileType type;
+ g_autoptr (GFile) src_file = g_file_new_for_path (source);
+ g_autoptr (GFile) dest_file = g_file_new_for_path (target);
+
+ type = g_file_query_file_type (src_file, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL);
+
+ if (type == G_FILE_TYPE_DIRECTORY) {
+ g_autoptr (GFileEnumerator) enumerator = NULL;
+ g_autoptr (GFileInfo) info = NULL;
+
+ if (!g_file_make_directory_with_parents (dest_file, NULL, &error)) {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS)) {
+ g_warning ("Could not create target directory for webextension: %s", error->message);
+ return;
+ }
+
+ g_error_free (error);
+ }
+
+ if (!g_file_copy_attributes (src_file, dest_file, G_FILE_COPY_NONE, NULL, &error)) {
+ g_warning ("Could not copy file attributes for webextension: %s", error->message);
+ return;
+ }
+
+ enumerator = g_file_enumerate_children (src_file, G_FILE_ATTRIBUTE_STANDARD_NAME, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &error);
+ if (!enumerator) {
+ g_warning ("Could not create file enumberator for webextensions: %s", error->message);
+ return;
+ }
+
+ for (info = g_file_enumerator_next_file (enumerator, NULL, NULL); info != NULL; info = g_file_enumerator_next_file (enumerator, NULL, NULL)) {
+ ephy_copy_directory (
+ g_build_filename (source, g_file_info_get_name (info), NULL),
+ g_build_filename (target, g_file_info_get_name (info), NULL));
+ }
+ } else if (type == G_FILE_TYPE_REGULAR) {
+ if (!g_file_copy (src_file, dest_file, G_FILE_COPY_NONE, NULL, NULL, NULL, &error)) {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS)) {
+ g_warning ("Could not copy file for webextensions: %s", error->message);
+ return;
+ }
+ }
+ }
+}
diff --git a/lib/ephy-file-helpers.h b/lib/ephy-file-helpers.h
index 42477b745..c09d145c8 100644
--- a/lib/ephy-file-helpers.h
+++ b/lib/ephy-file-helpers.h
@@ -87,4 +87,7 @@ gboolean ephy_file_open_uri_in_default_browser (const char
gboolean ephy_file_browse_to (GFile *file,
guint32 user_time);
+void ephy_copy_directory (const char *source,
+ const char *target);
+
G_END_DECLS
diff --git a/lib/ephy-prefs.h b/lib/ephy-prefs.h
index fb0f37ef8..89d567e6c 100644
--- a/lib/ephy-prefs.h
+++ b/lib/ephy-prefs.h
@@ -117,6 +117,8 @@ static const char * const ephy_prefs_state_schema[] = {
#define EPHY_PREFS_WEB_HARDWARE_ACCELERATION_POLICY "hardware-acceleration-policy"
#define EPHY_PREFS_WEB_ASK_ON_DOWNLOAD "ask-on-download"
#define EPHY_PREFS_WEB_SWITCH_TO_NEW_TAB "switch-to-new-tab"
+#define EPHY_PREFS_WEB_ENABLE_WEBEXTENSIONS "enable-webextensions"
+#define EPHY_PREFS_WEB_WEBEXTENSIONS_ACTIVE "webextensions-active"
static const char * const ephy_prefs_web_schema[] = {
EPHY_PREFS_WEB_FONT_MIN_SIZE,
@@ -146,6 +148,7 @@ static const char * const ephy_prefs_web_schema[] = {
EPHY_PREFS_WEB_HARDWARE_ACCELERATION_POLICY,
EPHY_PREFS_WEB_ASK_ON_DOWNLOAD,
EPHY_PREFS_WEB_SWITCH_TO_NEW_TAB,
+ EPHY_PREFS_WEB_ENABLE_WEBEXTENSIONS,
};
#define EPHY_PREFS_SCHEMA "org.gnome.Epiphany"
diff --git a/lib/ephy-string.c b/lib/ephy-string.c
index 509490c86..5dbf66c9b 100644
--- a/lib/ephy-string.c
+++ b/lib/ephy-string.c
@@ -316,35 +316,6 @@ ephy_string_remove_trailing (char *string,
}
char **
-ephy_strv_append (const char * const *strv,
- const char *str)
-{
- char **new_strv;
- char **n;
- const char * const *s;
- guint len;
-
- if (g_strv_contains (strv, str))
- return g_strdupv ((char **)strv);
-
- /* Needs room for one more string than before, plus one for trailing NULL. */
- len = g_strv_length ((char **)strv);
- new_strv = g_malloc ((len + 1 + 1) * sizeof (char *));
- n = new_strv;
- s = strv;
-
- while (*s != NULL) {
- *n = g_strdup (*s);
- n++;
- s++;
- }
- new_strv[len] = g_strdup (str);
- new_strv[len + 1] = NULL;
-
- return new_strv;
-}
-
-char **
ephy_strv_remove (const char * const *strv,
const char *str)
{
diff --git a/lib/ephy-string.h b/lib/ephy-string.h
index 2ad0a0c90..14515fa6d 100644
--- a/lib/ephy-string.h
+++ b/lib/ephy-string.h
@@ -49,8 +49,6 @@ char *ephy_string_remove_leading (char *string,
char *ephy_string_remove_trailing (char *string,
char ch);
-char **ephy_strv_append (const char * const *strv,
- const char *str);
char **ephy_strv_remove (const char * const *strv,
const char *str);
diff --git a/lib/widgets/ephy-location-entry.c b/lib/widgets/ephy-location-entry.c
index 4c8ea0a36..17055fc00 100644
--- a/lib/widgets/ephy-location-entry.c
+++ b/lib/widgets/ephy-location-entry.c
@@ -57,6 +57,8 @@ struct _EphyLocationEntry {
GtkOverlay parent_instance;
GtkWidget *url_entry;
+ GtkWidget *button_box;
+ GtkWidget *page_action_box;
GtkWidget *bookmark;
GtkWidget *bookmark_event_box;
GtkWidget *reader_mode;
@@ -990,7 +992,6 @@ static void
ephy_location_entry_construct_contents (EphyLocationEntry *entry)
{
GtkWidget *event;
- GtkWidget *box;
GtkStyleContext *context;
DzlShortcutController *controller;
@@ -1030,14 +1031,26 @@ ephy_location_entry_construct_contents (EphyLocationEntry *entry)
gtk_overlay_add_overlay (GTK_OVERLAY (entry), event);
/* Button Box */
- box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
- gtk_container_add (GTK_CONTAINER (event), box);
- g_signal_connect (G_OBJECT (box), "size-allocate", G_CALLBACK (button_box_size_allocated_cb), entry);
- gtk_widget_set_halign (box, GTK_ALIGN_END);
- gtk_widget_set_valign (box, GTK_ALIGN_CENTER);
- gtk_widget_show (box);
-
- context = gtk_widget_get_style_context (box);
+ entry->button_box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
+ gtk_container_add (GTK_CONTAINER (event), entry->button_box);
+ gtk_box_set_homogeneous (GTK_BOX (entry->button_box), FALSE);
+ g_signal_connect (G_OBJECT (entry->button_box), "size-allocate", G_CALLBACK (button_box_size_allocated_cb), entry);
+ gtk_button_box_set_layout (GTK_BUTTON_BOX (entry->button_box), GTK_BUTTONBOX_EXPAND);
+ gtk_widget_set_valign (entry->button_box, GTK_ALIGN_CENTER);
+ gtk_widget_set_halign (entry->button_box, GTK_ALIGN_END);
+ gtk_widget_set_margin_end (entry->button_box, 5);
+ gtk_widget_show (entry->button_box);
+
+ /* Page action box */
+ entry->page_action_box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
+ gtk_box_set_homogeneous (GTK_BOX (entry->page_action_box), FALSE);
+ gtk_widget_show (entry->page_action_box);
+ gtk_button_box_set_layout (GTK_BUTTON_BOX (entry->page_action_box), GTK_BUTTONBOX_EXPAND);
+ gtk_widget_set_valign (entry->page_action_box, GTK_ALIGN_CENTER);
+ gtk_widget_set_halign (entry->page_action_box, GTK_ALIGN_END);
+ gtk_box_pack_start (GTK_BOX (entry->button_box), entry->page_action_box, FALSE, FALSE, 0);
+
+ context = gtk_widget_get_style_context (entry->button_box);
gtk_style_context_add_class (context, "entry_icon_box");
/* Bookmark */
@@ -1048,7 +1061,7 @@ ephy_location_entry_construct_contents (EphyLocationEntry *entry)
gtk_widget_show (entry->bookmark);
g_signal_connect (G_OBJECT (entry->bookmark_event_box), "button_press_event", G_CALLBACK (bookmark_icon_button_press_event_cb), entry);
gtk_container_add (GTK_CONTAINER (entry->bookmark_event_box), entry->bookmark);
- gtk_box_pack_end (GTK_BOX (box), entry->bookmark_event_box, FALSE, FALSE, 0);
+ gtk_box_pack_end (GTK_BOX (entry->button_box), entry->bookmark_event_box, FALSE, FALSE, 6);
context = gtk_widget_get_style_context (entry->bookmark);
gtk_style_context_add_class (context, "entry_icon");
@@ -1066,7 +1079,7 @@ ephy_location_entry_construct_contents (EphyLocationEntry *entry)
gtk_widget_set_valign (entry->reader_mode, GTK_ALIGN_CENTER);
gtk_widget_show (entry->reader_mode);
gtk_container_add (GTK_CONTAINER (entry->reader_mode_event_box), entry->reader_mode);
- gtk_box_pack_end (GTK_BOX (box), entry->reader_mode_event_box, FALSE, FALSE, 0);
+ gtk_box_pack_end (GTK_BOX (entry->button_box), entry->reader_mode_event_box, FALSE, FALSE, 6);
context = gtk_widget_get_style_context (entry->reader_mode);
gtk_style_context_add_class (context, "entry_icon");
@@ -1505,3 +1518,35 @@ ephy_location_entry_set_mobile_popdown (EphyLocationEntry *entry,
else
dzl_suggestion_entry_set_position_func (DZL_SUGGESTION_ENTRY (entry->url_entry), position_func, NULL, NULL);
}
+
+void
+ephy_location_entry_page_action_add (EphyLocationEntry *entry,
+ GtkWidget *action)
+{
+ GtkStyleContext *context;
+
+ context = gtk_widget_get_style_context (action);
+ gtk_style_context_add_class (context, "entry_icon");
+
+ gtk_box_pack_end (GTK_BOX (entry->page_action_box), action, FALSE, FALSE, 6);
+}
+
+static
+void clear_page_actions (GtkWidget *child,
+ gpointer user_data)
+{
+ EphyLocationEntry *entry = EPHY_LOCATION_ENTRY (user_data);
+ GtkStyleContext *context;
+
+ context = gtk_widget_get_style_context (child);
+
+ gtk_style_context_remove_class (context, "entry_icon");
+
+ gtk_container_remove (GTK_CONTAINER (entry->page_action_box), child);
+}
+
+void
+ephy_location_entry_page_action_clear (EphyLocationEntry *entry)
+{
+ gtk_container_foreach (GTK_CONTAINER (entry->page_action_box), clear_page_actions, entry);
+}
diff --git a/lib/widgets/ephy-location-entry.h b/lib/widgets/ephy-location-entry.h
index fb8074b83..a9ce24084 100644
--- a/lib/widgets/ephy-location-entry.h
+++ b/lib/widgets/ephy-location-entry.h
@@ -79,6 +79,10 @@ gboolean ephy_location_entry_get_reader_mode_state (EphyLocationEntr
void ephy_location_entry_set_progress (EphyLocationEntry *entry,
gdouble progress,
gboolean loading);
+void ephy_location_entry_page_action_add (EphyLocationEntry *entry,
+ GtkWidget *action);
+
+void ephy_location_entry_page_action_clear (EphyLocationEntry *entry);
void ephy_location_entry_set_mobile_popdown (EphyLocationEntry *entry,
gboolean mobile_popdown);