[epiphany/mcatanzaro/cookies-prefs: 10/12] Add setting to disable website data storage



commit 19f42f37d80de7bc4c6b08475f71026b26c60fea
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Sun Jul 19 12:35:31 2020 -0500

    Add setting to disable website data storage
    
    This will block access to cookies, localStorage, and IndexedDB. That is,
    it will finally do what users who previously disabled cookies *actually*
    wanted to do.
    
    This is our replacement for the previous tri-state cookie policy, which
    no longer makes sense now that we have ITP.

 data/org.gnome.epiphany.gschema.xml     |  5 +++++
 embed/ephy-embed-prefs.c                | 24 ++++++++++++++++++++++++
 lib/ephy-prefs.h                        |  2 ++
 src/preferences/prefs-privacy-page.c    | 16 ++++++++++++++++
 src/resources/gtk/prefs-privacy-page.ui | 21 +++++++++++++++++++++
 5 files changed, 68 insertions(+)
---
diff --git a/data/org.gnome.epiphany.gschema.xml b/data/org.gnome.epiphany.gschema.xml
index 71ff97b4b..fbeec0986 100644
--- a/data/org.gnome.epiphany.gschema.xml
+++ b/data/org.gnome.epiphany.gschema.xml
@@ -196,6 +196,11 @@
                        <summary>Enable Intelligent Tracking Prevention (ITP)</summary>
                        <description>Whether to enable Intelligent Tracking Prevention.</description>
                </key>
+               <key type="b" name="enable-website-data-storage">
+                       <default>true</default>
+                       <summary>Allow websites to store local website data</summary>
+                       <description>Whether to allow websites to store cookies, local storage data, and 
IndexedDB databases. Disabling this will break many websites.</description>
+               </key>
                <key type="d" name="default-zoom-level">
                        <default>1.0</default>
                        <summary>Default zoom level for new pages</summary>
diff --git a/embed/ephy-embed-prefs.c b/embed/ephy-embed-prefs.c
index 6982fdd1f..0a4290a23 100644
--- a/embed/ephy-embed-prefs.c
+++ b/embed/ephy-embed-prefs.c
@@ -449,6 +449,26 @@ webkit_pref_callback_enable_spell_checking (GSettings  *settings,
   }
 }
 
