| 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} path | 9 * @param {string} path |
| 10 * @private | 10 * @private |
| 11 */ | 11 */ |
| 12 var Route = function(path) { | 12 var Route = function(path) { |
| 13 this.path = path; | 13 this.path = path; |
| 14 | 14 |
| 15 /** @type {?settings.Route} */ | 15 /** @type {?settings.Route} */ |
| 16 this.parent = null; | 16 this.parent = null; |
| 17 | 17 |
| 18 /** @type {number} */ |
| 19 this.depth = 0; |
| 20 |
| 18 // Below are all legacy properties to provide compatibility with the old | 21 // Below are all legacy properties to provide compatibility with the old |
| 19 // routing system. TODO(tommycli): Remove once routing refactor complete. | 22 // routing system. TODO(tommycli): Remove once routing refactor complete. |
| 20 this.section = ''; | 23 this.section = ''; |
| 21 }; | 24 }; |
| 22 | 25 |
| 23 Route.prototype = { | 26 Route.prototype = { |
| 24 /** | 27 /** |
| 25 * Returns a new Route instance that's a child of this route. | 28 * Returns a new Route instance that's a child of this route. |
| 26 * @param {string} path Extends this route's path if it doesn't contain a | 29 * @param {string} path Extends this route's path if it doesn't contain a |
| 27 * leading slash. | 30 * leading slash. |
| 28 * @return {!settings.Route} | 31 * @return {!settings.Route} |
| 29 * @private | 32 * @private |
| 30 */ | 33 */ |
| 31 createChild: function(path) { | 34 createChild: function(path) { |
| 32 assert(path); | 35 assert(path); |
| 33 | 36 |
| 34 // |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. |
| 35 // 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. |
| 36 var newUrl = path[0] == '/' ? path : this.path + '/' + path; | 39 var newUrl = path[0] == '/' ? path : this.path + '/' + path; |
| 37 | 40 |
| 38 var route = new Route(newUrl); | 41 var route = new Route(newUrl); |
| 39 route.parent = this; | 42 route.parent = this; |
| 40 route.section = this.section; | 43 route.section = this.section; |
| 44 route.depth = this.depth + 1; |
| 41 | 45 |
| 42 return route; | 46 return route; |
| 43 }, | 47 }, |
| 44 | 48 |
| 45 /** | 49 /** |
| 46 * Returns a new Route instance that's a child section of this route. | 50 * Returns a new Route instance that's a child section of this route. |
| 47 * TODO(tommycli): Remove once we've obsoleted the concept of sections. | 51 * TODO(tommycli): Remove once we've obsoleted the concept of sections. |
| 48 * @param {string} path | 52 * @param {string} path |
| 49 * @param {string} section | 53 * @param {string} section |
| 50 * @return {!settings.Route} | 54 * @return {!settings.Route} |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 r.CERTIFICATES = r.PRIVACY.createChild('/certificates'); | 128 r.CERTIFICATES = r.PRIVACY.createChild('/certificates'); |
| 125 | 129 |
| 126 // CLEAR_BROWSER_DATA is the only navigable dialog route. It's the only child | 130 // CLEAR_BROWSER_DATA is the only navigable dialog route. It's the only child |
| 127 // of a section that's not a subpage. Don't add any more routes like these. | 131 // of a section that's not a subpage. Don't add any more routes like these. |
| 128 // If more navigable dialogs are needed, add explicit support in Route. | 132 // If more navigable dialogs are needed, add explicit support in Route. |
| 129 r.CLEAR_BROWSER_DATA = r.PRIVACY.createChild('/clearBrowserData'); | 133 r.CLEAR_BROWSER_DATA = r.PRIVACY.createChild('/clearBrowserData'); |
| 130 r.CLEAR_BROWSER_DATA.isSubpage = function() { return false; }; | 134 r.CLEAR_BROWSER_DATA.isSubpage = function() { return false; }; |
| 131 | 135 |
| 132 r.SITE_SETTINGS = r.PRIVACY.createChild('/siteSettings'); | 136 r.SITE_SETTINGS = r.PRIVACY.createChild('/siteSettings'); |
| 133 r.SITE_SETTINGS_ALL = r.SITE_SETTINGS.createChild('all'); | 137 r.SITE_SETTINGS_ALL = r.SITE_SETTINGS.createChild('all'); |
| 134 r.SITE_SETTINGS_ALL_DETAILS = r.SITE_SETTINGS_ALL.createChild('details'); | 138 r.SITE_SETTINGS_SITE_DETAILS = |
| 139 r.SITE_SETTINGS_ALL.createChild('/siteSettings/siteDetails'); |
| 135 | 140 |
| 136 r.SITE_SETTINGS_HANDLERS = r.SITE_SETTINGS.createChild('handlers'); | 141 r.SITE_SETTINGS_HANDLERS = r.SITE_SETTINGS.createChild('handlers'); |
| 137 | 142 |
| 138 // TODO(tommycli): Find a way to refactor these repetitive category routes. | 143 // TODO(tommycli): Find a way to refactor these repetitive category routes. |
| 139 r.SITE_SETTINGS_AUTOMATIC_DOWNLOADS = | 144 r.SITE_SETTINGS_AUTOMATIC_DOWNLOADS = |
| 140 r.SITE_SETTINGS.createChild('automaticDownloads'); | 145 r.SITE_SETTINGS.createChild('automaticDownloads'); |
| 141 r.SITE_SETTINGS_BACKGROUND_SYNC = | 146 r.SITE_SETTINGS_BACKGROUND_SYNC = |
| 142 r.SITE_SETTINGS.createChild('backgroundSync'); | 147 r.SITE_SETTINGS.createChild('backgroundSync'); |
| 143 r.SITE_SETTINGS_CAMERA = r.SITE_SETTINGS.createChild('camera'); | 148 r.SITE_SETTINGS_CAMERA = r.SITE_SETTINGS.createChild('camera'); |
| 144 r.SITE_SETTINGS_COOKIES = r.SITE_SETTINGS.createChild('cookies'); | 149 r.SITE_SETTINGS_COOKIES = r.SITE_SETTINGS.createChild('cookies'); |
| 145 r.SITE_SETTINGS_IMAGES = r.SITE_SETTINGS.createChild('images'); | 150 r.SITE_SETTINGS_IMAGES = r.SITE_SETTINGS.createChild('images'); |
| 146 r.SITE_SETTINGS_JAVASCRIPT = r.SITE_SETTINGS.createChild('javascript'); | 151 r.SITE_SETTINGS_JAVASCRIPT = r.SITE_SETTINGS.createChild('javascript'); |
| 147 r.SITE_SETTINGS_KEYGEN = r.SITE_SETTINGS.createChild('keygen'); | 152 r.SITE_SETTINGS_KEYGEN = r.SITE_SETTINGS.createChild('keygen'); |
| 148 r.SITE_SETTINGS_LOCATION = r.SITE_SETTINGS.createChild('location'); | 153 r.SITE_SETTINGS_LOCATION = r.SITE_SETTINGS.createChild('location'); |
| 149 r.SITE_SETTINGS_MICROPHONE = r.SITE_SETTINGS.createChild('microphone'); | 154 r.SITE_SETTINGS_MICROPHONE = r.SITE_SETTINGS.createChild('microphone'); |
| 150 r.SITE_SETTINGS_NOTIFICATIONS = r.SITE_SETTINGS.createChild('notifications'); | 155 r.SITE_SETTINGS_NOTIFICATIONS = r.SITE_SETTINGS.createChild('notifications'); |
| 151 r.SITE_SETTINGS_PLUGINS = r.SITE_SETTINGS.createChild('plugins'); | 156 r.SITE_SETTINGS_PLUGINS = r.SITE_SETTINGS.createChild('plugins'); |
| 152 r.SITE_SETTINGS_POPUPS = r.SITE_SETTINGS.createChild('popups'); | 157 r.SITE_SETTINGS_POPUPS = r.SITE_SETTINGS.createChild('popups'); |
| 153 r.SITE_SETTINGS_UNSANDBOXED_PLUGINS = | 158 r.SITE_SETTINGS_UNSANDBOXED_PLUGINS = |
| 154 r.SITE_SETTINGS.createChild('unsandboxedPlugins'); | 159 r.SITE_SETTINGS.createChild('unsandboxedPlugins'); |
| 155 r.SITE_SETTINGS_USB_DEVICES = r.SITE_SETTINGS.createChild('usbDevices'); | 160 r.SITE_SETTINGS_USB_DEVICES = r.SITE_SETTINGS.createChild('usbDevices'); |
| 156 | 161 |
| 157 r.SITE_SETTINGS_AUTOMATIC_DOWNLOADS_DETAILS = | |
| 158 r.SITE_SETTINGS_AUTOMATIC_DOWNLOADS.createChild('details'); | |
| 159 r.SITE_SETTINGS_BACKGROUND_SYNC_DETAILS = | |
| 160 r.SITE_SETTINGS_BACKGROUND_SYNC.createChild('details'); | |
| 161 r.SITE_SETTINGS_CAMERA_DETAILS = | |
| 162 r.SITE_SETTINGS_CAMERA.createChild('details'); | |
| 163 r.SITE_SETTINGS_COOKIES_DETAILS = | |
| 164 r.SITE_SETTINGS_COOKIES.createChild('details'); | |
| 165 r.SITE_SETTINGS_IMAGES_DETAILS = | |
| 166 r.SITE_SETTINGS_IMAGES.createChild('details'); | |
| 167 r.SITE_SETTINGS_JAVASCRIPT_DETAILS = | |
| 168 r.SITE_SETTINGS_JAVASCRIPT.createChild('details'); | |
| 169 r.SITE_SETTINGS_KEYGEN_DETAILS = | |
| 170 r.SITE_SETTINGS_KEYGEN.createChild('details'); | |
| 171 r.SITE_SETTINGS_LOCATION_DETAILS = | |
| 172 r.SITE_SETTINGS_LOCATION.createChild('details'); | |
| 173 r.SITE_SETTINGS_MICROPHONE_DETAILS = | |
| 174 r.SITE_SETTINGS_MICROPHONE.createChild('details'); | |
| 175 r.SITE_SETTINGS_NOTIFICATIONS_DETAILS = | |
| 176 r.SITE_SETTINGS_NOTIFICATIONS.createChild('details'); | |
| 177 r.SITE_SETTINGS_PLUGINS_DETAILS = | |
| 178 r.SITE_SETTINGS_PLUGINS.createChild('details'); | |
| 179 r.SITE_SETTINGS_POPUPS_DETAILS = | |
| 180 r.SITE_SETTINGS_POPUPS.createChild('details'); | |
| 181 r.SITE_SETTINGS_UNSANDBOXED_PLUGINS_DETAILS = | |
| 182 r.SITE_SETTINGS_UNSANDBOXED_PLUGINS.createChild('details'); | |
| 183 | |
| 184 <if expr="chromeos"> | 162 <if expr="chromeos"> |
| 185 r.DATETIME = r.ADVANCED.createSection('/dateTime', 'dateTime'); | 163 r.DATETIME = r.ADVANCED.createSection('/dateTime', 'dateTime'); |
| 186 | 164 |
| 187 r.BLUETOOTH = r.ADVANCED.createSection('/bluetooth', 'bluetooth'); | 165 r.BLUETOOTH = r.ADVANCED.createSection('/bluetooth', 'bluetooth'); |
| 188 r.BLUETOOTH_ADD_DEVICE = r.BLUETOOTH.createChild('/bluetoothAddDevice'); | 166 r.BLUETOOTH_ADD_DEVICE = r.BLUETOOTH.createChild('/bluetoothAddDevice'); |
| 189 r.BLUETOOTH_PAIR_DEVICE = | 167 r.BLUETOOTH_PAIR_DEVICE = |
| 190 r.BLUETOOTH_ADD_DEVICE.createChild('bluetoothPairDevice'); | 168 r.BLUETOOTH_ADD_DEVICE.createChild('bluetoothPairDevice'); |
| 191 </if> | 169 </if> |
| 192 | 170 |
| 193 r.PASSWORDS = r.ADVANCED.createSection('/passwords', 'passwordsAndForms'); | 171 r.PASSWORDS = r.ADVANCED.createSection('/passwords', 'passwordsAndForms'); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 return { | 327 return { |
| 350 Route: Route, | 328 Route: Route, |
| 351 RouteObserverBehavior: RouteObserverBehavior, | 329 RouteObserverBehavior: RouteObserverBehavior, |
| 352 getRouteForPath: getRouteForPath, | 330 getRouteForPath: getRouteForPath, |
| 353 initializeRouteFromUrl: initializeRouteFromUrl, | 331 initializeRouteFromUrl: initializeRouteFromUrl, |
| 354 getCurrentRoute: getCurrentRoute, | 332 getCurrentRoute: getCurrentRoute, |
| 355 getQueryParameters: getQueryParameters, | 333 getQueryParameters: getQueryParameters, |
| 356 navigateTo: navigateTo, | 334 navigateTo: navigateTo, |
| 357 }; | 335 }; |
| 358 }); | 336 }); |
| OLD | NEW |