messageHandler = function(event) {
    var request = event.data;
    var port = event.target;
    if (gmonkeyApi) { // API is already loaded
      processApiRequest(port, request);
    } else {
      if (!gmonkey || !gmonkey.load) {
        sendError(port, request, 'gmonkey is not available.');
        return;
      }
      gmonkey.load('2', function(api) {
        // Load the API
        gmonkeyApi = api;
        processApiRequest(port, request);
        // The following function probes for newly-opened draft messages
        // and sends an 'openCompose' Website API request when a new draft
        // has been found. It's to workaround a yet-missing gmonkey
        // functionality.
        var draftMessagesHunter = function() {
          var newCount = gmonkeyApi.getMainWindow().getOpenDraftMessages()
              .length;
          if (lastDraftMessagesCount !== null &&
              newCount > lastDraftMessagesCount) {
            setTimeout(function() {
              // NOTE: Timeout to workaround a Gmail issue. Plaintext body is
              // HTML for some time.
              getDraft(function(draft) {
                port.postMessage({
                  id: String(requestId++),
                  call: 'openCompose',
                  args: {
                    'to': draft.getToEmails(),
                    'cc': draft.getCcEmails(),
                    'body': draft.getPlainTextBody()
                  }
                });
              });
            }, 100); // Chosen experimentally.
          }
          lastDraftMessagesCount = newCount;
        };
        setInterval(draftMessagesHunter, 50);
      });
    }
  }
Handles incoming E2E requests, delaying the response until gmonkey API has
loaded.
@param  {MessageEvent} event Event to handle.