Bug 1364972 - Allow WebExtensions to disable animated images, r=mixedpuppy
authorBob Silverberg <bsilverberg@mozilla.com>
Wed, 06 Sep 2017 16:46:38 -0400
changeset 429225 39a2a87fc10013e2dbdbdd66a3c203d04df564ba
parent 429224 41f350766d7d7b9417df5255824db7fde4745b47
child 429226 ed8bd83b7ec66114e89dd07e6cb4003e27b7b7b1
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy
bugs1364972
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1364972 - Allow WebExtensions to disable animated images, r=mixedpuppy This adds a browserSetting.imageAnimationBehavior API which accepts one of three values: "normal", "none", "once". Behind the scenes it sets the image.animation_mode preference to the same value. MozReview-Commit-ID: GLT6oJgpF3
toolkit/components/extensions/ext-browserSettings.js
toolkit/components/extensions/schemas/browser_settings.json
toolkit/components/extensions/test/xpcshell/test_ext_browserSettings.js
--- a/toolkit/components/extensions/ext-browserSettings.js
+++ b/toolkit/components/extensions/ext-browserSettings.js
@@ -67,16 +67,26 @@ ExtensionPreferencesManager.addSetting("
     let returnObj = {};
     for (let pref of this.prefNames) {
       returnObj[pref] = value;
     }
     return returnObj;
   },
 });
 
+ExtensionPreferencesManager.addSetting("imageAnimationBehavior", {
+  prefNames: [
+    "image.animation_mode",
+  ],
+
+  setCallback(value) {
+    return {[this.prefNames[0]]: value};
+  },
+});
+
 this.browserSettings = class extends ExtensionAPI {
   getAPI(context) {
     let {extension} = context;
     return {
       browserSettings: {
         allowPopupsForUserEvents: getSettingsAPI(extension,
           "allowPopupsForUserEvents",
           () => {
@@ -89,16 +99,21 @@ this.browserSettings = class extends Ext
               Services.prefs.getBoolPref("browser.cache.memory.enable");
           }),
         homepageOverride: getSettingsAPI(extension,
           HOMEPAGE_OVERRIDE_SETTING,
           () => {
             return Services.prefs.getComplexValue(
               HOMEPAGE_URL_PREF, Ci.nsIPrefLocalizedString).data;
           }, undefined, true),
+        imageAnimationBehavior: getSettingsAPI(extension,
+          "imageAnimationBehavior",
+          () => {
+            return Services.prefs.getCharPref("image.animation_mode");
+          }),
         newTabPageOverride: getSettingsAPI(extension,
           NEW_TAB_OVERRIDE_SETTING,
           () => {
             return aboutNewTabService.newTabURL;
           }, URL_STORE_TYPE, true),
       },
     };
   }
--- a/toolkit/components/extensions/schemas/browser_settings.json
+++ b/toolkit/components/extensions/schemas/browser_settings.json
@@ -16,28 +16,40 @@
         }]
       }
     ]
   },
   {
     "namespace": "browserSettings",
     "description": "Use the <code>browser.browserSettings</code> API to control global settings of the browser.",
     "permissions": ["browserSettings"],
+    "types": [
+      {
+        "id": "ImageAnimationBehavior",
+        "type": "string",
+        "enum": ["normal", "none", "once"],
+        "description": "How images should be animated in the browser."
+      }
+    ],
     "properties": {
       "allowPopupsForUserEvents": {
         "$ref": "types.Setting",
         "description": "Allows or disallows pop-up windows from opening in response to user events."
       },
       "cacheEnabled": {
         "$ref": "types.Setting",
         "description": "Enables or disables the browser cache."
       },
       "homepageOverride": {
         "$ref": "types.Setting",
         "description": "Returns the value of the overridden home page. Read-only."
       },
+      "imageAnimationBehavior": {
+        "$ref": "types.Setting",
+        "description": "Controls the behaviour of image animation in the browser. This setting's value is of type ImageAnimationBehavior, defaulting to <code>normal</code>."
+      },
       "newTabPageOverride": {
         "$ref": "types.Setting",
         "description": "Returns the value of the overridden new tab page. Read-only."
       }
     }
   }
 ]
--- a/toolkit/components/extensions/test/xpcshell/test_ext_browserSettings.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_browserSettings.js
@@ -18,16 +18,17 @@ AddonTestUtils.init(this);
 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "42");
 
 add_task(async function test_browser_settings() {
   // Create an object to hold the values to which we will initialize the prefs.
   const PREFS = {
     "browser.cache.disk.enable": true,
     "browser.cache.memory.enable": true,
     "dom.popup_allowed_events": Preferences.get("dom.popup_allowed_events"),
+    "image.animation_mode": "none",
   };
 
   async function background() {
     browser.test.onMessage.addListener(async (msg, apiName, value) => {
       let apiObj = browser.browserSettings[apiName];
       await apiObj.set({value});
       browser.test.sendMessage("settingData", await apiObj.get({}));
     });
@@ -83,12 +84,18 @@ add_task(async function test_browser_set
 
   await testSetting(
     "allowPopupsForUserEvents", false,
     {"dom.popup_allowed_events": ""});
   await testSetting(
     "allowPopupsForUserEvents", true,
     {"dom.popup_allowed_events": PREFS["dom.popup_allowed_events"]});
 
+  for (let value of ["normal", "none", "once"]) {
+    await testSetting(
+      "imageAnimationBehavior", value,
+      {"image.animation_mode": value});
+  }
+
   await extension.unload();
 
   await promiseShutdownManager();
 });