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
This commit is contained in:
Jonathan Almeida [:jonalmeida] 2015-10-29 03:20:20 -04:00
Родитель 04db37c682
Коммит 48d9153973
8 изменённых файлов: 70 добавлений и 46 удалений

Просмотреть файл

@ -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");

Просмотреть файл

@ -213,8 +213,10 @@
<!ENTITY pref_cookies_not_accept_foreign "Enabled, excluding 3rd party">
<!ENTITY pref_cookies_disabled "Disabled">
<!ENTITY pref_tap_to_load_images_title "Tap-to-load images">
<!ENTITY pref_tap_to_load_images_summary2 "Load images only when you long press them">
<!ENTITY pref_tap_to_load_images_title2 "Show images">
<!ENTITY pref_tap_to_load_images_enabled "Always">
<!ENTITY pref_tap_to_load_images_data "Only over Wi-Fi">
<!ENTITY pref_tap_to_load_images_disabled "Never">
<!ENTITY pref_tracking_protection_title "Tracking protection">
<!ENTITY pref_tracking_protection_summary3 "Enabled in Private Browsing">

Просмотреть файл

@ -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--;

Просмотреть файл

@ -174,4 +174,15 @@
<item>20</item>
<item>21</item>
</integer-array>
<!-- browser.image_blocking -->
<string-array name="pref_browser_image_blocking_entries">
<item>@string/pref_tap_to_load_images_enabled</item>
<item>@string/pref_tap_to_load_images_data</item>
<item>@string/pref_tap_to_load_images_disabled</item>
</string-array>
<string-array name="pref_browser_image_blocking_values">
<item>1</item> <!-- Always -->
<item>2</item> <!-- Wifi-only -->
<item>0</item> <!-- Never -->
</string-array>
</resources>

Просмотреть файл

@ -32,10 +32,11 @@
android:entryValues="@array/pref_restore_values"
android:persistent="true" />
<CheckBoxPreference android:key="browser.image_blocking.enabled"
android:title="@string/pref_tap_to_load_images_title"
android:summary="@string/pref_tap_to_load_images_summary2"
android:defaultValue="false"/>
<ListPreference android:key="browser.image_blocking"
android:title="@string/pref_tap_to_load_images_title2"
android:entries="@array/pref_browser_image_blocking_entries"
android:entryValues="@array/pref_browser_image_blocking_values"
android:persistent="false" />
<ListPreference android:key="plugin.enable"
android:title="@string/pref_plugins"

Просмотреть файл

@ -208,8 +208,10 @@
<string name="pref_cookies_not_accept_foreign">&pref_cookies_not_accept_foreign;</string>
<string name="pref_cookies_disabled">&pref_cookies_disabled;</string>
<string name="pref_tap_to_load_images_title">&pref_tap_to_load_images_title;</string>
<string name="pref_tap_to_load_images_summary2">&pref_tap_to_load_images_summary2;</string>
<string name="pref_tap_to_load_images_title2">&pref_tap_to_load_images_title2;</string>
<string name="pref_tap_to_load_images_enabled">&pref_tap_to_load_images_enabled;</string>
<string name="pref_tap_to_load_images_data">&pref_tap_to_load_images_data;</string>
<string name="pref_tap_to_load_images_disabled">&pref_tap_to_load_images_disabled;</string>
<string name="pref_tracking_protection_title">&pref_tracking_protection_title;</string>
<string name="pref_tracking_protection_summary">&pref_tracking_protection_summary3;</string>

Просмотреть файл

@ -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;

Просмотреть файл

@ -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]);