From 87be8368ebeeb218de805f2faa12e4d74f37bb1d Mon Sep 17 00:00:00 2001
From: Shane Tomlinson <stomlinson@mozilla.com>
Date: Fri, 14 Sep 2012 14:04:30 +0100
Subject: [PATCH] report which rp_api is used from include.js and
 internal_api.js

---
 .../static/dialog/js/misc/internal_api.js     |  1 +
 resources/static/include_js/include.js        | 21 ++++++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/resources/static/dialog/js/misc/internal_api.js b/resources/static/dialog/js/misc/internal_api.js
index 5a5e644c0..ffc1e91ee 100644
--- a/resources/static/dialog/js/misc/internal_api.js
+++ b/resources/static/dialog/js/misc/internal_api.js
@@ -89,6 +89,7 @@
       // options block directly to the dialog.
       var controller = moduleManager.getRunningModule("dialog");
       if(controller) {
+        options.rp_api = "internal";
         controller.get(origin, options, complete, complete);
       }
       else {
diff --git a/resources/static/include_js/include.js b/resources/static/include_js/include.js
index 3b775cca6..4fd51d0e0 100644
--- a/resources/static/include_js/include.js
+++ b/resources/static/include_js/include.js
@@ -1125,6 +1125,17 @@
       _open_hidden_iframe();
     }
 
+    var api_called;
+    function getRPAPI() {
+      var rp_api = api_called;
+      if (rp_api === "request") {
+        if (observers.ready) rp_api = "watch_with_onready";
+        else rp_api = "watch_without_onready";
+      }
+
+      return rp_api;
+    }
+
     function internalRequest(options) {
       checkDeprecated(options, "requiredEmail");
       checkRenamed(options, "tosURL", "termsOfService");
@@ -1138,6 +1149,11 @@
         warn("privacyPolicy ignored unless termsOfService also defined");
       }
 
+      options.rp_api = getRPAPI();
+      // reset the api_called in case the site implementor changes which api
+      // method called the next time around.
+      api_called = null;
+
       // focus an existing window
       if (w) {
         try {
@@ -1216,6 +1232,7 @@
           throw new Error("all navigator.id calls must be made on the navigator.id object");
         options = options || {};
         checkCompat(false);
+        api_called = "request";
         // returnTo is used for post-email-verification redirect
         if (!options.returnTo) options.returnTo = document.location.pathname;
         return internalRequest(options);
@@ -1251,7 +1268,8 @@
         opts.tosURL = passedOptions.tosURL || undefined;
         opts.siteName = passedOptions.siteName || undefined;
         opts.siteLogo = passedOptions.siteLogo || undefined;
-
+        // api_called could have been set to getVerifiedEmail already
+        api_called = api_called || "get";
         if (checkDeprecated(passedOptions, "silent")) {
           // Silent has been deprecated, do nothing.  Placing the check here
           // prevents the callback from being called twice, once with null and
@@ -1283,6 +1301,7 @@
       getVerifiedEmail: function(callback) {
         warn("navigator.id.getVerifiedEmail has been deprecated");
         checkCompat(true);
+        api_called = "getVerifiedEmail";
         navigator.id.get(callback);
       },
       // required for forwards compatibility with native implementations
-- 
GitLab