Show an extension badge when a kill switch is active

Kill switches allow the extension maintainer to remotely disable some
features in case they start working in an undiserable manner (for
instance when Google updates the Community Console and the extension
breaks the CC completely).

This change makes it clear whether a kill switch is active by adding a
badge to the extension icon.

Change-Id: I5fbbbc33aa78c613d91625ba0ea10deb2d478a83
diff --git a/src/killSwitch/index.js b/src/killSwitch/index.js
index f0b1294..a1083b1 100644
--- a/src/killSwitch/index.js
+++ b/src/killSwitch/index.js
@@ -1,5 +1,6 @@
 import {compareLoose} from 'semver';
 
+import actionApi from '../common/actionApi.js';
 import {getExtVersion} from '../common/extUtils.js';
 
 import * as commonPb from './api_proto/common_pb.js';
@@ -10,11 +11,31 @@
     (PRODUCTION ? 'https://twpt-grpc-web.avm99963.com/' :
                   'http://localhost:8081');
 
+const KILLSWITCH_BADGE_OPTIONS = {
+  'iconTitleI18nKey': 'actionbadge_killswitch_enabled',
+  'badgeText': '!',
+  'bgColor': '#B71C1C',
+};
+
 export default class KillSwitchMechanism {
   constructor() {
     this.client = new KillSwitchServicePromiseClient(host, null, null);
   }
 
+  setBadge(anyKillSwitchEnabled) {
+    if (anyKillSwitchEnabled) {
+      actionApi.setBadgeBackgroundColor(
+          {color: KILLSWITCH_BADGE_OPTIONS.bgColor});
+      actionApi.setBadgeText({text: KILLSWITCH_BADGE_OPTIONS.badgeText});
+      let title =
+          chrome.i18n.getMessage(KILLSWITCH_BADGE_OPTIONS.iconTitleI18nKey);
+      actionApi.setTitle({title});
+    } else {
+      actionApi.setBadgeText({text: ''});
+      actionApi.setTitle({title: ''});
+    }
+  }
+
   getCurrentBrowser() {
     // #!if browser_target == 'gecko'
     return commonPb.Environment.Browser.BROWSER_GECKO;
@@ -68,10 +89,8 @@
 
           chrome.storage.sync.set(
               {_forceDisabledFeatures: forceDisabledFeatures}, () => {
-                if (forceDisabledFeatures.length > 0) {
-                  // TODO(avm99963): show a badge to warn that some features
-                  // have been force disabled.
-                }
+                let anyKillSwitchEnabled = forceDisabledFeatures.length > 0;
+                this.setBadge(anyKillSwitchEnabled);
               });
         })
         .catch(err => {
@@ -79,4 +98,4 @@
               '[killSwitch] Can\'t retrieve kill switch status: ', err);
         });
   }
-};
+}