+static void
+webkit_pref_callback_enable_website_data_storage (GSettings  *settings,
+                                                  const char *key,
+                                                  gpointer    data)
+{
+  EphyEmbedShell *shell;
+  WebKitWebContext *context;
+  WebKitCookieManager *manager;
+  gboolean value;
+
+  value = g_settings_get_boolean (settings, key);
+  webkit_settings_set_enable_html5_database (webkit_settings, value);
+  webkit_settings_set_enable_html5_local_storage (webkit_settings, value);
+
+  shell = ephy_embed_shell_get_default ();
+  context = ephy_embed_shell_get_web_context (shell);
+  manager = webkit_web_context_get_cookie_manager (context);
+  webkit_cookie_manager_set_accept_policy (manager, value ? WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS : 
WEBKIT_COOKIE_POLICY_ACCEPT_NEVER);
+}
+
 static void
 webkit_pref_callback_hardware_acceleration_policy (GSettings  *settings,
                                                    const char *key,
@@ -528,6 +548,10 @@ static const PrefData webkit_pref_entries[] = {
     EPHY_PREFS_WEB_USER_AGENT,
     "user-agent",
     webkit_pref_callback_user_agent },
+  { EPHY_PREFS_WEB_SCHEMA,
+    EPHY_PREFS_WEB_ENABLE_WEBSITE_DATA_STORAGE,
+    NULL,
+    webkit_pref_callback_enable_website_data_storage },
   { EPHY_PREFS_WEB_SCHEMA,
     EPHY_PREFS_WEB_HARDWARE_ACCELERATION_POLICY,
     "hardware-acceleration-policy",
diff --git a/lib/ephy-prefs.h b/lib/ephy-prefs.h
index 5def16c39..0f0e54f3f 100644
--- a/lib/ephy-prefs.h
+++ b/lib/ephy-prefs.h
@@ -109,6 +109,7 @@ static const char * const ephy_prefs_state_schema[] = {
 #define EPHY_PREFS_WEB_ENABLE_SAFE_BROWSING         "enable-safe-browsing"
 #define EPHY_PREFS_WEB_GSB_API_KEY                  "gsb-api-key"
 #define EPHY_PREFS_WEB_ENABLE_ITP                   "enable-itp"
+#define EPHY_PREFS_WEB_ENABLE_WEBSITE_DATA_STORAGE  "enable-website-data-storage"
 #define EPHY_PREFS_WEB_DEFAULT_ZOOM_LEVEL           "default-zoom-level"
 #define EPHY_PREFS_WEB_ENABLE_AUTOSEARCH            "enable-autosearch"
 #define EPHY_PREFS_WEB_ENABLE_MOUSE_GESTURES        "enable-mouse-gestures"
@@ -138,6 +139,7 @@ static const char * const ephy_prefs_web_schema[] = {
   EPHY_PREFS_WEB_ENABLE_SAFE_BROWSING,
   EPHY_PREFS_WEB_GSB_API_KEY,
   EPHY_PREFS_WEB_ENABLE_ITP,
+  EPHY_PREFS_WEB_ENABLE_WEBSITE_DATA_STORAGE,
   EPHY_PREFS_WEB_DEFAULT_ZOOM_LEVEL,
   EPHY_PREFS_WEB_ENABLE_AUTOSEARCH,
   EPHY_PREFS_WEB_ENABLE_MOUSE_GESTURES,
diff --git a/src/preferences/prefs-privacy-page.c b/src/preferences/prefs-privacy-page.c
index 5fffb914a..b339b024e 100644
--- a/src/preferences/prefs-privacy-page.c
+++ b/src/preferences/prefs-privacy-page.c
@@ -37,7 +37,10 @@ struct _PrefsPrivacyPage {
 
   /* Web Safety */
   GtkWidget *enable_safe_browsing_switch;
+
+  /* Web Tracking */
   GtkWidget *enable_itp_switch;
+  GtkWidget *enable_website_data_storage_switch;
 
   /* Passwords */
   GtkWidget *remember_passwords_switch;
@@ -76,12 +79,22 @@ setup_privacy_page (PrefsPrivacyPage *privacy_page)
                    "active",
                    G_SETTINGS_BIND_DEFAULT);
 
+  /* ======================================================================== */
+  /* ========================== Web Tracking ================================ */
+  /* ======================================================================== */
+
   g_settings_bind (web_settings,
                    EPHY_PREFS_WEB_ENABLE_ITP,
                    privacy_page->enable_itp_switch,
                    "active",
                    G_SETTINGS_BIND_DEFAULT);
 
+  g_settings_bind (web_settings,
+                   EPHY_PREFS_WEB_ENABLE_WEBSITE_DATA_STORAGE,
+                   privacy_page->enable_website_data_storage_switch,
+                   "active",
+                   G_SETTINGS_BIND_DEFAULT);
+
   /* ======================================================================== */
   /* ========================== Passwords =================================== */
   /* ======================================================================== */
@@ -116,7 +129,10 @@ prefs_privacy_page_class_init (PrefsPrivacyPageClass *klass)
 
   /* Web Safety */
   gtk_widget_class_bind_template_child (widget_class, PrefsPrivacyPage, enable_safe_browsing_switch);
+
+  /* Web Tracking */
   gtk_widget_class_bind_template_child (widget_class, PrefsPrivacyPage, enable_itp_switch);
+  gtk_widget_class_bind_template_child (widget_class, PrefsPrivacyPage, enable_website_data_storage_switch);
 
   /* Passwords */
   gtk_widget_class_bind_template_child (widget_class, PrefsPrivacyPage, remember_passwords_switch);
diff --git a/src/resources/gtk/prefs-privacy-page.ui b/src/resources/gtk/prefs-privacy-page.ui
index 562632ede..9580cda42 100644
--- a/src/resources/gtk/prefs-privacy-page.ui
+++ b/src/resources/gtk/prefs-privacy-page.ui
@@ -26,6 +26,12 @@
             </child>
           </object>
         </child>
+      </object>
+    </child>
+    <child>
+      <object class="HdyPreferencesGroup">
+        <property name="title" translatable="yes">Web Tracking</property>
+        <property name="visible">True</property>
         <child>
           <object class="HdyActionRow">
             <property name="activatable_widget">enable_itp_switch</property>
@@ -40,6 +46,21 @@
             </child>
           </object>
         </child>
+        <child>
+          <object class="HdyActionRow">
+            <property name="activatable_widget">enable_website_data_storage_switch</property>
+            <property name="subtitle" translatable="yes">Allow websites to store cookies, databases, and 
local storage data.</property>
+            <property name="title" translatable="yes">_Website Data Storage</property>
+            <property name="use_underline">True</property>
+            <property name="visible">True</property>
+            <child>
+              <object class="GtkSwitch" id="enable_website_data_storage_switch">
+                <property name="valign">center</property>
+                <property name="visible">True</property>
+              </object>
+            </child>
+          </object>
+        </child>
       </object>
     </child>
     <child>


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