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

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

Issue 2696183005: [Devtools] Added Product Registry module in prep for Network Grouping (Closed)
Patch Set: changes Created 3 years, 10 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4 /**
5 * @param {!Common.ParsedURL} parsedUrl
6 * @return {?string}
7 */
8 ProductRegistry.nameForUrl = function(parsedUrl) {
9 if (parsedUrl.isDataURL())
10 return null;
11 // TODO(allada) This should be expanded to allow paths as as well as domain to find a product.
12 var productsByDomain = ProductRegistry._productsByDomain;
13 var domain = parsedUrl.domain();
14 var domainParts = domain.split('.');
15 while (domainParts.length > 1) {
16 var subDomain = domainParts.join('.');
17 var entry = productsByDomain.get(subDomain);
18 if (entry && (!entry.exact || subDomain === domain))
19 return entry.name;
20 domainParts.shift();
21 }
22 return null;
23 };
24
25 /**
26 * @param {!Array<!{url: string, name: string, exact: boolean}>} data
27 */
28 ProductRegistry.register = function(data) {
29 for (var i = 0; i < data.length; i++) {
30 var entry = data[i];
31 ProductRegistry._productsByDomain.set(entry.url, entry);
32 }
33 };
34
35 /** @type {!Map<string, !{url: string, name: string, exact: boolean}>} */
36 ProductRegistry._productsByDomain;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698