Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / google_apis / test / embedded_setup_chromeos.html
blobc8c7b0142b435af18e7d8bfff50f8a2120825c21
1 <html>
2 <head>
3 <script>
4 var gaia = gaia || {};
5 gaia.chromeOSLogin = {};
7 gaia.chromeOSLogin.parent_webview_signin_url_ = 'chrome://chrome-signin';
8 gaia.chromeOSLogin.parent_webview_oob_url_ = 'chrome://oobe';
9 gaia.chromeOSLogin.parent_webview_ = undefined;
10 gaia.chromeOSLogin.parent_webview_url_ = undefined;
12 gaia.chromeOSLogin.registerHtml5Listener = function() {
13 var onMessage = function(e) {
14 if (e.origin == gaia.chromeOSLogin.parent_webview_signin_url_ ||
15 e.origin == gaia.chromeOSLogin.parent_webview_oob_url_) {
16 gaia.chromeOSLogin.parent_webview_ = e.source;
17 gaia.chromeOSLogin.parent_webview_url_ = e.origin;
19 // Repeat clearOldAttempts as soon as we got parent.
20 gaia.chromeOSLogin.clearOldAttempts();
23 window.addEventListener('message', onMessage);
24 window.addEventListener("popstate", function(e) { goBack(); });
25 window.postMessage({
26 type: 'gaia_saml_api',
27 call: {method: 'initialize', requestedVersion: 1}}, '/');
30 gaia.chromeOSLogin.clearOldAttempts = function() {
31 var msg = {
32 'method': 'clearOldAttempts'
34 gaia.chromeOSLogin.parent_webview_.postMessage(msg,
35 gaia.chromeOSLogin.parent_webview_url_);
38 gaia.chromeOSLogin.attemptLogin = function(email, password) {
39 var msg = {
40 'method': 'attemptLogin',
41 'email': email,
43 gaia.chromeOSLogin.parent_webview_.postMessage(msg,
44 gaia.chromeOSLogin.parent_webview_url_);
46 // SAML credential passing api for password.
47 window.postMessage(
48 {type: 'gaia_saml_api',
49 call: {method: 'add',
50 token: 'token',
51 user: email,
52 passwordBytes: password,
53 keyType: 'KEY_TYPE_PASSWORD_PLAIN'}
54 }, '/');
57 gaia.chromeOSLogin.backButton = function(show) {
58 var msg = {
59 'method': 'backButton',
60 'show': show,
62 gaia.chromeOSLogin.parent_webview_.postMessage(msg,
63 gaia.chromeOSLogin.parent_webview_url_);
66 function goFirstPage() {
67 document.getElementById('page1').hidden = false;
68 document.getElementById('page2').hidden = true;
69 history.replaceState({}, '', window.location.pathname + '#identifier');
70 gaia.chromeOSLogin.backButton(false);
73 function goBack() {
74 if (!document.getElementById('page2').hidden) {
75 goFirstPage();
79 function goNext() {
80 if (!document.getElementById("page1").hidden) {
81 document.getElementById("page1").hidden = true;
82 document.getElementById("page2").hidden = false;
83 history.pushState({}, "", window.location.pathname + "#challengepassword");
85 request = new XMLHttpRequest();
86 request.open('POST', '/_/embedded/lookup/accountlookup', true);
87 request.onreadystatechange = function() {
88 if (request.readyState == 4 && request.status == 200) {
89 if (request.getResponseHeader("continue"))
90 location.assign(request.getResponseHeader("continue"));
93 var email = document.getElementById("identifier").value;
94 request.send('identifier=' + encodeURIComponent(email));
96 gaia.chromeOSLogin.attemptLogin(email, "");
97 gaia.chromeOSLogin.backButton(true);
98 } else if (!document.getElementById("page2").hidden) {
99 var email = document.getElementById("identifier").value;
100 var password = document.getElementById("password").value;
102 request = new XMLHttpRequest();
103 request.open('POST', '/_/embedded/signin/challenge', true);
104 request.onreadystatechange = function() {
105 if (request.readyState == 4 && request.status == 200) {
106 history.pushState({}, "", window.location.pathname + "#close");
109 request.send('identifier=' + encodeURIComponent(email));
111 gaia.chromeOSLogin.attemptLogin(email, password);
115 function onLoad() {
116 gaia.chromeOSLogin.registerHtml5Listener();
117 goFirstPage();
118 gaia.chromeOSLogin.clearOldAttempts();
121 </script>
122 </head>
123 <body onload='onLoad();'>
124 Local Auth Server:<br>
125 <div id="page1" hidden>
126 Email
127 <input id="identifier" name="identifier" type="email" spellcheck="false" autocomplete="off" formnovalidate="">
128 </div>
129 <div id="page2" hidden>
130 Password
131 <input id="password" name="password" type="password" spellcheck="false" autocomplete="off" formnovalidate="">
132 </div><br>
133 <div id='nextButton' onclick='goNext();'>Next</div>
134 </body>
135 </html>