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

Side by Side Diff: chrome/browser/resources/options2/options_page.js

Issue 10834142: [options2] Fix issue when deleting a user and pressing back. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 cr.define('options', function() { 5 cr.define('options', function() {
6 ///////////////////////////////////////////////////////////////////////////// 6 /////////////////////////////////////////////////////////////////////////////
7 // OptionsPage class: 7 // OptionsPage class:
8 8
9 /** 9 /**
10 * Base class for options page. 10 * Base class for options page.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 */ 65 */
66 OptionsPage.navigateToPage = function(pageName) { 66 OptionsPage.navigateToPage = function(pageName) {
67 this.showPageByName(pageName, true); 67 this.showPageByName(pageName, true);
68 }; 68 };
69 69
70 /** 70 /**
71 * Shows a registered page. This handles both top-level and overlay pages. 71 * Shows a registered page. This handles both top-level and overlay pages.
72 * @param {string} pageName Page name. 72 * @param {string} pageName Page name.
73 * @param {boolean} updateHistory True if we should update the history after 73 * @param {boolean} updateHistory True if we should update the history after
74 * showing the page. 74 * showing the page.
75 * @param {Object=} opt_propertyBag An optional bag of properties including 75 * @param {{replaceState: (boolean|undefined), hash: (string|undefined)}=}
76 * replaceState (if history state should be replaced instead of pushed). 76 * opt_historyOptions An optional bag of history behavior modifiers.
77 * @private 77 * @private
78 */ 78 */
79 OptionsPage.showPageByName = function(pageName, 79 OptionsPage.showPageByName = function(pageName,
80 updateHistory, 80 updateHistory,
81 opt_propertyBag) { 81 opt_historyOptions) {
82 // If |opt_propertyBag| is non-truthy, homogenize to object. 82 // If |opt_propertyBag| is non-truthy, homogenize to object.
83 opt_propertyBag = opt_propertyBag || {}; 83 opt_historyOptions = opt_historyOptions || {};
84 84
85 // Find the currently visible root-level page. 85 // Find the currently visible root-level page.
86 var rootPage = null; 86 var rootPage = null;
87 for (var name in this.registeredPages) { 87 for (var name in this.registeredPages) {
88 var page = this.registeredPages[name]; 88 var page = this.registeredPages[name];
89 if (page.visible && !page.parentPage) { 89 if (page.visible && !page.parentPage) {
90 rootPage = page; 90 rootPage = page;
91 break; 91 break;
92 } 92 }
93 } 93 }
94 94
95 // Find the target page. 95 // Find the target page.
96 var targetPage = this.registeredPages[pageName.toLowerCase()]; 96 var targetPage = this.registeredPages[pageName.toLowerCase()];
97 if (!targetPage || !targetPage.canShowPage()) { 97 if (!targetPage || !targetPage.canShowPage()) {
98 // If it's not a page, try it as an overlay. 98 // If it's not a page, try it as an overlay.
99 if (!targetPage && this.showOverlay_(pageName, rootPage)) { 99 if (!targetPage && this.showOverlay_(pageName, rootPage)) {
100 if (updateHistory) 100 if (updateHistory) {
101 this.updateHistoryState_(!!opt_propertyBag.replaceState); 101 this.updateHistoryState_(!!opt_historyOptions.replaceState,
102 {hash: opt_historyOptions.hash});
103 }
102 return; 104 return;
103 } else { 105 } else {
104 targetPage = this.getDefaultPage(); 106 targetPage = this.getDefaultPage();
105 } 107 }
106 } 108 }
107 109
108 pageName = targetPage.name.toLowerCase(); 110 pageName = targetPage.name.toLowerCase();
109 var targetPageWasVisible = targetPage.visible; 111 var targetPageWasVisible = targetPage.visible;
110 112
111 // Determine if the root page is 'sticky', meaning that it 113 // Determine if the root page is 'sticky', meaning that it
(...skipping 23 matching lines...) Expand all
135 for (var i = 0; i < allPageNames.length; ++i) { 137 for (var i = 0; i < allPageNames.length; ++i) {
136 var name = allPageNames[i]; 138 var name = allPageNames[i];
137 var page = this.registeredPages[name] || 139 var page = this.registeredPages[name] ||
138 this.registeredOverlayPages[name]; 140 this.registeredOverlayPages[name];
139 if (!page.parentPage && isRootPageLocked) 141 if (!page.parentPage && isRootPageLocked)
140 continue; 142 continue;
141 page.visible = name == pageName || page.isAncestorOfPage(targetPage); 143 page.visible = name == pageName || page.isAncestorOfPage(targetPage);
142 } 144 }
143 145
144 // Update the history and current location. 146 // Update the history and current location.
145 if (updateHistory) 147 if (updateHistory) {
146 this.updateHistoryState_(!!opt_propertyBag.replaceState); 148 this.updateHistoryState_(
149 !!opt_historyOptions.replaceState, {hash: opt_historyOptions.hash});
150 }
147 151
148 // Update tab title. 152 // Update tab title.
149 this.setTitle_(targetPage.title); 153 this.setTitle_(targetPage.title);
150 154
151 // Notify pages if they were shown. 155 // Notify pages if they were shown.
152 for (var i = 0; i < allPageNames.length; ++i) { 156 for (var i = 0; i < allPageNames.length; ++i) {
153 var name = allPageNames[i]; 157 var name = allPageNames[i];
154 var page = this.registeredPages[name] || 158 var page = this.registeredPages[name] ||
155 this.registeredOverlayPages[name]; 159 this.registeredOverlayPages[name];
156 if (!page.parentPage && isRootPageLocked) 160 if (!page.parentPage && isRootPageLocked)
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 var path = window.location.pathname + window.location.hash; 201 var path = window.location.pathname + window.location.hash;
198 if (path) 202 if (path)
199 path = path.slice(1).replace(/\/(?:#|$)/, ''); // Remove trailing slash. 203 path = path.slice(1).replace(/\/(?:#|$)/, ''); // Remove trailing slash.
200 // The page is already in history (the user may have clicked the same link 204 // The page is already in history (the user may have clicked the same link
201 // twice). Do nothing. 205 // twice). Do nothing.
202 if (path == page.name && 206 if (path == page.name &&
203 !document.documentElement.classList.contains('loading')) { 207 !document.documentElement.classList.contains('loading')) {
204 return; 208 return;
205 } 209 }
206 210
207 var hash = opt_params && opt_params.ignoreHash ? '' : window.location.hash; 211 opt_params = opt_params || {};
212 assert(!(opt_params.ignoreHash && opt_params.hash),
213 'mutually exclusive hash params given to updateHistoryState_');
214
215 var hash = '';
216 if (!opt_params.ignoreHash) {
217 if (opt_params.hash) {
218 assert('#' == opt_params.hash.substr(0, 1));
219 hash = opt_params.hash;
220 } else {
221 hash = window.location.hash;
222 }
223 }
208 224
209 // If settings are embedded, tell the outer page to set its "path" to the 225 // If settings are embedded, tell the outer page to set its "path" to the
210 // inner frame's path. 226 // inner frame's path.
211 var outerPath = (page == this.getDefaultPage() ? '' : page.name) + hash; 227 var outerPath = (page == this.getDefaultPage() ? '' : page.name) + hash;
212 uber.invokeMethodOnParent('setPath', {path: outerPath}); 228 uber.invokeMethodOnParent('setPath', {path: outerPath});
213 229
214 // If there is no path, the current location is chrome://settings/. 230 // If there is no path, the current location is chrome://settings/.
215 // Override this with the new page. 231 // Override this with the new page.
216 var historyFunction = path && !replace ? window.history.pushState : 232 var historyFunction = path && !replace ? window.history.pushState :
217 window.history.replaceState; 233 window.history.replaceState;
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 canShowPage: function() { 915 canShowPage: function() {
900 return true; 916 return true;
901 }, 917 },
902 }; 918 };
903 919
904 // Export 920 // Export
905 return { 921 return {
906 OptionsPage: OptionsPage 922 OptionsPage: OptionsPage
907 }; 923 };
908 }); 924 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698