summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authoravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-03 16:34:34 +0000
committeravi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-03 16:34:34 +0000
commit51c490b5cb0ff02f391e514cfa2ba892e08a2edc (patch)
treea576c2399f37016a495997786fd6d9244912944d /chrome
parentcf76214c53788effec9c2e9cf14dbfc91887921e (diff)
downloadchromium_src-51c490b5cb0ff02f391e514cfa2ba892e08a2edc.zip
chromium_src-51c490b5cb0ff02f391e514cfa2ba892e08a2edc.tar.gz
chromium_src-51c490b5cb0ff02f391e514cfa2ba892e08a2edc.tar.bz2
Implement kCurrentThemeID so we can know what the last theme to be installed was.
BUG=none TEST=not visible in UI Review URL: http://codereview.chromium.org/159705 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22270 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/browser_theme_provider.cc14
-rw-r--r--chrome/browser/browser_theme_provider.h9
-rw-r--r--chrome/browser/profile.cc17
-rw-r--r--chrome/browser/profile.h5
-rw-r--r--chrome/test/testing_profile.h3
5 files changed, 47 insertions, 1 deletions
diff --git a/chrome/browser/browser_theme_provider.cc b/chrome/browser/browser_theme_provider.cc
index 9e6b9ec..116b4d8 100644
--- a/chrome/browser/browser_theme_provider.cc
+++ b/chrome/browser/browser_theme_provider.cc
@@ -126,6 +126,9 @@ const skia::HSL BrowserThemeProvider::kDefaultTintFrameIncognitoInactive =
const skia::HSL BrowserThemeProvider::kDefaultTintBackgroundTab =
{ -1, 0.5, 0.75 };
+// Saved default values.
+const char* BrowserThemeProvider::kDefaultThemeID = "";
+
// Default display properties.
static const int kDefaultDisplayPropertyNTPAlignment =
BrowserThemeProvider::ALIGN_BOTTOM;
@@ -369,6 +372,7 @@ void BrowserThemeProvider::SetTheme(Extension* extension) {
SaveColorData();
SaveTintData();
SaveDisplayPropertyData();
+ SaveThemeID(extension->id());
NotifyThemeChanged();
UserMetrics::RecordAction(L"Themes_Installed", profile_);
@@ -380,6 +384,11 @@ void BrowserThemeProvider::UseDefaultTheme() {
UserMetrics::RecordAction(L"Themes_Reset", profile_);
}
+std::string BrowserThemeProvider::GetThemeID() {
+ std::wstring id = profile_->GetPrefs()->GetString(prefs::kCurrentThemeID);
+ return WideToUTF8(id);
+}
+
bool BrowserThemeProvider::ReadThemeFileData(
int id, std::vector<unsigned char>* raw_data) {
if (images_.count(id)) {
@@ -776,6 +785,7 @@ void BrowserThemeProvider::ClearAllThemeData() {
SaveColorData();
SaveTintData();
SaveDisplayPropertyData();
+ SaveThemeID(kDefaultThemeID);
}
SkBitmap* BrowserThemeProvider::GenerateBitmap(int id) {
@@ -905,6 +915,10 @@ void BrowserThemeProvider::SaveDisplayPropertyData() {
}
}
+void BrowserThemeProvider::SaveThemeID(const std::string& id) {
+ profile_->GetPrefs()->SetString(prefs::kCurrentThemeID, UTF8ToWide(id));
+}
+
void BrowserThemeProvider::NotifyThemeChanged() {
// Redraw!
NotificationService* service = NotificationService::current();
diff --git a/chrome/browser/browser_theme_provider.h b/chrome/browser/browser_theme_provider.h
index 63eca78..d1cd510 100644
--- a/chrome/browser/browser_theme_provider.h
+++ b/chrome/browser/browser_theme_provider.h
@@ -96,6 +96,8 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>,
static const skia::HSL kDefaultTintFrameIncognitoInactive;
static const skia::HSL kDefaultTintBackgroundTab;
+ static const char* kDefaultThemeID;
+
public:
BrowserThemeProvider();
virtual ~BrowserThemeProvider();
@@ -170,6 +172,10 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>,
// theme is the default theme.
virtual void SetNativeTheme() { UseDefaultTheme(); }
+ // Gets the id of the last installed theme. (The theme may have been further
+ // locally customized.)
+ std::string GetThemeID();
+
// Convert a bitfield alignment into a string like "top left". Public so that
// it can be used to generate CSS values. Takes a bitfield of AlignmentMasks.
static std::string AlignmentToString(int alignment);
@@ -272,6 +278,9 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>,
void SaveTintData();
void SaveDisplayPropertyData();
+ // Save the id of the last theme installed.
+ void SaveThemeID(const std::string& id);
+
SkColor FindColor(const char* id, SkColor default_color);
// Frees generated images and clears the image cache.
diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc
index dcfe530..f468bfa 100644
--- a/chrome/browser/profile.cc
+++ b/chrome/browser/profile.cc
@@ -126,7 +126,8 @@ void Profile::RegisterUserPrefs(PrefService* prefs) {
#if defined(OS_LINUX)
prefs->RegisterBooleanPref(prefs::kUsesSystemTheme, false);
#endif
- prefs->RegisterStringPref(prefs::kCurrentThemeID, L"");
+ prefs->RegisterStringPref(prefs::kCurrentThemeID,
+ UTF8ToWide(BrowserThemeProvider::kDefaultThemeID));
prefs->RegisterDictionaryPref(prefs::kCurrentThemeImages);
prefs->RegisterDictionaryPref(prefs::kCurrentThemeColors);
prefs->RegisterDictionaryPref(prefs::kCurrentThemeTints);
@@ -309,6 +310,10 @@ class OffTheRecordProfileImpl : public Profile,
GetOriginalProfile()->ClearTheme();
}
+ virtual Extension* GetTheme() {
+ return GetOriginalProfile()->GetTheme();
+ }
+
virtual ThemeProvider* GetThemeProvider() {
return GetOriginalProfile()->GetThemeProvider();
}
@@ -980,6 +985,16 @@ void ProfileImpl::ClearTheme() {
theme_provider_.get()->UseDefaultTheme();
}
+Extension* ProfileImpl::GetTheme() {
+ InitThemes();
+
+ std::string id = theme_provider_.get()->GetThemeID();
+ if (id == BrowserThemeProvider::kDefaultThemeID)
+ return NULL;
+
+ return extensions_service_->GetExtensionById(id);
+}
+
ThemeProvider* ProfileImpl::GetThemeProvider() {
InitThemes();
return theme_provider_.get();
diff --git a/chrome/browser/profile.h b/chrome/browser/profile.h
index fb72da5..656af37 100644
--- a/chrome/browser/profile.h
+++ b/chrome/browser/profile.h
@@ -200,6 +200,10 @@ class Profile {
// Clear the theme and reset it to default.
virtual void ClearTheme() = 0;
+ // Gets the theme that was last set. Returns NULL if the theme is no longer
+ // installed, if there is no installed theme, or the theme was cleared.
+ virtual Extension* GetTheme() = 0;
+
// Returns or creates the ThemeProvider associated with this profile
virtual ThemeProvider* GetThemeProvider() = 0;
@@ -352,6 +356,7 @@ class ProfileImpl : public Profile,
virtual void SetTheme(Extension* extension);
virtual void SetNativeTheme();
virtual void ClearTheme();
+ virtual Extension* GetTheme();
virtual ThemeProvider* GetThemeProvider();
virtual ThumbnailStore* GetThumbnailStore();
virtual bool HasCreatedDownloadManager() const;
diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h
index 0794e3c..e8a2c7a 100644
--- a/chrome/test/testing_profile.h
+++ b/chrome/test/testing_profile.h
@@ -138,6 +138,9 @@ class TestingProfile : public Profile {
virtual void SetTheme(Extension* extension) { }
virtual void SetNativeTheme() { }
virtual void ClearTheme() { }
+ virtual Extension* GetTheme() {
+ return NULL;
+ }
virtual ThemeProvider* GetThemeProvider() {
return theme_provider_.get();
}