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

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

Issue 6480039: chrome://settings - Provide method for pages to prevent themselves being shown. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment update Created 9 years, 10 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 25 matching lines...) Expand all
36 */ 36 */
37 OptionsPage.registeredOverlayPages = {}; 37 OptionsPage.registeredOverlayPages = {};
38 38
39 /** 39 /**
40 * Whether or not |initialize| has been called. 40 * Whether or not |initialize| has been called.
41 * @private 41 * @private
42 */ 42 */
43 OptionsPage.initialized_ = false; 43 OptionsPage.initialized_ = false;
44 44
45 /** 45 /**
46 * Gets the default page (to be shown on initial load).
47 */
48 OptionsPage.getDefaultPage = function() {
49 return BrowserOptions.getInstance();
50 };
51
52 /**
46 * Shows the default page. 53 * Shows the default page.
47 */ 54 */
48 OptionsPage.showDefaultPage = function() { 55 OptionsPage.showDefaultPage = function() {
49 this.navigateToPage(BrowserOptions.getInstance().name); 56 this.navigateToPage(this.getDefaultPage().name);
50 }; 57 };
51 58
52 /** 59 /**
53 * "Navigates" to a page, meaning that the page will be shown and the 60 * "Navigates" to a page, meaning that the page will be shown and the
54 * appropriate entry is placed in the history. 61 * appropriate entry is placed in the history.
55 * @param {string} pageName Page name. 62 * @param {string} pageName Page name.
56 */ 63 */
57 OptionsPage.navigateToPage = function(pageName) { 64 OptionsPage.navigateToPage = function(pageName) {
58 this.showPageByName(pageName, true); 65 this.showPageByName(pageName, true);
59 }; 66 };
60 67
61 /** 68 /**
62 * Shows a registered page. This handles both top-level pages and sub-pages. 69 * Shows a registered page. This handles both top-level pages and sub-pages.
63 * @param {string} pageName Page name. 70 * @param {string} pageName Page name.
64 * @param {boolean} updateHistory True if we should update the history after 71 * @param {boolean} updateHistory True if we should update the history after
65 * showing the page. 72 * showing the page.
66 * @private 73 * @private
67 */ 74 */
68 OptionsPage.showPageByName = function(pageName, updateHistory) { 75 OptionsPage.showPageByName = function(pageName, updateHistory) {
69 var targetPage = this.registeredPages[pageName]; 76 var targetPage = this.registeredPages[pageName];
70 if (!targetPage) { 77 if (!targetPage || !targetPage.canShowPage()) {
71 this.showOverlay_(pageName); 78 // If it's not a page, try it as an overlay.
72 if (updateHistory) 79 if (!targetPage && this.showOverlay_(pageName)) {
73 this.updateHistoryState_(); 80 if (updateHistory)
74 return; 81 this.updateHistoryState_();
82 return;
83 } else {
84 targetPage = this.getDefaultPage();
85 }
75 } 86 }
76 87
88 pageName = targetPage.name;
89
77 // Determine if the root page is 'sticky', meaning that it 90 // Determine if the root page is 'sticky', meaning that it
78 // shouldn't change when showing a sub-page. This can happen for special 91 // shouldn't change when showing a sub-page. This can happen for special
79 // pages like Search. 92 // pages like Search.
80 var rootPage = null; 93 var rootPage = null;
81 for (var name in this.registeredPages) { 94 for (var name in this.registeredPages) {
82 var page = this.registeredPages[name]; 95 var page = this.registeredPages[name];
83 if (page.visible && !page.parentPage) { 96 if (page.visible && !page.parentPage) {
84 rootPage = page; 97 rootPage = page;
85 break; 98 break;
86 } 99 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 window.history.replaceState; 157 window.history.replaceState;
145 historyFunction.call(window.history, 158 historyFunction.call(window.history,
146 {pageName: page.name}, 159 {pageName: page.name},
147 page.title, 160 page.title,
148 '/' + page.name); 161 '/' + page.name);
149 // Update tab title. 162 // Update tab title.
150 document.title = page.title; 163 document.title = page.title;
151 }; 164 };
152 165
153 /** 166 /**
154 * Called on load. Dispatch the URL hash to the given page's handleHash
155 * function.
156 * @param {string} pageName The string name of the (registered) options page.
157 * @param {string} hash The value of the hash component of the URL.
158 */
159 OptionsPage.handleHashForPage = function(pageName, hash) {
160 var page = this.registeredPages[pageName];
161 page.handleHash(hash);
162 };
163
164 /**
165 * Shows a registered Overlay page. Does not update history. 167 * Shows a registered Overlay page. Does not update history.
166 * @param {string} overlayName Page name. 168 * @param {string} overlayName Page name.
169 * @return {boolean} whether we showed an overlay.
167 */ 170 */
168 OptionsPage.showOverlay_ = function(overlayName) { 171 OptionsPage.showOverlay_ = function(overlayName) {
169 var overlay = this.registeredOverlayPages[overlayName]; 172 var overlay = this.registeredOverlayPages[overlayName];
173 if (!overlay || !overlay.canShowPage())
174 return false;
170 175
171 if (overlay.parentPage) 176 if (overlay.parentPage)
172 this.showPageByName(overlay.parentPage.name, false); 177 this.showPageByName(overlay.parentPage.name, false);
173 178
174 this.registeredOverlayPages[overlayName].visible = true; 179 this.registeredOverlayPages[overlayName].visible = true;
180 return true;
175 }; 181 };
176 182
177 /** 183 /**
178 * Returns whether or not an overlay is visible. 184 * Returns whether or not an overlay is visible.
179 * @return {boolean} True if an overlay is visible. 185 * @return {boolean} True if an overlay is visible.
180 * @private 186 * @private
181 */ 187 */
182 OptionsPage.isOverlayVisible_ = function() { 188 OptionsPage.isOverlayVisible_ = function() {
183 return this.getVisibleOverlay_() != null; 189 return this.getVisibleOverlay_() != null;
184 }; 190 };
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 var parent = page.parentPage; 727 var parent = page.parentPage;
722 while (parent) { 728 while (parent) {
723 if (parent == this) 729 if (parent == this)
724 return true; 730 return true;
725 parent = parent.parentPage; 731 parent = parent.parentPage;
726 } 732 }
727 return false; 733 return false;
728 }, 734 },
729 735
730 /** 736 /**
731 * Handles a hash value in the URL (such as bar in 737 * Whether it should be possible to show the page.
732 * chrome://options/foo#bar). Called on page load. 738 * @return {boolean} True if the page should be shown
733 * @param {string} hash The hash value.
734 */ 739 */
735 handleHash: function(hash) { 740 canShowPage: function() {
741 return true;
736 }, 742 },
737 }; 743 };
738 744
739 // Export 745 // Export
740 return { 746 return {
741 OptionsPage: OptionsPage 747 OptionsPage: OptionsPage
742 }; 748 };
743 }); 749 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698