| 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, serving three main purposes: | 7 * Script to be injected into SAML provider pages, serving three main purposes: |
| 8 * 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 |
| 9 * UI around it should be changed accordingly; | 9 * UI around it should be changed accordingly; |
| 10 * 2. Provide an API via which the SAML provider can pass user credentials to | 10 * 2. Provide an API via which the SAML provider can pass user credentials to |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 * @param {!HTMLInputElement} passworField The password field to track. | 136 * @param {!HTMLInputElement} passworField The password field to track. |
| 137 */ | 137 */ |
| 138 trackPasswordField: function(passwordField) { | 138 trackPasswordField: function(passwordField) { |
| 139 var existing = this.passwordFields_.filter(function(element) { | 139 var existing = this.passwordFields_.filter(function(element) { |
| 140 return element === passwordField; | 140 return element === passwordField; |
| 141 }); | 141 }); |
| 142 if (existing.length != 0) | 142 if (existing.length != 0) |
| 143 return; | 143 return; |
| 144 | 144 |
| 145 var index = this.passwordFields_.length; | 145 var index = this.passwordFields_.length; |
| 146 var fieldId = passwordField.id || passwordField.name || ''; |
| 146 passwordField.addEventListener( | 147 passwordField.addEventListener( |
| 147 'input', this.onPasswordChanged_.bind(this, index)); | 148 'input', this.onPasswordChanged_.bind(this, index, fieldId)); |
| 148 this.passwordFields_.push(passwordField); | 149 this.passwordFields_.push(passwordField); |
| 149 this.passwordValues_.push(passwordField.value); | 150 this.passwordValues_.push(passwordField.value); |
| 150 }, | 151 }, |
| 151 | 152 |
| 152 /** | 153 /** |
| 153 * Check if the password field at |index| has changed. If so, sends back | 154 * Check if the password field at |index| has changed. If so, sends back |
| 154 * the updated value. | 155 * the updated value. |
| 155 */ | 156 */ |
| 156 maybeSendUpdatedPassword: function(index) { | 157 maybeSendUpdatedPassword: function(index, fieldId) { |
| 157 var newValue = this.passwordFields_[index].value; | 158 var newValue = this.passwordFields_[index].value; |
| 158 if (newValue == this.passwordValues_[index]) | 159 if (newValue == this.passwordValues_[index]) |
| 159 return; | 160 return; |
| 160 | 161 |
| 161 this.passwordValues_[index] = newValue; | 162 this.passwordValues_[index] = newValue; |
| 162 | 163 |
| 163 // Use an invalid char for URL as delimiter to concatenate page url and | 164 // Use an invalid char for URL as delimiter to concatenate page url, |
| 164 // password field index to construct a unique ID for the password field. | 165 // password field index and id to construct a unique ID for the password |
| 165 var passwordId = this.pageURL_.split('#')[0].split('?')[0] + '|' + index; | 166 // field. |
| 167 var passwordId = this.pageURL_.split('#')[0].split('?')[0] + |
| 168 '|' + index + '|' + fieldId; |
| 166 this.channel_.send({ | 169 this.channel_.send({ |
| 167 name: 'updatePassword', | 170 name: 'updatePassword', |
| 168 id: passwordId, | 171 id: passwordId, |
| 169 password: newValue | 172 password: newValue |
| 170 }); | 173 }); |
| 171 }, | 174 }, |
| 172 | 175 |
| 173 /** | 176 /** |
| 174 * Handles 'change' event in the scraped password fields. | 177 * Handles 'change' event in the scraped password fields. |
| 175 * @param {number} index The index of the password fields in | 178 * @param {number} index The index of the password fields in |
| 176 * |passwordFields_|. | 179 * |passwordFields_|. |
| 180 * @param {string} fieldId The id or name of the password field or blank. |
| 177 */ | 181 */ |
| 178 onPasswordChanged_: function(index) { | 182 onPasswordChanged_: function(index, fieldId) { |
| 179 this.maybeSendUpdatedPassword(index); | 183 this.maybeSendUpdatedPassword(index, fieldId); |
| 180 } | 184 } |
| 181 }; | 185 }; |
| 182 | 186 |
| 183 function onGetSAMLFlag(channel, isSAMLPage) { | 187 function onGetSAMLFlag(channel, isSAMLPage) { |
| 184 if (!isSAMLPage) | 188 if (!isSAMLPage) |
| 185 return; | 189 return; |
| 186 var pageURL = window.location.href; | 190 var pageURL = window.location.href; |
| 187 | 191 |
| 188 channel.send({name: 'pageLoaded', url: pageURL}); | 192 channel.send({name: 'pageLoaded', url: pageURL}); |
| 189 | 193 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 205 } | 209 } |
| 206 | 210 |
| 207 var channel = Channel.create(); | 211 var channel = Channel.create(); |
| 208 channel.connect('injected'); | 212 channel.connect('injected'); |
| 209 channel.sendWithCallback({name: 'getSAMLFlag'}, | 213 channel.sendWithCallback({name: 'getSAMLFlag'}, |
| 210 onGetSAMLFlag.bind(undefined, channel)); | 214 onGetSAMLFlag.bind(undefined, channel)); |
| 211 | 215 |
| 212 var apiCallForwarder = new APICallForwarder(); | 216 var apiCallForwarder = new APICallForwarder(); |
| 213 apiCallForwarder.init(channel); | 217 apiCallForwarder.init(channel); |
| 214 })(); | 218 })(); |
| OLD | NEW |