summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/resources/options/options.js17
-rw-r--r--chrome/browser/resources/options/options_page.js55
-rw-r--r--chrome/browser/resources/uber/uber.js2
-rw-r--r--chrome/browser/ui/webui/options/options_browsertest.js21
4 files changed, 60 insertions, 35 deletions
diff --git a/chrome/browser/resources/options/options.js b/chrome/browser/resources/options/options.js
index a67e18e..dea67ba 100644
--- a/chrome/browser/resources/options/options.js
+++ b/chrome/browser/resources/options/options.js
@@ -227,15 +227,11 @@ function load() {
AutomaticSettingsResetBanner.getInstance().initialize();
OptionsPage.initialize();
- var path = document.location.pathname;
-
- if (path.length > 1) {
- // Skip starting slash and remove trailing slash (if any).
- var pageName = path.slice(1).replace(/\/$/, '');
- OptionsPage.showPageByName(pageName, true, {replaceState: true});
- } else {
- OptionsPage.showDefaultPage({replaceState: true});
- }
+ var pageName = OptionsPage.getPageNameFromPath();
+ // Still update history so that chrome://settings/nonexistant redirects
+ // appropriately to chrome://settings/. If the URL matches, updateHistory_
+ // will avoid the extra replaceState.
+ OptionsPage.showPageByName(pageName, true, {replaceState: true});
var subpagesNavTabs = document.querySelectorAll('.subpages-nav-tabs');
for (var i = 0; i < subpagesNavTabs.length; i++) {
@@ -265,5 +261,6 @@ window.onbeforeunload = function() {
* @param {Event} e The |popstate| event.
*/
window.onpopstate = function(e) {
- options.OptionsPage.setState(e.state);
+ var pageName = options.OptionsPage.getPageNameFromPath();
+ options.OptionsPage.setState(pageName, e.state);
};
diff --git a/chrome/browser/resources/options/options_page.js b/chrome/browser/resources/options/options_page.js
index 5a0ee18..d747060 100644
--- a/chrome/browser/resources/options/options_page.js
+++ b/chrome/browser/resources/options/options_page.js
@@ -71,22 +71,18 @@ cr.define('options', function() {
/**
* Shows the default page.
- * @param {Object=} opt_propertyBag An optional bag of properties including
- * replaceState (if history state should be replaced instead of pushed).
*/
- OptionsPage.showDefaultPage = function(opt_propertyBag) {
- this.navigateToPage(this.getDefaultPage().name, opt_propertyBag);
+ OptionsPage.showDefaultPage = function() {
+ this.navigateToPage(this.getDefaultPage().name);
};
/**
* "Navigates" to a page, meaning that the page will be shown and the
* appropriate entry is placed in the history.
* @param {string} pageName Page name.
- * @param {Object=} opt_propertyBag An optional bag of properties including
- * replaceState (if history state should be replaced instead of pushed).
*/
- OptionsPage.navigateToPage = function(pageName, opt_propertyBag) {
- this.showPageByName(pageName, true, opt_propertyBag);
+ OptionsPage.navigateToPage = function(pageName) {
+ this.showPageByName(pageName, true);
};
/**
@@ -234,15 +230,15 @@ cr.define('options', function() {
if (path)
path = path.slice(1).replace(/\/(?:#|$)/, ''); // Remove trailing slash.
- // The page is already in history (the user may have clicked the same link
- // twice). Do nothing.
+ // If the page is already in history (the user may have clicked the same
+ // link twice, or this is the initial load), do nothing.
var hash = opt_params && opt_params.ignoreHash ? '' : window.location.hash;
var newPath = (page == this.getDefaultPage() ? '' : page.name) + hash;
- if (path == newPath && !OptionsPage.isLoading())
+ if (path == newPath)
return;
var historyFunction = replace ? uber.replaceState : uber.pushState;
- historyFunction.call(uber, {pageName: page.name}, newPath);
+ historyFunction.call(uber, {}, newPath);
};
/**
@@ -576,22 +572,33 @@ cr.define('options', function() {
};
/**
+ * Returns the name of the page from the current path.
+ */
+ OptionsPage.getPageNameFromPath = function() {
+ var path = location.pathname;
+ if (path.length <= 1)
+ return this.getDefaultPage().name;
+
+ // Skip starting slash and remove trailing slash (if any).
+ return path.slice(1).replace(/\/$/, '');
+ };
+
+ /**
* Callback for window.onpopstate to handle back/forward navigations.
+ * @param {string} pageName The current page name.
* @param {Object} data State data pushed into history.
*/
- OptionsPage.setState = function(data) {
- if (data && data.pageName) {
- var currentOverlay = this.getVisibleOverlay_();
- var lowercaseName = data.pageName.toLowerCase();
- var newPage = this.registeredPages[lowercaseName] ||
- this.registeredOverlayPages[lowercaseName] ||
- this.getDefaultPage();
- if (currentOverlay && !currentOverlay.isAncestorOfPage(newPage)) {
- currentOverlay.visible = false;
- if (currentOverlay.didClosePage) currentOverlay.didClosePage();
- }
- this.showPageByName(data.pageName, false);
+ OptionsPage.setState = function(pageName, data) {
+ var currentOverlay = this.getVisibleOverlay_();
+ var lowercaseName = pageName.toLowerCase();
+ var newPage = this.registeredPages[lowercaseName] ||
+ this.registeredOverlayPages[lowercaseName] ||
+ this.getDefaultPage();
+ if (currentOverlay && !currentOverlay.isAncestorOfPage(newPage)) {
+ currentOverlay.visible = false;
+ if (currentOverlay.didClosePage) currentOverlay.didClosePage();
}
+ this.showPageByName(pageName, false);
};
/**
diff --git a/chrome/browser/resources/uber/uber.js b/chrome/browser/resources/uber/uber.js
index a872d6e..488310f 100644
--- a/chrome/browser/resources/uber/uber.js
+++ b/chrome/browser/resources/uber/uber.js
@@ -116,7 +116,7 @@ cr.define('uber', function() {
// under this origin are compatible. All of the downstream pages which
// navigate use pushState and replaceState.
invokeMethodOnPage(params.id, 'popState',
- {state: e.state, path: params.path});
+ {state: e.state, path: '/' + params.path});
}
/**
diff --git a/chrome/browser/ui/webui/options/options_browsertest.js b/chrome/browser/ui/webui/options/options_browsertest.js
index 115aa99..022fdd3 100644
--- a/chrome/browser/ui/webui/options/options_browsertest.js
+++ b/chrome/browser/ui/webui/options/options_browsertest.js
@@ -778,3 +778,24 @@ TEST_F('OptionsWebUIExtendedTest', 'SupervisingUsers', function() {
});
});
});
+
+/**
+ * TestFixture that loads the options page at a bogus URL.
+ * @extends {OptionsWebUIExtendedTest}
+ * @constructor
+ */
+function OptionsWebUIRedirectTest() {
+ OptionsWebUIExtendedTest.call(this);
+}
+
+OptionsWebUIRedirectTest.prototype = {
+ __proto__: OptionsWebUIExtendedTest.prototype,
+
+ /** @override */
+ browsePreload: 'chrome://settings-frame/nonexistantPage',
+};
+
+TEST_F('OptionsWebUIRedirectTest', 'TestURL', function() {
+ assertEquals('chrome://settings-frame/', document.location.href);
+ this.verifyHistory_([''], testDone);
+});