[epiphany] Add enable_gsb option to active safe browising feature



commit fda3de9f89c63aa530a34ffa7365439a8bfd369e
Author: Jan-Michael Brummer <jan brummer tabos org>
Date:   Tue Sep 29 17:51:04 2020 +0200

    Add enable_gsb option to active safe browising feature
    
    In case we cannot provide a gsb api key, we should disable the service entirely and
    hide the config option in preferences window.

 lib/safe-browsing/ephy-gsb-service.c    | 4 ++++
 meson.build                             | 1 +
 meson_options.txt                       | 7 +++++++
 src/preferences/prefs-privacy-page.c    | 5 +++++
 src/resources/gtk/prefs-privacy-page.ui | 2 +-
 5 files changed, 18 insertions(+), 1 deletion(-)
---
diff --git a/lib/safe-browsing/ephy-gsb-service.c b/lib/safe-browsing/ephy-gsb-service.c
index 98d23d3fa..795049a3f 100644
--- a/lib/safe-browsing/ephy-gsb-service.c
+++ b/lib/safe-browsing/ephy-gsb-service.c
@@ -475,6 +475,7 @@ EphyGSBService *
 ephy_gsb_service_new (const char *api_key,
                       const char *db_path)
 {
+#ifdef ENABLE_GSB
   EphyGSBService *service;
   EphyGSBStorage *storage;
 
@@ -486,6 +487,9 @@ ephy_gsb_service_new (const char *api_key,
   g_object_unref (storage);
 
   return service;
+#else
+  return NULL;
+#endif
 }
 
 static void
diff --git a/meson.build b/meson.build
index 977b49d8c..9160738bd 100644
--- a/meson.build
+++ b/meson.build
@@ -72,6 +72,7 @@ conf.set_quoted('GSB_API_KEY', gsb_api_key)
 if gsb_api_key != ''
   message('GSB API Key provided')
 endif
+conf.set10('ENABLE_GSB', get_option('enable_gsb'))
 
 config_h = declare_dependency(
   sources: vcs_tag(
diff --git a/meson_options.txt b/meson_options.txt
index 43e58e2a0..7f3648781 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -28,9 +28,16 @@ option('unit_tests',
   description: 'Enable unit tests'
 )
 
+option('enable_gsb',
+  type: 'boolean',
+  value: false,
+  description: 'Enable Google Safe Browsing support'
+)
+
 option('gsb_api_key',
   type: 'string',
   value: '',
   description: 'The API key used to access the Google Safe Browsing API v4'
 )
 
+
diff --git a/src/preferences/prefs-privacy-page.c b/src/preferences/prefs-privacy-page.c
index b339b024e..a5fc7d98c 100644
--- a/src/preferences/prefs-privacy-page.c
+++ b/src/preferences/prefs-privacy-page.c
@@ -20,6 +20,7 @@
  *  along with Epiphany.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "config.h"
 #include "prefs-privacy-page.h"
 
 #include "ephy-settings.h"
@@ -36,6 +37,7 @@ struct _PrefsPrivacyPage {
   HdyPreferencesPage parent_instance;
 
   /* Web Safety */
+  GtkWidget *safe_browsing_group;
   GtkWidget *enable_safe_browsing_switch;
 
   /* Web Tracking */
@@ -79,6 +81,8 @@ setup_privacy_page (PrefsPrivacyPage *privacy_page)
                    "active",
                    G_SETTINGS_BIND_DEFAULT);
 
+  gtk_widget_set_visible (privacy_page->safe_browsing_group, ENABLE_GSB);
+
   /* ======================================================================== */
   /* ========================== Web Tracking ================================ */
   /* ======================================================================== */
@@ -128,6 +132,7 @@ prefs_privacy_page_class_init (PrefsPrivacyPageClass *klass)
                   G_TYPE_NONE, 0);
 
   /* Web Safety */
+  gtk_widget_class_bind_template_child (widget_class, PrefsPrivacyPage, safe_browsing_group);
   gtk_widget_class_bind_template_child (widget_class, PrefsPrivacyPage, enable_safe_browsing_switch);
 
   /* Web Tracking */
diff --git a/src/resources/gtk/prefs-privacy-page.ui b/src/resources/gtk/prefs-privacy-page.ui
index ab80bcdd1..8be4e548b 100644
--- a/src/resources/gtk/prefs-privacy-page.ui
+++ b/src/resources/gtk/prefs-privacy-page.ui
@@ -6,7 +6,7 @@
     <property name="title" translatable="yes">Privacy</property>
     <property name="visible">True</property>
     <child>
-      <object class="HdyPreferencesGroup">
+      <object class="HdyPreferencesGroup" id="safe_browsing_group">
         <property name="title" translatable="yes">Web Safety</property>
         <property name="visible">True</property>
         <child>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]