Chromium Code Reviews| 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 // Maps a tab id to its associated BackgroundBridge. | |
| 32 this.bridges_ = {}; | |
| 31 } | 33 } |
| 32 | 34 |
| 33 BackgroundBridgeManager.prototype = { | 35 BackgroundBridgeManager.prototype = { |
| 34 CONTINUE_URL_BASE: 'chrome-extension://mfffpogegjflfpflabcdkioaeobkgjik' + | 36 CONTINUE_URL_BASE: 'chrome-extension://mfffpogegjflfpflabcdkioaeobkgjik' + |
| 35 '/success.html', | 37 '/success.html', |
| 36 // Maps a tab id to its associated BackgroundBridge. | |
| 37 bridges_: {}, | |
|
dzhioev (left Google)
2015/06/10 20:04:18
Can you replace this with 'bridges_: null' instead
xiyuan
2015/06/10 20:21:12
It is not deleted. It is moved to BackgroundBridge
dzhioev (left Google)
2015/06/10 21:20:46
I understand this. That's a matter of opinion, but
xiyuan
2015/06/10 21:32:45
I see what you mean now. Done here and other place
| |
| 38 | |
| 39 run: function() { | 38 run: function() { |
| 40 chrome.runtime.onConnect.addListener(this.onConnect_.bind(this)); | 39 chrome.runtime.onConnect.addListener(this.onConnect_.bind(this)); |
| 41 | 40 |
| 42 chrome.webRequest.onBeforeRequest.addListener( | 41 chrome.webRequest.onBeforeRequest.addListener( |
| 43 function(details) { | 42 function(details) { |
| 44 if (this.bridges_[details.tabId]) | 43 if (this.bridges_[details.tabId]) |
| 45 return this.bridges_[details.tabId].onInsecureRequest(details.url); | 44 return this.bridges_[details.tabId].onInsecureRequest(details.url); |
| 46 }.bind(this), | 45 }.bind(this), |
| 47 {urls: ['http://*/*', 'file://*/*', 'ftp://*/*']}, | 46 {urls: ['http://*/*', 'file://*/*', 'ftp://*/*']}, |
| 48 ['blocking']); | 47 ['blocking']); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 }; | 95 }; |
| 97 | 96 |
| 98 /** | 97 /** |
| 99 * BackgroundBridge allows the main script and the injected script to | 98 * BackgroundBridge allows the main script and the injected script to |
| 100 * collaborate. It forwards credentials API calls to the main script and | 99 * collaborate. It forwards credentials API calls to the main script and |
| 101 * maintains a list of scraped passwords. | 100 * maintains a list of scraped passwords. |
| 102 * @param {string} tabId The associated tab ID. | 101 * @param {string} tabId The associated tab ID. |
| 103 */ | 102 */ |
| 104 function BackgroundBridge(tabId) { | 103 function BackgroundBridge(tabId) { |
| 105 this.tabId_ = tabId; | 104 this.tabId_ = tabId; |
| 105 this.passwordStore_ = {}; | |
| 106 } | 106 } |
| 107 | 107 |
| 108 BackgroundBridge.prototype = { | 108 BackgroundBridge.prototype = { |
| 109 // The associated tab ID. Only used for debugging now. | 109 // The associated tab ID. Only used for debugging now. |
| 110 tabId: null, | 110 tabId: null, |
| 111 | 111 |
| 112 // The initial URL loaded in the gaia iframe. We only want to handle | 112 // The initial URL loaded in the gaia iframe. We only want to handle |
| 113 // onCompleted() for the frame that loaded this URL. | 113 // onCompleted() for the frame that loaded this URL. |
| 114 initialFrameUrlWithoutParams: null, | 114 initialFrameUrlWithoutParams: null, |
| 115 | 115 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 141 // content served over an unencrypted connection is detected. | 141 // content served over an unencrypted connection is detected. |
| 142 blockInsecureContent_: false, | 142 blockInsecureContent_: false, |
| 143 | 143 |
| 144 // Whether auth flow has started. It is used as a signal of whether the | 144 // Whether auth flow has started. It is used as a signal of whether the |
| 145 // injected script should scrape passwords. | 145 // injected script should scrape passwords. |
| 146 authStarted_: false, | 146 authStarted_: false, |
| 147 | 147 |
| 148 // Whether SAML flow is going. | 148 // Whether SAML flow is going. |
| 149 isSAML_: false, | 149 isSAML_: false, |
| 150 | 150 |
| 151 passwordStore_: {}, | |
|
dzhioev (left Google)
2015/06/10 20:04:18
ditto
xiyuan
2015/06/10 20:21:12
Same here. It is moved to BackgroundBridge constru
| |
| 152 | |
| 153 channelMain_: null, | 151 channelMain_: null, |
| 154 channelInjected_: null, | 152 channelInjected_: null, |
| 155 | 153 |
| 156 /** | 154 /** |
| 157 * Sets up the communication channel with the main script. | 155 * Sets up the communication channel with the main script. |
| 158 */ | 156 */ |
| 159 setupForAuthMain: function(port) { | 157 setupForAuthMain: function(port) { |
| 160 this.channelMain_ = new Channel(); | 158 this.channelMain_ = new Channel(); |
| 161 this.channelMain_.init(port); | 159 this.channelMain_.init(port); |
| 162 | 160 |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 452 isSAMLPage: this.isSAML_}); | 450 isSAMLPage: this.isSAML_}); |
| 453 }, | 451 }, |
| 454 | 452 |
| 455 onGetSAMLFlag_: function(msg) { | 453 onGetSAMLFlag_: function(msg) { |
| 456 return this.isSAML_; | 454 return this.isSAML_; |
| 457 } | 455 } |
| 458 }; | 456 }; |
| 459 | 457 |
| 460 var backgroundBridgeManager = new BackgroundBridgeManager(); | 458 var backgroundBridgeManager = new BackgroundBridgeManager(); |
| 461 backgroundBridgeManager.run(); | 459 backgroundBridgeManager.run(); |
| OLD | NEW |