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.
6 * @fileoverview Offline login implementation.
10 * Initialize the offline page.
11 * @param {Object} params Intialization params passed from parent page.
13 function load(params) {
14 // Setup localized strings.
15 $('sign-in-title').textContent = decodeURIComponent(params['stringSignIn']);
16 $('email-label').textContent = decodeURIComponent(params['stringEmail']);
17 $('password-label').textContent =
18 decodeURIComponent(params['stringPassword']);
19 $('submit-button').value = decodeURIComponent(params['stringSignIn']);
20 $('empty-email-alert').textContent =
21 decodeURIComponent(params['stringEmptyEmail']);
22 $('empty-password-alert').textContent =
23 decodeURIComponent(params['stringEmptyPassword']);
24 $('errormsg-alert').textContent = decodeURIComponent(params['stringError']);
27 var form = $('offline-login-form');
28 form.addEventListener('submit', function(e) {
29 // Clear all previous errors.
30 form.email.classList.remove('field-error');
31 form.password.classList.remove('field-error');
32 form.password.classList.remove('form-error');
34 if (form.email.value == '') {
35 form.email.classList.add('field-error');
37 } else if (form.password.value == '') {
38 form.password.classList.add('field-error');
39 form.password.focus();
42 'method': 'offlineLogin',
43 'email': form.email.value,
44 'password': form.password.value
46 window.parent.postMessage(msg, 'chrome://oobe/');
51 var email = params['email'];
53 // Email is present, which means that unsuccessful login attempt has been
54 // made. Try to mimic Gaia's behaviour.
55 form.email.value = email;
56 form.password.classList.add('form-error');
57 form.password.focus();
61 window.parent.postMessage({'method': 'loginUILoaded'}, 'chrome://oobe/');
65 * Handles initialization message from parent page.
66 * @param {MessageEvent} e
68 function handleInitializeMessage(e) {
69 var ALLOWED_PARENT_ORIGINS = [
71 'chrome://chrome-signin'
74 if (ALLOWED_PARENT_ORIGINS.indexOf(e.origin) == -1)
77 window.removeEventListener('message', handleInitializeMessage);
80 params.parentPage = e.origin;
84 document.addEventListener('DOMContentLoaded', function() {
85 window.addEventListener('message', handleInitializeMessage);
86 window.parent.postMessage({'method': 'loginUIDOMContentLoaded'}, '*');