diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-14 23:53:55 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-14 23:53:55 +0000 |
commit | 98723c4a32b20c4ba1ed95b0e9056788fb413ce6 (patch) | |
tree | cd2ef3578daee9e61e05e63f84b43f2c837da7aa | |
parent | 5713e56f49c7897050ae60affa5701c11b23aeab (diff) | |
download | chromium_src-98723c4a32b20c4ba1ed95b0e9056788fb413ce6.zip chromium_src-98723c4a32b20c4ba1ed95b0e9056788fb413ce6.tar.gz chromium_src-98723c4a32b20c4ba1ed95b0e9056788fb413ce6.tar.bz2 |
chrome://settings - Provide method for pages to prevent themselves being shown.
use this method in:
- alert overlay
- add startup page overlay
- password manager overlay
these are the places I determined should be sometimes disabled when I did a sweep of the code, but I'm probably missing something.
BUG=none
TEST=chrome://settings/alertOverlay should show the basic browser page
Review URL: http://codereview.chromium.org/6480039
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74878 0039d316-1c4b-4281-b951-d872f2087c98
7 files changed, 77 insertions, 33 deletions
diff --git a/chrome/browser/resources/options/add_startup_page_overlay.js b/chrome/browser/resources/options/add_startup_page_overlay.js index 6e9e1b2..4678629 100644 --- a/chrome/browser/resources/options/add_startup_page_overlay.js +++ b/chrome/browser/resources/options/add_startup_page_overlay.js @@ -111,6 +111,12 @@ cr.define('options', function() { $('addStartupPageURL').value = url; this.updateAddButtonState_(); }, + + /** @inheritDoc */ + canShowPage: function() { + return BrowserOptions.getInstance(). + shouldEnableCustomStartupPageControls(); + }, }; AddStartupPageOverlay.updateRecentPageList = function(pages) { diff --git a/chrome/browser/resources/options/alert_overlay.js b/chrome/browser/resources/options/alert_overlay.js index e8ecced..eb1fb8e 100644 --- a/chrome/browser/resources/options/alert_overlay.js +++ b/chrome/browser/resources/options/alert_overlay.js @@ -21,6 +21,13 @@ cr.define('options', function() { __proto__: OptionsPage.prototype, /** + * Whether the page can be shown. Used to make sure the page is only + * shown via AlertOverlay.Show(), and not via the address bar. + * @private + */ + canShow_: false, + + /** * Initialize the page. */ initializePage: function() { @@ -59,7 +66,19 @@ cr.define('options', function() { if (this.cancelCallback != undefined) { this.cancelCallback.call(); } - } + }, + + /** + * The page is getting hidden. Don't let it be shown again. + */ + willHidePage: function() { + canShow_ = false; + }, + + /** @inheritDoc */ + canShowPage: function() { + return this.canShow_; + }, }; /** @@ -108,9 +127,13 @@ cr.define('options', function() { $('alertOverlayCancel').style.display = 'none'; } - AlertOverlay.getInstance().okCallback = okCallback; - AlertOverlay.getInstance().cancelCallback = cancelCallback; + var alertOverlay = AlertOverlay.getInstance(); + alertOverlay.okCallback = okCallback; + alertOverlay.cancelCallback = cancelCallback; + alertOverlay.canShow_ = true; + // Intentionally don't show the URL in the location bar as we don't want + // people trying to navigate here by hand. OptionsPage.showPageByName('alertOverlay', false); } diff --git a/chrome/browser/resources/options/browser_options.js b/chrome/browser/resources/options/browser_options.js index 123247a..4711539 100644 --- a/chrome/browser/resources/options/browser_options.js +++ b/chrome/browser/resources/options/browser_options.js @@ -160,11 +160,10 @@ cr.define('options', function() { /** * Returns true if the custom startup page control block should * be enabled. - * @private * @returns {boolean} Whether the startup page controls should be * enabled. */ - shouldEnableCustomStartupPageControls_: function(pages) { + shouldEnableCustomStartupPageControls: function(pages) { return $('startupShowPagesButton').checked; }, @@ -336,7 +335,7 @@ cr.define('options', function() { * @private */ updateCustomStartupPageControlStates_: function() { - var disable = !this.shouldEnableCustomStartupPageControls_(); + var disable = !this.shouldEnableCustomStartupPageControls(); $('startupPagesList').disabled = disable; $('startupUseCurrentButton').disabled = disable; $('startupAddButton').disabled = disable; diff --git a/chrome/browser/resources/options/options.js b/chrome/browser/resources/options/options.js index dfae2b3..dc69759 100644 --- a/chrome/browser/resources/options/options.js +++ b/chrome/browser/resources/options/options.js @@ -161,16 +161,11 @@ function load() { OptionsPage.initialize(); var path = document.location.pathname; - // TODO(estade): remove this explicit hash handling. Pages should check for - // location.hash in didShowPage. - var hash = document.location.hash; if (path.length > 1) { var pageName = path.slice(1); // Show page, but don't update history (there's already an entry for it). OptionsPage.showPageByName(pageName, false); - if (hash.length > 1) - OptionsPage.handleHashForPage(pageName, hash.slice(1)); } else { OptionsPage.showDefaultPage(); } diff --git a/chrome/browser/resources/options/options_page.js b/chrome/browser/resources/options/options_page.js index da0cb1e..4d563ab 100644 --- a/chrome/browser/resources/options/options_page.js +++ b/chrome/browser/resources/options/options_page.js @@ -43,10 +43,17 @@ cr.define('options', function() { OptionsPage.initialized_ = false; /** + * Gets the default page (to be shown on initial load). + */ + OptionsPage.getDefaultPage = function() { + return BrowserOptions.getInstance(); + }; + + /** * Shows the default page. */ OptionsPage.showDefaultPage = function() { - this.navigateToPage(BrowserOptions.getInstance().name); + this.navigateToPage(this.getDefaultPage().name); }; /** @@ -67,13 +74,19 @@ cr.define('options', function() { */ OptionsPage.showPageByName = function(pageName, updateHistory) { var targetPage = this.registeredPages[pageName]; - if (!targetPage) { - this.showOverlay_(pageName); - if (updateHistory) - this.updateHistoryState_(); - return; + if (!targetPage || !targetPage.canShowPage()) { + // If it's not a page, try it as an overlay. + if (!targetPage && this.showOverlay_(pageName)) { + if (updateHistory) + this.updateHistoryState_(); + return; + } else { + targetPage = this.getDefaultPage(); + } } + pageName = targetPage.name; + // Determine if the root page is 'sticky', meaning that it // shouldn't change when showing a sub-page. This can happen for special // pages like Search. @@ -151,27 +164,20 @@ cr.define('options', function() { }; /** - * Called on load. Dispatch the URL hash to the given page's handleHash - * function. - * @param {string} pageName The string name of the (registered) options page. - * @param {string} hash The value of the hash component of the URL. - */ - OptionsPage.handleHashForPage = function(pageName, hash) { - var page = this.registeredPages[pageName]; - page.handleHash(hash); - }; - - /** * Shows a registered Overlay page. Does not update history. * @param {string} overlayName Page name. + * @return {boolean} whether we showed an overlay. */ OptionsPage.showOverlay_ = function(overlayName) { var overlay = this.registeredOverlayPages[overlayName]; + if (!overlay || !overlay.canShowPage()) + return false; if (overlay.parentPage) this.showPageByName(overlay.parentPage.name, false); this.registeredOverlayPages[overlayName].visible = true; + return true; }; /** @@ -728,11 +734,11 @@ cr.define('options', function() { }, /** - * Handles a hash value in the URL (such as bar in - * chrome://options/foo#bar). Called on page load. - * @param {string} hash The hash value. + * Whether it should be possible to show the page. + * @return {boolean} True if the page should be shown */ - handleHash: function(hash) { + canShowPage: function() { + return true; }, }; diff --git a/chrome/browser/resources/options/password_manager.js b/chrome/browser/resources/options/password_manager.js index 9a10090..41a8c5d 100644 --- a/chrome/browser/resources/options/password_manager.js +++ b/chrome/browser/resources/options/password_manager.js @@ -50,6 +50,11 @@ cr.define('options', function() { }, /** @inheritDoc */ + canShowPage: function() { + return !PersonalOptions.disablePasswordManagement(); + }, + + /** @inheritDoc */ didShowPage: function() { // Updating the password lists may cause a blocking platform dialog pop up // (Mac, Linux), so we delay this operation until the page is shown. diff --git a/chrome/browser/resources/options/personal_options.js b/chrome/browser/resources/options/personal_options.js index 930be56..8775ec0 100644 --- a/chrome/browser/resources/options/personal_options.js +++ b/chrome/browser/resources/options/personal_options.js @@ -80,8 +80,9 @@ cr.define('options', function() { if (cr.commandLine.options['--bwsi']) { // Disable the screen lock checkbox for the guest mode. $('enable-screen-lock').disabled = true; + } - // Disable passwords management settings for the guest mode. + if (PersonalOptions.disablePasswordManagement()) { $('passwords-offersave').disabled = true; $('passwords-neversave').disabled = true; $('passwords-offersave').value = false; @@ -184,6 +185,15 @@ cr.define('options', function() { }, }; + /** + * Returns whether the user should be able to manage (view and edit) their + * stored passwords. Password management is disabled in guest mode. + * @return {boolean} True if password management should be disabled. + */ + PersonalOptions.disablePasswordManagement = function() { + return cr.commandLine.options['--bwsi']; + }; + // Forward public APIs to private implementations. [ 'setSyncEnabled', |