| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 * @implements {ProductRegistry.Registry} | 6 * @implements {ProductRegistry.Registry} |
| 7 */ | 7 */ |
| 8 ProductRegistryImpl.Registry = class { | 8 ProductRegistryImpl.Registry = class { |
| 9 constructor() { | 9 constructor() { |
| 10 } | 10 } |
| 11 | 11 |
| 12 /** | 12 /** |
| 13 * @override | 13 * @override |
| 14 * @param {!Common.ParsedURL} parsedUrl | 14 * @param {!Common.ParsedURL} parsedUrl |
| 15 * @return {?string} | 15 * @return {?string} |
| 16 */ | 16 */ |
| 17 nameForUrl(parsedUrl) { | 17 nameForUrl(parsedUrl) { |
| 18 var entry = this.entryForUrl(parsedUrl); | 18 var entry = this.entryForUrl(parsedUrl); |
| 19 if (entry) | 19 if (entry) |
| 20 return entry.name; | 20 return entry.name; |
| 21 return null; | 21 return null; |
| 22 } | 22 } |
| 23 | 23 |
| 24 /** | 24 /** |
| 25 * @override | 25 * @override |
| 26 * @param {!Common.ParsedURL} parsedUrl | 26 * @param {!Common.ParsedURL} parsedUrl |
| 27 * @return {?ProductRegistry.Registry.ProductEntry} | 27 * @return {?ProductRegistry.Registry.ProductEntry} |
| 28 */ | 28 */ |
| 29 entryForUrl(parsedUrl) { | 29 entryForUrl(parsedUrl) { |
| 30 if (parsedUrl.isDataURL() || !parsedUrl.isValid) | 30 if (parsedUrl.isDataURL()) |
| 31 return null; | 31 return null; |
| 32 // TODO(allada) This should be expanded to allow paths as as well as domain
to find a product. | 32 // TODO(allada) This should be expanded to allow paths as as well as domain
to find a product. |
| 33 var productsByDomainHash = ProductRegistryImpl._productsByDomainHash; | 33 var productsByDomainHash = ProductRegistryImpl._productsByDomainHash; |
| 34 // Remove leading www. if it is the only subdomain. | 34 // Remove leading www. if it is the only subdomain. |
| 35 var domain = parsedUrl.domain().replace(/^www\.(?=[^.]+\.[^.]+$)/, ''); | 35 var domain = parsedUrl.domain().replace(/^www\.(?=[^.]+\.[^.]+$)/, ''); |
| 36 | 36 |
| 37 var previousIndex = -1; | 37 var previousIndex = -1; |
| 38 var index = -1; | 38 var index = -1; |
| 39 // Ensure we loop with full domain first, but do not loop over last part (ie
: ".com"). | 39 // Ensure we loop with full domain first, but do not loop over last part (ie
: ".com"). |
| 40 for (var nextIndex = domain.indexOf('.'); nextIndex !== -1; nextIndex = doma
in.indexOf('.', nextIndex + 1)) { | 40 for (var nextIndex = domain.indexOf('.'); nextIndex !== -1; nextIndex = doma
in.indexOf('.', nextIndex + 1)) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 var prefixEntry = entry.prefixes[prefix]; | 95 var prefixEntry = entry.prefixes[prefix]; |
| 96 var type = prefixEntry.type !== undefined ? prefixEntry.type : null; | 96 var type = prefixEntry.type !== undefined ? prefixEntry.type : null; |
| 97 prefixes[prefix] = {name: productNames[prefixEntry.product], type: type}; | 97 prefixes[prefix] = {name: productNames[prefixEntry.product], type: type}; |
| 98 } | 98 } |
| 99 ProductRegistryImpl._productsByDomainHash.set(entry.hash, prefixes); | 99 ProductRegistryImpl._productsByDomainHash.set(entry.hash, prefixes); |
| 100 } | 100 } |
| 101 }; | 101 }; |
| 102 | 102 |
| 103 /** @type {!Map<string, !Object<string, !ProductRegistry.Registry.ProductEntry>>
}} */ | 103 /** @type {!Map<string, !Object<string, !ProductRegistry.Registry.ProductEntry>>
}} */ |
| 104 ProductRegistryImpl._productsByDomainHash = new Map(); | 104 ProductRegistryImpl._productsByDomainHash = new Map(); |
| OLD | NEW |