Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / gaia_auth / desktop_injected.js
1 // Copyright 2013 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 Code injected into Gaia sign in page for inline sign in flow.
7  * On load stop, it receives a message from the embedder extension with a
8  * JavaScript reference to the embedder window. Then upon submit of the sign
9  * in form, it posts the username and password to the embedder window.
10  * Prototype Only.
11  */
12
13 (function() {
14   var $ = function(id) { return document.getElementById(id); };
15
16   var gaiaLoginForm = $('gaia_loginform');
17   if (!gaiaLoginForm) {
18     return;
19   }
20
21   var onLoginSubmit = function(e) {
22     var checkboxElement = $('advanced-box');
23     var chooseWhatToSync = checkboxElement && checkboxElement.checked;
24     var msg = {method: 'attemptLogin',
25                email: gaiaLoginForm['Email'].value,
26                password: gaiaLoginForm['Passwd'].value,
27                attemptToken: new Date().getTime(),
28                chooseWhatToSync: chooseWhatToSync};
29
30     window.parent.postMessage(
31         msg, 'chrome-extension://mfffpogegjflfpflabcdkioaeobkgjik');
32
33     return;
34   };
35   // Overrides the submit handler for the gaia login form.
36   gaiaLoginForm.onsubmit = onLoginSubmit;
37 })();