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

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

Issue 2153113003: Settings Router Refactor: Migrate canonical route list to new-style. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make setting-router use new list. Delete old list. 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 /** @private {?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 this.dialog = false;
24 }; 23 };
25 24
26 Route.prototype = { 25 Route.prototype = {
27 /** 26 /**
28 * 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.
29 * @param {string} url 28 * @param {string} path Extends this route's path if it doesn't contain a
29 * leading slash.
Dan Beam 2016/07/15 23:28:27 i think * @param {string} param Multi-line desc
tommycli 2016/07/15 23:47:51 Done.
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(url, opt_subpageName) { 34 createChild: function(path, opt_subpageName) {
35 var route = new Route(url); 35 assert(path.length > 0);
Dan Beam 2016/07/15 23:28:26 maybe assert(path) instead?
tommycli 2016/07/15 23:47:51 Done.
36
37 var newUrl = path[0] == '/' ? path : this.url + '/' + path;
Dan Beam 2016/07/15 23:28:26 can you add a comment to what this is doing? also
tommycli 2016/07/15 23:47:51 Done. I think using URL doesn't work since that co
38
39 var route = new Route(newUrl);
36 route.parent_ = this; 40 route.parent_ = this;
37 route.page = this.page; 41 route.page = this.page;
38 route.section = this.section; 42 route.section = this.section;
39 route.subpage = this.subpage.slice(); // Shallow copy. 43 route.subpage = this.subpage.slice(); // Shallow copy.
40 44
41 if (opt_subpageName) 45 if (opt_subpageName)
42 route.subpage.push(opt_subpageName); 46 route.subpage.push(opt_subpageName);
43 47
44 return route; 48 return route;
45 }, 49 },
46 50
47 /** 51 /**
48 * Returns a new Route instance that's a child dialog of this route. 52 * Returns a new Route instance that's a child dialog of this route.
49 * @param {string} url 53 * @param {string} url
54 * @param {string} dialogName
50 * @return {!settings.Route} 55 * @return {!settings.Route}
51 * @private 56 * @private
52 */ 57 */
53 createDialog: function(url) { 58 createDialog: function(url, dialogName) {
54 var route = this.createChild(url); 59 var route = this.createChild(url);
55 route.dialog = true; 60 route.dialog = dialogName;
56 return route; 61 return route;
57 }, 62 },
58 63
64 /**
65 * Returns a new Route instance that's a child section of this route.
66 * TODO(tommycli): Remove once we've obsoleted the concept of sections.
67 * @param {string} url
68 * @param {string} section
69 * @return {!settings.Route}
70 * @private
71 */
72 createSection: function(url, section) {
73 var route = this.createChild(url);
74 route.section = section;
75 return route;
76 },
77
59 /** 78 /**
60 * Returns true if this route is a descendant of the parameter. 79 * Returns true if this route is a descendant of the parameter.
61 * @param {!settings.Route} route 80 * @param {!settings.Route} route
62 * @return {boolean} 81 * @return {boolean}
63 */ 82 */
64 isDescendantOf: function(route) { 83 isDescendantOf: function(route) {
65 for (var parent = this.parent_; parent != null; parent = parent.parent_) { 84 for (var parent = this.parent_; parent != null; parent = parent.parent_) {
66 if (route == parent) 85 if (route == parent)
67 return true; 86 return true;
68 } 87 }
69 88
70 return false; 89 return false;
71 }, 90 },
72 }; 91 };
73 92
93 // Abbreviated variable for easier definitions.
94 var r = Route;
95
96 // Root pages
Dan Beam 2016/07/15 23:28:26 nit: end with .
tommycli 2016/07/15 23:47:51 Done.
97 r.BASIC = new Route('/');
98 r.BASIC.page = 'basic';
99 r.ADVANCED = new Route('/advanced');
100 r.ADVANCED.page = 'advanced';
101 r.ABOUT = new Route('/help');
102 r.ABOUT.page = 'about';
103
104 <if expr="chromeos">
105 r.INTERNET = r.BASIC.createSection('/internet', 'internet');
106 r.NETWORK_DETAIL = r.INTERNET.createChild('/networkDetail', 'network-detail');
107 r.KNOWN_NETWORKS = r.INTERNET.createChild('/knownNetworks', 'known-networks');
108 </if>
109
110 r.APPEARANCE = r.BASIC.createSection('/appearance', 'appearance');
111 r.FONTS = r.APPEARANCE.createChild('/fonts', 'appearance-fonts');
112
113 r.DEFAULT_BROWSER =
114 r.BASIC.createSection('/defaultBrowser', 'defaultBrowser');
115
116 r.SEARCH = r.BASIC.createSection('/search', 'search');
117 r.SEARCH_ENGINES = r.SEARCH.createChild('/searchEngines', 'search-engines');
118
119 r.ON_STARTUP = r.BASIC.createSection('/onStartup', 'onStartup');
120
121 r.PEOPLE = r.BASIC.createSection('/people', 'people');
122 r.SYNC = r.PEOPLE.createChild('/syncSetup', 'sync');
123 <if expr="not chromeos">
124 r.MANAGE_PROFILE = r.PEOPLE.createChild('/manageProfile', 'manageProfile');
125 </if>
126 <if expr="chromeos">
127 r.CHANGE_PICTURE = r.PEOPLE.createChild('/changePicture', 'changePicture');
128 r.QUICK_UNLOCK_AUTHENTICATE =
129 r.PEOPLE.createChild('/quickUnlock/authenticate',
130 'quick-unlock-authenticate');
131 r.QUICK_UNLOCK_CHOOSE_METHOD =
132 r.PEOPLE.createChild('/quickUnlock/chooseMethod',
133 'quick-unlock-choose-method');
134 r.QUICK_UNLOCK_SETUP_PIN =
135 r.QUICK_UNLOCK_CHOOSE_METHOD.createChild('/quickUnlock/setupPin',
136 'quick-unlock-setup-pin');
137 r.ACCOUNTS = r.PEOPLE.createChild('/accounts', 'users');
138
139 r.DEVICE = r.BASIC.createSection('/device', 'device');
140 r.TOUCHPAD = r.DEVICE.createChild('/pointer-overlay', 'touchpad');
141 r.KEYBARD = r.DEVICE.createChild('/keyboard-overlay', 'keyboard');
142 r.DISPLAY = r.DEVICE.createChild('/display', 'display');
143 </if>
144
145 r.PRIVACY = r.ADVANCED.createSection('/privacy', 'privacy');
146 r.CERTIFICATES =
147 r.PRIVACY.createChild('/certificates', 'manage-certificates');
148 r.CLEAR_BROWSER_DATA =
149 r.PRIVACY.createDialog('/clearBrowserData', 'clear-browsing-data');
150 r.SITE_SETTINGS = r.PRIVACY.createChild('/siteSettings', 'site-settings');
151 r.SITE_SETTINGS_ALL = r.SITE_SETTINGS.createChild('all', 'all-sites');
152 r.SITE_SETTINGS_ALL_DETAILS =
153 r.SITE_SETTINGS_ALL.createChild('details', 'site-details');
154
155 r.SITE_SETTINGS_HANDLERS = r.SITE_SETTINGS.createChild(
156 'handlers', 'protocol-handlers');
157
158 // TODO(tommicli): Find a way to refactor these repetitive category routes.
159 r.SITE_SETTINGS_AUTOMATIC_DOWNLOADS = r.SITE_SETTINGS.createChild(
160 'automaticDownloads', 'site-settings-category-automatic-downloads');
161 r.SITE_SETTINGS_BACKGROUND_SYNC = r.SITE_SETTINGS.createChild(
162 'backgroundSync', 'site-settings-category-background-sync');
163 r.SITE_SETTINGS_CAMERA = r.SITE_SETTINGS.createChild(
164 'camera', 'site-settings-category-camera');
165 r.SITE_SETTINGS_COOKIES = r.SITE_SETTINGS.createChild(
166 'cookies', 'site-settings-category-cookies');
167 r.SITE_SETTINGS_FULLSCREEN = r.SITE_SETTINGS.createChild(
168 'fullscreen', 'site-settings-category-fullscreen');
169 r.SITE_SETTINGS_IMAGES = r.SITE_SETTINGS.createChild(
170 'images', 'site-settings-category-images');
171 r.SITE_SETTINGS_JAVASCRIPT = r.SITE_SETTINGS.createChild(
172 'javascript', 'site-settings-category-javascript');
173 r.SITE_SETTINGS_KEYGEN = r.SITE_SETTINGS.createChild(
174 'keygen', 'site-settings-category-keygen');
175 r.SITE_SETTINGS_LOCATION = r.SITE_SETTINGS.createChild(
176 'location', 'site-settings-category-location');
177 r.SITE_SETTINGS_MICROPHONE = r.SITE_SETTINGS.createChild(
178 'microphone', 'site-settings-category-microphone');
179 r.SITE_SETTINGS_NOTIFICATIONS = r.SITE_SETTINGS.createChild(
180 'notifications', 'site-settings-category-notifications');
181 r.SITE_SETTINGS_PLUGINS = r.SITE_SETTINGS.createChild(
182 'plugins', 'site-settings-category-plugins');
183 r.SITE_SETTINGS_POPUPS = r.SITE_SETTINGS.createChild(
184 'popups', 'site-settings-category-popups');
185 r.SITE_SETTINGS_UNSANDBOXED_PLUGINS = r.SITE_SETTINGS.createChild(
186 'unsandboxedPlugins', 'site-settings-category-unsandboxed-plugins');
187
188 r.SITE_SETTINGS_AUTOMATIC_DOWNLOADS_DETAILS =
189 r.SITE_SETTINGS_AUTOMATIC_DOWNLOADS.createChild('details',
190 'site-details');
191 r.SITE_SETTINGS_BACKGROUND_SYNC_DETAILS =
192 r.SITE_SETTINGS_BACKGROUND_SYNC.createChild('details', 'site-details');
193 r.SITE_SETTINGS_CAMERA_DETAILS =
194 r.SITE_SETTINGS_CAMERA.createChild('details', 'site-details');
195 r.SITE_SETTINGS_COOKIES_DETAILS =
196 r.SITE_SETTINGS_COOKIES.createChild('details', 'site-details');
197 r.SITE_SETTINGS_FULLSCREEN_DETAILS =
198 r.SITE_SETTINGS_FULLSCREEN.createChild('details', 'site-details');
199 r.SITE_SETTINGS_IMAGES_DETAILS =
200 r.SITE_SETTINGS_IMAGES.createChild('details', 'site-details');
201 r.SITE_SETTINGS_JAVASCRIPT_DETAILS =
202 r.SITE_SETTINGS_JAVASCRIPT.createChild('details', 'site-details');
203 r.SITE_SETTINGS_KEYGEN_DETAILS =
204 r.SITE_SETTINGS_KEYGEN.createChild('details', 'site-details');
205 r.SITE_SETTINGS_LOCATION_DETAILS =
206 r.SITE_SETTINGS_LOCATION.createChild('details', 'site-details');
207 r.SITE_SETTINGS_MICROPHONE_DETAILS =
208 r.SITE_SETTINGS_MICROPHONE.createChild('details', 'site-details');
209 r.SITE_SETTINGS_NOTIFICATIONS_DETAILS =
210 r.SITE_SETTINGS_NOTIFICATIONS.createChild('details', 'site-details');
211 r.SITE_SETTINGS_PLUGINS_DETAILS =
212 r.SITE_SETTINGS_PLUGINS.createChild('details', 'site-details');
213 r.SITE_SETTINGS_POPUPS_DETAILS =
214 r.SITE_SETTINGS_POPUPS.createChild('details', 'site-details');
215 r.SITE_SETTINGS_UNSANDBOXED_PLUGINS_DETAILS =
216 r.SITE_SETTINGS_UNSANDBOXED_PLUGINS.createChild('details',
217 'site-details');
218
219 <if expr="chromeos">
220 r.DATETIME = r.ADVANCED.createSection('/dateTime', 'dateTime');
221
222 r.BLUETOOTH = r.ADVANCED.createSection('/bluetooth', 'bluetooth');
223 r.BLUETOOTH_ADD_DEVICE =
224 r.BLUETOOTH.createChild('/bluetoothAddDevice', 'bluetooth-add-device');
225 r.BLUETOOTH_PAIR_DEVICE = r.BLUETOOTH_ADD_DEVICE.createChild(
226 'bluetoothPairDevice', 'bluetooth-pair-device');
227 </if>
228
229 r.PASSWORDS = r.ADVANCED.createSection('/passwords', 'passwordsAndForms');
230 r.AUTOFILL = r.PASSWORDS.createChild('/autofill', 'manage-autofill');
231 r.MANAGE_PASSWORDS =
232 r.PASSWORDS.createChild('/managePasswords', 'manage-passwords');
233
234 r.LANGUAGES = r.ADVANCED.createSection('/languages', 'languages');
235 r.LANGUAGES_DETAIL = r.LANGUAGES.createChild('edit', 'language-detail');
236 r.MANAGE_LANGUAGES =
237 r.LANGUAGES.createChild('/manageLanguages', 'manage-languages');
238 <if expr="chromeos">
239 r.INPUT_METHODS =
240 r.LANGUAGES.createChild('/inputMethods', 'manage-input-methods');
241 </if>
242 <if expr="not is_macosx">
243 r.EDIT_DICTIONARY =
244 r.LANGUAGES.createChild('/editDictionary', 'edit-dictionary');
245 </if>
246
247 r.DOWNLOADS = r.ADVANCED.createSection('/downloadsDirectory', 'downloads');
248
249 r.PRINTING = r.ADVANCED.createSection('/printing', 'printing');
250 r.CLOUD_PRINTERS = r.PRINTING.createChild('/cloudPrinters', 'cloud-printers');
251 <if expr="chromeos">
252 r.CUPS_PRINTERS = r.PRINTING.createChild('/cupsPrinters', 'cups-printers');
253 </if>
254
255 r.ACCESSIBILITY = r.ADVANCED.createSection('/accessibility', 'a11y');
256 r.SYSTEM = r.ADVANCED.createSection('/system', 'system');
257 r.RESET = r.ADVANCED.createSection('/reset', 'reset');
258
259 <if expr="chromeos">
260 r.INPUT_METHODS =
261 r.LANGUAGES.createChild('/inputMethods', 'manage-input-methods');
262 r.DETAILED_BUILD_INFO =
263 r.ABOUT.createChild('/help/details', 'detailed-build-info');
264 r.DETAILED_BUILD_INFO.section = 'about';
265 </if>
266
74 return { 267 return {
75 Route: Route, 268 Route: Route,
76 }; 269 };
77 }); 270 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698