Commit ed0d539e authored by rlp@chromium.org's avatar rlp@chromium.org

[Hotword] Add new base URLs for the additional languages so it works on their...

[Hotword] Add new base URLs for the additional languages so it works on their respective local search urls.

The function has been tested manually inside Chrome since it will not work as part of the larger system until the extension and some server side pieces are in place.

BUG=345806

Review URL: https://codereview.chromium.org/277523005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269950 0039d316-1c4b-4281-b951-d872f2087c98
parent b77164cd
...@@ -129,32 +129,67 @@ OptInManager.prototype.handleMessage_ = function( ...@@ -129,32 +129,67 @@ OptInManager.prototype.handleMessage_ = function(
return false; return false;
}; };
/**
* Helper function to test URLs as being valid for running the
* hotwording extension. It's used by isEligibleUrl to make that
* function clearer.
* @param {string} url URL to check.
* @param {string} base Base URL to compare against..
* @return {boolean} True if url is an eligible hotword URL.
*/
OptInManager.prototype.checkEligibleUrl = function(url, base) {
if (!url)
return false;
if (url === base ||
url === base + '/' ||
url.indexOf(base + '/_/chrome/newtab?') === 0 || // Appcache NTP.
url.indexOf(base + '/?') === 0 ||
url.indexOf(base + '/#') === 0 ||
url.indexOf(base + '/webhp') === 0 ||
url.indexOf(base + '/search') === 0) {
return true;
}
return false;
};
/** /**
* Determines if a URL is eligible for hotwording. For now, the * Determines if a URL is eligible for hotwording. For now, the
* valid pages are the Google HP and SERP (this will include the NTP). * valid pages are the Google HP and SERP (this will include the NTP).
* @param {string} url Url to check. * @param {string} url URL to check.
* @return {boolean} True if url is eligible hotword url. * @return {boolean} True if url is an eligible hotword URL.
*/ */
OptInManager.prototype.isEligibleUrl = function(url) { OptInManager.prototype.isEligibleUrl = function(url) {
if (!url) if (!url)
return false; return false;
// More URLs will be added in the future so leaving this as an array.
var baseUrls = [ var baseUrls = [
'https://www.google.com', 'chrome://newtab'
'chrome://newtab', ];
'https://encrypted.google.com' var baseGoogleUrls = [
'https://www.google.',
'https://encrypted.google.'
]; ];
var tlds = [
'com',
'co.uk',
'de',
'fr',
'ru'
];
// Check URLs which do not have locale-based TLDs first.
if (this.checkEligibleUrl(url, baseUrls[0]))
return true;
for (var i = 0; i < baseUrls.length; i++) { // Check URLs with each type of local-based TLD.
var base = baseUrls[i]; for (var i = 0; i < baseGoogleUrls.length; i++) {
if (url === base + '/' || for (var j = 0; j < tlds.length; j++) {
url.indexOf(base + '/_/chrome/newtab?') === 0 || // Appcache NTP. var base = baseGoogleUrls[i] + tlds[j];
url.indexOf(base + '/?') === 0 || if (this.checkEligibleUrl(url, base))
url.indexOf(base + '/#') === 0 || return true;
url.indexOf(base + '/webhp') === 0 ||
url.indexOf(base + '/search') === 0) {
return true;
} }
} }
return false; return false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment