summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-22 18:50:57 +0000
committerakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-22 18:50:57 +0000
commit6d3eb2e4c787bce698ede74ced0dd8cae69cadc8 (patch)
tree682f8802132f1eb040fc6a6bc3990111bfe6f7dc /chrome/browser
parente521565fe8c0611559a7b289b8d923a79b5871d0 (diff)
downloadchromium_src-6d3eb2e4c787bce698ede74ced0dd8cae69cadc8.zip
chromium_src-6d3eb2e4c787bce698ede74ced0dd8cae69cadc8.tar.gz
chromium_src-6d3eb2e4c787bce698ede74ced0dd8cae69cadc8.tar.bz2
[Themes] Add UsingNativeTheme() method to ThemeService
Remove GtkThemeInstalledInfobarDelegate and make ThemeInstalledInfobarDelegate use UsingNativeTheme(). Make some sync code use UsingNativeTheme(). BUG=80197 TEST= Review URL: http://codereview.chromium.org/6883129 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82680 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/extensions/extension_install_ui.cc34
-rw-r--r--chrome/browser/extensions/extension_install_ui.h6
-rw-r--r--chrome/browser/extensions/gtk_theme_installed_infobar_delegate.cc25
-rw-r--r--chrome/browser/extensions/gtk_theme_installed_infobar_delegate.h30
-rw-r--r--chrome/browser/extensions/theme_installed_infobar_delegate.cc10
-rw-r--r--chrome/browser/extensions/theme_installed_infobar_delegate.h4
-rw-r--r--chrome/browser/sync/glue/theme_util.cc18
-rw-r--r--chrome/browser/sync/glue/theme_util_unittest.cc2
-rw-r--r--chrome/browser/themes/theme_service.cc6
-rw-r--r--chrome/browser/themes/theme_service.h6
-rw-r--r--chrome/browser/ui/gtk/gtk_theme_service.cc8
-rw-r--r--chrome/browser/ui/gtk/gtk_theme_service.h6
12 files changed, 50 insertions, 105 deletions
diff --git a/chrome/browser/extensions/extension_install_ui.cc b/chrome/browser/extensions/extension_install_ui.cc
index bfed0be..912b8cf 100644
--- a/chrome/browser/extensions/extension_install_ui.cc
+++ b/chrome/browser/extensions/extension_install_ui.cc
@@ -17,6 +17,7 @@
#include "chrome/browser/platform_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/tabs/tab_strip_model.h"
+#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_dialogs.h"
@@ -34,11 +35,6 @@
#include "grit/theme_resources.h"
#include "ui/base/l10n/l10n_util.h"
-#if defined(TOOLKIT_GTK)
-#include "chrome/browser/extensions/gtk_theme_installed_infobar_delegate.h"
-#include "chrome/browser/ui/gtk/gtk_theme_service.h"
-#endif
-
// static
const int ExtensionInstallUI::kTitleIds[NUM_PROMPT_TYPES] = {
IDS_EXTENSION_INSTALL_PROMPT_TITLE,
@@ -92,7 +88,7 @@ void ShowAppInstalledAnimation(Browser* browser, const std::string& app_id) {
ExtensionInstallUI::ExtensionInstallUI(Profile* profile)
: profile_(profile),
ui_loop_(MessageLoop::current()),
- previous_use_system_theme_(false),
+ previous_using_native_theme_(false),
extension_(NULL),
delegate_(NULL),
prompt_type_(NUM_PROMPT_TYPES),
@@ -103,14 +99,8 @@ ExtensionInstallUI::ExtensionInstallUI(Profile* profile)
ThemeServiceFactory::GetThemeForProfile(profile_);
if (previous_theme)
previous_theme_id_ = previous_theme->id();
-#if defined(TOOLKIT_GTK)
- // On Linux, we also need to take the user's system settings into account
- // to undo theme installation.
- previous_use_system_theme_ =
- GtkThemeService::GetFrom(profile_)->UseGtkTheme();
-#else
- DCHECK(!previous_use_system_theme_);
-#endif
+ previous_using_native_theme_ =
+ ThemeServiceFactory::GetForProfile(profile_)->UsingNativeTheme();
}
}
@@ -149,7 +139,7 @@ void ExtensionInstallUI::OnInstallSuccess(const Extension* extension,
SetIcon(icon);
if (extension->is_theme()) {
- ShowThemeInfoBar(previous_theme_id_, previous_use_system_theme_,
+ ShowThemeInfoBar(previous_theme_id_, previous_using_native_theme_,
extension, profile_);
return;
}
@@ -216,7 +206,7 @@ void ExtensionInstallUI::OnImageLoaded(
}
void ExtensionInstallUI::ShowThemeInfoBar(const std::string& previous_theme_id,
- bool previous_use_system_theme,
+ bool previous_using_native_theme,
const Extension* new_theme,
Profile* profile) {
if (!new_theme->is_theme())
@@ -252,7 +242,7 @@ void ExtensionInstallUI::ShowThemeInfoBar(const std::string& previous_theme_id,
// Then either replace that old one or add a new one.
InfoBarDelegate* new_delegate = GetNewThemeInstalledInfoBarDelegate(
- tab_contents, new_theme, previous_theme_id, previous_use_system_theme);
+ tab_contents, new_theme, previous_theme_id, previous_using_native_theme);
if (old_delegate)
tab_contents->ReplaceInfoBar(old_delegate, new_delegate);
@@ -275,12 +265,8 @@ InfoBarDelegate* ExtensionInstallUI::GetNewThemeInstalledInfoBarDelegate(
TabContents* tab_contents,
const Extension* new_theme,
const std::string& previous_theme_id,
- bool previous_use_system_theme) {
-#if defined(TOOLKIT_GTK)
- return new GtkThemeInstalledInfoBarDelegate(tab_contents, new_theme,
- previous_theme_id, previous_use_system_theme);
-#else
+ bool previous_using_native_theme) {
return new ThemeInstalledInfoBarDelegate(tab_contents, new_theme,
- previous_theme_id);
-#endif
+ previous_theme_id,
+ previous_using_native_theme);
}
diff --git a/chrome/browser/extensions/extension_install_ui.h b/chrome/browser/extensions/extension_install_ui.h
index bdafa5a..13974be 100644
--- a/chrome/browser/extensions/extension_install_ui.h
+++ b/chrome/browser/extensions/extension_install_ui.h
@@ -79,7 +79,7 @@ class ExtensionInstallUI : public ImageLoadingTracker::Observer {
// should be empty if the previous theme was the system/default
// theme.
static void ShowThemeInfoBar(
- const std::string& previous_theme_id, bool previous_use_system_theme,
+ const std::string& previous_theme_id, bool previous_using_native_theme,
const Extension* new_theme, Profile* profile);
// Sets the icon that will be used in any UI. If |icon| is NULL, or contains
@@ -97,14 +97,14 @@ class ExtensionInstallUI : public ImageLoadingTracker::Observer {
TabContents* tab_contents,
const Extension* new_theme,
const std::string& previous_theme_id,
- bool previous_use_system_theme);
+ bool previous_using_native_theme);
Profile* profile_;
MessageLoop* ui_loop_;
// Used to undo theme installation.
std::string previous_theme_id_;
- bool previous_use_system_theme_;
+ bool previous_using_native_theme_;
// The extensions installation icon.
SkBitmap icon_;
diff --git a/chrome/browser/extensions/gtk_theme_installed_infobar_delegate.cc b/chrome/browser/extensions/gtk_theme_installed_infobar_delegate.cc
deleted file mode 100644
index 385f2c4..0000000
--- a/chrome/browser/extensions/gtk_theme_installed_infobar_delegate.cc
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright (c) 2011 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/extensions/gtk_theme_installed_infobar_delegate.h"
-
-#include "chrome/browser/themes/theme_service.h"
-
-GtkThemeInstalledInfoBarDelegate::GtkThemeInstalledInfoBarDelegate(
- TabContents* tab_contents,
- const Extension* new_theme,
- const std::string& previous_theme_id,
- bool previous_use_gtk_theme)
- : ThemeInstalledInfoBarDelegate(tab_contents, new_theme, previous_theme_id),
- previous_use_gtk_theme_(previous_use_gtk_theme) {
-}
-
-bool GtkThemeInstalledInfoBarDelegate::Cancel() {
- if (previous_use_gtk_theme_) {
- theme_service()->SetNativeTheme();
- return true;
- } else {
- return ThemeInstalledInfoBarDelegate::Cancel();
- }
-}
diff --git a/chrome/browser/extensions/gtk_theme_installed_infobar_delegate.h b/chrome/browser/extensions/gtk_theme_installed_infobar_delegate.h
deleted file mode 100644
index 6fd7f72..0000000
--- a/chrome/browser/extensions/gtk_theme_installed_infobar_delegate.h
+++ /dev/null
@@ -1,30 +0,0 @@
-// 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_EXTENSIONS_GTK_THEME_INSTALLED_INFOBAR_DELEGATE_H_
-#define CHROME_BROWSER_EXTENSIONS_GTK_THEME_INSTALLED_INFOBAR_DELEGATE_H_
-#pragma once
-
-#include "chrome/browser/extensions/theme_installed_infobar_delegate.h"
-
-#include <string>
-
-class Extension;
-class TabContents;
-
-// A specialization of ThemeInstalledInfoBarDelegate to make "Undo" reset to the
-// GTK theme if the user was in GTK theme mode before installing the theme.
-class GtkThemeInstalledInfoBarDelegate : public ThemeInstalledInfoBarDelegate {
- public:
- GtkThemeInstalledInfoBarDelegate(TabContents* tab_contents,
- const Extension* new_theme,
- const std::string& previous_theme_id,
- bool previous_use_gtk_theme);
- virtual bool Cancel();
-
- private:
- bool previous_use_gtk_theme_;
-};
-
-#endif // CHROME_BROWSER_EXTENSIONS_GTK_THEME_INSTALLED_INFOBAR_DELEGATE_H_
diff --git a/chrome/browser/extensions/theme_installed_infobar_delegate.cc b/chrome/browser/extensions/theme_installed_infobar_delegate.cc
index 822f42e..45c7524 100644
--- a/chrome/browser/extensions/theme_installed_infobar_delegate.cc
+++ b/chrome/browser/extensions/theme_installed_infobar_delegate.cc
@@ -22,13 +22,15 @@
ThemeInstalledInfoBarDelegate::ThemeInstalledInfoBarDelegate(
TabContents* tab_contents,
const Extension* new_theme,
- const std::string& previous_theme_id)
+ const std::string& previous_theme_id,
+ bool previous_using_native_theme)
: ConfirmInfoBarDelegate(tab_contents),
profile_(tab_contents->profile()),
theme_service_(ThemeServiceFactory::GetForProfile(profile_)),
name_(new_theme->name()),
theme_id_(new_theme->id()),
previous_theme_id_(previous_theme_id),
+ previous_using_native_theme_(previous_using_native_theme),
tab_contents_(tab_contents) {
theme_service_->OnInfobarDisplayed();
registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
@@ -59,7 +61,11 @@ bool ThemeInstalledInfoBarDelegate::Cancel() {
}
}
- theme_service_->UseDefaultTheme();
+ if (previous_using_native_theme_) {
+ theme_service_->SetNativeTheme();
+ } else {
+ theme_service_->UseDefaultTheme();
+ }
return true;
}
diff --git a/chrome/browser/extensions/theme_installed_infobar_delegate.h b/chrome/browser/extensions/theme_installed_infobar_delegate.h
index b21395f..bbde65c 100644
--- a/chrome/browser/extensions/theme_installed_infobar_delegate.h
+++ b/chrome/browser/extensions/theme_installed_infobar_delegate.h
@@ -21,7 +21,8 @@ class ThemeInstalledInfoBarDelegate : public ConfirmInfoBarDelegate,
public:
ThemeInstalledInfoBarDelegate(TabContents* tab_contents,
const Extension* new_theme,
- const std::string& previous_theme_id);
+ const std::string& previous_theme_id,
+ bool previous_using_native_theme);
// Returns true if the given theme is the same as the one associated with this
// info bar.
@@ -60,6 +61,7 @@ class ThemeInstalledInfoBarDelegate : public ConfirmInfoBarDelegate,
// Used to undo theme install.
std::string previous_theme_id_;
+ bool previous_using_native_theme_;
// Tab to which this info bar is associated.
TabContents* tab_contents_;
diff --git a/chrome/browser/sync/glue/theme_util.cc b/chrome/browser/sync/glue/theme_util.cc
index 2b47885..c17ea3d 100644
--- a/chrome/browser/sync/glue/theme_util.cc
+++ b/chrome/browser/sync/glue/theme_util.cc
@@ -10,9 +10,6 @@
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_updater.h"
-#if defined(TOOLKIT_USES_GTK)
-#include "chrome/browser/ui/gtk/gtk_theme_service.h"
-#endif
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/protocol/theme_specifics.pb.h"
#include "chrome/browser/themes/theme_service.h"
@@ -27,6 +24,7 @@ const char kCurrentThemeClientTag[] = "current_theme";
namespace {
+// TODO(akalin): Remove this.
bool IsSystemThemeDistinctFromDefaultTheme() {
#if defined(TOOLKIT_USES_GTK)
return true;
@@ -35,14 +33,6 @@ bool IsSystemThemeDistinctFromDefaultTheme() {
#endif
}
-bool UseSystemTheme(Profile* profile) {
-#if defined(TOOLKIT_USES_GTK)
- return GtkThemeService::GetFrom(profile)->UseGtkTheme();
-#else
- return false;
-#endif
-}
-
} // namespace
bool AreThemeSpecificsEqual(const sync_pb::ThemeSpecifics& a,
@@ -131,7 +121,7 @@ bool UpdateThemeSpecificsOrSetCurrentThemeIfNecessary(
Profile* profile, sync_pb::ThemeSpecifics* theme_specifics) {
if (!theme_specifics->use_custom_theme() &&
(ThemeServiceFactory::GetThemeForProfile(profile) ||
- (UseSystemTheme(profile) &&
+ (ThemeServiceFactory::GetForProfile(profile)->UsingNativeTheme() &&
IsSystemThemeDistinctFromDefaultTheme()))) {
GetThemeSpecificsFromCurrentTheme(profile, theme_specifics);
return true;
@@ -153,7 +143,7 @@ void GetThemeSpecificsFromCurrentTheme(
GetThemeSpecificsFromCurrentThemeHelper(
current_theme,
IsSystemThemeDistinctFromDefaultTheme(),
- UseSystemTheme(profile),
+ ThemeServiceFactory::GetForProfile(profile)->UsingNativeTheme(),
theme_specifics);
}
@@ -167,8 +157,6 @@ void GetThemeSpecificsFromCurrentThemeHelper(
if (is_system_theme_distinct_from_default_theme) {
theme_specifics->set_use_system_theme_by_default(
use_system_theme_by_default);
- } else {
- DCHECK(!use_system_theme_by_default);
}
if (use_custom_theme) {
DCHECK(current_theme);
diff --git a/chrome/browser/sync/glue/theme_util_unittest.cc b/chrome/browser/sync/glue/theme_util_unittest.cc
index d72eb4a..7afe2c6 100644
--- a/chrome/browser/sync/glue/theme_util_unittest.cc
+++ b/chrome/browser/sync/glue/theme_util_unittest.cc
@@ -20,6 +20,7 @@ namespace browser_sync {
namespace {
+using ::testing::AnyNumber;
using ::testing::Return;
class ThemeUtilTest : public testing::Test {
@@ -222,6 +223,7 @@ TEST_F(ThemeUtilTest, SetCurrentThemeIfNecessaryDefaultThemeNotNecessary) {
EXPECT_CALL(*mock_theme_service, GetThemeID()).WillRepeatedly(Return(
ThemeService::kDefaultThemeID));
+ EXPECT_CALL(*mock_theme_service, UseDefaultTheme()).Times(AnyNumber());
// TODO(akalin): Mock out call to GetPrefs() under TOOLKIT_USES_GTK.
diff --git a/chrome/browser/themes/theme_service.cc b/chrome/browser/themes/theme_service.cc
index 132208f..a23a013 100644
--- a/chrome/browser/themes/theme_service.cc
+++ b/chrome/browser/themes/theme_service.cc
@@ -346,12 +346,16 @@ void ThemeService::SetNativeTheme() {
UseDefaultTheme();
}
-bool ThemeService::UsingDefaultTheme() {
+bool ThemeService::UsingDefaultTheme() const {
std::string id = GetThemeID();
return id == ThemeService::kDefaultThemeID ||
id == kDefaultThemeGalleryID;
}
+bool ThemeService::UsingNativeTheme() const {
+ return UsingDefaultTheme();
+}
+
std::string ThemeService::GetThemeID() const {
return profile_->GetPrefs()->GetString(prefs::kCurrentThemeID);
}
diff --git a/chrome/browser/themes/theme_service.h b/chrome/browser/themes/theme_service.h
index c4f5df2..de9f59e 100644
--- a/chrome/browser/themes/theme_service.h
+++ b/chrome/browser/themes/theme_service.h
@@ -172,7 +172,11 @@ class ThemeService : public base::NonThreadSafe,
// Whether we're using the chrome default theme. Virtual so linux can check
// if we're using the GTK theme.
- virtual bool UsingDefaultTheme();
+ virtual bool UsingDefaultTheme() const;
+
+ // Whether we're using the native theme (which may or may not be the
+ // same as the default theme).
+ virtual bool UsingNativeTheme() const;
// Gets the id of the last installed theme. (The theme may have been further
// locally customized.)
diff --git a/chrome/browser/ui/gtk/gtk_theme_service.cc b/chrome/browser/ui/gtk/gtk_theme_service.cc
index ced0710..4ca5c9b 100644
--- a/chrome/browser/ui/gtk/gtk_theme_service.cc
+++ b/chrome/browser/ui/gtk/gtk_theme_service.cc
@@ -352,10 +352,14 @@ void GtkThemeService::SetNativeTheme() {
NotifyThemeChanged();
}
-bool GtkThemeService::UsingDefaultTheme() {
+bool GtkThemeService::UsingDefaultTheme() const {
return !use_gtk_ && ThemeService::UsingDefaultTheme();
}
+bool GtkThemeService::UsingNativeTheme() const {
+ return use_gtk_;
+}
+
void GtkThemeService::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
@@ -390,7 +394,7 @@ GtkWidget* GtkThemeService::CreateToolbarSeparator() {
}
bool GtkThemeService::UseGtkTheme() const {
- return use_gtk_;
+ return UsingNativeTheme();
}
GdkColor GtkThemeService::GetGdkColor(int id) const {
diff --git a/chrome/browser/ui/gtk/gtk_theme_service.h b/chrome/browser/ui/gtk/gtk_theme_service.h
index 1206546..127a04d 100644
--- a/chrome/browser/ui/gtk/gtk_theme_service.h
+++ b/chrome/browser/ui/gtk/gtk_theme_service.h
@@ -56,7 +56,8 @@ class GtkThemeService : public ThemeService {
virtual void SetTheme(const Extension* extension);
virtual void UseDefaultTheme();
virtual void SetNativeTheme();
- virtual bool UsingDefaultTheme();
+ virtual bool UsingDefaultTheme() const;
+ virtual bool UsingNativeTheme() const;
// Overridden from ThemeService, NotificationObserver:
virtual void Observe(NotificationType type,
@@ -72,6 +73,9 @@ class GtkThemeService : public ThemeService {
GtkWidget* CreateToolbarSeparator();
// Whether we should use the GTK system theme.
+ //
+ // TODO(akalin): Make all callers use UsingNativeTheme() instead and
+ // remove this.
bool UseGtkTheme() const;
// A wrapper around ui::ThemeProvider::GetColor, transforming the result to a