Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 (this.showOverlay_(pageName)) { |
|
stuartmorgan
2011/02/12 01:09:06
Change to |if (!targetPage && this.showOverlay_(pa
Evan Stade
2011/02/12 03:06:42
Done.
| |
| 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; | |
|
stuartmorgan
2011/02/12 01:09:06
Setting paramaters generally makes code harder to
Evan Stade
2011/02/12 03:06:42
on the other hand, I don't want someone coming in
| |
| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 // Override this with the new page. | 155 // Override this with the new page. |
| 143 var historyFunction = path ? window.history.pushState : | 156 var historyFunction = path ? window.history.pushState : |
| 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 }; | 162 }; |
| 150 | 163 |
| 151 /** | 164 /** |
| 152 * Called on load. Dispatch the URL hash to the given page's handleHash | |
| 153 * function. | |
| 154 * @param {string} pageName The string name of the (registered) options page. | |
| 155 * @param {string} hash The value of the hash component of the URL. | |
| 156 */ | |
| 157 OptionsPage.handleHashForPage = function(pageName, hash) { | |
| 158 var page = this.registeredPages[pageName]; | |
| 159 page.handleHash(hash); | |
| 160 }; | |
| 161 | |
| 162 /** | |
| 163 * Shows a registered Overlay page. Does not update history. | 165 * Shows a registered Overlay page. Does not update history. |
| 164 * @param {string} overlayName Page name. | 166 * @param {string} overlayName Page name. |
| 167 * @return {boolean} whether we showed an overlay. | |
| 165 */ | 168 */ |
| 166 OptionsPage.showOverlay_ = function(overlayName) { | 169 OptionsPage.showOverlay_ = function(overlayName) { |
| 167 var overlay = this.registeredOverlayPages[overlayName]; | 170 var overlay = this.registeredOverlayPages[overlayName]; |
| 171 if (!overlay || !overlay.canShowPage()) | |
| 172 return false; | |
| 168 | 173 |
| 169 if (overlay.parentPage) | 174 if (overlay.parentPage) |
| 170 this.showPageByName(overlay.parentPage.name, false); | 175 this.showPageByName(overlay.parentPage.name, false); |
| 171 | 176 |
| 172 this.registeredOverlayPages[overlayName].visible = true; | 177 this.registeredOverlayPages[overlayName].visible = true; |
| 178 return true; | |
| 173 }; | 179 }; |
| 174 | 180 |
| 175 /** | 181 /** |
| 176 * Returns whether or not an overlay is visible. | 182 * Returns whether or not an overlay is visible. |
| 177 * @return {boolean} True if an overlay is visible. | 183 * @return {boolean} True if an overlay is visible. |
| 178 * @private | 184 * @private |
| 179 */ | 185 */ |
| 180 OptionsPage.isOverlayVisible_ = function() { | 186 OptionsPage.isOverlayVisible_ = function() { |
| 181 return this.getVisibleOverlay_() != null; | 187 return this.getVisibleOverlay_() != null; |
| 182 }; | 188 }; |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 719 var parent = page.parentPage; | 725 var parent = page.parentPage; |
| 720 while (parent) { | 726 while (parent) { |
| 721 if (parent == this) | 727 if (parent == this) |
| 722 return true; | 728 return true; |
| 723 parent = parent.parentPage; | 729 parent = parent.parentPage; |
| 724 } | 730 } |
| 725 return false; | 731 return false; |
| 726 }, | 732 }, |
| 727 | 733 |
| 728 /** | 734 /** |
| 729 * Handles a hash value in the URL (such as bar in | 735 * Whether it should be possible to show the page. |
| 730 * chrome://options/foo#bar). Called on page load. | 736 * @return {boolean} True if the page should be shown |
| 731 * @param {string} hash The hash value. | |
| 732 */ | 737 */ |
| 733 handleHash: function(hash) { | 738 canShowPage: function() { |
| 739 return true; | |
| 734 }, | 740 }, |
| 735 }; | 741 }; |
| 736 | 742 |
| 737 // Export | 743 // Export |
| 738 return { | 744 return { |
| 739 OptionsPage: OptionsPage | 745 OptionsPage: OptionsPage |
| 740 }; | 746 }; |
| 741 }); | 747 }); |
| OLD | NEW |