| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <include src="post_message_channel.js"> | 5 <include src="post_message_channel.js"> |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * @fileoverview Saml support for webview based auth. | 8 * @fileoverview Saml support for webview based auth. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 150 |
| 151 this.webview_.request.onBeforeRequest.addListener( | 151 this.webview_.request.onBeforeRequest.addListener( |
| 152 this.onInsecureRequest.bind(this), | 152 this.onInsecureRequest.bind(this), |
| 153 {urls: ['http://*/*', 'file://*/*', 'ftp://*/*']}, | 153 {urls: ['http://*/*', 'file://*/*', 'ftp://*/*']}, |
| 154 ['blocking']); | 154 ['blocking']); |
| 155 this.webview_.request.onHeadersReceived.addListener( | 155 this.webview_.request.onHeadersReceived.addListener( |
| 156 this.onHeadersReceived_.bind(this), | 156 this.onHeadersReceived_.bind(this), |
| 157 {urls: ['<all_urls>'], types: ['main_frame', 'xmlhttprequest']}, | 157 {urls: ['<all_urls>'], types: ['main_frame', 'xmlhttprequest']}, |
| 158 ['blocking', 'responseHeaders']); | 158 ['blocking', 'responseHeaders']); |
| 159 | 159 |
| 160 this.webview_.addContentScripts([{ |
| 161 'name': 'samlInjected', |
| 162 'matches': ['http://*/*', 'https://*/*'], |
| 163 'code': injectedJs, |
| 164 'all_frames': true, |
| 165 'run_at': 'document_start' |
| 166 }]); |
| 167 |
| 160 PostMessageChannel.runAsDaemon(this.onConnected_.bind(this)); | 168 PostMessageChannel.runAsDaemon(this.onConnected_.bind(this)); |
| 161 } | 169 } |
| 162 | 170 |
| 163 SamlHandler.prototype = { | 171 SamlHandler.prototype = { |
| 164 __proto__: cr.EventTarget.prototype, | 172 __proto__: cr.EventTarget.prototype, |
| 165 | 173 |
| 166 /** | 174 /** |
| 167 * Whether Saml API is used during auth. | 175 * Whether Saml API is used during auth. |
| 168 * @return {boolean} | 176 * @return {boolean} |
| 169 */ | 177 */ |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 | 224 |
| 217 /** | 225 /** |
| 218 * Check whether the given |password| is in the scraped passwords. | 226 * Check whether the given |password| is in the scraped passwords. |
| 219 * @return {boolean} True if the |password| is found. | 227 * @return {boolean} True if the |password| is found. |
| 220 */ | 228 */ |
| 221 verifyConfirmedPassword: function(password) { | 229 verifyConfirmedPassword: function(password) { |
| 222 return this.getConsolidatedScrapedPasswords_().indexOf(password) >= 0; | 230 return this.getConsolidatedScrapedPasswords_().indexOf(password) >= 0; |
| 223 }, | 231 }, |
| 224 | 232 |
| 225 /** | 233 /** |
| 226 * Injects JS code to all frames. | |
| 227 * @private | |
| 228 */ | |
| 229 injectJs_: function() { | |
| 230 if (!injectedJs) | |
| 231 return; | |
| 232 | |
| 233 // TODO(xiyuan): Replace this with webview.addContentScript. | |
| 234 this.webview_.executeScript({ | |
| 235 code: injectedJs, | |
| 236 allFrames: true, | |
| 237 runAt: 'document_start' | |
| 238 }); | |
| 239 }, | |
| 240 | |
| 241 /** | |
| 242 * Invoked on the webview's contentload event. | 234 * Invoked on the webview's contentload event. |
| 243 * @private | 235 * @private |
| 244 */ | 236 */ |
| 245 onContentLoad_: function(e) { | 237 onContentLoad_: function(e) { |
| 246 PostMessageChannel.init(this.webview_.contentWindow); | 238 PostMessageChannel.init(this.webview_.contentWindow); |
| 247 }, | 239 }, |
| 248 | 240 |
| 249 /** | 241 /** |
| 250 * Invoked on the webview's loadabort event. | 242 * Invoked on the webview's loadabort event. |
| 251 * @private | 243 * @private |
| (...skipping 14 matching lines...) Expand all Loading... |
| 266 return; | 258 return; |
| 267 } | 259 } |
| 268 | 260 |
| 269 // Skip for none http/https url. | 261 // Skip for none http/https url. |
| 270 if (e.url.indexOf('https://') != 0 && | 262 if (e.url.indexOf('https://') != 0 && |
| 271 e.url.indexOf('http://') != 0) { | 263 e.url.indexOf('http://') != 0) { |
| 272 return; | 264 return; |
| 273 } | 265 } |
| 274 | 266 |
| 275 this.isSamlPage_ = this.pendingIsSamlPage_; | 267 this.isSamlPage_ = this.pendingIsSamlPage_; |
| 276 this.injectJs_(); | |
| 277 }, | 268 }, |
| 278 | 269 |
| 279 /** | 270 /** |
| 280 * Handler for webRequest.onBeforeRequest, invoked when content served over | 271 * Handler for webRequest.onBeforeRequest, invoked when content served over |
| 281 * an unencrypted connection is detected. Determines whether the request | 272 * an unencrypted connection is detected. Determines whether the request |
| 282 * should be blocked and if so, signals that an error message needs to be | 273 * should be blocked and if so, signals that an error message needs to be |
| 283 * shown. | 274 * shown. |
| 284 * @param {Object} details | 275 * @param {Object} details |
| 285 * @return {!Object} Decision whether to block the request. | 276 * @return {!Object} Decision whether to block the request. |
| 286 */ | 277 */ |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 {detail: {url: url, | 438 {detail: {url: url, |
| 448 isSAMLPage: this.isSamlPage_, | 439 isSAMLPage: this.isSamlPage_, |
| 449 domain: this.authDomain}})); | 440 domain: this.authDomain}})); |
| 450 }, | 441 }, |
| 451 | 442 |
| 452 onGetSAMLFlag_: function(channel, msg) { | 443 onGetSAMLFlag_: function(channel, msg) { |
| 453 return this.isSamlPage_; | 444 return this.isSamlPage_; |
| 454 }, | 445 }, |
| 455 }; | 446 }; |
| 456 | 447 |
| 457 /** | |
| 458 * Sets the saml injected JS code. | |
| 459 * @param {string} samlInjectedJs JS code to inejct for Saml. | |
| 460 */ | |
| 461 SamlHandler.setSamlInjectedJs = function(samlInjectedJs) { | |
| 462 injectedJs = samlInjectedJs; | |
| 463 }; | |
| 464 | |
| 465 return { | 448 return { |
| 466 SamlHandler: SamlHandler | 449 SamlHandler: SamlHandler |
| 467 }; | 450 }; |
| 468 }); | 451 }); |
| OLD | NEW |