Bug 1400805 - added WebExtension API to get/set browser.display.use_document_fonts draft
authorSoeren Hentzschel <cadeyrn@ymail.com>
Thu, 05 Apr 2018 00:49:51 +0200
changeset 777524 78d8f675ac82256ba1296865a880f0b02c1d6c44
parent 777437 c23c7481957f7b982cffc0ce1d25979c69ca2c2f
child 777743 b3cb0a0014b1aa3b68c69b19df60dd7d829200fd
push id105240
push userbmo:cadeyrn@ymail.com
push dateWed, 04 Apr 2018 22:50:47 +0000
bugs1400805
milestone61.0a1
Bug 1400805 - added WebExtension API to get/set browser.display.use_document_fonts MozReview-Commit-ID: COBDLLa4bwt
toolkit/components/extensions/parent/ext-browserSettings.js
toolkit/components/extensions/schemas/browser_settings.json
toolkit/components/extensions/test/xpcshell/test_ext_browserSettings.js
--- a/toolkit/components/extensions/parent/ext-browserSettings.js
+++ b/toolkit/components/extensions/parent/ext-browserSettings.js
@@ -234,16 +234,26 @@ ExtensionPreferencesManager.addSetting("
     "browser.display.document_color_use",
   ],
 
   setCallback(value) {
     return {[this.prefNames[0]]: value};
   },
 });
 
+ExtensionPreferencesManager.addSetting("useDocumentFonts", {
+  prefNames: [
+    "browser.display.use_document_fonts",
+  ],
+
+  setCallback(value) {
+    return {[this.prefNames[0]]: value};
+  },
+});
+
 this.browserSettings = class extends ExtensionAPI {
   getAPI(context) {
     let {extension} = context;
     return {
       browserSettings: {
         allowPopupsForUserEvents: getSettingsAPI(
           extension, "allowPopupsForUserEvents",
           () => {
@@ -443,12 +453,42 @@ this.browserSettings = class extends Ext
               } else if (details.value === "always") {
                 prefValue = 2;
               }
               return ExtensionPreferencesManager.setSetting(
                 extension.id, "overrideDocumentColors", prefValue);
             },
           }
         ),
+        useDocumentFonts: Object.assign(
+          getSettingsAPI(
+            extension, "useDocumentFonts",
+            () => {
+              let prefValue = Services.prefs.getIntPref("browser.display.use_document_fonts");
+              if (prefValue === 0) {
+                return "never";
+              } else if (prefValue === 2) {
+                return "always";
+              }
+              return "allow_pages_own_fonts";
+            }
+          ),
+          {
+            set: details => {
+              if (!["allow_pages_own_fonts", "always", "never"].includes(details.value)) {
+                throw new ExtensionError(
+                  `${details.value} is not a valid value for useDocumentFonts.`);
+              }
+              let prefValue = 1; // initialize to 1 - allow pages to choose their own fonts
+              if (details.value === "never") {
+                prefValue = 0;
+              } else if (details.value === "always") {
+                prefValue = 2;
+              }
+              return ExtensionPreferencesManager.setSetting(
+                extension.id, "useDocumentFonts", prefValue);
+            },
+          }
+        ),
       },
     };
   }
 };
--- a/toolkit/components/extensions/schemas/browser_settings.json
+++ b/toolkit/components/extensions/schemas/browser_settings.json
@@ -155,12 +155,16 @@
       },
       "webNotificationsDisabled": {
         "$ref": "types.Setting",
         "description": "Disables webAPI notifications."
       },
       "overrideDocumentColors": {
         "$ref": "types.Setting",
         "description": "This setting controls whether the user-chosen colors override the page's colors."
+      },
+      "useDocumentFonts": {
+        "$ref": "types.Setting",
+        "description": "This setting controls whether the document's fonts are used."
       }
     }
   }
 ]
--- a/toolkit/components/extensions/test/xpcshell/test_ext_browserSettings.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_browserSettings.js
@@ -46,16 +46,17 @@ add_task(async function test_browser_set
     "network.proxy.socks_version": 5,
     "network.proxy.socks_remote_dns": false,
     "network.proxy.no_proxies_on": "localhost, 127.0.0.1",
     "network.proxy.autoconfig_url": "",
     "signon.autologin.proxy": false,
     "browser.tabs.insertRelatedAfterCurrent": true,
     "browser.tabs.insertAfterCurrent": false,
     "browser.display.document_color_use": 1,
+    "browser.display.use_document_fonts": 1,
   };
 
   async function background() {
     browser.test.onMessage.addListener(async (msg, apiName, value) => {
       let apiObj = browser.browserSettings[apiName];
       let result = await apiObj.set({value});
       if (msg === "set") {
         browser.test.assertTrue(result, "set returns true.");
@@ -215,16 +216,26 @@ add_task(async function test_browser_set
     {"browser.display.document_color_use": 0});
   await testSetting(
     "overrideDocumentColors", "never",
     {"browser.display.document_color_use": 1});
   await testSetting(
     "overrideDocumentColors", "always",
     {"browser.display.document_color_use": 2});
 
+  await testSetting(
+    "useDocumentFonts", "never",
+    {"browser.display.use_document_fonts": 0});
+  await testSetting(
+    "useDocumentFonts", "allow_pages_own_fonts",
+    {"browser.display.use_document_fonts": 1});
+  await testSetting(
+    "useDocumentFonts", "always",
+    {"browser.display.use_document_fonts": 2});
+
   async function testProxy(config, expectedPrefs) {
     // proxyConfig is not supported on Android.
     if (AppConstants.platform === "android") {
       return Promise.resolve();
     }
 
     let proxyConfig = {
       proxyType: "system",