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

Unified Diff: chrome/browser/resources/options2/chromeos/accounts_options.js

Issue 9464053: Hide/Disable several (meaningless) options in Settings uber-page for Guest. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Another merge Created 8 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/options2/chromeos/accounts_options.js
diff --git a/chrome/browser/resources/options2/chromeos/accounts_options.js b/chrome/browser/resources/options2/chromeos/accounts_options.js
index 03d37e40a191e617f9ffd9a34363673cffd9c5d6..ce32b620049c6b9e182e897a381c1a40d139c152 100644
--- a/chrome/browser/resources/options2/chromeos/accounts_options.js
+++ b/chrome/browser/resources/options2/chromeos/accounts_options.js
@@ -141,7 +141,7 @@ cr.define('options', function() {
* Returns whether we're currently in guest mode.
*/
AccountsOptions.loggedInAsGuest = function() {
- return localStrings.getString('logged_in_as_guest') == 'true';
+ return localStrings.getString('loggedInAsGuest') == 'true';
};
/**
@@ -160,6 +160,73 @@ cr.define('options', function() {
$('userList').updateAccountPicture(username);
};
+ /**
+ * Disable or hide some elements in Guest mode in ChromeOS.
+ * All elements within given document with guest-visibility
+ * attribute are either hidden (for guest-visibility="hidden")
+ * or disabled (for guest-visibility="disabled").
+ *
+ * @param {Document} document Document that should processed.
+ */
+ AccountsOptions.applyGuestModeVisibility = function(document) {
+ if (!cr.isChromeOS || !AccountsOptions.loggedInAsGuest())
+ return;
+ var elements = document.querySelectorAll('[guest-visibility]');
+ for (var i = 0; i < elements.length; i++) {
+ var element = elements[i];
+ var visibility = element.getAttribute('guest-visibility');
+ if (visibility == 'hidden') {
+ element.hidden = true;
+ } else if (visibility == 'disabled') {
+ AccountsOptions.disableElementsForGuest(element);
+ }
+ }
+ }
+
+ /**
+ * Disables and marks page elements for Guest mode.
+ * Adds guest-disabled css class to all elements within given subtree,
+ * disables interactive elements (input/select/button), and removes href
+ * attribute from <a> elements.
+ *
+ * @param {Element} element Root element of DOM subtree that should be
+ * disabled.
+ */
+ AccountsOptions.disableElementsForGuest = function(element) {
+ AccountsOptions.disableElementForGuest_(element);
+
+ // Walk the tree, searching each ELEMENT node.
+ var walker = document.createTreeWalker(element,
+ NodeFilter.SHOW_ELEMENT,
+ null,
+ false);
+
+ var node = walker.nextNode();
+ while (node) {
+ AccountsOptions.disableElementForGuest_(node);
+ node = walker.nextNode();
+ }
+ };
+
+ /**
+ * Disables single element for Guest mode.
+ * Adds guest-disabled css class, adds disabled attribute for appropriate
+ * elements (input/select/button), and removes href attribute from
+ * <a> element.
+ *
+ * @private
+ * @param {Element} element Element that should be disabled.
+ */
+ AccountsOptions.disableElementForGuest_ = function(element) {
+ element.classList.add('guest-disabled');
+ if (element.nodeName == 'INPUT' ||
+ element.nodeName == 'SELECT' ||
+ element.nodeName == 'BUTTON')
+ element.disabled = true;
+ if (element.nodeName == 'A')
+ element.removeAttribute('href');
+ };
+
// Export
return {
AccountsOptions: AccountsOptions

Powered by Google App Engine
This is Rietveld 408576698