Add XHR proxy kill switch

Since the XHRProxy loads very early to be able to catch all requests,
we cache the kill switch value in the localStorage and this cached
value is consulted early in the page load to determine whether the
XHR proxy should be put in place.

Thus, this kill switch only takes effect after a page reload.

Fixed: twpowertools:162
Change-Id: I43a163c506657d5ba9fb4ec268b2d4409d6401e3
diff --git a/src/xhrInterceptor/killSwitchHandler.js b/src/xhrInterceptor/killSwitchHandler.js
new file mode 100644
index 0000000..02df59b
--- /dev/null
+++ b/src/xhrInterceptor/killSwitchHandler.js
@@ -0,0 +1,21 @@
+import InternalKillSwitchWatcher from '../killSwitch/internalKillSwitchWatcher.js';
+
+export const KILL_SWITCH = 'killswitch_xhrproxy';
+export const KILL_SWITCH_LOCALSTORAGE_KEY = 'TWPTKillSwitchXHRProxyEnabled';
+export const KILL_SWITCH_LOCALSTORAGE_VALUE = 'true';
+
+export default class XHRProxyKillSwitchHandler {
+  constructor() {
+    this.watcher =
+        new InternalKillSwitchWatcher(KILL_SWITCH, this.onChange, true);
+  }
+
+  onChange(isActive) {
+    if (isActive) {
+      window.localStorage.setItem(
+          KILL_SWITCH_LOCALSTORAGE_KEY, KILL_SWITCH_LOCALSTORAGE_VALUE);
+    } else {
+      window.localStorage.removeItem(KILL_SWITCH_LOCALSTORAGE_KEY);
+    }
+  }
+}