Bug 1241566 - Put malware download protection behind a switchboard flag. r=liuche
--- a/mobile/android/app/mobile.js
+++ b/mobile/android/app/mobile.js
@@ -630,18 +630,18 @@ pref("media.android-media-codec.preferre
pref("media.mediasource.enabled", true);
// optimize images memory usage
pref("image.downscale-during-decode.enabled", true);
#ifdef MOZ_SAFE_BROWSING
pref("browser.safebrowsing.enabled", true);
pref("browser.safebrowsing.malware.enabled", true);
-pref("browser.safebrowsing.downloads.enabled", true);
-pref("browser.safebrowsing.downloads.remote.enabled", true);
+pref("browser.safebrowsing.downloads.enabled", false);
+pref("browser.safebrowsing.downloads.remote.enabled", false);
pref("browser.safebrowsing.downloads.remote.timeout_ms", 10000);
pref("browser.safebrowsing.downloads.remote.url", "https://sb-ssl.google.com/safebrowsing/clientreport/download?key=%GOOGLE_API_KEY%");
pref("browser.safebrowsing.debug", false);
pref("browser.safebrowsing.provider.google.lists", "goog-badbinurl-shavar,goog-downloadwhite-digest256,goog-phish-shavar,goog-malware-shavar,goog-unwanted-shavar");
pref("browser.safebrowsing.provider.google.updateURL", "https://safebrowsing.google.com/safebrowsing/downloads?client=SAFEBROWSING_ID&appver=%VERSION%&pver=2.2&key=%GOOGLE_API_KEY%");
pref("browser.safebrowsing.provider.google.gethashURL", "https://safebrowsing.google.com/safebrowsing/gethash?client=SAFEBROWSING_ID&appver=%VERSION%&pver=2.2");
pref("browser.safebrowsing.provider.google.reportURL", "https://safebrowsing.google.com/safebrowsing/diagnostic?client=%NAME%&hl=%LOCALE%&site=");
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -3,16 +3,17 @@
* 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/. */
package org.mozilla.gecko;
import android.Manifest;
import android.os.AsyncTask;
import android.support.annotation.NonNull;
+import org.json.JSONArray;
import org.mozilla.gecko.adjust.AdjustHelperInterface;
import org.mozilla.gecko.annotation.RobocopTarget;
import org.mozilla.gecko.AppConstants.Versions;
import org.mozilla.gecko.DynamicToolbar.PinReason;
import org.mozilla.gecko.DynamicToolbar.VisibilityTransition;
import org.mozilla.gecko.GeckoProfileDirectories.NoMozillaDirectoryException;
import org.mozilla.gecko.Tabs.TabEvents;
import org.mozilla.gecko.animation.PropertyAnimator;
@@ -677,16 +678,17 @@ public class BrowserApp extends GeckoApp
"Menu:Update",
"LightweightTheme:Update",
"Search:Keyword",
"Prompt:ShowTop");
EventDispatcher.getInstance().registerGeckoThreadListener((NativeEventListener)this,
"CharEncoding:Data",
"CharEncoding:State",
+ "Experiments:GetActive",
"Favicon:CacheLoad",
"Feedback:LastUrl",
"Feedback:MaybeLater",
"Feedback:OpenPlayStore",
"Menu:Add",
"Menu:Remove",
"Reader:Share",
"Sanitize:ClearHistory",
@@ -1372,16 +1374,17 @@ public class BrowserApp extends GeckoApp
"Menu:Update",
"LightweightTheme:Update",
"Search:Keyword",
"Prompt:ShowTop");
EventDispatcher.getInstance().unregisterGeckoThreadListener((NativeEventListener) this,
"CharEncoding:Data",
"CharEncoding:State",
+ "Experiments:GetActive",
"Favicon:CacheLoad",
"Feedback:LastUrl",
"Feedback:MaybeLater",
"Feedback:OpenPlayStore",
"Menu:Add",
"Menu:Remove",
"Reader:Share",
"Sanitize:ClearHistory",
@@ -1654,16 +1657,20 @@ public class BrowserApp extends GeckoApp
@Override
public void run() {
if (menu != null) {
menu.findItem(R.id.char_encoding).setVisible(visible);
}
}
});
+ } else if ("Experiments:GetActive".equals(event)) {
+ final List<String> experiments = SwitchBoard.getActiveExperiments(this);
+ final JSONArray json = new JSONArray(experiments);
+ callback.sendSuccess(json.toString());
} else if ("Favicon:CacheLoad".equals(event)) {
final String url = message.getString("url");
getFaviconFromCache(callback, url);
} else if ("Feedback:LastUrl".equals(event)) {
getLastUrl(callback);
} else if ("Feedback:MaybeLater".equals(event)) {
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -498,16 +498,17 @@ var BrowserApp = {
CharacterEncoding.init();
ActivityObserver.init();
RemoteDebugger.init();
UserAgentOverrides.init();
DesktopUserAgent.init();
Distribution.init();
Tabs.init();
SearchEngines.init();
+ Experiments.init();
if ("arguments" in window) {
if (window.arguments[0])
gScreenWidth = window.arguments[0];
if (window.arguments[1])
gScreenHeight = window.arguments[1];
}
@@ -6817,16 +6818,45 @@ var ActivityObserver = {
var Telemetry = {
addData: function addData(aHistogramId, aValue) {
let histogram = Services.telemetry.getHistogramById(aHistogramId);
histogram.add(aValue);
},
};
+var Experiments = {
+
+ // Enable malware download protection (bug 936041)
+ MALWARE_DOWNLOAD_PROTECTION: "malware-download-protection",
+
+ init() {
+ // Clear preferences that may have been set by previously active switchboard experiments.
+ // Given the way switchboard experiments work, we choose not to support migrating
+ // user preferences that have been set through about:config.
+ Services.prefs.clearUserPref("browser.safebrowsing.downloads.enabled");
+ Services.prefs.clearUserPref("browser.safebrowsing.downloads.remote.enabled");
+
+ Messaging.sendRequestForResult({
+ type: "Experiments:GetActive"
+ }).then(experiments => {
+ let names = JSON.parse(experiments);
+ for (let name of names) {
+ switch (name) {
+ case this.MALWARE_DOWNLOAD_PROTECTION: {
+ Services.prefs.setBoolPref("browser.safebrowsing.downloads.enabled", true);
+ Services.prefs.setBoolPref("browser.safebrowsing.downloads.remote.enabled", true);
+ continue;
+ }
+ }
+ }
+ });
+ }
+};
+
var ExternalApps = {
_contextMenuId: null,
// extend _getLink to pickup html5 media links.
_getMediaLink: function(aElement) {
let uri = NativeWindow.contextmenus._getLink(aElement);
if (uri == null && aElement.nodeType == Ci.nsIDOMNode.ELEMENT_NODE && (aElement instanceof Ci.nsIDOMHTMLMediaElement)) {
try {