summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources/options2
diff options
context:
space:
mode:
authordbeam@chromium.org <dbeam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-09 23:00:47 +0000
committerdbeam@chromium.org <dbeam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-09 23:00:47 +0000
commit65a77f20f323cefb0bd68870abc064cf985d0980 (patch)
treed52fe0de9736795c836c6382e5d794771503f053 /chrome/browser/resources/options2
parenta340e3d88c5742860f9e2469a12029a1193a10c9 (diff)
downloadchromium_src-65a77f20f323cefb0bd68870abc064cf985d0980.zip
chromium_src-65a77f20f323cefb0bd68870abc064cf985d0980.tar.gz
chromium_src-65a77f20f323cefb0bd68870abc064cf985d0980.tar.bz2
[uber page] Push navigation urls for subpages
R=estade@chromium.org,csilv@chromium.org BUG=112377,116196 TEST=Settings sub URLs come through to the uber page and do reasonable things when refreshed or navigated to / from. NOTRY=true Review URL: http://codereview.chromium.org/9436002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@125928 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/resources/options2')
-rw-r--r--chrome/browser/resources/options2/content_settings.js7
-rw-r--r--chrome/browser/resources/options2/options.js11
-rw-r--r--chrome/browser/resources/options2/options_page.js67
3 files changed, 56 insertions, 29 deletions
diff --git a/chrome/browser/resources/options2/content_settings.js b/chrome/browser/resources/options2/content_settings.js
index 1ec2743..0663650 100644
--- a/chrome/browser/resources/options2/content_settings.js
+++ b/chrome/browser/resources/options2/content_settings.js
@@ -55,8 +55,11 @@ cr.define('options', function() {
// Add on the proper hash for the content type, and store that in the
// history so back/forward and tab restore works.
var hash = event.target.getAttribute('contentType');
- window.history.replaceState({pageName: page.name}, page.title,
- '/' + page.name + '#' + hash);
+ var url = page.name + '#' + hash;
+ window.history.replaceState({pageName: page.name},
+ page.title,
+ '/' + url);
+ uber.invokeMethodOnParent('setPath', {path: url});
};
}
diff --git a/chrome/browser/resources/options2/options.js b/chrome/browser/resources/options2/options.js
index 55287dc..bb86d9f 100644
--- a/chrome/browser/resources/options2/options.js
+++ b/chrome/browser/resources/options2/options.js
@@ -189,11 +189,14 @@ function load() {
if (path.length > 1) {
// Skip starting slash and remove trailing slash (if any).
var pageName = path.slice(1).replace(/\/$/, '');
- // Proxy page is now per network and only reachable from internet details.
- if (pageName != 'proxy') {
- // Show page, but don't update history (there's already an entry for it).
- OptionsPage.showPageByName(pageName, false);
+
+ if (pageName == 'proxy') {
+ // The following page doesn't have a unique URL at the moment, so do
+ // something sensible if a user pastes this link or refreshes on this URL.
+ pageName = ProxyOptions ? ProxyOptions.getInstance().parentPage.name :
+ AdvancedOptions.getInstance().name;
}
+ OptionsPage.showPageByName(pageName, true, {replaceState: true});
} else {
OptionsPage.showDefaultPage();
}
diff --git a/chrome/browser/resources/options2/options_page.js b/chrome/browser/resources/options2/options_page.js
index 0f4ca81..e0afb0e 100644
--- a/chrome/browser/resources/options2/options_page.js
+++ b/chrome/browser/resources/options2/options_page.js
@@ -77,9 +77,16 @@ cr.define('options', function() {
* @param {string} pageName Page name.
* @param {boolean} updateHistory True if we should update the history after
* showing the page.
+ * @param {Object=} opt_propertyBag An optional bag of properties including
+ * replaceState (if history state should be replaced instead of pushed).
* @private
*/
- OptionsPage.showPageByName = function(pageName, updateHistory) {
+ OptionsPage.showPageByName = function(pageName,
+ updateHistory,
+ opt_propertyBag) {
+ // If |opt_propertyBag| is non-truthy, homogenize to object.
+ opt_propertyBag = opt_propertyBag || {};
+
// Find the currently visible root-level page.
var rootPage = null;
for (var name in this.registeredPages) {
@@ -96,7 +103,7 @@ cr.define('options', function() {
// If it's not a page, try it as an overlay.
if (!targetPage && this.showOverlay_(pageName, rootPage)) {
if (updateHistory)
- this.updateHistoryState_();
+ this.updateHistoryState_(!!opt_propertyBag.replaceState);
return;
} else {
targetPage = this.getDefaultPage();
@@ -112,9 +119,15 @@ cr.define('options', function() {
var isRootPageLocked =
rootPage && rootPage.sticky && targetPage.parentPage;
+ var allPageNames = Array.prototype.concat.call(
+ Object.keys(this.registeredPages),
+ Object.keys(this.registeredOverlayPages));
+
// Notify pages if they will be hidden.
- for (var name in this.registeredPages) {
- var page = this.registeredPages[name];
+ for (var i = 0; i < allPageNames.length; ++i) {
+ var name = allPageNames[i];
+ var page = this.registeredPages[name] ||
+ this.registeredOverlayPages[name];
if (!page.parentPage && isRootPageLocked)
continue;
if (page.willHidePage && name != pageName &&
@@ -124,8 +137,10 @@ cr.define('options', function() {
}
// Update visibilities to show only the hierarchy of the target page.
- for (var name in this.registeredPages) {
- var page = this.registeredPages[name];
+ for (var i = 0; i < allPageNames.length; ++i) {
+ var name = allPageNames[i];
+ var page = this.registeredPages[name] ||
+ this.registeredOverlayPages[name];
if (!page.parentPage && isRootPageLocked)
continue;
page.visible = name == pageName || page.isAncestorOfPage(targetPage);
@@ -133,14 +148,16 @@ cr.define('options', function() {
// Update the history and current location.
if (updateHistory)
- this.updateHistoryState_();
+ this.updateHistoryState_(!!opt_propertyBag.replaceState);
// Update tab title.
this.setTitle_(targetPage.title);
// Notify pages if they were shown.
- for (var name in this.registeredPages) {
- var page = this.registeredPages[name];
+ for (var i = 0; i < allPageNames.length; ++i) {
+ var name = allPageNames[i];
+ var page = this.registeredPages[name] ||
+ this.registeredOverlayPages[name];
if (!page.parentPage && isRootPageLocked)
continue;
if (!targetPageWasVisible && page.didShowPage &&
@@ -175,22 +192,31 @@ cr.define('options', function() {
/**
* Pushes the current page onto the history stack, overriding the last page
* if it is the generic chrome://settings/.
+ * @param {boolean} replace If true, allow no history events to be created.
* @private
*/
- OptionsPage.updateHistoryState_ = function() {
+ OptionsPage.updateHistoryState_ = function(replace) {
var page = this.getTopmostVisiblePage();
- var path = location.pathname;
+ var path = window.location.pathname + window.location.hash;
if (path)
- path = path.slice(1).replace(/\/$/, ''); // Remove trailing slash.
+ 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 (path == page.name)
+ if (path == page.name &&
+ !document.documentElement.classList.contains('loading')) {
return;
+ }
+
+ // If settings are embedded, tell the outer page to set its "path" to the
+ // inner frame's path.
+ var outerPath = (page == this.getDefaultPage() ? '' : page.name) +
+ window.location.hash;
+ uber.invokeMethodOnParent('setPath', {path: outerPath});
// If there is no path, the current location is chrome://settings/.
// Override this with the new page.
- var historyFunction = path ? window.history.pushState :
- window.history.replaceState;
+ var historyFunction = path && !replace ? window.history.pushState :
+ window.history.replaceState;
historyFunction.call(window.history,
{pageName: page.name},
page.title,
@@ -262,7 +288,7 @@ cr.define('options', function() {
overlay.visible = false;
if (overlay.didClosePage) overlay.didClosePage();
- this.updateHistoryState_();
+ this.updateHistoryState_(false);
};
/**
@@ -440,12 +466,7 @@ cr.define('options', function() {
*/
OptionsPage.setState = function(data) {
if (data && data.pageName) {
- // It's possible an overlay may be the last top-level page shown.
- if (this.isOverlayVisible_() &&
- !this.registeredOverlayPages[data.pageName.toLowerCase()]) {
- this.hideOverlay_();
- }
-
+ this.willClose();
this.showPageByName(data.pageName, false);
}
};
@@ -603,7 +624,7 @@ cr.define('options', function() {
OptionsPage.reinitializeCore = function() {
if (this.initialized_)
chrome.send('coreOptionsInitialize');
- }
+ };
OptionsPage.prototype = {
__proto__: cr.EventTarget.prototype,