Add XHR response modifier

- Add ResponseModifier class which is responsible for handling the
  modification of the responses intercepted by XHRProxy. The
  modifications occur by processing requests via several individual
  response modifiers sequentially, which are applied if the URL matches
  a RegEx condition and, if applicable, passes a condition based on the
  features enabled by the user.

- A sample response modifier called "demo" is included, to show how a
  simple modifier would work.

- Add mainWorldOptionsWatcher with 2 components: a server and a client,
  so main world scripts (clients) can retrieve the extension options via
  their corresponding content scripts (the servers) using an
  OptionsWatcher class instantiated by the server. This is used by the
  ResponseModifier class since it's injected into the main world because
  it's the only way to intercept requests.

Bug: twpowertools:153
Change-Id: I8a9767e1eadd60d3a0f1054669e1e1f5e7a49fbb
diff --git a/src/common/protojs.js b/src/common/protojs.js
index 026559b..a2e2d06 100644
--- a/src/common/protojs.js
+++ b/src/common/protojs.js
@@ -11,3 +11,26 @@
   }
   return object;
 }
+
+// The inverse function.
+export function inverseCorrectArrayKeys(input) {
+  if (Array.isArray(input)) {
+    if (input[0] === null || input[0] === undefined) {
+      // Make a copy of the input array so we don't modify the original one.
+      input = Array.from(input);
+      input.shift();
+    }
+    for (let i = 0; i < input.length; ++i) {
+      input[i] = inverseCorrectArrayKeys(input[i]);
+    }
+    return input;
+  }
+
+  if (typeof input !== 'object' || input === null) return input;
+
+  let array = [];
+  Object.entries(input).forEach(entry => {
+    array[entry[0] - 1] = inverseCorrectArrayKeys(entry[1]);
+  });
+  return array;
+}