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

Unified Diff: chrome/browser/resources/shared/js/chromeos/ui_account_tweaks.js

Issue 10006028: Plugins page in BWSI session has unnecessary and misleading UI components (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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/shared/js/chromeos/ui_account_tweaks.js
diff --git a/chrome/browser/resources/shared/js/chromeos/ui_account_tweaks.js b/chrome/browser/resources/shared/js/chromeos/ui_account_tweaks.js
new file mode 100644
index 0000000000000000000000000000000000000000..40b51578423c6168fa64e6c7b4053b68c248641e
--- /dev/null
+++ b/chrome/browser/resources/shared/js/chromeos/ui_account_tweaks.js
@@ -0,0 +1,117 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
Nikita (slow) 2012/04/06 12:36:09 Please do a git cp chrome/browser/resources/option
Denis Kuznetsov (DE-MUC) 2012/04/09 11:21:30 Done.
Nikita (slow) 2012/04/09 12:18:49 Ok, so it won't treat this as edit. Nm.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * @fileoverview This file contains methods that allow to tweak
+ * internal page UI based on the status of current user (owner/user/guest).
+ * It is assumed that required data is passed via i18n strings
+ * (using templateData variable) that are filled with call to
+ * AddAccountUITweaksLocalizedValues in ui_account_tweaks.cc.
+ * It is also assumed that tweaked page has chrome://resources/css/widgets.css
+ * included.
+ */
+
+cr.define('uiAccountTweaks', function() {
+
+ /////////////////////////////////////////////////////////////////////////////
+ // UIAccountTweaks class:
+
+ /**
+ * Encapsulated handling of ChromeOS accounts options page.
+ * @constructor
+ */
+ function UIAccountTweaks() {
+ }
+
+ /**
+ * Returns whether the current user is owner or not.
+ */
+ UIAccountTweaks.currentUserIsOwner = function() {
+ return templateData['currentUserIsOwner'] == 'true';
+ };
+
+ /**
+ * Returns whether we're currently in guest mode.
+ */
+ UIAccountTweaks.loggedInAsGuest = function() {
+ return templateData['loggedInAsGuest'] == 'true';
+ };
+
+ /**
+ * 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.
+ */
+ UIAccountTweaks.applyGuestModeVisibility = function(document) {
+ if (!cr.isChromeOS || !UIAccountTweaks.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') {
+ UIAccountTweaks.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.
+ */
+ UIAccountTweaks.disableElementsForGuest = function(element) {
+ UIAccountTweaks.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) {
+ UIAccountTweaks.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.
+ */
+ UIAccountTweaks.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') {
+ console.log(element);
+ element.onclick = function() {
+ return false;
+ };
+ }
+ };
+
+ // Export
+ return {
+ UIAccountTweaks: UIAccountTweaks
+ };
+
+});

Powered by Google App Engine
This is Rietveld 408576698