Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * @fileoverview This extension manages communications between Chrome, | 8 * @fileoverview This extension manages communications between Chrome, |
| 9 * Google.com pages and the Chrome Hotword extension. | 9 * Google.com pages and the Chrome Hotword extension. |
| 10 * | 10 * |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 chrome.hotwordPrivate.setAudioLoggingEnabled) { | 117 chrome.hotwordPrivate.setAudioLoggingEnabled) { |
| 118 chrome.hotwordPrivate.setAudioLoggingEnabled(false); | 118 chrome.hotwordPrivate.setAudioLoggingEnabled(false); |
| 119 } | 119 } |
| 120 break; | 120 break; |
| 121 default: | 121 default: |
| 122 break; | 122 break; |
| 123 } | 123 } |
| 124 return false; | 124 return false; |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 /** | |
| 128 * Helper function to test urls as being valid for running the | |
|
James Hawkins
2014/05/12 18:13:43
nit: URLs.
rpetterson
2014/05/12 21:09:05
Done.
| |
| 129 * hotwording extension. It's used by isEligibleUrl to make that | |
| 130 * function clearer. | |
| 131 * @param {string} url Url to check. | |
| 132 * @param {string} base Base url to compare against.. | |
| 133 * @return {boolean} True if url is eligible hotword url. | |
| 134 */ | |
| 135 OptInManager.prototype.checkEligibleUrl = function(url, base) { | |
| 136 if (!url) | |
| 137 return false; | |
| 138 | |
| 139 if (url === base || | |
| 140 url === base + '/' || | |
| 141 url.indexOf(base + '/_/chrome/newtab?') === 0 || // Appcache NTP. | |
| 142 url.indexOf(base + '/?') === 0 || | |
| 143 url.indexOf(base + '/#') === 0 || | |
| 144 url.indexOf(base + '/webhp') === 0 || | |
| 145 url.indexOf(base + '/search') === 0) { | |
| 146 return true; | |
| 147 } | |
| 148 return false; | |
| 149 | |
| 150 }; | |
| 127 | 151 |
| 128 /** | 152 /** |
| 129 * Determines if a URL is eligible for hotwording. For now, the | 153 * Determines if a URL is eligible for hotwording. For now, the |
| 130 * valid pages are the Google HP and SERP (this will include the NTP). | 154 * valid pages are the Google HP and SERP (this will include the NTP). |
| 131 * @param {string} url Url to check. | 155 * @param {string} url Url to check. |
| 132 * @return {boolean} True if url is eligible hotword url. | 156 * @return {boolean} True if url is eligible hotword url. |
| 133 */ | 157 */ |
| 134 OptInManager.prototype.isEligibleUrl = function(url) { | 158 OptInManager.prototype.isEligibleUrl = function(url) { |
| 135 if (!url) | 159 if (!url) |
| 136 return false; | 160 return false; |
| 137 | 161 |
| 138 var baseUrls = [ | 162 var baseUrls = [ |
| 139 'https://www.google.com', | 163 'chrome://newtab' |
| 140 'chrome://newtab', | 164 ]; |
| 141 'https://encrypted.google.com' | 165 var baseGoogleUrls = [ |
| 166 'https://www.google.', | |
| 167 'https://encrypted.google.' | |
| 168 ]; | |
| 169 var tlds = [ | |
| 170 'com', | |
| 171 'co.uk', | |
| 172 'de', | |
| 173 'fr', | |
| 174 'ru' | |
| 142 ]; | 175 ]; |
| 143 | 176 |
| 144 for (var i = 0; i < baseUrls.length; i++) { | 177 if (this.checkEligibleUrl(url, baseUrls[0])) |
|
James Hawkins
2014/05/12 18:13:43
Can you clarify why we need to check baseUrls[0] s
rpetterson
2014/05/12 19:42:39
chrome://newtab doesn't have the local tlds (.com,
James Hawkins
2014/05/12 19:44:39
No, that's fine. Just add a comment to the code t
rpetterson
2014/05/12 21:09:05
Done.
| |
| 145 var base = baseUrls[i]; | 178 return true; |
| 146 if (url === base + '/' || | 179 |
| 147 url.indexOf(base + '/_/chrome/newtab?') === 0 || // Appcache NTP. | 180 for (var i = 0; i < baseGoogleUrls.length; i++) { |
| 148 url.indexOf(base + '/?') === 0 || | 181 for (var j = 0; j < tlds.length; j++) { |
| 149 url.indexOf(base + '/#') === 0 || | 182 var base = baseGoogleUrls[i] + tlds[j]; |
| 150 url.indexOf(base + '/webhp') === 0 || | 183 if (this.checkEligibleUrl(url, base)) |
| 151 url.indexOf(base + '/search') === 0) { | 184 return true; |
| 152 return true; | |
| 153 } | 185 } |
| 154 } | 186 } |
| 155 return false; | 187 return false; |
| 156 }; | 188 }; |
| 157 | 189 |
| 158 | 190 |
| 159 /** | 191 /** |
| 160 * Initializes the extension. | 192 * Initializes the extension. |
| 161 */ | 193 */ |
| 162 OptInManager.prototype.initialize = function() { | 194 OptInManager.prototype.initialize = function() { |
| 163 // TODO(rlp): Possibly remove the next line. It's proably not used, but | 195 // TODO(rlp): Possibly remove the next line. It's proably not used, but |
| 164 // leaving for now to be safe. We should remove it once all messsage | 196 // leaving for now to be safe. We should remove it once all messsage |
| 165 // relaying is removed form the content scripts. | 197 // relaying is removed form the content scripts. |
| 166 chrome.runtime.onMessage.addListener(this.handleMessage_.bind(this)); | 198 chrome.runtime.onMessage.addListener(this.handleMessage_.bind(this)); |
| 167 chrome.runtime.onMessageExternal.addListener( | 199 chrome.runtime.onMessageExternal.addListener( |
| 168 this.handleMessage_.bind(this)); | 200 this.handleMessage_.bind(this)); |
| 169 }; | 201 }; |
| 170 | 202 |
| 171 | 203 |
| 172 new OptInManager().initialize(); | 204 new OptInManager().initialize(); |
| OLD | NEW |