OLD | NEW |
| (Empty) |
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. | |
4 | |
5 /** | |
6 * @fileoverview Offline login implementation. | |
7 */ | |
8 | |
9 /** | |
10 * Initialize the offline page. | |
11 * @param {Object} params Intialization params passed from parent page. | |
12 */ | |
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']); | |
25 | |
26 // Setup actions. | |
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'); | |
33 | |
34 if (form.email.value == '') { | |
35 form.email.classList.add('field-error'); | |
36 form.email.focus(); | |
37 } else if (form.password.value == '') { | |
38 form.password.classList.add('field-error'); | |
39 form.password.focus(); | |
40 } else { | |
41 var msg = { | |
42 'method': 'offlineLogin', | |
43 'email': form.email.value, | |
44 'password': form.password.value | |
45 }; | |
46 window.parent.postMessage(msg, 'chrome://oobe/'); | |
47 } | |
48 e.preventDefault(); | |
49 }); | |
50 | |
51 var email = params['email']; | |
52 if (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(); | |
58 } else { | |
59 form.email.focus(); | |
60 } | |
61 window.parent.postMessage({'method': 'loginUILoaded'}, 'chrome://oobe/'); | |
62 } | |
63 | |
64 /** | |
65 * Handles initialization message from parent page. | |
66 * @param {MessageEvent} e | |
67 */ | |
68 function handleInitializeMessage(e) { | |
69 var ALLOWED_PARENT_ORIGINS = [ | |
70 'chrome://oobe', | |
71 'chrome://chrome-signin' | |
72 ]; | |
73 | |
74 if (ALLOWED_PARENT_ORIGINS.indexOf(e.origin) == -1) | |
75 return; | |
76 | |
77 window.removeEventListener('message', handleInitializeMessage); | |
78 | |
79 var params = e.data; | |
80 params.parentPage = e.origin; | |
81 load(params); | |
82 } | |
83 | |
84 document.addEventListener('DOMContentLoaded', function() { | |
85 window.addEventListener('message', handleInitializeMessage); | |
86 window.parent.postMessage({'method': 'loginUIDOMContentLoaded'}, '*'); | |
87 }); | |
OLD | NEW |