GitHub PullRequestReviewCommentEvent at 2014-06-05 10:14:18
Repository: gaia
Actor: ferjm
Payload: {"comment":{"url":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/comments/13432547","id":13432547,"diff_hunk":"@@ -0,0 +1,150 @@\n+/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /\n+/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */\n+\n+'use strict';\n+\n+/* global MobileIdDialog, applications */\n+\n+// Event names.\n+const CONTENT_EVENT = 'mozMobileIdContentEvent';\n+const UNSOLICITED_EVENT = 'mozMobileIdUnsolContentEvent';\n+\n+var MobileIdManager = {\n+  dialog: null,\n+  iframe: null,\n+  init: function mobileid_init() {\n+    // Add listener to the events from Gecko related with the\n+    // Mobile ID\n+    window.addEventListener(\n+      'mozMobileIdChromeEvent',\n+      this.onChromeEvent.bind(this)\n+    );\n+  },\n+\n+  onChromeEvent: function mobileid_onChromeEvent(event) {\n+    if (!event || !event.detail) {\n+      console.error('Wrong event');\n+      return;\n+    }\n+\n+    var message = event.detail;\n+    var params = message.data;\n+\n+    if (message.id) {\n+      this.chromeEventId = message.id;\n+    }\n+\n+    switch (message.eventName) {\n+      case 'onpermissionrequest':\n+        // If the user introduced a wrong phone number we will be receiving\n+        // an \"onerror\" notifying about the incorrect input followed by a new\n+        // \"onpermissionrequest\" restarting the mobileid flow. If that's the\n+        // case as we would already have an opened dialog, we just bail out\n+        // discarding the event.\n+        if (this.dialog) {\n+          return;\n+        }\n+        this.openDialog(params);\n+        break;\n+      default:\n+        this.sendEventToDialog(message.eventName, params);\n+    }\n+  },\n+\n+  cleanup: function mobileid_cleanup() {\n+    this.iframe = null;\n+    this.dialog = null;\n+  },\n+\n+  cancel: function mobileid_cancel(isVerificationDone) {\n+    // Once the UI is closed we clean the vars\n+    this.cleanup();\n+\n+    // Let the backend close this as an error\n+    if (!isVerificationDone) {\n+      this.sendContentEvent(UNSOLICITED_EVENT, {\n+        eventName: 'cancel'\n+      });\n+    }\n+  },\n+\n+  close: function mobileid_close(isVerificationDone) {\n+    if (!this.dialog) {\n+      return;\n+    }\n+    // Close with transition\n+    this.dialog.close(this.cancel.bind(this, isVerificationDone));\n+  },\n+\n+  sendMsisdn: function mobileid_close(msisdnSelected) {\n+    // Send info retrieved from UI to API\n+    this.sendContentEvent(CONTENT_EVENT, {\n+      id: this.chromeEventId || null,\n+      result: msisdnSelected\n+    });\n+  },\n+\n+  sendVerificationCode: function mobileid_sendVerificationCode(code) {\n+    this.sendContentEvent(CONTENT_EVENT, {\n+      id: this.chromeEventId || null,\n+      result: {\n+        verificationCode: code || ''\n+      }\n+    });\n+  },\n+\n+  requestNewCode: function mobileid_askForNewCode() {\n+    this.sendContentEvent(\n+      UNSOLICITED_EVENT,\n+      {\n+        eventName: 'resendcode'\n+      }\n+    );\n+  },\n+\n+  sendContentEvent: function mobileid_sendContentEvent(eventName, msg) {\n+    var event = new CustomEvent(eventName, {\n+      detail: msg\n+    });\n+    window.dispatchEvent(event);\n+  },\n+\n+  sendEventToDialog: function mobileid_sendContentEvent(eventName, params) {\n+    if (!this.iframe) {\n+      return;\n+    }\n+\n+    var event = new CustomEvent(\n+      eventName,\n+      {\n+        detail: params\n+      }\n+    );\n+    this.iframe.contentWindow.dispatchEvent(event);\n+  },\n+\n+  openDialog: function mobileid_openDialog(params) {\n+    // Create Dialog\n+    this.dialog = new MobileIdDialog();\n+    // Create & Append the iframe\n+    this.panel = this.dialog.getView();\n+    this.iframe = this.dialog.createIframe(function onLoaded() {\n+      // Retrieve the info of the app given the manifestURL\n+      var app = applications.getByManifestURL(params.manifestURL);\n+      // Set params to send to the iframe\n+      var iframeParams = {\n+        appName: app.manifest.name,","path":"apps/system/js/mobileid_manager.js","position":136,"original_position":136,"commit_id":"05636912082f95d515c3b6fe60e185e6567d1fcc","original_commit_id":"05636912082f95d515c3b6fe60e185e6567d1fcc","user":{"login":"ferjm","id":480202,"avatar_url":"https://avatars.githubusercontent.com/u/480202?","gravatar_id":"70d31c1a33b186395de444536e37dd6d","url":"https://api.github.com/users/ferjm","html_url":"https://github.com/ferjm","followers_url":"https://api.github.com/users/ferjm/followers","following_url":"https://api.github.com/users/ferjm/following{/other_user}","gists_url":"https://api.github.com/users/ferjm/gists{/gist_id}","starred_url":"https://api.github.com/users/ferjm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ferjm/subscriptions","organizations_url":"https://api.github.com/users/ferjm/orgs","repos_url":"https://api.github.com/users/ferjm/repos","events_url":"https://api.github.com/users/ferjm/events{/privacy}","received_events_url":"https://api.github.com/users/ferjm/received_events","type":"User","site_admin":false},"body":"Check that `app` actually exists before accessing its manifest, please. Also, we might want to have a default value here.","created_at":"2014-06-05T10:14:18Z","updated_at":"2014-06-05T10:14:18Z","html_url":"https://github.com/mozilla-b2g/gaia/pull/20011#discussion_r13432547","pull_request_url":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/20011","_links":{"self":{"href":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/comments/13432547"},"html":{"href":"https://github.com/mozilla-b2g/gaia/pull/20011#discussion_r13432547"},"pull_request":{"href":"https://api.github.com/repos/mozilla-b2g/gaia/pulls/20011"}}}}