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. | |
James Hawkins
2014/05/09 02:54:27
Can you update the method name and documentation t
rpetterson
2014/05/09 06:07:20
Done.
| |
129 * @param {string} url Url to check. | |
130 * @param {string} base Base url to compare against.. | |
131 * @return {boolean} True if url is eligible hotword url. | |
132 */ | |
133 OptInManager.prototype.checkUrl = function(url, base) { | |
134 if (!url) | |
135 return false; | |
136 | |
137 if (url === base + '/' || | |
138 url.indexOf(base + '/_/chrome/newtab?') === 0 || // Appcache NTP. | |
139 url.indexOf(base + '/?') === 0 || | |
140 url.indexOf(base + '/#') === 0 || | |
141 url.indexOf(base + '/webhp') === 0 || | |
142 url.indexOf(base + '/search') === 0) { | |
143 return true; | |
144 } | |
145 return false; | |
146 | |
147 }; | |
127 | 148 |
128 /** | 149 /** |
129 * Determines if a URL is eligible for hotwording. For now, the | 150 * 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). | 151 * valid pages are the Google HP and SERP (this will include the NTP). |
131 * @param {string} url Url to check. | 152 * @param {string} url Url to check. |
132 * @return {boolean} True if url is eligible hotword url. | 153 * @return {boolean} True if url is eligible hotword url. |
133 */ | 154 */ |
134 OptInManager.prototype.isEligibleUrl = function(url) { | 155 OptInManager.prototype.isEligibleUrl = function(url) { |
135 if (!url) | 156 if (!url) |
136 return false; | 157 return false; |
137 | 158 |
138 var baseUrls = [ | 159 var baseUrls = [ |
139 'https://www.google.com', | 160 'chrome://newtab' |
140 'chrome://newtab', | 161 ]; |
141 'https://encrypted.google.com' | 162 var baseGoogleUrls = [ |
163 'https://www.google.', | |
164 'https://encrypted.google.' | |
165 ]; | |
166 var tlds = [ | |
167 'com', | |
168 'co.uk', | |
169 'de', | |
170 'fr', | |
171 'ru' | |
142 ]; | 172 ]; |
143 | 173 |
144 for (var i = 0; i < baseUrls.length; i++) { | 174 if (this.checkUrl(url, baseUrls[0])) |
145 var base = baseUrls[i]; | 175 return true; |
146 if (url === base + '/' || | 176 |
147 url.indexOf(base + '/_/chrome/newtab?') === 0 || // Appcache NTP. | 177 for (var i = 0; i < baseGoogleUrls.length; i++) { |
148 url.indexOf(base + '/?') === 0 || | 178 for (var j = 0; j < tlds.length; j++) { |
149 url.indexOf(base + '/#') === 0 || | 179 var base = baseGoogleUrls[i] + tlds[j]; |
150 url.indexOf(base + '/webhp') === 0 || | 180 if (this.checkUrl(url, base)) |
151 url.indexOf(base + '/search') === 0) { | 181 return true; |
152 return true; | |
153 } | 182 } |
154 } | 183 } |
155 return false; | 184 return false; |
156 }; | 185 }; |
157 | 186 |
158 | 187 |
159 /** | 188 /** |
160 * Initializes the extension. | 189 * Initializes the extension. |
161 */ | 190 */ |
162 OptInManager.prototype.initialize = function() { | 191 OptInManager.prototype.initialize = function() { |
163 // TODO(rlp): Possibly remove the next line. It's proably not used, but | 192 // 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 | 193 // leaving for now to be safe. We should remove it once all messsage |
165 // relaying is removed form the content scripts. | 194 // relaying is removed form the content scripts. |
166 chrome.runtime.onMessage.addListener(this.handleMessage_.bind(this)); | 195 chrome.runtime.onMessage.addListener(this.handleMessage_.bind(this)); |
167 chrome.runtime.onMessageExternal.addListener( | 196 chrome.runtime.onMessageExternal.addListener( |
168 this.handleMessage_.bind(this)); | 197 this.handleMessage_.bind(this)); |
169 }; | 198 }; |
170 | 199 |
171 | 200 |
172 new OptInManager().initialize(); | 201 new OptInManager().initialize(); |
OLD | NEW |