| 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 * A background script of the auth extension that bridges the communication | 7 * A background script of the auth extension that bridges the communication |
| 8 * between the main and injected scripts. | 8 * between the main and injected scripts. |
| 9 * | 9 * |
| 10 * Here is an overview of the communication flow when SAML is being used: | 10 * Here is an overview of the communication flow when SAML is being used: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * c) The injected script scrapes passwords. They are sent to this background | 21 * c) The injected script scrapes passwords. They are sent to this background |
| 22 * script in |updatePassword| messages. The main script can request a list | 22 * script in |updatePassword| messages. The main script can request a list |
| 23 * of the scraped passwords by sending the |getScrapedPasswords| message. | 23 * of the scraped passwords by sending the |getScrapedPasswords| message. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 /** | 26 /** |
| 27 * BackgroundBridgeManager maintains an array of BackgroundBridge, indexed by | 27 * BackgroundBridgeManager maintains an array of BackgroundBridge, indexed by |
| 28 * the associated tab id. | 28 * the associated tab id. |
| 29 */ | 29 */ |
| 30 function BackgroundBridgeManager() { | 30 function BackgroundBridgeManager() { |
| 31 this.bridges_ = {}; |
| 31 } | 32 } |
| 32 | 33 |
| 33 BackgroundBridgeManager.prototype = { | 34 BackgroundBridgeManager.prototype = { |
| 34 CONTINUE_URL_BASE: 'chrome-extension://mfffpogegjflfpflabcdkioaeobkgjik' + | 35 CONTINUE_URL_BASE: 'chrome-extension://mfffpogegjflfpflabcdkioaeobkgjik' + |
| 35 '/success.html', | 36 '/success.html', |
| 36 // Maps a tab id to its associated BackgroundBridge. | 37 // Maps a tab id to its associated BackgroundBridge. |
| 37 bridges_: {}, | 38 bridges_: null, |
| 38 | 39 |
| 39 run: function() { | 40 run: function() { |
| 40 chrome.runtime.onConnect.addListener(this.onConnect_.bind(this)); | 41 chrome.runtime.onConnect.addListener(this.onConnect_.bind(this)); |
| 41 | 42 |
| 42 chrome.webRequest.onBeforeRequest.addListener( | 43 chrome.webRequest.onBeforeRequest.addListener( |
| 43 function(details) { | 44 function(details) { |
| 44 if (this.bridges_[details.tabId]) | 45 if (this.bridges_[details.tabId]) |
| 45 return this.bridges_[details.tabId].onInsecureRequest(details.url); | 46 return this.bridges_[details.tabId].onInsecureRequest(details.url); |
| 46 }.bind(this), | 47 }.bind(this), |
| 47 {urls: ['http://*/*', 'file://*/*', 'ftp://*/*']}, | 48 {urls: ['http://*/*', 'file://*/*', 'ftp://*/*']}, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 }; | 97 }; |
| 97 | 98 |
| 98 /** | 99 /** |
| 99 * BackgroundBridge allows the main script and the injected script to | 100 * BackgroundBridge allows the main script and the injected script to |
| 100 * collaborate. It forwards credentials API calls to the main script and | 101 * collaborate. It forwards credentials API calls to the main script and |
| 101 * maintains a list of scraped passwords. | 102 * maintains a list of scraped passwords. |
| 102 * @param {string} tabId The associated tab ID. | 103 * @param {string} tabId The associated tab ID. |
| 103 */ | 104 */ |
| 104 function BackgroundBridge(tabId) { | 105 function BackgroundBridge(tabId) { |
| 105 this.tabId_ = tabId; | 106 this.tabId_ = tabId; |
| 107 this.passwordStore_ = {}; |
| 106 } | 108 } |
| 107 | 109 |
| 108 BackgroundBridge.prototype = { | 110 BackgroundBridge.prototype = { |
| 109 // The associated tab ID. Only used for debugging now. | 111 // The associated tab ID. Only used for debugging now. |
| 110 tabId: null, | 112 tabId: null, |
| 111 | 113 |
| 112 // The initial URL loaded in the gaia iframe. We only want to handle | 114 // The initial URL loaded in the gaia iframe. We only want to handle |
| 113 // onCompleted() for the frame that loaded this URL. | 115 // onCompleted() for the frame that loaded this URL. |
| 114 initialFrameUrlWithoutParams: null, | 116 initialFrameUrlWithoutParams: null, |
| 115 | 117 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 141 // content served over an unencrypted connection is detected. | 143 // content served over an unencrypted connection is detected. |
| 142 blockInsecureContent_: false, | 144 blockInsecureContent_: false, |
| 143 | 145 |
| 144 // Whether auth flow has started. It is used as a signal of whether the | 146 // Whether auth flow has started. It is used as a signal of whether the |
| 145 // injected script should scrape passwords. | 147 // injected script should scrape passwords. |
| 146 authStarted_: false, | 148 authStarted_: false, |
| 147 | 149 |
| 148 // Whether SAML flow is going. | 150 // Whether SAML flow is going. |
| 149 isSAML_: false, | 151 isSAML_: false, |
| 150 | 152 |
| 151 passwordStore_: {}, | 153 passwordStore_: null, |
| 152 | 154 |
| 153 channelMain_: null, | 155 channelMain_: null, |
| 154 channelInjected_: null, | 156 channelInjected_: null, |
| 155 | 157 |
| 156 /** | 158 /** |
| 157 * Sets up the communication channel with the main script. | 159 * Sets up the communication channel with the main script. |
| 158 */ | 160 */ |
| 159 setupForAuthMain: function(port) { | 161 setupForAuthMain: function(port) { |
| 160 this.channelMain_ = new Channel(); | 162 this.channelMain_ = new Channel(); |
| 161 this.channelMain_.init(port); | 163 this.channelMain_.init(port); |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 isSAMLPage: this.isSAML_}); | 454 isSAMLPage: this.isSAML_}); |
| 453 }, | 455 }, |
| 454 | 456 |
| 455 onGetSAMLFlag_: function(msg) { | 457 onGetSAMLFlag_: function(msg) { |
| 456 return this.isSAML_; | 458 return this.isSAML_; |
| 457 } | 459 } |
| 458 }; | 460 }; |
| 459 | 461 |
| 460 var backgroundBridgeManager = new BackgroundBridgeManager(); | 462 var backgroundBridgeManager = new BackgroundBridgeManager(); |
| 461 backgroundBridgeManager.run(); | 463 backgroundBridgeManager.run(); |
| OLD | NEW |