Chromium Code Reviews| 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 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 return true; | 67 return true; |
| 68 } | 68 } |
| 69 return false; | 69 return false; |
| 70 }, | 70 }, |
| 71 | 71 |
| 72 /** | 72 /** |
| 73 * Returns true if this route is a subpage of a section. | 73 * Returns true if this route is a subpage of a section. |
| 74 * @return {boolean} | 74 * @return {boolean} |
| 75 */ | 75 */ |
| 76 isSubpage: function() { | 76 isSubpage: function() { |
| 77 return !!this.parent && this.parent.section == this.section; | 77 return !!this.parent && !!this.section && |
|
michaelpg
2016/08/17 00:21:31
lol, bet that was fun to debug :(
tommycli
2016/08/17 16:48:49
Acknowledged.
| |
| 78 this.parent.section == this.section; | |
| 78 }, | 79 }, |
| 79 }; | 80 }; |
| 80 | 81 |
| 81 // Abbreviated variable for easier definitions. | 82 // Abbreviated variable for easier definitions. |
| 82 var r = Route; | 83 var r = Route; |
| 83 | 84 |
| 84 // Root pages. | 85 // Root pages. |
| 85 r.BASIC = new Route('/'); | 86 r.BASIC = new Route('/'); |
| 86 r.ADVANCED = new Route('/advanced'); | 87 r.ADVANCED = new Route('/advanced'); |
| 87 r.ABOUT = new Route('/help'); | 88 r.ABOUT = new Route('/help'); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 117 r.POINTERS = r.DEVICE.createChild('/pointer-overlay'); | 118 r.POINTERS = r.DEVICE.createChild('/pointer-overlay'); |
| 118 r.KEYBOARD = r.DEVICE.createChild('/keyboard-overlay'); | 119 r.KEYBOARD = r.DEVICE.createChild('/keyboard-overlay'); |
| 119 r.DISPLAY = r.DEVICE.createChild('/display'); | 120 r.DISPLAY = r.DEVICE.createChild('/display'); |
| 120 r.NOTES = r.DEVICE.createChild('/note'); | 121 r.NOTES = r.DEVICE.createChild('/note'); |
| 121 </if> | 122 </if> |
| 122 | 123 |
| 123 r.PRIVACY = r.ADVANCED.createSection('/privacy', 'privacy'); | 124 r.PRIVACY = r.ADVANCED.createSection('/privacy', 'privacy'); |
| 124 r.CERTIFICATES = r.PRIVACY.createChild('/certificates'); | 125 r.CERTIFICATES = r.PRIVACY.createChild('/certificates'); |
| 125 | 126 |
| 126 // CLEAR_BROWSER_DATA is the only navigable dialog route. It's the only child | 127 // 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. | 128 // of a root page that's not a section. Don't add any more routes like these. |
| 128 // If more navigable dialogs are needed, add explicit support in Route. | 129 // If more navigable dialogs are needed, add explicit support in Route. |
| 129 r.CLEAR_BROWSER_DATA = r.PRIVACY.createChild('/clearBrowserData'); | 130 r.CLEAR_BROWSER_DATA = r.ADVANCED.createChild('/clearBrowserData'); |
| 130 r.CLEAR_BROWSER_DATA.isSubpage = function() { return false; }; | |
| 131 | 131 |
| 132 r.SITE_SETTINGS = r.PRIVACY.createChild('/siteSettings'); | 132 r.SITE_SETTINGS = r.PRIVACY.createChild('/siteSettings'); |
| 133 r.SITE_SETTINGS_ALL = r.SITE_SETTINGS.createChild('all'); | 133 r.SITE_SETTINGS_ALL = r.SITE_SETTINGS.createChild('all'); |
| 134 r.SITE_SETTINGS_ALL_DETAILS = r.SITE_SETTINGS_ALL.createChild('details'); | 134 r.SITE_SETTINGS_ALL_DETAILS = r.SITE_SETTINGS_ALL.createChild('details'); |
| 135 | 135 |
| 136 r.SITE_SETTINGS_HANDLERS = r.SITE_SETTINGS.createChild('handlers'); | 136 r.SITE_SETTINGS_HANDLERS = r.SITE_SETTINGS.createChild('handlers'); |
| 137 | 137 |
| 138 // TODO(tommycli): Find a way to refactor these repetitive category routes. | 138 // TODO(tommycli): Find a way to refactor these repetitive category routes. |
| 139 r.SITE_SETTINGS_AUTOMATIC_DOWNLOADS = | 139 r.SITE_SETTINGS_AUTOMATIC_DOWNLOADS = |
| 140 r.SITE_SETTINGS.createChild('automaticDownloads'); | 140 r.SITE_SETTINGS.createChild('automaticDownloads'); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 333 if (queryString) | 333 if (queryString) |
| 334 url += '?' + queryString; | 334 url += '?' + queryString; |
| 335 } | 335 } |
| 336 | 336 |
| 337 // History serializes the state, so we don't push the actual route object. | 337 // History serializes the state, so we don't push the actual route object. |
| 338 var previousRoutePath = currentRoute_.path; | 338 var previousRoutePath = currentRoute_.path; |
| 339 setCurrentRoute(route, params); | 339 setCurrentRoute(route, params); |
| 340 window.history.pushState(previousRoutePath, '', url); | 340 window.history.pushState(previousRoutePath, '', url); |
| 341 }; | 341 }; |
| 342 | 342 |
| 343 /** | |
| 344 * Navigates to the previous route, but will never exit Settings. If there is | |
| 345 * no previous route in the history, navigates to the immediate parent. | |
| 346 * @private | |
|
michaelpg
2016/08/17 00:21:31
no private
tommycli
2016/08/17 16:48:49
Done.
| |
| 347 */ | |
| 348 var navigateToPreviousRoute = function() { | |
| 349 var previousRoute = | |
| 350 window.history.state && | |
| 351 assert(getRouteForPath(/** @type {string} */ (window.history.state))); | |
| 352 | |
| 353 if (previousRoute && previousRoute.contains(settings.getCurrentRoute())) | |
|
michaelpg
2016/08/17 00:21:31
why does it matter if it contains the current rout
tommycli
2016/08/17 16:48:49
Done.
| |
| 354 window.history.back(); | |
| 355 else | |
| 356 navigateTo(assert(settings.getCurrentRoute().parent)); | |
|
michaelpg
2016/08/17 00:21:31
so navigateToPreviousRoute throws if called on a r
tommycli
2016/08/17 16:48:49
Done.
| |
| 357 }; | |
| 358 | |
| 343 window.addEventListener('popstate', function(event) { | 359 window.addEventListener('popstate', function(event) { |
| 344 // On pop state, do not push the state onto the window.history again. | 360 // On pop state, do not push the state onto the window.history again. |
| 345 setCurrentRoute(getRouteForPath(window.location.pathname) || Route.BASIC, | 361 setCurrentRoute(getRouteForPath(window.location.pathname) || Route.BASIC, |
| 346 new URLSearchParams(window.location.search)); | 362 new URLSearchParams(window.location.search)); |
| 347 }); | 363 }); |
| 348 | 364 |
| 349 return { | 365 return { |
| 350 Route: Route, | 366 Route: Route, |
| 351 RouteObserverBehavior: RouteObserverBehavior, | 367 RouteObserverBehavior: RouteObserverBehavior, |
| 352 getRouteForPath: getRouteForPath, | 368 getRouteForPath: getRouteForPath, |
| 353 initializeRouteFromUrl: initializeRouteFromUrl, | 369 initializeRouteFromUrl: initializeRouteFromUrl, |
| 354 getCurrentRoute: getCurrentRoute, | 370 getCurrentRoute: getCurrentRoute, |
| 355 getQueryParameters: getQueryParameters, | 371 getQueryParameters: getQueryParameters, |
| 356 navigateTo: navigateTo, | 372 navigateTo: navigateTo, |
| 373 navigateToPreviousRoute: navigateToPreviousRoute, | |
| 357 }; | 374 }; |
| 358 }); | 375 }); |
| OLD | NEW |