From 48d915397366f22b1302f8a0422ca541e725e1d7 Mon Sep 17 00:00:00 2001 From: "Jonathan Almeida [:jonalmeida]" Date: Thu, 29 Oct 2015 03:20:20 -0400 Subject: [PATCH] Bug 1209293 - Add option for click-to-play images depending on network bearer r=mfinkle - Replaced bool pref for int list option: Never, Always, or Only over Wi-Fi - Pref browser.image_blocking.enabled -> browser.image_blocking - Converted the early return to check for cellular as well. - Note that in the cellular check, I do not consider LINK_TYPE_USB as "cellular". - Tested this on a physical device with all combinations of WiFi ON/OFF (falling back to cellular and each menu state. - Tested if menu options work as well for each state mentioned above. --HG-- extra : commitid : 3xKvKEgZv9A extra : rebase_source : 888cfa9843ca515bef4a3596f6b01bf562065125 --- mobile/android/app/mobile.js | 7 ++- .../base/locales/en-US/android_strings.dtd | 6 +- .../base/preferences/GeckoPreferences.java | 6 +- .../android/base/resources/values/arrays.xml | 11 ++++ .../resources/xml/preferences_advanced.xml | 9 +-- mobile/android/base/strings.xml.in | 6 +- mobile/android/chrome/content/browser.js | 8 +-- .../android/components/ImageBlockingPolicy.js | 63 ++++++++++--------- 8 files changed, 70 insertions(+), 46 deletions(-) diff --git a/mobile/android/app/mobile.js b/mobile/android/app/mobile.js index 4e458936a5fb..f012635e6d73 100644 --- a/mobile/android/app/mobile.js +++ b/mobile/android/app/mobile.js @@ -350,8 +350,9 @@ pref("browser.link.open_newwindow", 3); // 0=force all new windows to tabs, 1=don't force, 2=only force those with no features set pref("browser.link.open_newwindow.restriction", 0); -// Image blocking policy -pref("browser.image_blocking.enabled", false); +// image blocking policy +// 0=disabled, 1=enabled, 2=cellular-only +pref("browser.image_blocking", 0); // controls which bits of private data to clear. by default we clear them all. pref("privacy.item.cache", true); @@ -955,7 +956,7 @@ pref("identity.fxaccounts.remote.webchannel.uri", "https://accounts.firefox.com" pref("identity.fxaccounts.remote.profile.uri", "https://profile.accounts.firefox.com/v1"); // The remote URL of the Firefox Account oauth server. -pref("identity.fxaccounts.remote.oauth.uri", "https://oauth.accounts.firefox.com/v1"); +pref("identity.fxaccounts.remote.oauth.uri", "https://oauth.accounts.firefox.com/v1"); // Token server used by Firefox Account-authenticated Sync. pref("identity.sync.tokenserver.uri", "https://token.services.mozilla.com/1.0/sync/1.5"); diff --git a/mobile/android/base/locales/en-US/android_strings.dtd b/mobile/android/base/locales/en-US/android_strings.dtd index 60ab560bbe35..8bc0a0c1908b 100644 --- a/mobile/android/base/locales/en-US/android_strings.dtd +++ b/mobile/android/base/locales/en-US/android_strings.dtd @@ -213,8 +213,10 @@ - - + + + + diff --git a/mobile/android/base/preferences/GeckoPreferences.java b/mobile/android/base/preferences/GeckoPreferences.java index c9e22431acdc..258744a6de29 100644 --- a/mobile/android/base/preferences/GeckoPreferences.java +++ b/mobile/android/base/preferences/GeckoPreferences.java @@ -133,7 +133,10 @@ OnSharedPreferenceChangeListener public static final String PREFS_OPEN_URLS_IN_PRIVATE = NON_PREF_PREFIX + "openExternalURLsPrivately"; public static final String PREFS_VOICE_INPUT_ENABLED = NON_PREF_PREFIX + "voice_input_enabled"; public static final String PREFS_QRCODE_ENABLED = NON_PREF_PREFIX + "qrcode_enabled"; - private static final String PREFS_CUSTOMIZE_IMAGE_BLOCKING = "browser.image_blocking.enabled"; + private static final String PREFS_ADVANCED = NON_PREF_PREFIX + "advanced.enabled"; + private static final String PREFS_ACCESSIBILITY = NON_PREF_PREFIX + "accessibility.enabled"; + private static final String PREFS_CUSTOMIZE_HOME = NON_PREF_PREFIX + "customize_home"; + private static final String PREFS_CUSTOMIZE_IMAGE_BLOCKING = "browser.image_blocking"; private static final String PREFS_TRACKING_PROTECTION_PRIVATE_BROWSING = "privacy.trackingprotection.pbmode.enabled"; private static final String PREFS_TRACKING_PROTECTION_LEARN_MORE = NON_PREF_PREFIX + "trackingprotection.learn_more"; private static final String PREFS_CLEAR_PRIVATE_DATA = NON_PREF_PREFIX + "privacy.clear"; @@ -882,7 +885,6 @@ OnSharedPreferenceChangeListener continue; } } else if (PREFS_CUSTOMIZE_IMAGE_BLOCKING.equals(key)) { - // Only enable the ZoomedView / magnifying pref on Nightly. if (!AppConstants.NIGHTLY_BUILD) { preferences.removePreference(pref); i--; diff --git a/mobile/android/base/resources/values/arrays.xml b/mobile/android/base/resources/values/arrays.xml index 81b8fabe2541..9876fabdb4bf 100644 --- a/mobile/android/base/resources/values/arrays.xml +++ b/mobile/android/base/resources/values/arrays.xml @@ -174,4 +174,15 @@ 20 21 + + + @string/pref_tap_to_load_images_enabled + @string/pref_tap_to_load_images_data + @string/pref_tap_to_load_images_disabled + + + 1 + 2 + 0 + diff --git a/mobile/android/base/resources/xml/preferences_advanced.xml b/mobile/android/base/resources/xml/preferences_advanced.xml index 0666d69f16a4..a38b0efed3ef 100644 --- a/mobile/android/base/resources/xml/preferences_advanced.xml +++ b/mobile/android/base/resources/xml/preferences_advanced.xml @@ -32,10 +32,11 @@ android:entryValues="@array/pref_restore_values" android:persistent="true" /> - + &pref_cookies_not_accept_foreign; &pref_cookies_disabled; - &pref_tap_to_load_images_title; - &pref_tap_to_load_images_summary2; + &pref_tap_to_load_images_title2; + &pref_tap_to_load_images_enabled; + &pref_tap_to_load_images_data; + &pref_tap_to_load_images_disabled; &pref_tracking_protection_title; &pref_tracking_protection_summary3; diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index c1473bede34c..2c67be1e9947 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -1553,6 +1553,7 @@ var BrowserApp = { case "network.cookie.cookieBehavior": case "font.size.inflation.minTwips": case "home.sync.updateMode": + case "browser.image_blocking": pref.type = "string"; pref.value = pref.value.toString(); break; @@ -1629,6 +1630,7 @@ var BrowserApp = { case "network.cookie.cookieBehavior": case "font.size.inflation.minTwips": case "home.sync.updateMode": + case "browser.image_blocking": json.type = "int"; json.value = parseInt(json.value); break; @@ -2632,11 +2634,7 @@ var NativeWindow = { imageBlockingPolicyContext: { matches: function imageBlockingPolicyContextMatches(aElement) { - if (!Services.prefs.getBoolPref("browser.image_blocking.enabled")) { - return false; - } - - if (aElement instanceof Ci.nsIDOMHTMLImageElement) { + if (aElement instanceof Ci.nsIDOMHTMLImageElement && aElement.getAttribute("data-ctv-src")) { // Only show the menuitem if we are blocking the image if (aElement.getAttribute("data-ctv-show") == "true") { return false; diff --git a/mobile/android/components/ImageBlockingPolicy.js b/mobile/android/components/ImageBlockingPolicy.js index 8e81b0d3a9f7..353b29c2ac1e 100644 --- a/mobile/android/components/ImageBlockingPolicy.js +++ b/mobile/android/components/ImageBlockingPolicy.js @@ -26,35 +26,34 @@ ImageBlockingPolicy.prototype = { // nsIContentPolicy interface implementation shouldLoad: function(contentType, contentLocation, requestOrigin, node, mimeTypeGuess, extra) { - if (!getEnabled()) { - return Ci.nsIContentPolicy.ACCEPT; - } - - if (contentType === Ci.nsIContentPolicy.TYPE_IMAGE || contentType === Ci.nsIContentPolicy.TYPE_IMAGESET) { - // Accept any non-http(s) image URLs - if (!contentLocation.schemeIs("http") && !contentLocation.schemeIs("https")) { - return Ci.nsIContentPolicy.ACCEPT; - } - - if (node instanceof Ci.nsIDOMHTMLImageElement) { - // Accept if the user has asked to view the image - if (node.getAttribute("data-ctv-show") == "true") { + // When enabled or when on cellular, and option for cellular-only is selected + if (this._enabled() == 1 || (this._enabled() == 2 && this._usingCellular())) { + if (contentType === Ci.nsIContentPolicy.TYPE_IMAGE || contentType === Ci.nsIContentPolicy.TYPE_IMAGESET) { + // Accept any non-http(s) image URLs + if (!contentLocation.schemeIs("http") && !contentLocation.schemeIs("https")) { return Ci.nsIContentPolicy.ACCEPT; } - setTimeout(() => { - // Cache the original image URL and swap in our placeholder - node.setAttribute("data-ctv-src", contentLocation.spec); - node.setAttribute("src", PLACEHOLDER_IMG); + if (node instanceof Ci.nsIDOMHTMLImageElement) { + // Accept if the user has asked to view the image + if (node.getAttribute("data-ctv-show") == "true") { + return Ci.nsIContentPolicy.ACCEPT; + } - // For imageset (img + srcset) the "srcset" is used even after we reset the "src" causing a loop. - // We are given the final image URL anyway, so it's OK to just remove the "srcset" value. - node.removeAttribute("srcset"); - }, 0); + setTimeout(() => { + // Cache the original image URL and swap in our placeholder + node.setAttribute("data-ctv-src", contentLocation.spec); + node.setAttribute("src", PLACEHOLDER_IMG); + + // For imageset (img + srcset) the "srcset" is used even after we reset the "src" causing a loop. + // We are given the final image URL anyway, so it's OK to just remove the "srcset" value. + node.removeAttribute("srcset"); + }, 0); + } + + // Reject any image that is not associated with a DOM element + return Ci.nsIContentPolicy.REJECT; } - - // Reject any image that is not associated with a DOM element - return Ci.nsIContentPolicy.REJECT; } // Accept all other content types @@ -65,10 +64,18 @@ ImageBlockingPolicy.prototype = { return Ci.nsIContentPolicy.ACCEPT; }, + _usingCellular: function() { + let network = Cc["@mozilla.org/network/network-link-service;1"].getService(Ci.nsINetworkLinkService); + return !(network.linkType == Ci.nsINetworkLinkService.LINK_TYPE_UNKNOWN || + network.linkType == Ci.nsINetworkLinkService.LINK_TYPE_ETHERNET || + network.linkType == Ci.nsINetworkLinkService.LINK_TYPE_USB || + network.linkType == Ci.nsINetworkLinkService.LINK_TYPE_WIFI); + }, + + _enabled: function() { + return Services.prefs.getIntPref("browser.image_blocking"); + }, + }; -function getEnabled() { - return Services.prefs.getBoolPref("browser.image_blocking.enabled"); -} - this.NSGetFactory = XPCOMUtils.generateNSGetFactory([ImageBlockingPolicy]);