Chromium Code Reviews| 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, |
| + }; |
| +}); |