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

Unified Diff: chrome/browser/resources/settings/route.js

Issue 2184893002: Settings Router Refactor: Remove route.page legacy property. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@0217-settings-refactor-settings-menu
Patch Set: fix contains issue. Created 4 years, 5 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: chrome/browser/resources/settings/route.js
diff --git a/chrome/browser/resources/settings/route.js b/chrome/browser/resources/settings/route.js
index 0ef6c3fab622800f2120279fc2d99e7fcd9ec704..453e693115ffac4d0d4a494ebfe6705818ec6e62 100644
--- a/chrome/browser/resources/settings/route.js
+++ b/chrome/browser/resources/settings/route.js
@@ -17,7 +17,6 @@ cr.define('settings', function() {
// Below are all legacy properties to provide compatibility with the old
// routing system. TODO(tommycli): Remove once routing refactor complete.
- this.page = '';
this.section = '';
/** @type {!Array<string>} */ this.subpage = [];
};
@@ -40,7 +39,6 @@ cr.define('settings', function() {
var route = new Route(newUrl);
route.parent = this;
- route.page = this.page;
route.section = this.section;
route.subpage = this.subpage.slice(); // Shallow copy.
@@ -78,16 +76,15 @@ cr.define('settings', function() {
},
/**
- * Returns true if this route is a descendant of the parameter.
+ * Returns true if this route matches or is an ancestor of the parameter.
* @param {!settings.Route} route
* @return {boolean}
*/
- isDescendantOf: function(route) {
- for (var parent = this.parent; parent != null; parent = parent.parent) {
- if (route == parent)
+ contains: function(route) {
+ for (var r = route; r != null; r = r.parent) {
+ if (this == r)
return true;
}
-
return false;
},
};
@@ -97,11 +94,8 @@ cr.define('settings', function() {
// Root pages.
r.BASIC = new Route('/');
- r.BASIC.page = 'basic';
r.ADVANCED = new Route('/advanced');
- r.ADVANCED.page = 'advanced';
r.ABOUT = new Route('/help');
- r.ABOUT.page = 'about';
<if expr="chromeos">
r.INTERNET = r.BASIC.createSection('/internet', 'internet');
@@ -270,8 +264,27 @@ cr.define('settings', function() {
*/
var navigateTo = null;
+ /**
+ * Returns the matching canonical route, or null if none matches.
+ * @param {string} path
+ * @return {?settings.Route}
+ * @private
+ */
+ var getRouteForPath = function(path) {
+ // TODO(tommycli): Use Object.values once Closure compilation supports it.
+ var matchingKey = Object.keys(Route).find(function(key) {
+ return Route[key].path == path;
+ });
+
+ if (!matchingKey)
+ return null;
+
+ return Route[matchingKey];
+ };
+
return {
Route: Route,
navigateTo: navigateTo,
+ getRouteForPath: getRouteForPath,
};
});

Powered by Google App Engine
This is Rietveld 408576698