summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authormnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-08 09:55:47 +0000
committermnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-08 09:55:47 +0000
commit1703157a0410dbd23b8968aa8e6ce9e4adc45def (patch)
treeef2744a079dd79302e9e334c47bf227341243c94 /chrome/browser
parentc7f143e3f200aa626af2e29fec1f801081b2e31a (diff)
downloadchromium_src-1703157a0410dbd23b8968aa8e6ce9e4adc45def.zip
chromium_src-1703157a0410dbd23b8968aa8e6ce9e4adc45def.tar.gz
chromium_src-1703157a0410dbd23b8968aa8e6ce9e4adc45def.tar.bz2
Managed preferences warning banner for the Linux preferences dialog.
BUG=43423 TEST=Unit test in managed_prefs_banner_base_unittest.cc, manual UI tests Review URL: http://codereview.chromium.org/2425006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49151 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/gtk/options/general_page_gtk.cc15
-rw-r--r--chrome/browser/gtk/options/general_page_gtk.h4
-rw-r--r--chrome/browser/gtk/options/managed_prefs_banner_gtk.cc51
-rw-r--r--chrome/browser/gtk/options/managed_prefs_banner_gtk.h39
-rw-r--r--chrome/browser/gtk/options/options_layout_gtk.cc6
-rw-r--r--chrome/browser/gtk/options/options_layout_gtk.h11
-rw-r--r--chrome/browser/managed_prefs_banner_base.cc47
-rw-r--r--chrome/browser/managed_prefs_banner_base.h47
-rw-r--r--chrome/browser/managed_prefs_banner_base_unittest.cc66
9 files changed, 279 insertions, 7 deletions
diff --git a/chrome/browser/gtk/options/general_page_gtk.cc b/chrome/browser/gtk/options/general_page_gtk.cc
index e0778dc..3919232 100644
--- a/chrome/browser/gtk/options/general_page_gtk.cc
+++ b/chrome/browser/gtk/options/general_page_gtk.cc
@@ -14,6 +14,7 @@
#include "chrome/browser/gtk/accessible_widget_helper_gtk.h"
#include "chrome/browser/gtk/gtk_util.h"
#include "chrome/browser/gtk/keyword_editor_view.h"
+#include "chrome/browser/gtk/options/managed_prefs_banner_gtk.h"
#include "chrome/browser/gtk/options/options_layout_gtk.h"
#include "chrome/browser/gtk/options/url_picker_dialog_gtk.h"
#include "chrome/browser/net/url_fixer_upper.h"
@@ -54,6 +55,12 @@ enum {
SEARCH_ENGINES_COL_COUNT,
};
+// Set of preferences which might be unavailable for editing when managed.
+const wchar_t* kGeneralManagablePrefs[] = {
+ prefs::kHomePage,
+ prefs::kHomePageIsNewTabPage
+};
+
} // namespace
///////////////////////////////////////////////////////////////////////////////
@@ -65,12 +72,14 @@ GeneralPageGtk::GeneralPageGtk(Profile* profile)
default_search_initializing_(true),
initializing_(true),
default_browser_worker_(
- new ShellIntegration::DefaultBrowserWorker(this)) {
+ new ShellIntegration::DefaultBrowserWorker(this)),
+ managed_prefs_banner_(profile->GetPrefs(), kGeneralManagablePrefs,
+ arraysize(kGeneralManagablePrefs)) {
OptionsLayoutBuilderGtk options_builder;
page_ = options_builder.get_page_widget();
- accessible_widget_helper_.reset(new AccessibleWidgetHelper(
- page_, profile));
+ accessible_widget_helper_.reset(new AccessibleWidgetHelper(page_, profile));
+ options_builder.AddWidget(managed_prefs_banner_.banner_widget(), false);
options_builder.AddOptionGroup(
l10n_util::GetStringUTF8(IDS_OPTIONS_STARTUP_GROUP_NAME),
InitStartupGroup(), true);
diff --git a/chrome/browser/gtk/options/general_page_gtk.h b/chrome/browser/gtk/options/general_page_gtk.h
index 10ec4c8..e2d0629 100644
--- a/chrome/browser/gtk/options/general_page_gtk.h
+++ b/chrome/browser/gtk/options/general_page_gtk.h
@@ -11,6 +11,7 @@
#include "app/gtk_signal.h"
#include "chrome/browser/gtk/gtk_tree.h"
+#include "chrome/browser/gtk/options/managed_prefs_banner_gtk.h"
#include "chrome/browser/options_page_base.h"
#include "chrome/browser/pref_member.h"
#include "chrome/browser/search_engines/template_url_model.h"
@@ -150,6 +151,9 @@ class GeneralPageGtk : public OptionsPageBase,
// Helper object to manage accessibility metadata.
scoped_ptr<AccessibleWidgetHelper> accessible_widget_helper_;
+ // Tracks managed preference warning banner state.
+ ManagedPrefsBannerGtk managed_prefs_banner_;
+
DISALLOW_COPY_AND_ASSIGN(GeneralPageGtk);
};
diff --git a/chrome/browser/gtk/options/managed_prefs_banner_gtk.cc b/chrome/browser/gtk/options/managed_prefs_banner_gtk.cc
new file mode 100644
index 0000000..71e3309
--- /dev/null
+++ b/chrome/browser/gtk/options/managed_prefs_banner_gtk.cc
@@ -0,0 +1,51 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/gtk/options/managed_prefs_banner_gtk.h"
+
+#include "app/l10n_util.h"
+#include "app/resource_bundle.h"
+#include "chrome/browser/gtk/gtk_theme_provider.h"
+#include "chrome/browser/gtk/gtk_util.h"
+#include "grit/generated_resources.h"
+
+namespace {
+
+// Padding within the banner box.
+const int kBannerPadding = 3;
+
+}
+
+ManagedPrefsBannerGtk::ManagedPrefsBannerGtk(PrefService* prefs,
+ const wchar_t** relevant_prefs,
+ size_t count)
+ : ManagedPrefsBannerBase(prefs, relevant_prefs, count),
+ banner_widget_(NULL) {
+ InitWidget();
+ OnUpdateVisibility();
+}
+
+void ManagedPrefsBannerGtk::InitWidget() {
+ banner_widget_ = gtk_frame_new(NULL);
+ GtkWidget* contents = gtk_hbox_new(FALSE, kBannerPadding);
+ gtk_container_set_border_width(GTK_CONTAINER(contents), kBannerPadding);
+ gtk_container_add(GTK_CONTAINER(banner_widget_), contents);
+ GtkWidget* warning_image =
+ gtk_image_new_from_stock(GTK_STOCK_DIALOG_WARNING,
+ GTK_ICON_SIZE_SMALL_TOOLBAR);
+ gtk_box_pack_start(GTK_BOX(contents), warning_image, FALSE, FALSE, 0);
+ std::string info_text(l10n_util::GetStringUTF8(IDS_OPTIONS_MANAGED_PREFS));
+ GtkWidget* info_label = gtk_label_new(info_text.c_str());
+ gtk_box_pack_start(GTK_BOX(contents), info_label, FALSE, FALSE, 0);
+ gtk_widget_show_all(banner_widget_);
+ gtk_widget_set_no_show_all(GTK_WIDGET(banner_widget_), TRUE);
+}
+
+void ManagedPrefsBannerGtk::OnUpdateVisibility() {
+ DCHECK(banner_widget_);
+ if (DetermineVisibility())
+ gtk_widget_show(banner_widget_);
+ else
+ gtk_widget_hide(banner_widget_);
+}
diff --git a/chrome/browser/gtk/options/managed_prefs_banner_gtk.h b/chrome/browser/gtk/options/managed_prefs_banner_gtk.h
new file mode 100644
index 0000000..5007d98
--- /dev/null
+++ b/chrome/browser/gtk/options/managed_prefs_banner_gtk.h
@@ -0,0 +1,39 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_GTK_OPTIONS_MANAGED_PREFS_BANNER_GTK_H_
+#define CHROME_BROWSER_GTK_OPTIONS_MANAGED_PREFS_BANNER_GTK_H_
+
+#include <set>
+
+#include <gtk/gtk.h>
+
+#include "chrome/browser/managed_prefs_banner_base.h"
+
+// Constructs and maintains a GTK widget displaying a warning banner. The banner
+// is displayed on the preferences dialog whenever there are options that are
+// not settable by the user due to policy.
+class ManagedPrefsBannerGtk : public ManagedPrefsBannerBase {
+ public:
+ ManagedPrefsBannerGtk(PrefService* prefs,
+ const wchar_t** relevant_prefs,
+ size_t count);
+ virtual ~ManagedPrefsBannerGtk() { }
+
+ GtkWidget* banner_widget() { return banner_widget_; }
+
+ protected:
+ // Update widget visibility.
+ virtual void OnUpdateVisibility();
+
+ private:
+ // Construct the widget.
+ void InitWidget();
+
+ GtkWidget* banner_widget_;
+
+ DISALLOW_COPY_AND_ASSIGN(ManagedPrefsBannerGtk);
+};
+
+#endif // CHROME_BROWSER_GTK_OPTIONS_MANAGED_PREFS_BANNER_GTK_H_
diff --git a/chrome/browser/gtk/options/options_layout_gtk.cc b/chrome/browser/gtk/options/options_layout_gtk.cc
index 07fe2e1..c4a6e60 100644
--- a/chrome/browser/gtk/options/options_layout_gtk.cc
+++ b/chrome/browser/gtk/options/options_layout_gtk.cc
@@ -21,5 +21,9 @@ void OptionsLayoutBuilderGtk::AddOptionGroup(const std::string& title,
gtk_box_pack_start(GTK_BOX(group), title_label, FALSE, FALSE, 0);
gtk_container_add(GTK_CONTAINER(group), gtk_util::IndentWidget(content));
- gtk_box_pack_start(GTK_BOX(page_), group, expandable, expandable, 0);
+ AddWidget(group, expandable);
+}
+
+void OptionsLayoutBuilderGtk::AddWidget(GtkWidget* content, bool expandable) {
+ gtk_box_pack_start(GTK_BOX(page_), content, expandable, expandable, 0);
}
diff --git a/chrome/browser/gtk/options/options_layout_gtk.h b/chrome/browser/gtk/options/options_layout_gtk.h
index c4fedc6..0d397c0 100644
--- a/chrome/browser/gtk/options/options_layout_gtk.h
+++ b/chrome/browser/gtk/options/options_layout_gtk.h
@@ -18,12 +18,17 @@ class OptionsLayoutBuilderGtk {
return page_;
}
- // Adds an option group to the table. Handles layout and the placing of
- // separators between groups. If expandable is true, the content widget will
- // be allowed to expand and fill any extra space when the dialog is resized.
+ // Adds an option group to the table. Handles layout and labels the group
+ // with the given title. If expandable is true, the content widget will be
+ // allowed to expand and fill any extra space when the dialog is resized.
void AddOptionGroup(const std::string& title, GtkWidget* content,
bool expandable);
+ // Adds a widget without title or special layout. If expandable is true, the
+ // content widget will be allowed to expand and fill any extra space when the
+ // dialog is resized.
+ void AddWidget(GtkWidget* content, bool expandable);
+
private:
// The parent widget
GtkWidget* page_;
diff --git a/chrome/browser/managed_prefs_banner_base.cc b/chrome/browser/managed_prefs_banner_base.cc
new file mode 100644
index 0000000..5251d7f
--- /dev/null
+++ b/chrome/browser/managed_prefs_banner_base.cc
@@ -0,0 +1,47 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/managed_prefs_banner_base.h"
+
+#include "chrome/browser/pref_service.h"
+#include "chrome/common/notification_details.h"
+#include "chrome/common/notification_source.h"
+#include "chrome/common/notification_type.h"
+
+ManagedPrefsBannerBase::ManagedPrefsBannerBase(PrefService* prefs,
+ const wchar_t** relevant_prefs,
+ size_t count)
+ : prefs_(prefs),
+ relevant_prefs_(relevant_prefs, relevant_prefs + count) {
+ for (PrefSet::const_iterator pref(relevant_prefs_.begin());
+ pref != relevant_prefs_.end(); ++pref)
+ prefs_->AddPrefObserver(pref->c_str(), this);
+}
+
+ManagedPrefsBannerBase::~ManagedPrefsBannerBase() {
+ for (PrefSet::const_iterator pref(relevant_prefs_.begin());
+ pref != relevant_prefs_.end(); ++pref)
+ prefs_->RemovePrefObserver(pref->c_str(), this);
+}
+
+void ManagedPrefsBannerBase::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (NotificationType::PREF_CHANGED == type) {
+ std::wstring* pref = Details<std::wstring>(details).ptr();
+ if (pref && relevant_prefs_.count(*pref))
+ OnUpdateVisibility();
+ }
+}
+
+bool ManagedPrefsBannerBase::DetermineVisibility() const {
+ for (PrefSet::const_iterator pref_name(relevant_prefs_.begin());
+ pref_name != relevant_prefs_.end(); ++pref_name) {
+ const PrefService::Preference* pref =
+ prefs_->FindPreference(pref_name->c_str());
+ if (pref && pref->IsManaged())
+ return true;
+ }
+ return false;
+}
diff --git a/chrome/browser/managed_prefs_banner_base.h b/chrome/browser/managed_prefs_banner_base.h
new file mode 100644
index 0000000..f0013ca
--- /dev/null
+++ b/chrome/browser/managed_prefs_banner_base.h
@@ -0,0 +1,47 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_MANAGED_PREFS_BANNER_BASE_H_
+#define CHROME_BROWSER_MANAGED_PREFS_BANNER_BASE_H_
+
+#include <set>
+#include <string>
+
+#include "base/basictypes.h"
+#include "chrome/common/notification_observer.h"
+
+class PrefService;
+
+// Common base functionality for the managed prefs warning banner displayed in
+// the preference dialogs when there are options that are controlled by
+// configuration policy and thus cannot be changed by the user.
+class ManagedPrefsBannerBase : public NotificationObserver {
+ public:
+ ManagedPrefsBannerBase(PrefService* prefs,
+ const wchar_t** relevant_prefs,
+ size_t count);
+ virtual ~ManagedPrefsBannerBase();
+
+ // Determine whether the banner should be visible.
+ bool DetermineVisibility() const;
+
+ // |NotificationObserver| implementation.
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
+ protected:
+ // Update banner visibility. This is called whenever a preference change is
+ // observed that may lead to changed visibility of the banner. Subclasses may
+ // override this in order to show/hide the banner.
+ virtual void OnUpdateVisibility() { }
+
+ private:
+ PrefService* prefs_;
+ typedef std::set<std::wstring> PrefSet;
+ const PrefSet relevant_prefs_;
+
+ DISALLOW_COPY_AND_ASSIGN(ManagedPrefsBannerBase);
+};
+#endif // CHROME_BROWSER_MANAGED_PREFS_BANNER_BASE_H_
diff --git a/chrome/browser/managed_prefs_banner_base_unittest.cc b/chrome/browser/managed_prefs_banner_base_unittest.cc
new file mode 100644
index 0000000..d11bbc1
--- /dev/null
+++ b/chrome/browser/managed_prefs_banner_base_unittest.cc
@@ -0,0 +1,66 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/dummy_pref_store.h"
+#include "chrome/browser/managed_prefs_banner_base.h"
+#include "chrome/browser/pref_service.h"
+#include "chrome/common/pref_names.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+// Tests whether managed preferences banner base functionality correctly
+// determines banner visiblity.
+class ManagedPrefsBannerBaseTest : public testing::Test {
+ public:
+ virtual void SetUp() {
+ managed_prefs_ = new DummyPrefStore;
+ user_prefs_ = new DummyPrefStore;
+ default_prefs_ = new DummyPrefStore;
+ pref_service_.reset(new PrefService(
+ new PrefValueStore(managed_prefs_, user_prefs_, default_prefs_)));
+ pref_service_->RegisterStringPref(prefs::kHomePage, L"http://google.com");
+ pref_service_->RegisterBooleanPref(prefs::kHomePageIsNewTabPage, false);
+ }
+
+ scoped_ptr<PrefService> pref_service_;
+ DummyPrefStore* managed_prefs_;
+ DummyPrefStore* user_prefs_;
+ DummyPrefStore* default_prefs_;
+};
+
+static const wchar_t* managed_prefs[] = {
+ prefs::kHomePage
+};
+
+TEST_F(ManagedPrefsBannerBaseTest, VisibilityTest) {
+ ManagedPrefsBannerBase banner(pref_service_.get(), managed_prefs,
+ arraysize(managed_prefs));
+ EXPECT_FALSE(banner.DetermineVisibility());
+ managed_prefs_->prefs()->SetBoolean(prefs::kHomePageIsNewTabPage, true);
+ EXPECT_FALSE(banner.DetermineVisibility());
+ user_prefs_->prefs()->SetString(prefs::kHomePage, L"http://foo.com");
+ EXPECT_FALSE(banner.DetermineVisibility());
+ managed_prefs_->prefs()->SetString(prefs::kHomePage, L"http://bar.com");
+ EXPECT_TRUE(banner.DetermineVisibility());
+}
+
+// Mock class that allows to capture the notification callback.
+class ManagedPrefsBannerBaseMock : public ManagedPrefsBannerBase {
+ public:
+ ManagedPrefsBannerBaseMock(PrefService* pref_service,
+ const wchar_t** relevant_prefs,
+ size_t count)
+ : ManagedPrefsBannerBase(pref_service, relevant_prefs, count) { }
+
+ MOCK_METHOD0(OnUpdateVisibility, void());
+};
+
+TEST_F(ManagedPrefsBannerBaseTest, NotificationTest) {
+ ManagedPrefsBannerBaseMock banner(pref_service_.get(), managed_prefs,
+ arraysize(managed_prefs));
+ EXPECT_CALL(banner, OnUpdateVisibility()).Times(0);
+ pref_service_->SetBoolean(prefs::kHomePageIsNewTabPage, true);
+ EXPECT_CALL(banner, OnUpdateVisibility()).Times(1);
+ pref_service_->SetString(prefs::kHomePage, L"http://foo.com");
+}