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

Unified 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 side-by-side diff with in-line comments
Download patch
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
new file mode 100644
index 0000000000000000000000000000000000000000..2cbd3f11c953b19d2220887dadf7fdb202374142
--- /dev/null
+++ b/third_party/WebKit/Source/devtools/front_end/product_registry/ProductNameForURL.js
@@ -0,0 +1,36 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+/**
+ * @param {!Common.ParsedURL} parsedUrl
+ * @return {?string}
+ */
+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();
+ }
+ return null;
+};
+
+/**
+ * @param {!Array<!{url: string, name: string, exact: boolean}>} data
+ */
+ProductRegistry.register = function(data) {
+ for (var i = 0; i < data.length; i++) {
+ var entry = data[i];
+ ProductRegistry._productsByDomain.set(entry.url, entry);
+ }
+};
+
+/** @type {!Map<string, !{url: string, name: string, exact: boolean}>} */
+ProductRegistry._productsByDomain;

Powered by Google App Engine
This is Rietveld 408576698