OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview | 6 * @fileoverview |
7 * Script to be injected into SAML provider pages that do not support the | 7 * Script to be injected into SAML provider pages, serving three main purposes: |
8 * auth service provider postMessage API. It serves two main purposes: | |
9 * 1. Signal hosting extension that an external page is loaded so that the | 8 * 1. Signal hosting extension that an external page is loaded so that the |
10 * UI around it could be changed accordingly; | 9 * UI around it should be changed accordingly; |
11 * 2. Scrape password and send it back to be used for encrypt user data and | 10 * 2. Provide an API via which the SAML provider can pass user credentials to |
12 * use for offline login; | 11 * Chrome OS, allowing the password to be used for encrypting user data and |
| 12 * offline login. |
| 13 * 3. Scrape password fields, making the password available to Chrome OS even if |
| 14 * the SAML provider does not support the credential passing API. |
13 */ | 15 */ |
14 | 16 |
15 (function() { | 17 (function() { |
| 18 function APICallForwarder() { |
| 19 } |
| 20 |
| 21 /** |
| 22 * The credential passing API is used by sending messages to the SAML page's |
| 23 * |window| object. This class forwards the calls to a background script via a |
| 24 * |Channel|. |
| 25 */ |
| 26 APICallForwarder.prototype = { |
| 27 // Channel to which API calls are forwarded. |
| 28 channel_: null, |
| 29 |
| 30 /** |
| 31 * Initialize the API call forwarder. |
| 32 * @param {!Object} channel Channel to which API calls should be forwarded. |
| 33 */ |
| 34 init: function(channel) { |
| 35 this.channel_ = channel; |
| 36 window.addEventListener('message', this.onMessage_.bind(this)); |
| 37 }, |
| 38 |
| 39 onMessage_: function(event) { |
| 40 if (event.source != window || |
| 41 typeof event.data != 'object' || |
| 42 !event.data.hasOwnProperty('type') || |
| 43 event.data.type != 'gaia_saml_api') { |
| 44 return; |
| 45 } |
| 46 if (event.data.call.method == 'initialize') { |
| 47 // Respond to the |initialize| call directly. |
| 48 event.source.postMessage({ |
| 49 type: 'gaia_saml_api_reply', |
| 50 response: {result: 'initialized', version: 1}}, '/'); |
| 51 } else { |
| 52 // Forward all other calls. |
| 53 this.channel_.send({name: 'apiCall', call: event.data.call}); |
| 54 } |
| 55 } |
| 56 }; |
| 57 |
16 /** | 58 /** |
17 * A class to scrape password from type=password input elements under a given | 59 * A class to scrape password from type=password input elements under a given |
18 * docRoot and send them back via a Channel. | 60 * docRoot and send them back via a Channel. |
19 */ | 61 */ |
20 function PasswordInputScraper() { | 62 function PasswordInputScraper() { |
21 } | 63 } |
22 | 64 |
23 PasswordInputScraper.prototype = { | 65 PasswordInputScraper.prototype = { |
24 // URL of the page. | 66 // URL of the page. |
25 pageURL_: null, | 67 pageURL_: null, |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 } else { | 160 } else { |
119 var channel; | 161 var channel; |
120 var passwordScraper; | 162 var passwordScraper; |
121 if (isSAMLPage()) { | 163 if (isSAMLPage()) { |
122 var pageURL = window.location.href; | 164 var pageURL = window.location.href; |
123 | 165 |
124 channel = new Channel(); | 166 channel = new Channel(); |
125 channel.connect('injected'); | 167 channel.connect('injected'); |
126 channel.send({name: 'pageLoaded', url: pageURL}); | 168 channel.send({name: 'pageLoaded', url: pageURL}); |
127 | 169 |
| 170 apiCallForwarder = new APICallForwarder(); |
| 171 apiCallForwarder.init(channel); |
| 172 |
128 passwordScraper = new PasswordInputScraper(); | 173 passwordScraper = new PasswordInputScraper(); |
129 passwordScraper.init(channel, pageURL, document.documentElement); | 174 passwordScraper.init(channel, pageURL, document.documentElement); |
130 } | 175 } |
131 } | 176 } |
132 })(); | 177 })(); |
OLD | NEW |