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

Unified Diff: chrome/browser/resources/settings/settings_page/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: 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/settings_page/route.js
diff --git a/chrome/browser/resources/settings/settings_page/route.js b/chrome/browser/resources/settings/settings_page/route.js
new file mode 100644
index 0000000000000000000000000000000000000000..1879d1b8513ddc2c157d4077d8d52742dc3c9939
--- /dev/null
+++ b/chrome/browser/resources/settings/settings_page/route.js
@@ -0,0 +1,85 @@
+// 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.
+ * @private
michaelpg 2016/07/13 05:53:39 optional CL-wide nit: our convention is to put @pr
tommycli 2016/07/13 17:45:03 Done.
+ * @constructor
+ * @param {string} url
+ */
+ var Route = function(url) {
+ /** @type {string} */
michaelpg 2016/07/13 05:53:39 closure doesn't infer this?
tommycli 2016/07/13 17:45:03 Done.
+ this.url = url;
+
+ /** @type {settings.Route} */
michaelpg 2016/07/13 05:53:39 {?settings.Route}
tommycli 2016/07/13 17:45:03 Done.
+ this.parent = null;
+
+ // Below are all legacy properties to provide compatibility with the old
+ // routing system. TODO(tommycli): Remove once routing refactor complete.
+
+ /** @type {string} */
michaelpg 2016/07/13 05:53:39 same questions about types
tommycli 2016/07/13 17:45:03 Done.
+ this.page = '';
+
+ /** @type {string} */
+ this.section = '';
+
+ /** @type {!Array<string>} */
+ this.subpage = [];
+
+ /** @type {boolean} */
+ this.dialog = false;
+ };
+
+ Route.prototype = {
+ /**
+ * Returns a new Route instance that's a child of this route.
+ * @private
+ * @param {string} url
+ * @param {string=} opt_subpageName
+ * @return {!settings.Route}
+ */
+ createChild: function(url, opt_subpageName) {
+ var route = new Route(url);
+ route.parent = this;
+ route.page = this.page;
+ route.section = this.section;
+
+ if (opt_subpageName)
+ route.subpage.push(opt_subpageName);
+
+ return route;
+ },
+
+ /**
+ * Return a new Route instance that's a child dialog of this route.
michaelpg 2016/07/13 05:53:39 Returns
tommycli 2016/07/13 17:45:03 Done.
+ * @private
+ * @param {string} url
+ * @return {!settings.Route}
+ */
+ 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,
+ };
+});

Powered by Google App Engine
This is Rietveld 408576698