Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(715)

Unified Diff: third_party/WebKit/Source/devtools/front_end/product_registry/ProductNameForURL.js

Issue 2772493002: [Devtools] Product registry to support prefix & import of data (Closed)
Patch Set: Merge branch 'ADD_SHA1' into NEW_PRODUCT_REGISTRY_STRUCTURE Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/product_registry/ProductRegistryData.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/devtools/front_end/product_registry/ProductNameForURL.js
diff --git a/third_party/WebKit/Source/devtools/front_end/product_registry/ProductNameForURL.js b/third_party/WebKit/Source/devtools/front_end/product_registry/ProductNameForURL.js
index edbbdff0b0ce68848ab920a28c89857131ea8041..2a1f885b6795ad000a18dd6929e6e6120ec87600 100644
--- a/third_party/WebKit/Source/devtools/front_end/product_registry/ProductNameForURL.js
+++ b/third_party/WebKit/Source/devtools/front_end/product_registry/ProductNameForURL.js
@@ -9,28 +9,61 @@ ProductRegistry.nameForUrl = function(parsedUrl) {
if (parsedUrl.isDataURL())
return null;
// TODO(allada) This should be expanded to allow paths as as well as domain to find a product.
- var productsByDomain = ProductRegistry._productsByDomain;
- var domain = parsedUrl.domain();
- var domainParts = domain.split('.');
- while (domainParts.length > 1) {
- var subDomain = domainParts.join('.');
- var entry = productsByDomain.get(subDomain);
- if (entry && (!entry.exact || subDomain === domain))
- return entry.name;
- domainParts.shift();
+ var productsByDomainHash = ProductRegistry._productsByDomainHash;
+ // Remove leading www. if it is the only subdomain.
+ var domain = parsedUrl.domain().replace(/^www\.(?=[^.]+\.[^.]+$)/, '');
+
+ var previousIndex = -1;
+ var index = -1;
+ // Ensure we loop with full domain first, but do not loop over last part (ie: ".com").
+ for (var nextIndex = domain.indexOf('.'); nextIndex !== -1; nextIndex = domain.indexOf('.', nextIndex + 1)) {
+ var previousSubdomain = domain.substring(previousIndex + 1, index);
+ var subDomain = domain.substring(index + 1);
+ var prefixes = productsByDomainHash.get(ProductRegistry._hashForDomain(subDomain));
+ previousIndex = index;
+ index = nextIndex;
+ if (!prefixes)
+ continue;
+ // Exact match domains are always highest priority.
+ if ('' in prefixes && domain === subDomain)
+ return prefixes[''];
+ if (previousSubdomain) {
+ for (var prefix in prefixes) {
+ var domainPrefix = previousSubdomain.substr(0, prefix.length);
+ if (domainPrefix === prefix && prefix !== '')
+ return prefixes[prefix];
+ }
+ }
+ // Process wildcard subdomain if no better match found.
+ if (prefixes && '*' in prefixes)
+ return prefixes['*'];
}
return null;
};
/**
- * @param {!Array<!{url: string, name: string, exact: boolean}>} data
+ * @param {string} domain
+ * @return {string}
+ */
+ProductRegistry._hashForDomain = function(domain) {
+ return ProductRegistry.sha1(domain).substr(0, 16);
+};
+
+/**
+ * @param {!Array<string>} productNames
+ * @param {!Array<!{hash: string, prefixes: !Object<string, number>}>} data
*/
-ProductRegistry.register = function(data) {
+ProductRegistry.register = function(productNames, data) {
for (var i = 0; i < data.length; i++) {
var entry = data[i];
- ProductRegistry._productsByDomain.set(entry.url, entry);
+ var prefixes = {};
+ for (var prefix in entry.prefixes) {
+ var productNameIndex = entry.prefixes[prefix];
+ prefixes[prefix] = productNames[productNameIndex];
+ }
+ ProductRegistry._productsByDomainHash.set(entry.hash, prefixes);
}
};
-/** @type {!Map<string, !{url: string, name: string, exact: boolean}>} */
-ProductRegistry._productsByDomain = new Map();
+/** @type {!Map<string, !Object<string, string>>}} */
+ProductRegistry._productsByDomainHash = new Map();
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/product_registry/ProductRegistryData.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698