Fix XHR interceptor in CC RCE thread page

The XHR interceptor stopped working in the redesigned Community Console
thread pages (aka RCE/interop thread page). This is due to the fact that
the Javascript loaded before the XHR interceptor was set, and because
the requests differed in the Javascript types used, and the format of
the requests (an array to encode protobuf messages is used instead of
objects in the RCE thread page).

This CL fixes these issues.

Change-Id: I591d58f5f597a71a2794ee59b2c5cb9dd88cca9f
diff --git a/src/common/xhrInterceptorUtils.js b/src/common/xhrInterceptorUtils.js
index 867c323..526296c 100644
--- a/src/common/xhrInterceptorUtils.js
+++ b/src/common/xhrInterceptorUtils.js
@@ -1,3 +1,5 @@
+import {correctArrayKeys} from '../common/protojs';
+
 import xhrInterceptors from './xhrInterceptors.json5';
 
 export {xhrInterceptors};
@@ -10,25 +12,30 @@
 }
 
 export function getResponseJSON(xhr) {
+  let response;
   if (xhr.responseType === 'arraybuffer') {
     var arrBuffer = xhr.response;
     if (!arrBuffer) {
       console.error('No array buffer.');
       return undefined;
     }
-    var byteArray = new Uint8Array(arrBuffer);
-    var dec = new TextDecoder('utf-8');
-    var rawResponse = dec.decode(byteArray);
-    return JSON.parse(rawResponse);
+    let byteArray = new Uint8Array(arrBuffer);
+    let dec = new TextDecoder('utf-8');
+    let rawResponse = dec.decode(byteArray);
+    response = JSON.parse(rawResponse);
+  } else if (xhr.responseType === 'text' || xhr.responseType === '') {
+    response = JSON.parse(xhr.responseText);
+  } else if (xhr.responseType === 'json') {
+    response = xhr.response;
+  } else {
+    console.error(
+        'Unexpected responseType ' + xhr.responseType + '. Request url: ',
+        xhr.$TWPTRequestURL);
+    return undefined;
   }
-  if (xhr.responseType === 'text' || xhr.responseType === '')
-    return JSON.parse(xhr.responseText);
-  if (xhr.responseType === 'json') return xhr.response;
 
-  console.error(
-      'Unexpected responseType ' + xhr.responseType + '. Request url: ',
-      xhr.$TWPTRequestURL);
-  return undefined;
+  if (xhr.$isArrayProto) response = correctArrayKeys(response);
+  return response;
 }
 
 export function triggerEvent(eventName, body, id) {