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

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: update test 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..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,
};
});

Powered by Google App Engine
This is Rietveld 408576698