Home | History | Annotate | Download | only in cros
      1 // Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 var gaia = gaia || {};
      6 gaia.chromeOSLogin = {};
      7 
      8 gaia.chromeOSLogin.parent_page_url_ =
      9 'chrome-extension://mfffpogegjflfpflabcdkioaeobkgjik/main.html';
     10 
     11 gaia.chromeOSLogin.attemptLogin = function(email, password, attemptToken) {
     12   var msg = {
     13     'method': 'attemptLogin',
     14     'email': email,
     15     'password': password,
     16     'attemptToken': attemptToken
     17   };
     18   window.parent.postMessage(msg, gaia.chromeOSLogin.parent_page_url_);
     19 };
     20 
     21 gaia.chromeOSLogin.clearOldAttempts = function() {
     22   var msg = {
     23     'method': 'clearOldAttempts'
     24   };
     25   window.parent.postMessage(msg, gaia.chromeOSLogin.parent_page_url_);
     26 };
     27 
     28 gaia.chromeOSLogin.onAttemptedLogin = function(emailFormElement,
     29                                                passwordFormElement,
     30                                                continueUrlElement) {
     31     var email = emailFormElement.value;
     32     var passwd = passwordFormElement.value;
     33     var attemptToken = new Date().getTime();
     34 
     35     gaia.chromeOSLogin.attemptLogin(email, passwd, attemptToken);
     36 
     37     if (continueUrlElement) {
     38       var prevAttemptIndex = continueUrlElement.value.indexOf('?attemptToken');
     39       if (prevAttemptIndex != -1) {
     40         continueUrlElement.value =
     41             continueUrlElement.value.substr(0, prevAttemptIndex);
     42       }
     43       continueUrlElement.value += '?attemptToken=' + attemptToken;
     44     }
     45 }
     46