Bug 1322576 - [3.3] Add GeckoView settings module. r=snorp
authorEugen Sawin <esawin@mozilla.com>
Tue, 14 Feb 2017 22:41:04 +0100
changeset 373329 162492fcf4a9ecad41d71ff55c8a9341f44411bc
parent 373328 dd8000832878e2f2f4f066a295c81b02b94f1c0d
child 373330 fb8a931adf8e834ded30116a5bf193c333f33405
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1322576
milestone54.0a1
Bug 1322576 - [3.3] Add GeckoView settings module. r=snorp
mobile/android/chrome/content/geckoview.js
mobile/android/modules/GeckoViewSettings.jsm
mobile/android/modules/moz.build
--- a/mobile/android/chrome/content/geckoview.js
+++ b/mobile/android/chrome/content/geckoview.js
@@ -42,16 +42,18 @@ var ModuleManager = {
       return;
     }
     delete this.modules[type];
   }
 };
 
 function startup() {
   ModuleManager.init();
+  ModuleManager.add("resource://gre/modules/GeckoViewSettings.jsm",
+                    "GeckoViewSettings");
   ModuleManager.add("resource://gre/modules/GeckoViewContent.jsm",
                     "GeckoViewContent");
   ModuleManager.add("resource://gre/modules/GeckoViewNavigation.jsm",
                     "GeckoViewNavigation");
   ModuleManager.add("resource://gre/modules/GeckoViewProgress.jsm",
                     "GeckoViewProgress");
 
   dump("zerdatime " + Date.now() + " - geckoview chrome startup finished.");
new file mode 100644
--- /dev/null
+++ b/mobile/android/modules/GeckoViewSettings.jsm
@@ -0,0 +1,55 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+this.EXPORTED_SYMBOLS = ["GeckoViewSettings"];
+
+const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
+
+Cu.import("resource://gre/modules/GeckoViewModule.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+XPCOMUtils.defineLazyModuleGetter(this, "SafeBrowsing",
+  "resource://gre/modules/SafeBrowsing.jsm");
+
+var dump = Cu.import("resource://gre/modules/AndroidLog.jsm", {})
+           .AndroidLog.d.bind(null, "ViewSettings");
+
+function debug(msg) {
+  // dump(msg);
+}
+
+// Handles GeckoView settings including:
+// * tracking protection
+class GeckoViewSettings extends GeckoViewModule {
+  init() {
+    this._isSafeBrowsingInit = false;
+    this._useTrackingProtection = false;
+  }
+
+  onSettingsUpdate() {
+    debug("onSettingsUpdate: " + JSON.stringify(this.settings));
+
+    this.useTrackingProtection = !!this.settings.useTrackingProtection;
+  }
+
+  get useTrackingProtection() {
+    return this._useTrackingProtection;
+  }
+
+  set useTrackingProtection(use) {
+    if (use && !this._isSafeBrowsingInit) {
+      SafeBrowsing.init();
+      this._isSafeBrowsingInit = true;
+    }
+    if (use != this._useTrackingProtection) {
+      this.messageManager.loadFrameScript('data:,' +
+        'docShell.useTrackingProtection = ' + use,
+        true
+      );
+      this._useTrackingProtection = use;
+    }
+  }
+}
--- a/mobile/android/modules/moz.build
+++ b/mobile/android/modules/moz.build
@@ -31,10 +31,11 @@ EXTRA_JS_MODULES += [
     'WebsiteMetadata.jsm'
 ]
 
 # GeckoView-sepcific modules added separately.
 EXTRA_JS_MODULES += [
     'GeckoViewContent.jsm',
     'GeckoViewModule.jsm',
     'GeckoViewNavigation.jsm',
-    'GeckoViewProgress.jsm'
+    'GeckoViewProgress.jsm',
+    'GeckoViewSettings.jsm',
 ]