B2G/gecko/services/aitc/modules/browserid.js
/**
   * Open a login window and ask the user to login, returning the assertion
   * generated as a result to the caller.
   */
Open a login window and ask the user to login, returning the assertion
generated as a result to the caller.
Open a login window and ask the user to login returning the assertion generated as a result to the caller .
function _getAssertionWithLogin(cb, win) {
    let pm = Services.perms;
    let principal = win.document.nodePrincipal;
    let oldPerm = pm.testExactPermissionFromPrincipal(principal, "popup");
    try {
      pm.addFromPrincipal(principal, "popup", pm.ALLOW_ACTION);
    } catch(e) {
      this._log.warn("Setting popup blocking to false failed " + e);
    }
    let sandbox = new Cu.Sandbox(win, {
      wantXrays:        false,
      sandboxPrototype: win
    });
    let self = this;
    function callback(val) {
      try {
        pm.addFromPrincipal(principal, "popup", oldPerm);
      } catch(e) {
        this._log.warn("Setting popup blocking to original value failed " + e);
      }
      if (val) {
        self._log.info("_getAssertionWithLogin succeeded");
        try {
          cb(null, val);
        } catch(e) {
          self._log.warn("Callback threw in _getAssertionWithLogin " +
                         CommonUtils.exceptionStr(e));
        }
      } else {
        let msg = "Could not obtain assertion in _getAssertionWithLogin";
        self._log.error(msg);
        try {
          cb(new Error(msg), null);
        } catch(e) {
          self._log.warn("Callback threw in _getAssertionWithLogin " +
                         CommonUtils.exceptionStr(e));
        }
      }
    }
    sandbox.importFunction(callback);
    function doGetAssertion() {
      self._log.info("_getAssertionWithLogin Started");
      let scriptText = "window.navigator.id.get(" +
                       "  callback, {allowPersistent: true}" +
                       ");";
      Cu.evalInSandbox(scriptText, sandbox, "1.8", self.ID_URI, 1);
    }
    if (!win.document || (win.document.readyState != "complete")) {
      win.addEventListener("DOMContentLoaded", function _contentLoaded() {
        win.removeEventListener("DOMContentLoaded", _contentLoaded, false);
        doGetAssertion();
      }, false);
    } else {
      doGetAssertion();
    }
  }
function _getAssertionWithLogin ( cb , win ) { let pm = Services . perms ; let principal = win . document . nodePrincipal ; let oldPerm = pm . testExactPermissionFromPrincipal ( principal , "popup" ) ; try { pm . addFromPrincipal ( principal , "popup" , pm . ALLOW_ACTION ) ; } catch ( e ) { this . _log . warn ( "Setting popup blocking to false failed " + e ) ; } let sandbox = new Cu . Sandbox ( win , { wantXrays : false , sandboxPrototype : win } ) ; let self = this ; function callback ( val ) { try { pm . addFromPrincipal ( principal , "popup" , oldPerm ) ; } catch ( e ) { this . _log . warn ( "Setting popup blocking to original value failed " + e ) ; } if ( val ) { self . _log . info ( "_getAssertionWithLogin succeeded" ) ; try { cb ( null , val ) ; } catch ( e ) { self . _log . warn ( "Callback threw in _getAssertionWithLogin " + CommonUtils . exceptionStr ( e ) ) ; } } else { let msg = "Could not obtain assertion in _getAssertionWithLogin" ; self . _log . error ( msg ) ; try { cb ( new Error ( msg ) , null ) ; } catch ( e ) { self . _log . warn ( "Callback threw in _getAssertionWithLogin " + CommonUtils . exceptionStr ( e ) ) ; } } } sandbox . importFunction ( callback ) ; function doGetAssertion ( ) { self . _log . info ( "_getAssertionWithLogin Started" ) ; let scriptText = "window.navigator.id.get(" + "  callback, {allowPersistent: true}" + ");" ; Cu . evalInSandbox ( scriptText , sandbox , "1.8" , self . ID_URI , 1 ) ; } if ( ! win . document || ( win . document . readyState != "complete" ) ) { win . addEventListener ( "DOMContentLoaded" , function _contentLoaded ( ) { win . removeEventListener ( "DOMContentLoaded" , _contentLoaded , false ) ; doGetAssertion ( ) ; } , false ) ; } else { doGetAssertion ( ) ; } }
Open a login window and ask the user to login, returning the assertion
 generated as a result to the caller.
Open a login window and ask the user to login returning the assertion generated as a result to the caller .
// We're executing navigator.id.get as a content script in win. // This results in a popup that we will temporarily unblock. // Open sandbox and execute script. This sandbox will be GC'ed. // Set popup blocker permission to original value. // Sometimes the provided win hasn't fully loaded yet