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