Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(423)

Side by Side Diff: chrome/browser/resources/settings/settings_page/settings_router.js

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

Powered by Google App Engine
This is Rietveld 408576698