Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 | |
|
michaelpg
2016/04/29 20:19:04
remove newline
dschuyler
2016/04/29 21:27:46
Done.
| |
| 6 /** | |
| 7 * @typedef {{ | |
| 8 * url: string, | |
| 9 * page: string, | |
| 10 * section: string, | |
| 11 * subpage: !Array<string>, | |
| 12 * }} | |
| 13 */ | |
| 14 var SettingsRoute; | |
|
michaelpg
2016/04/29 20:19:04
nice
dschuyler
2016/04/29 21:27:46
Acknowledged.
| |
| 15 | |
| 5 /** | 16 /** |
| 6 * @fileoverview | 17 * @fileoverview |
| 7 * 'settings-router' is a simple router for settings. Its responsibilities: | 18 * 'settings-router' is a simple router for settings. Its responsibilities: |
| 8 * - Update the URL when the routing state changes. | 19 * - Update the URL when the routing state changes. |
| 9 * - Initialize the routing state with the initial URL. | 20 * - Initialize the routing state with the initial URL. |
| 10 * - Process and validate all routing state changes. | 21 * - Process and validate all routing state changes. |
| 11 * | 22 * |
| 12 * Example: | 23 * Example: |
| 13 * | 24 * |
| 14 * <settings-router current-route="{{currentRoute}}"> | 25 * <settings-router current-route="{{currentRoute}}"> |
| 15 * </settings-router> | 26 * </settings-router> |
| 16 */ | 27 */ |
| 17 Polymer({ | 28 Polymer({ |
| 18 is: 'settings-router', | 29 is: 'settings-router', |
| 19 | 30 |
| 20 properties: { | 31 properties: { |
| 21 /** | 32 /** |
| 22 * The current active route. This is reflected to the URL. Updates to this | 33 * The current active route. This is reflected to the URL. Updates to this |
| 23 * property should replace the whole object. | 34 * property should replace the whole object. |
| 24 * | 35 * |
| 25 * currentRoute.page refers to top-level pages such as Basic and Advanced. | 36 * currentRoute.page refers to top-level pages such as Basic and Advanced. |
| 26 * | 37 * |
| 27 * currentRoute.section is only non-empty when the user is on a subpage. If | 38 * currentRoute.section is only non-empty when the user is on a subpage. If |
| 28 * the user is on Basic, for instance, this is an empty string. | 39 * the user is on Basic, for instance, this is an empty string. |
| 29 * | 40 * |
| 30 * currentRoute.subpage is an Array. The last element is the actual subpage | 41 * currentRoute.subpage is an Array. The last element is the actual subpage |
| 31 * the user is on. The previous elements are the ancestor subpages. This | 42 * the user is on. The previous elements are the ancestor subpages. This |
| 32 * enables support for multiple paths to the same subpage. This is used by | 43 * enables support for multiple paths to the same subpage. This is used by |
| 33 * both the Back button and the Breadcrumb to determine ancestor subpages. | 44 * both the Back button and the Breadcrumb to determine ancestor subpages. |
| 45 * @type {SettingsRoute} | |
| 34 */ | 46 */ |
| 35 currentRoute: { | 47 currentRoute: { |
| 36 notify: true, | 48 notify: true, |
| 37 observer: 'currentRouteChanged_', | 49 observer: 'currentRouteChanged_', |
| 38 type: Object, | 50 type: Object, |
| 39 value: function() { | 51 value: function() { |
| 40 // Take the current URL, find a matching pre-defined route, and | 52 // Take the current URL, find a matching pre-defined route, and |
| 41 // initialize the currentRoute to that pre-defined route. | 53 // initialize the currentRoute to that pre-defined route. |
| 42 for (var i = 0; i < this.routes_.length; ++i) { | 54 for (var i = 0; i < this.routes_.length; ++i) { |
| 43 var route = this.routes_[i]; | 55 var route = this.routes_[i]; |
| 44 if (route.url == window.location.pathname) { | 56 if (route.url == window.location.pathname) { |
| 45 return { | 57 return { |
| 58 url: route.url, | |
| 46 page: route.page, | 59 page: route.page, |
| 47 section: route.section, | 60 section: route.section, |
| 48 subpage: route.subpage, | 61 subpage: route.subpage, |
| 49 }; | 62 }; |
| 50 } | 63 } |
| 51 } | 64 } |
| 52 | 65 |
| 53 // As a fallback return the default route. | 66 // As a fallback return the default route. |
| 54 return this.routes_[0]; | 67 return this.routes_[0]; |
| 55 }, | 68 }, |
| 56 }, | 69 }, |
| 57 | 70 |
| 58 /** | 71 /** |
| 59 * Page titles for the currently active route. Updated by the currentRoute | 72 * Page titles for the currently active route. Updated by the currentRoute |
| 60 * property observer. | 73 * property observer. |
| 61 * @type {{pageTitle: string}} | 74 * @type {{pageTitle: string}} |
| 62 */ | 75 */ |
| 63 currentRouteTitles: { | 76 currentRouteTitles: { |
| 64 notify: true, | 77 notify: true, |
| 65 type: Object, | 78 type: Object, |
| 66 value: function() { | 79 value: function() { |
| 67 return { | 80 return { |
| 68 pageTitle: '', | 81 pageTitle: '', |
| 69 }; | 82 }; |
| 70 }, | 83 }, |
| 71 }, | 84 }, |
| 72 }, | 85 }, |
| 73 | 86 |
| 74 | 87 |
| 75 /** | 88 /** |
| 76 * @private | 89 * @private {!Array<SettingsRoute>} |
|
michaelpg
2016/04/29 20:19:04
!SettingsRoute
dschuyler
2016/04/29 21:27:46
Done.
| |
| 77 * The 'url' property is not accessible to other elements. | 90 * The 'url' property is not accessible to other elements. |
| 78 */ | 91 */ |
| 79 routes_: [ | 92 routes_: [ |
| 80 { | 93 { |
| 81 url: '/', | 94 url: '/', |
| 82 page: 'basic', | 95 page: 'basic', |
| 83 section: '', | 96 section: '', |
| 84 subpage: [], | 97 subpage: [], |
| 85 }, | 98 }, |
| 86 { | 99 { |
| 87 url: '/advanced', | 100 url: '/advanced', |
| 88 page: 'advanced', | 101 page: 'advanced', |
| 89 section: '', | 102 section: '', |
| 90 subpage: [], | 103 subpage: [], |
| 91 }, | 104 }, |
| 92 <if expr="chromeos"> | 105 <if expr="chromeos"> |
| 93 { | 106 { |
| 107 url: '/internet', | |
| 108 page: 'basic', | |
| 109 section: 'internet', | |
| 110 subpage: [], | |
| 111 }, | |
| 112 { | |
| 94 url: '/networkDetail', | 113 url: '/networkDetail', |
| 95 page: 'basic', | 114 page: 'basic', |
| 96 section: 'internet', | 115 section: 'internet', |
| 97 subpage: ['network-detail'], | 116 subpage: ['network-detail'], |
| 98 }, | 117 }, |
| 99 { | 118 { |
| 100 url: '/knownNetworks', | 119 url: '/knownNetworks', |
| 101 page: 'basic', | 120 page: 'basic', |
| 102 section: 'internet', | 121 section: 'internet', |
| 103 subpage: ['known-networks'], | 122 subpage: ['known-networks'], |
| 104 }, | 123 }, |
| 105 </if> | 124 </if> |
| 106 { | 125 { |
| 126 url: '/appearance', | |
| 127 page: 'basic', | |
| 128 section: 'appearance', | |
| 129 subpage: [], | |
| 130 }, | |
| 131 { | |
| 107 url: '/fonts', | 132 url: '/fonts', |
| 108 page: 'basic', | 133 page: 'basic', |
| 109 section: 'appearance', | 134 section: 'appearance', |
| 110 subpage: ['appearance-fonts'], | 135 subpage: ['appearance-fonts'], |
| 111 }, | 136 }, |
| 112 { | 137 { |
| 138 url: '/defaultBrowser', | |
| 139 page: 'basic', | |
| 140 section: 'defaultBrowser', | |
| 141 subpage: [], | |
| 142 }, | |
| 143 { | |
| 144 url: '/search', | |
| 145 page: 'basic', | |
| 146 section: 'search', | |
| 147 subpage: [], | |
| 148 }, | |
| 149 { | |
| 113 url: '/searchEngines', | 150 url: '/searchEngines', |
| 114 page: 'basic', | 151 page: 'basic', |
| 115 section: 'search', | 152 section: 'search', |
| 116 subpage: ['search-engines'], | 153 subpage: ['search-engines'], |
| 117 }, | 154 }, |
| 118 { | 155 { |
| 119 url: '/searchEngines/advanced', | 156 url: '/searchEngines/advanced', |
| 120 page: 'basic', | 157 page: 'basic', |
| 121 section: 'search', | 158 section: 'search', |
| 122 subpage: ['search-engines', 'search-engines-advanced'], | 159 subpage: ['search-engines', 'search-engines-advanced'], |
| 123 }, | 160 }, |
| 161 { | |
| 162 url: '/onStartup', | |
| 163 page: 'basic', | |
| 164 section: 'onStartup', | |
| 165 subpage: [], | |
| 166 }, | |
| 167 { | |
| 168 url: '/people', | |
| 169 page: 'basic', | |
| 170 section: 'people', | |
| 171 subpage: [], | |
| 172 }, | |
| 124 <if expr="chromeos"> | 173 <if expr="chromeos"> |
| 125 { | 174 { |
| 126 url: '/changePicture', | 175 url: '/changePicture', |
| 127 page: 'basic', | 176 page: 'basic', |
| 128 section: 'people', | 177 section: 'people', |
| 129 subpage: ['changePicture'], | 178 subpage: ['changePicture'], |
| 130 }, | 179 }, |
| 131 </if> | 180 </if> |
| 132 <if expr="not chromeos"> | 181 <if expr="not chromeos"> |
| 133 { | 182 { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 145 }, | 194 }, |
| 146 <if expr="chromeos"> | 195 <if expr="chromeos"> |
| 147 { | 196 { |
| 148 url: '/accounts', | 197 url: '/accounts', |
| 149 page: 'basic', | 198 page: 'basic', |
| 150 section: 'people', | 199 section: 'people', |
| 151 subpage: ['users'], | 200 subpage: ['users'], |
| 152 }, | 201 }, |
| 153 </if> | 202 </if> |
| 154 { | 203 { |
| 204 url: '/advanced', | |
| 205 page: 'advanced', | |
| 206 section: 'privacy', | |
| 207 subpage: [], | |
| 208 }, | |
| 209 { | |
| 155 url: '/certificates', | 210 url: '/certificates', |
| 156 page: 'advanced', | 211 page: 'advanced', |
| 157 section: 'privacy', | 212 section: 'privacy', |
| 158 subpage: ['manage-certificates'], | 213 subpage: ['manage-certificates'], |
| 159 }, | 214 }, |
| 160 { | 215 { |
| 161 url: '/siteSettings', | 216 url: '/siteSettings', |
| 162 page: 'advanced', | 217 page: 'advanced', |
| 163 section: 'privacy', | 218 section: 'privacy', |
| 164 subpage: ['site-settings'], | 219 subpage: ['site-settings'], |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 'site-details'], | 350 'site-details'], |
| 296 }, | 351 }, |
| 297 { | 352 { |
| 298 url: '/clearBrowserData', | 353 url: '/clearBrowserData', |
| 299 page: 'advanced', | 354 page: 'advanced', |
| 300 section: 'privacy', | 355 section: 'privacy', |
| 301 subpage: ['clear-browsing-data'], | 356 subpage: ['clear-browsing-data'], |
| 302 }, | 357 }, |
| 303 <if expr="chromeos"> | 358 <if expr="chromeos"> |
| 304 { | 359 { |
| 360 url: '/bluetooth', | |
| 361 page: 'advanced', | |
| 362 section: 'bluetooth', | |
| 363 subpage: [], | |
| 364 }, | |
| 365 { | |
| 305 url: '/bluetoothAddDevice', | 366 url: '/bluetoothAddDevice', |
| 306 page: 'advanced', | 367 page: 'advanced', |
| 307 section: 'bluetooth', | 368 section: 'bluetooth', |
| 308 subpage: ['bluetooth-add-device'], | 369 subpage: ['bluetooth-add-device'], |
| 309 }, | 370 }, |
| 310 { | 371 { |
| 311 url: '/bluetoothAddDevice/bluetoothPairDevice', | 372 url: '/bluetoothAddDevice/bluetoothPairDevice', |
| 312 page: 'advanced', | 373 page: 'advanced', |
| 313 section: 'bluetooth', | 374 section: 'bluetooth', |
| 314 subpage: ['bluetooth-add-device', 'bluetooth-pair-device'], | 375 subpage: ['bluetooth-add-device', 'bluetooth-pair-device'], |
| 315 }, | 376 }, |
| 316 </if> | 377 </if> |
| 317 { | 378 { |
| 379 url: '/pw', /* TODO(dschuyler): find a better url. */ | |
|
michaelpg
2016/04/29 20:19:04
nit: 2 spaces separation and // style inline comme
dschuyler
2016/04/29 21:27:46
Done.
| |
| 380 page: 'advanced', | |
| 381 section: 'passwordsAndForms', | |
| 382 subpage: [], | |
| 383 }, | |
| 384 { | |
| 318 url: '/passwords', | 385 url: '/passwords', |
| 319 page: 'advanced', | 386 page: 'advanced', |
| 320 section: 'passwordsAndForms', | 387 section: 'passwordsAndForms', |
| 321 subpage: ['manage-passwords'], | 388 subpage: ['manage-passwords'], |
| 322 }, | 389 }, |
| 323 { | 390 { |
| 391 url: '/ln', /* TODO(dschuyler): find a better url. */ | |
| 392 page: 'advanced', | |
| 393 section: 'languages', | |
| 394 subpage: [], | |
| 395 }, | |
| 396 { | |
| 324 url: '/languages', | 397 url: '/languages', |
| 325 page: 'advanced', | 398 page: 'advanced', |
| 326 section: 'languages', | 399 section: 'languages', |
| 327 subpage: ['manage-languages'], | 400 subpage: ['manage-languages'], |
| 328 }, | 401 }, |
| 329 { | 402 { |
| 330 url: '/languages/edit', | 403 url: '/languages/edit', |
| 331 page: 'advanced', | 404 page: 'advanced', |
| 332 section: 'languages', | 405 section: 'languages', |
| 333 subpage: ['language-detail'], | 406 subpage: ['language-detail'], |
| 334 }, | 407 }, |
| 335 <if expr="chromeos"> | 408 <if expr="chromeos"> |
| 336 { | 409 { |
| 337 url: '/inputMethods', | 410 url: '/inputMethods', |
| 338 page: 'advanced', | 411 page: 'advanced', |
| 339 section: 'languages', | 412 section: 'languages', |
| 340 subpage: ['manage-input-methods'], | 413 subpage: ['manage-input-methods'], |
| 341 }, | 414 }, |
| 342 </if> | 415 </if> |
| 343 <if expr="not is_macosx"> | 416 <if expr="not is_macosx"> |
| 344 { | 417 { |
| 345 url: '/editDictionary', | 418 url: '/editDictionary', |
| 346 page: 'advanced', | 419 page: 'advanced', |
| 347 section: 'languages', | 420 section: 'languages', |
| 348 subpage: ['edit-dictionary'], | 421 subpage: ['edit-dictionary'], |
| 349 }, | 422 }, |
| 350 </if> | 423 </if> |
| 424 { | |
| 425 url: '/downloadsDirectory', | |
| 426 page: 'advanced', | |
| 427 section: 'downloads', | |
| 428 subpage: [], | |
| 429 }, | |
| 430 { | |
| 431 url: '/accessibility', | |
| 432 page: 'advanced', | |
| 433 section: 'a11y', | |
| 434 subpage: [], | |
| 435 }, | |
| 436 { | |
| 437 url: '/system', | |
| 438 page: 'advanced', | |
| 439 section: 'system', | |
| 440 subpage: [], | |
| 441 }, | |
| 442 { | |
| 443 url: '/reset', | |
| 444 page: 'advanced', | |
| 445 section: 'reset', | |
| 446 subpage: [], | |
| 447 }, | |
| 351 <if expr="chromeos"> | 448 <if expr="chromeos"> |
| 352 { | 449 { |
| 450 url: '/device', | |
| 451 page: 'basic', | |
| 452 section: 'device', | |
| 453 subpage: [], | |
| 454 }, | |
| 455 { | |
| 353 url: '/pointer-overlay', | 456 url: '/pointer-overlay', |
| 354 page: 'basic', | 457 page: 'basic', |
| 355 section: 'device', | 458 section: 'device', |
| 356 subpage: ['touchpad'], | 459 subpage: ['touchpad'], |
| 357 }, | 460 }, |
| 358 { | 461 { |
| 359 url: '/keyboard-overlay', | 462 url: '/keyboard-overlay', |
| 360 page: 'basic', | 463 page: 'basic', |
| 361 section: 'device', | 464 section: 'device', |
| 362 subpage: ['keyboard'], | 465 subpage: ['keyboard'], |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 374 * Sets up a history popstate observer. | 477 * Sets up a history popstate observer. |
| 375 */ | 478 */ |
| 376 created: function() { | 479 created: function() { |
| 377 window.addEventListener('popstate', function(event) { | 480 window.addEventListener('popstate', function(event) { |
| 378 if (event.state && event.state.page) | 481 if (event.state && event.state.page) |
| 379 this.currentRoute = event.state; | 482 this.currentRoute = event.state; |
| 380 }.bind(this)); | 483 }.bind(this)); |
| 381 }, | 484 }, |
| 382 | 485 |
| 383 /** | 486 /** |
| 384 * @private | |
| 385 * Is called when another element modifies the route. This observer validates | 487 * Is called when another element modifies the route. This observer validates |
| 386 * the route change against the pre-defined list of routes, and updates the | 488 * the route change against the pre-defined list of routes, and updates the |
| 387 * URL appropriately. | 489 * URL appropriately. |
| 490 * @param {SettingsRoute} newRoute Where we're headed. | |
|
michaelpg
2016/04/29 20:19:04
!
dschuyler
2016/04/29 21:27:46
Done.
| |
| 491 * @param {SettingsRoute} oldRoute Where we've been. | |
|
michaelpg
2016/04/29 20:19:04
!SettingsRoute|undefined
dschuyler
2016/04/29 21:27:46
Done.
| |
| 492 * @private | |
| 388 */ | 493 */ |
| 389 currentRouteChanged_: function(newRoute, oldRoute) { | 494 currentRouteChanged_: function(newRoute, oldRoute) { |
| 390 for (var i = 0; i < this.routes_.length; ++i) { | 495 for (var i = 0; i < this.routes_.length; ++i) { |
| 391 var route = this.routes_[i]; | 496 var route = this.routes_[i]; |
| 392 if (route.page == newRoute.page && route.section == newRoute.section && | 497 if (route.page == newRoute.page && route.section == newRoute.section && |
| 393 route.subpage.length == newRoute.subpage.length && | 498 route.subpage.length == newRoute.subpage.length && |
| 394 newRoute.subpage.every(function(value, index) { | 499 newRoute.subpage.every(function(value, index) { |
| 395 return value == route.subpage[index]; | 500 return value == route.subpage[index]; |
| 396 })) { | 501 })) { |
| 397 | 502 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 423 window.history.replaceState(historicState, document.title); | 528 window.history.replaceState(historicState, document.title); |
| 424 } | 529 } |
| 425 | 530 |
| 426 return; | 531 return; |
| 427 } | 532 } |
| 428 } | 533 } |
| 429 | 534 |
| 430 assertNotReached('Route not found: ' + JSON.stringify(newRoute)); | 535 assertNotReached('Route not found: ' + JSON.stringify(newRoute)); |
| 431 }, | 536 }, |
| 432 }); | 537 }); |
| OLD | NEW |