OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/browser_theme_provider.h" | 5 #include "chrome/browser/browser_theme_provider.h" |
6 | 6 |
7 #include "app/gfx/codec/png_codec.h" | 7 #include "app/gfx/codec/png_codec.h" |
8 #include "app/gfx/skbitmap_operations.h" | 8 #include "app/gfx/skbitmap_operations.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
(...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1063 void BrowserThemeProvider::SetImageData(DictionaryValue* images_value, | 1063 void BrowserThemeProvider::SetImageData(DictionaryValue* images_value, |
1064 FilePath images_path) { | 1064 FilePath images_path) { |
1065 images_.clear(); | 1065 images_.clear(); |
1066 | 1066 |
1067 if (!images_value) | 1067 if (!images_value) |
1068 return; | 1068 return; |
1069 | 1069 |
1070 for (DictionaryValue::key_iterator iter(images_value->begin_keys()); | 1070 for (DictionaryValue::key_iterator iter(images_value->begin_keys()); |
1071 iter != images_value->end_keys(); ++iter) { | 1071 iter != images_value->end_keys(); ++iter) { |
1072 std::string val; | 1072 std::string val; |
1073 if (images_value->GetString(*iter, &val)) { | 1073 if (images_value->GetStringWithoutPathExpansion(*iter, &val)) { |
1074 int id = ThemeResourcesUtil::GetId(WideToUTF8(*iter)); | 1074 int id = ThemeResourcesUtil::GetId(WideToUTF8(*iter)); |
1075 if (id != -1) { | 1075 if (id != -1) { |
1076 if (!images_path.empty()) { | 1076 if (!images_path.empty()) { |
1077 images_[id] = | 1077 images_[id] = |
1078 WideToUTF8(images_path.AppendASCII(val).ToWStringHack()); | 1078 WideToUTF8(images_path.AppendASCII(val).ToWStringHack()); |
1079 resource_names_[id] = WideToASCII(*iter); | 1079 resource_names_[id] = WideToASCII(*iter); |
1080 } else { | 1080 } else { |
1081 images_[id] = val; | 1081 images_[id] = val; |
1082 } | 1082 } |
1083 } | 1083 } |
1084 } | 1084 } |
1085 } | 1085 } |
1086 } | 1086 } |
1087 | 1087 |
1088 void BrowserThemeProvider::SetColorData(DictionaryValue* colors_value) { | 1088 void BrowserThemeProvider::SetColorData(DictionaryValue* colors_value) { |
1089 colors_.clear(); | 1089 colors_.clear(); |
1090 | 1090 |
1091 if (!colors_value) | 1091 if (!colors_value) |
1092 return; | 1092 return; |
1093 | 1093 |
1094 for (DictionaryValue::key_iterator iter(colors_value->begin_keys()); | 1094 for (DictionaryValue::key_iterator iter(colors_value->begin_keys()); |
1095 iter != colors_value->end_keys(); ++iter) { | 1095 iter != colors_value->end_keys(); ++iter) { |
1096 ListValue* color_list; | 1096 ListValue* color_list; |
1097 if (colors_value->GetList(*iter, &color_list) && | 1097 if (colors_value->GetListWithoutPathExpansion(*iter, &color_list) && |
1098 ((color_list->GetSize() == 3) || (color_list->GetSize() == 4))) { | 1098 ((color_list->GetSize() == 3) || (color_list->GetSize() == 4))) { |
1099 int r, g, b; | 1099 int r, g, b; |
1100 color_list->GetInteger(0, &r); | 1100 color_list->GetInteger(0, &r); |
1101 color_list->GetInteger(1, &g); | 1101 color_list->GetInteger(1, &g); |
1102 color_list->GetInteger(2, &b); | 1102 color_list->GetInteger(2, &b); |
1103 if (color_list->GetSize() == 4) { | 1103 if (color_list->GetSize() == 4) { |
1104 double alpha; | 1104 double alpha; |
1105 int alpha_int; | 1105 int alpha_int; |
1106 if (color_list->GetReal(3, &alpha)) { | 1106 if (color_list->GetReal(3, &alpha)) { |
1107 colors_[WideToUTF8(*iter)] = | 1107 colors_[WideToUTF8(*iter)] = |
(...skipping 12 matching lines...) Expand all Loading... |
1120 | 1120 |
1121 void BrowserThemeProvider::SetTintData(DictionaryValue* tints_value) { | 1121 void BrowserThemeProvider::SetTintData(DictionaryValue* tints_value) { |
1122 tints_.clear(); | 1122 tints_.clear(); |
1123 | 1123 |
1124 if (!tints_value) | 1124 if (!tints_value) |
1125 return; | 1125 return; |
1126 | 1126 |
1127 for (DictionaryValue::key_iterator iter(tints_value->begin_keys()); | 1127 for (DictionaryValue::key_iterator iter(tints_value->begin_keys()); |
1128 iter != tints_value->end_keys(); ++iter) { | 1128 iter != tints_value->end_keys(); ++iter) { |
1129 ListValue* tint_list; | 1129 ListValue* tint_list; |
1130 if (tints_value->GetList(*iter, &tint_list) && | 1130 if (tints_value->GetListWithoutPathExpansion(*iter, &tint_list) && |
1131 (tint_list->GetSize() == 3)) { | 1131 (tint_list->GetSize() == 3)) { |
1132 color_utils::HSL hsl = { -1, -1, -1 }; | 1132 color_utils::HSL hsl = { -1, -1, -1 }; |
1133 int value = 0; | 1133 int value = 0; |
1134 if (!tint_list->GetReal(0, &hsl.h) && tint_list->GetInteger(0, &value)) | 1134 if (!tint_list->GetReal(0, &hsl.h) && tint_list->GetInteger(0, &value)) |
1135 hsl.h = value; | 1135 hsl.h = value; |
1136 if (!tint_list->GetReal(1, &hsl.s) && tint_list->GetInteger(1, &value)) | 1136 if (!tint_list->GetReal(1, &hsl.s) && tint_list->GetInteger(1, &value)) |
1137 hsl.s = value; | 1137 hsl.s = value; |
1138 if (!tint_list->GetReal(2, &hsl.l) && tint_list->GetInteger(2, &value)) | 1138 if (!tint_list->GetReal(2, &hsl.l) && tint_list->GetInteger(2, &value)) |
1139 hsl.l = value; | 1139 hsl.l = value; |
1140 | 1140 |
1141 tints_[WideToUTF8(*iter)] = hsl; | 1141 tints_[WideToUTF8(*iter)] = hsl; |
1142 } | 1142 } |
1143 } | 1143 } |
1144 } | 1144 } |
1145 | 1145 |
1146 void BrowserThemeProvider::SetDisplayPropertyData( | 1146 void BrowserThemeProvider::SetDisplayPropertyData( |
1147 DictionaryValue* display_properties_value) { | 1147 DictionaryValue* display_properties_value) { |
1148 display_properties_.clear(); | 1148 display_properties_.clear(); |
1149 | 1149 |
1150 if (!display_properties_value) | 1150 if (!display_properties_value) |
1151 return; | 1151 return; |
1152 | 1152 |
1153 for (DictionaryValue::key_iterator iter( | 1153 for (DictionaryValue::key_iterator iter( |
1154 display_properties_value->begin_keys()); | 1154 display_properties_value->begin_keys()); |
1155 iter != display_properties_value->end_keys(); ++iter) { | 1155 iter != display_properties_value->end_keys(); ++iter) { |
1156 // New tab page alignment and background tiling. | 1156 // New tab page alignment and background tiling. |
1157 if (base::strcasecmp(WideToUTF8(*iter).c_str(), | 1157 if (base::strcasecmp(WideToUTF8(*iter).c_str(), |
1158 kDisplayPropertyNTPAlignment) == 0) { | 1158 kDisplayPropertyNTPAlignment) == 0) { |
1159 std::string val; | 1159 std::string val; |
1160 if (display_properties_value->GetString(*iter, &val)) { | 1160 if (display_properties_value->GetStringWithoutPathExpansion(*iter, |
| 1161 &val)) { |
1161 display_properties_[kDisplayPropertyNTPAlignment] = | 1162 display_properties_[kDisplayPropertyNTPAlignment] = |
1162 StringToAlignment(val); | 1163 StringToAlignment(val); |
1163 } | 1164 } |
1164 } else if (base::strcasecmp(WideToUTF8(*iter).c_str(), | 1165 } else if (base::strcasecmp(WideToUTF8(*iter).c_str(), |
1165 kDisplayPropertyNTPTiling) == 0) { | 1166 kDisplayPropertyNTPTiling) == 0) { |
1166 std::string val; | 1167 std::string val; |
1167 if (display_properties_value->GetString(*iter, &val)) { | 1168 if (display_properties_value->GetStringWithoutPathExpansion(*iter, &val)) |
1168 display_properties_[kDisplayPropertyNTPTiling] = | 1169 display_properties_[kDisplayPropertyNTPTiling] = StringToTiling(val); |
1169 StringToTiling(val); | |
1170 } | |
1171 } | 1170 } |
1172 if (base::strcasecmp(WideToUTF8(*iter).c_str(), | 1171 if (base::strcasecmp(WideToUTF8(*iter).c_str(), |
1173 kDisplayPropertyNTPInverseLogo) == 0) { | 1172 kDisplayPropertyNTPInverseLogo) == 0) { |
1174 int val = 0; | 1173 int val = 0; |
1175 if (display_properties_value->GetInteger(*iter, &val)) | 1174 if (display_properties_value->GetIntegerWithoutPathExpansion(*iter, &val)) |
1176 display_properties_[kDisplayPropertyNTPInverseLogo] = val; | 1175 display_properties_[kDisplayPropertyNTPInverseLogo] = val; |
1177 } | 1176 } |
1178 } | 1177 } |
1179 } | 1178 } |
1180 | 1179 |
1181 SkBitmap* BrowserThemeProvider::GenerateTabBackgroundBitmap(int id) const { | 1180 SkBitmap* BrowserThemeProvider::GenerateTabBackgroundBitmap(int id) const { |
1182 if (id == IDR_THEME_TAB_BACKGROUND || | 1181 if (id == IDR_THEME_TAB_BACKGROUND || |
1183 id == IDR_THEME_TAB_BACKGROUND_INCOGNITO) { | 1182 id == IDR_THEME_TAB_BACKGROUND_INCOGNITO) { |
1184 // The requested image is a background tab. Get a frame to create the | 1183 // The requested image is a background tab. Get a frame to create the |
1185 // tab against. As themes don't use the glass frame, we don't have to | 1184 // tab against. As themes don't use the glass frame, we don't have to |
(...skipping 24 matching lines...) Expand all Loading... |
1210 DictionaryValue* pref_images = | 1209 DictionaryValue* pref_images = |
1211 profile_->GetPrefs()->GetMutableDictionary(prefs::kCurrentThemeImages); | 1210 profile_->GetPrefs()->GetMutableDictionary(prefs::kCurrentThemeImages); |
1212 pref_images->Clear(); | 1211 pref_images->Clear(); |
1213 | 1212 |
1214 if (!images_value) | 1213 if (!images_value) |
1215 return; | 1214 return; |
1216 | 1215 |
1217 for (DictionaryValue::key_iterator iter(images_value->begin_keys()); | 1216 for (DictionaryValue::key_iterator iter(images_value->begin_keys()); |
1218 iter != images_value->end_keys(); ++iter) { | 1217 iter != images_value->end_keys(); ++iter) { |
1219 std::string val; | 1218 std::string val; |
1220 if (images_value->GetString(*iter, &val)) { | 1219 if (images_value->GetStringWithoutPathExpansion(*iter, &val)) { |
1221 int id = ThemeResourcesUtil::GetId(WideToUTF8(*iter)); | 1220 int id = ThemeResourcesUtil::GetId(WideToUTF8(*iter)); |
1222 if (id != -1) | 1221 if (id != -1) { |
1223 pref_images->SetString(*iter, images_.find(id)->second); | 1222 pref_images->SetWithoutPathExpansion(*iter, |
| 1223 Value::CreateStringValue(images_.find(id)->second)); |
| 1224 } |
1224 } | 1225 } |
1225 } | 1226 } |
1226 } | 1227 } |
1227 | 1228 |
1228 void BrowserThemeProvider::SaveColorData() const { | 1229 void BrowserThemeProvider::SaveColorData() const { |
1229 // Save our color data. | 1230 // Save our color data. |
1230 DictionaryValue* pref_colors = | 1231 DictionaryValue* pref_colors = |
1231 profile_->GetPrefs()->GetMutableDictionary(prefs::kCurrentThemeColors); | 1232 profile_->GetPrefs()->GetMutableDictionary(prefs::kCurrentThemeColors); |
1232 pref_colors->Clear(); | 1233 pref_colors->Clear(); |
1233 | 1234 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1333 } | 1334 } |
1334 | 1335 |
1335 bool BrowserThemeProvider::ShouldTintFrames() const { | 1336 bool BrowserThemeProvider::ShouldTintFrames() const { |
1336 return (HasCustomImage(IDR_THEME_FRAME) || | 1337 return (HasCustomImage(IDR_THEME_FRAME) || |
1337 tints_.count(GetTintKey(TINT_BACKGROUND_TAB)) || | 1338 tints_.count(GetTintKey(TINT_BACKGROUND_TAB)) || |
1338 tints_.count(GetTintKey(TINT_FRAME)) || | 1339 tints_.count(GetTintKey(TINT_FRAME)) || |
1339 tints_.count(GetTintKey(TINT_FRAME_INACTIVE)) || | 1340 tints_.count(GetTintKey(TINT_FRAME_INACTIVE)) || |
1340 tints_.count(GetTintKey(TINT_FRAME_INCOGNITO)) || | 1341 tints_.count(GetTintKey(TINT_FRAME_INCOGNITO)) || |
1341 tints_.count(GetTintKey(TINT_FRAME_INCOGNITO_INACTIVE))); | 1342 tints_.count(GetTintKey(TINT_FRAME_INCOGNITO_INACTIVE))); |
1342 } | 1343 } |
OLD | NEW |