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..231e1cb7e5363835804be2a7756c4b704d168c26 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,13 +76,16 @@ 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) { |
+ if (this == route) |
michaelpg
2016/07/29 20:28:53
optional alternative:
for (; route != null; r
tommycli
2016/07/29 21:04:39
Done. Though I had to make it a slight variant si
|
+ return true; |
+ |
+ for (var parent = route.parent; parent != null; parent = parent.parent) { |
+ if (this == parent) |
return true; |
} |
@@ -97,11 +98,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 +268,27 @@ cr.define('settings', function() { |
*/ |
var navigateTo = null; |
+ /** |
+ * Returns the matching canonical route, or null if none matches. |
+ * @param {string} path |
+ * @return {settings.Route} |
michaelpg
2016/07/29 20:28:53
{?s.R}
tommycli
2016/07/29 21:04:39
Done.
|
+ * @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, |
}; |
}); |