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

Unified Diff: chrome/browser/resources/settings/route.js

Issue 2297663008: MD Settings: Prevent unexpected scrolling to section on popstates. (Closed)
Patch Set: add test Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/resources/settings/settings_page/main_page_behavior.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/settings/route.js
diff --git a/chrome/browser/resources/settings/route.js b/chrome/browser/resources/settings/route.js
index 81e872d68458129929b598406914dce4bf599215..06b30fee2e792b675668a77c5082feedfa3c7631 100644
--- a/chrome/browser/resources/settings/route.js
+++ b/chrome/browser/resources/settings/route.js
@@ -253,6 +253,9 @@ cr.define('settings', function() {
*/
var currentQueryParameters_ = new URLSearchParams();
+ /** @private {boolean} */
+ var lastRouteChangeWasPopstate_ = false;
+
/** @private */
var initializeRouteFromUrlCalled_ = false;
@@ -277,11 +280,13 @@ cr.define('settings', function() {
* Helper function to set the current route and notify all observers.
* @param {!settings.Route} route
* @param {!URLSearchParams} queryParameters
+ * @param {boolean} isPopstate
*/
- var setCurrentRoute = function(route, queryParameters) {
+ var setCurrentRoute = function(route, queryParameters, isPopstate) {
var oldRoute = currentRoute_;
currentRoute_ = route;
currentQueryParameters_ = queryParameters;
+ lastRouteChangeWasPopstate_ = isPopstate;
for (var observer of routeObservers_)
observer.currentRouteChanged(currentRoute_, oldRoute);
};
@@ -294,6 +299,11 @@ cr.define('settings', function() {
return new URLSearchParams(currentQueryParameters_); // Defensive copy.
};
+ /** @return {boolean} */
+ var lastRouteChangeWasPopstate = function() {
+ return lastRouteChangeWasPopstate_;
+ };
+
/**
* Navigates to a canonical route and pushes a new history entry.
* @param {!settings.Route} route
@@ -312,7 +322,7 @@ cr.define('settings', function() {
// History serializes the state, so we don't push the actual route object.
window.history.pushState(currentRoute_.path, '', url);
- setCurrentRoute(route, params);
+ setCurrentRoute(route, params, false);
};
/**
@@ -334,7 +344,7 @@ cr.define('settings', function() {
window.addEventListener('popstate', function(event) {
// On pop state, do not push the state onto the window.history again.
setCurrentRoute(getRouteForPath(window.location.pathname) || Route.BASIC,
- new URLSearchParams(window.location.search));
+ new URLSearchParams(window.location.search), true);
});
return {
@@ -344,6 +354,7 @@ cr.define('settings', function() {
initializeRouteFromUrl: initializeRouteFromUrl,
getCurrentRoute: getCurrentRoute,
getQueryParameters: getQueryParameters,
+ lastRouteChangeWasPopstate: lastRouteChangeWasPopstate,
navigateTo: navigateTo,
navigateToPreviousRoute: navigateToPreviousRoute,
};
« no previous file with comments | « no previous file | chrome/browser/resources/settings/settings_page/main_page_behavior.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698