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 /** | 5 /** |
6 * @typedef {{ | 6 * @typedef {{ |
7 * url: string, | 7 * url: string, |
8 * page: string, | 8 * page: string, |
9 * section: string, | 9 * section: string, |
10 * subpage: !Array<string>, | 10 * subpage: !Array<string>, |
11 * dialog: (string|undefined), | |
12 * }} | 11 * }} |
13 */ | 12 */ |
14 var SettingsRoute; | 13 var SettingsRoute; |
15 | 14 |
16 /** | 15 /** |
17 * @fileoverview | 16 * @fileoverview |
18 * 'settings-router' is a simple router for settings. Its responsibilities: | 17 * 'settings-router' is a simple router for settings. Its responsibilities: |
19 * - Update the URL when the routing state changes. | 18 * - Update the URL when the routing state changes. |
20 * - Initialize the routing state with the initial URL. | 19 * - Initialize the routing state with the initial URL. |
21 * - Process and validate all routing state changes. | 20 * - Process and validate all routing state changes. |
(...skipping 30 matching lines...) Expand all Loading... |
52 // Take the current URL, find a matching pre-defined route, and | 51 // Take the current URL, find a matching pre-defined route, and |
53 // initialize the currentRoute to that pre-defined route. | 52 // initialize the currentRoute to that pre-defined route. |
54 for (var i = 0; i < this.routes_.length; ++i) { | 53 for (var i = 0; i < this.routes_.length; ++i) { |
55 var route = this.routes_[i]; | 54 var route = this.routes_[i]; |
56 if (route.url == window.location.pathname) { | 55 if (route.url == window.location.pathname) { |
57 return { | 56 return { |
58 url: route.url, | 57 url: route.url, |
59 page: route.page, | 58 page: route.page, |
60 section: route.section, | 59 section: route.section, |
61 subpage: route.subpage, | 60 subpage: route.subpage, |
62 dialog: route.dialog, | |
63 }; | 61 }; |
64 } | 62 } |
65 } | 63 } |
66 | 64 |
67 // As a fallback return the default route. | 65 // As a fallback return the default route. |
68 return this.routes_[0]; | 66 return this.routes_[0]; |
69 }, | 67 }, |
70 }, | 68 }, |
71 | 69 |
72 /** | 70 /** |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 url: '/siteSettings/unsandboxedPlugins/details', | 418 url: '/siteSettings/unsandboxedPlugins/details', |
421 page: 'advanced', | 419 page: 'advanced', |
422 section: 'privacy', | 420 section: 'privacy', |
423 subpage: ['site-settings', 'site-settings-category-unsandsboxed-plugins', | 421 subpage: ['site-settings', 'site-settings-category-unsandsboxed-plugins', |
424 'site-details'], | 422 'site-details'], |
425 }, | 423 }, |
426 { | 424 { |
427 url: '/clearBrowserData', | 425 url: '/clearBrowserData', |
428 page: 'advanced', | 426 page: 'advanced', |
429 section: 'privacy', | 427 section: 'privacy', |
430 subpage: [], | 428 subpage: ['clear-browsing-data'], |
431 dialog: 'clear-browsing-data', | |
432 }, | 429 }, |
433 <if expr="chromeos"> | 430 <if expr="chromeos"> |
434 { | 431 { |
435 url: '/dateTime', | 432 url: '/dateTime', |
436 page: 'advanced', | 433 page: 'advanced', |
437 section: 'dateTime', | 434 section: 'dateTime', |
438 subpage: [], | 435 subpage: [], |
439 }, | 436 }, |
440 { | 437 { |
441 url: '/bluetooth', | 438 url: '/bluetooth', |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 * Is called when another element modifies the route. This observer validates | 577 * Is called when another element modifies the route. This observer validates |
581 * the route change against the pre-defined list of routes, and updates the | 578 * the route change against the pre-defined list of routes, and updates the |
582 * URL appropriately. | 579 * URL appropriately. |
583 * @param {!SettingsRoute} newRoute Where we're headed. | 580 * @param {!SettingsRoute} newRoute Where we're headed. |
584 * @param {!SettingsRoute|undefined} oldRoute Where we've been. | 581 * @param {!SettingsRoute|undefined} oldRoute Where we've been. |
585 * @private | 582 * @private |
586 */ | 583 */ |
587 currentRouteChanged_: function(newRoute, oldRoute) { | 584 currentRouteChanged_: function(newRoute, oldRoute) { |
588 for (var i = 0; i < this.routes_.length; ++i) { | 585 for (var i = 0; i < this.routes_.length; ++i) { |
589 var route = this.routes_[i]; | 586 var route = this.routes_[i]; |
590 if (route.page == newRoute.page && | 587 if (route.page == newRoute.page && route.section == newRoute.section && |
591 route.section == newRoute.section && | |
592 route.dialog == newRoute.dialog && | |
593 route.subpage.length == newRoute.subpage.length && | 588 route.subpage.length == newRoute.subpage.length && |
594 newRoute.subpage.every(function(value, index) { | 589 newRoute.subpage.every(function(value, index) { |
595 return value == route.subpage[index]; | 590 return value == route.subpage[index]; |
596 })) { | 591 })) { |
| 592 |
597 // Update the property containing the titles for the current route. | 593 // Update the property containing the titles for the current route. |
598 this.currentRouteTitles = { | 594 this.currentRouteTitles = { |
599 pageTitle: loadTimeData.getString(route.page + 'PageTitle'), | 595 pageTitle: loadTimeData.getString(route.page + 'PageTitle'), |
600 }; | 596 }; |
601 | 597 |
602 // If we are restoring a state from history, don't push it again. | 598 // If we are restoring a state from history, don't push it again. |
603 if (newRoute.inHistory) | 599 if (newRoute.inHistory) |
604 return; | 600 return; |
605 | 601 |
606 // Mark routes persisted in history as already stored in history. | 602 // Mark routes persisted in history as already stored in history. |
607 var historicState = { | 603 var historicState = { |
608 inHistory: true, | 604 inHistory: true, |
609 page: newRoute.page, | 605 page: newRoute.page, |
610 section: newRoute.section, | 606 section: newRoute.section, |
611 subpage: newRoute.subpage, | 607 subpage: newRoute.subpage, |
612 dialog: newRoute.dialog, | |
613 }; | 608 }; |
614 | 609 |
615 // Push the current route to the history state, so when the user | 610 // Push the current route to the history state, so when the user |
616 // navigates with the browser back button, we can recall the route. | 611 // navigates with the browser back button, we can recall the route. |
617 if (oldRoute) { | 612 if (oldRoute) { |
618 window.history.pushState(historicState, document.title, route.url); | 613 window.history.pushState(historicState, document.title, route.url); |
619 } else { | 614 } else { |
620 // For the very first route (oldRoute will be undefined), we replace | 615 // For the very first route (oldRoute will be undefined), we replace |
621 // the existing state instead of pushing a new one. This is to allow | 616 // the existing state instead of pushing a new one. This is to allow |
622 // the user to use the browser back button to exit Settings entirely. | 617 // the user to use the browser back button to exit Settings entirely. |
623 window.history.replaceState(historicState, document.title); | 618 window.history.replaceState(historicState, document.title); |
624 } | 619 } |
625 | 620 |
626 return; | 621 return; |
627 } | 622 } |
628 } | 623 } |
629 | 624 |
630 assertNotReached('Route not found: ' + JSON.stringify(newRoute)); | 625 assertNotReached('Route not found: ' + JSON.stringify(newRoute)); |
631 }, | 626 }, |
632 }); | 627 }); |
OLD | NEW |