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

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

Issue 2141313002: Settings Router Refactor: Implement new Route class w/ test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move to root dir 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
new file mode 100644
index 0000000000000000000000000000000000000000..fca471b6013f7ece9167c7cd1f99fa2cdbfd44d5
--- /dev/null
+++ b/chrome/browser/resources/settings/route.js
@@ -0,0 +1,77 @@
+// Copyright 2016 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.
+
+cr.define('settings', function() {
+ /**
+ * Class for navigable routes. May only be instantiated within this file.
+ * @constructor
+ * @param {string} url
+ * @private
+ */
+ var Route = function(url) {
+ this.url = url;
+
+ /** @type {?settings.Route} */
+ this.parent = null;
Dan Beam 2016/07/13 20:20:06 can this be private?
+
+ // 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 = [];
+ this.dialog = false;
+ };
+
+ Route.prototype = {
+ /**
+ * Returns a new Route instance that's a child of this route.
+ * @param {string} url
+ * @param {string=} opt_subpageName
+ * @return {!settings.Route}
+ * @private
+ */
+ createChild: function(url, opt_subpageName) {
+ var route = new Route(url);
+ route.parent = this;
+ route.page = this.page;
+ route.section = this.section;
+ route.subpage = this.subpage.slice(); // Shallow copy.
+
+ if (opt_subpageName)
+ route.subpage.push(opt_subpageName);
+
+ return route;
+ },
+
+ /**
+ * Returns a new Route instance that's a child dialog of this route.
+ * @param {string} url
+ * @return {!settings.Route}
+ * @private
+ */
+ createDialog: function(url) {
+ var route = this.createChild(url);
+ route.dialog = true;
+ return route;
+ },
+
+ /**
+ * Returns true if this route is a descendant 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)
+ return true;
+ }
+
+ return false;
+ },
+ };
+
+ return {
+ Route: Route,
+ };
+});
« no previous file with comments | « chrome/browser/resources/settings/route.html ('k') | chrome/browser/resources/settings/settings_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698