Roll src/third_party/WebKit bf18a82:a9cee16 (svn 185297:185304)
[chromium-blink-merge.git] / chrome / browser / resources / gaia_auth / offline.js
blob7b4da1f528591f1144c2145c32f2808e1c65b970
1 // Copyright (c) 2012 The Chromium 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.
5 /**
6 * @fileoverview Offline login implementation.
7 */
9 function load() {
10 var params = getUrlSearchParams(location.search);
12 // Setup localized strings.
13 $('sign-in-title').textContent = decodeURIComponent(params['stringSignIn']);
14 $('email-label').textContent = decodeURIComponent(params['stringEmail']);
15 $('password-label').textContent =
16 decodeURIComponent(params['stringPassword']);
17 $('submit-button').value = decodeURIComponent(params['stringSignIn']);
18 $('empty-email-alert').textContent =
19 decodeURIComponent(params['stringEmptyEmail']);
20 $('empty-password-alert').textContent =
21 decodeURIComponent(params['stringEmptyPassword']);
22 $('errormsg-alert').textContent = decodeURIComponent(params['stringError']);
24 // Setup actions.
25 var form = $('offline-login-form');
26 form.addEventListener('submit', function(e) {
27 // Clear all previous errors.
28 form.email.classList.remove('field-error');
29 form.password.classList.remove('field-error');
30 form.password.classList.remove('form-error');
32 if (form.email.value == '') {
33 form.email.classList.add('field-error');
34 form.email.focus();
35 } else if (form.password.value == '') {
36 form.password.classList.add('field-error');
37 form.password.focus();
38 } else {
39 var msg = {
40 'method': 'offlineLogin',
41 'email': form.email.value,
42 'password': form.password.value
44 window.parent.postMessage(msg, 'chrome://oobe/');
46 e.preventDefault();
47 });
49 var email = params['email'];
50 if (email) {
51 // Email is present, which means that unsuccessful login attempt has been
52 // made. Try to mimic Gaia's behaviour.
53 form.email.value = email;
54 form.password.classList.add('form-error');
55 form.password.focus();
56 } else {
57 form.email.focus();
59 window.parent.postMessage({'method': 'loginUILoaded'}, 'chrome://oobe/');
62 document.addEventListener('DOMContentLoaded', load);