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

Side by Side Diff: chrome/browser/resources/settings/route.js

Issue 2156413002: Settings Router Refactor: Migrate to settings.Route.navigateTo calls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge origin/master 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.define('settings', function() { 5 cr.define('settings', function() {
6 /** 6 /**
7 * Class for navigable routes. May only be instantiated within this file. 7 * Class for navigable routes. May only be instantiated within this file.
8 * @constructor 8 * @constructor
9 * @param {string} url 9 * @param {string} url
10 * @private 10 * @private
11 */ 11 */
12 var Route = function(url) { 12 var Route = function(url) {
13 this.url = url; 13 this.url = url;
14 14
15 /** @private {?settings.Route} */ 15 /** @type {?settings.Route} */
16 this.parent_ = null; 16 this.parent = null;
17 17
18 // Below are all legacy properties to provide compatibility with the old 18 // Below are all legacy properties to provide compatibility with the old
19 // routing system. TODO(tommycli): Remove once routing refactor complete. 19 // routing system. TODO(tommycli): Remove once routing refactor complete.
20 this.page = ''; 20 this.page = '';
21 this.section = ''; 21 this.section = '';
22 /** @type {!Array<string>} */ this.subpage = []; 22 /** @type {!Array<string>} */ this.subpage = [];
23 }; 23 };
24 24
25 Route.prototype = { 25 Route.prototype = {
26 /** 26 /**
27 * Returns a new Route instance that's a child of this route. 27 * Returns a new Route instance that's a child of this route.
28 * @param {string} path Extends this route's path if it doesn't contain a 28 * @param {string} path Extends this route's path if it doesn't contain a
29 * leading slash. 29 * leading slash.
30 * @param {string=} opt_subpageName 30 * @param {string=} opt_subpageName
31 * @return {!settings.Route} 31 * @return {!settings.Route}
32 * @private 32 * @private
33 */ 33 */
34 createChild: function(path, opt_subpageName) { 34 createChild: function(path, opt_subpageName) {
35 assert(path); 35 assert(path);
36 36
37 // |path| extends this route's path if it doesn't have a leading slash. 37 // |path| extends this route's path if it doesn't have a leading slash.
38 // If it does have a leading slash, it's just set as the new route's URL. 38 // If it does have a leading slash, it's just set as the new route's URL.
39 var newUrl = path[0] == '/' ? path : this.url + '/' + path; 39 var newUrl = path[0] == '/' ? path : this.url + '/' + path;
40 40
41 var route = new Route(newUrl); 41 var route = new Route(newUrl);
42 route.parent_ = this; 42 route.parent = this;
43 route.page = this.page; 43 route.page = this.page;
44 route.section = this.section; 44 route.section = this.section;
45 route.subpage = this.subpage.slice(); // Shallow copy. 45 route.subpage = this.subpage.slice(); // Shallow copy.
46 46
47 if (opt_subpageName) 47 if (opt_subpageName)
48 route.subpage.push(opt_subpageName); 48 route.subpage.push(opt_subpageName);
49 49
50 return route; 50 return route;
51 }, 51 },
52 52
(...skipping 23 matching lines...) Expand all
76 route.section = section; 76 route.section = section;
77 return route; 77 return route;
78 }, 78 },
79 79
80 /** 80 /**
81 * Returns true if this route is a descendant of the parameter. 81 * Returns true if this route is a descendant of the parameter.
82 * @param {!settings.Route} route 82 * @param {!settings.Route} route
83 * @return {boolean} 83 * @return {boolean}
84 */ 84 */
85 isDescendantOf: function(route) { 85 isDescendantOf: function(route) {
86 for (var parent = this.parent_; parent != null; parent = parent.parent_) { 86 for (var parent = this.parent; parent != null; parent = parent.parent) {
87 if (route == parent) 87 if (route == parent)
88 return true; 88 return true;
89 } 89 }
90 90
91 return false; 91 return false;
92 }, 92 },
93 }; 93 };
94 94
95 // Abbreviated variable for easier definitions. 95 // Abbreviated variable for easier definitions.
96 var r = Route; 96 var r = Route;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 r.QUICK_UNLOCK_CHOOSE_METHOD = 133 r.QUICK_UNLOCK_CHOOSE_METHOD =
134 r.PEOPLE.createChild('/quickUnlock/chooseMethod', 134 r.PEOPLE.createChild('/quickUnlock/chooseMethod',
135 'quick-unlock-choose-method'); 135 'quick-unlock-choose-method');
136 r.QUICK_UNLOCK_SETUP_PIN = 136 r.QUICK_UNLOCK_SETUP_PIN =
137 r.QUICK_UNLOCK_CHOOSE_METHOD.createChild('/quickUnlock/setupPin', 137 r.QUICK_UNLOCK_CHOOSE_METHOD.createChild('/quickUnlock/setupPin',
138 'quick-unlock-setup-pin'); 138 'quick-unlock-setup-pin');
139 r.ACCOUNTS = r.PEOPLE.createChild('/accounts', 'users'); 139 r.ACCOUNTS = r.PEOPLE.createChild('/accounts', 'users');
140 140
141 r.DEVICE = r.BASIC.createSection('/device', 'device'); 141 r.DEVICE = r.BASIC.createSection('/device', 'device');
142 r.POINTERS = r.DEVICE.createChild('/pointer-overlay', 'pointers'); 142 r.POINTERS = r.DEVICE.createChild('/pointer-overlay', 'pointers');
143 r.KEYBARD = r.DEVICE.createChild('/keyboard-overlay', 'keyboard'); 143 r.KEYBOARD = r.DEVICE.createChild('/keyboard-overlay', 'keyboard');
Dan Beam 2016/07/23 00:17:11 KEYBARRRRRD!
tommycli 2016/07/25 16:47:20 Acknowledged.
144 r.DISPLAY = r.DEVICE.createChild('/display', 'display'); 144 r.DISPLAY = r.DEVICE.createChild('/display', 'display');
145 </if> 145 </if>
146 146
147 r.PRIVACY = r.ADVANCED.createSection('/privacy', 'privacy'); 147 r.PRIVACY = r.ADVANCED.createSection('/privacy', 'privacy');
148 r.CERTIFICATES = 148 r.CERTIFICATES =
149 r.PRIVACY.createChild('/certificates', 'manage-certificates'); 149 r.PRIVACY.createChild('/certificates', 'manage-certificates');
150 r.CLEAR_BROWSER_DATA = 150 r.CLEAR_BROWSER_DATA =
151 r.PRIVACY.createDialog('/clearBrowserData', 'clear-browsing-data'); 151 r.PRIVACY.createDialog('/clearBrowserData', 'clear-browsing-data');
152 r.SITE_SETTINGS = r.PRIVACY.createChild('/siteSettings', 'site-settings'); 152 r.SITE_SETTINGS = r.PRIVACY.createChild('/siteSettings', 'site-settings');
153 r.SITE_SETTINGS_ALL = r.SITE_SETTINGS.createChild('all', 'all-sites'); 153 r.SITE_SETTINGS_ALL = r.SITE_SETTINGS.createChild('all', 'all-sites');
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 r.RESET = r.ADVANCED.createSection('/reset', 'reset'); 255 r.RESET = r.ADVANCED.createSection('/reset', 'reset');
256 256
257 <if expr="chromeos"> 257 <if expr="chromeos">
258 r.INPUT_METHODS = 258 r.INPUT_METHODS =
259 r.LANGUAGES.createChild('/inputMethods', 'manage-input-methods'); 259 r.LANGUAGES.createChild('/inputMethods', 'manage-input-methods');
260 r.DETAILED_BUILD_INFO = 260 r.DETAILED_BUILD_INFO =
261 r.ABOUT.createChild('/help/details', 'detailed-build-info'); 261 r.ABOUT.createChild('/help/details', 'detailed-build-info');
262 r.DETAILED_BUILD_INFO.section = 'about'; 262 r.DETAILED_BUILD_INFO.section = 'about';
263 </if> 263 </if>
264 264
265 /**
266 * Use this function (and only this function) to navigate within Settings.
267 * This function is set by settings-router once it is created.
268 * @type {?function(!settings.Route):void}
269 */
270 var navigateTo = null;
271
265 return { 272 return {
266 Route: Route, 273 Route: Route,
274 navigateTo: navigateTo,
267 }; 275 };
268 }); 276 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698