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/string_util.h" | 11 #include "base/string_util.h" |
11 #include "base/thread.h" | 12 #include "base/thread.h" |
12 #include "base/values.h" | 13 #include "base/values.h" |
13 #include "chrome/browser/browser_list.h" | 14 #include "chrome/browser/browser_list.h" |
14 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/browser_window.h" | 16 #include "chrome/browser/browser_window.h" |
16 #include "chrome/browser/metrics/user_metrics.h" | 17 #include "chrome/browser/metrics/user_metrics.h" |
17 #include "chrome/browser/profile.h" | 18 #include "chrome/browser/profile.h" |
18 #include "chrome/browser/theme_resources_util.h" | 19 #include "chrome/browser/theme_resources_util.h" |
19 #include "chrome/common/chrome_constants.h" | 20 #include "chrome/common/chrome_constants.h" |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 IDR_THEME_TAB_BACKGROUND_V, | 188 IDR_THEME_TAB_BACKGROUND_V, |
188 IDR_THEME_NTP_BACKGROUND, | 189 IDR_THEME_NTP_BACKGROUND, |
189 IDR_THEME_FRAME_OVERLAY, | 190 IDR_THEME_FRAME_OVERLAY, |
190 IDR_THEME_FRAME_OVERLAY_INACTIVE, | 191 IDR_THEME_FRAME_OVERLAY_INACTIVE, |
191 IDR_THEME_BUTTON_BACKGROUND, | 192 IDR_THEME_BUTTON_BACKGROUND, |
192 IDR_THEME_NTP_ATTRIBUTION, | 193 IDR_THEME_NTP_ATTRIBUTION, |
193 IDR_THEME_WINDOW_CONTROL_BACKGROUND | 194 IDR_THEME_WINDOW_CONTROL_BACKGROUND |
194 }; | 195 }; |
195 | 196 |
196 // A map for kThemeableImages. | 197 // A map for kThemeableImages. |
197 static std::map<const int, bool> themeable_images_; | 198 static std::map<const int, bool> themeable_images; |
198 | 199 |
199 // A map of frame image IDs to the tints for those ids. | 200 // A map of frame image IDs to the tints for those ids. |
200 static std::map<const int, int> frame_tints_; | 201 typedef std::map<const int, int> FrameTintMap; |
| 202 static FrameTintMap frame_tints; |
201 | 203 |
202 Lock BrowserThemeProvider::themed_image_cache_lock_; | 204 Lock BrowserThemeProvider::themed_image_cache_lock_; |
203 | 205 |
204 namespace { | 206 namespace { |
205 | 207 |
206 class WriteImagesToDiskTask : public Task { | 208 class WriteImagesToDiskTask : public Task { |
207 public: | 209 public: |
208 WriteImagesToDiskTask( | 210 WriteImagesToDiskTask( |
209 const BrowserThemeProvider::ImagesDiskCache& images_disk_cache, | 211 const BrowserThemeProvider::ImagesDiskCache& images_disk_cache, |
210 const BrowserThemeProvider::ImageCache& themed_image_cache) : | 212 const BrowserThemeProvider::ImageCache& themed_image_cache) : |
211 images_disk_cache_(images_disk_cache), | 213 images_disk_cache_(images_disk_cache), |
212 themed_image_cache_(themed_image_cache) { | 214 themed_image_cache_(themed_image_cache) { |
213 } | 215 } |
214 | 216 |
215 virtual void Run() { | 217 virtual void Run() { |
216 AutoLock lock(BrowserThemeProvider::themed_image_cache_lock_); | 218 AutoLock lock(BrowserThemeProvider::themed_image_cache_lock_); |
217 BrowserThemeProvider::ImagesDiskCache::const_iterator iter; | 219 for (BrowserThemeProvider::ImagesDiskCache::const_iterator iter( |
218 for (iter = images_disk_cache_.begin(); | 220 images_disk_cache_.begin()); iter != images_disk_cache_.end(); |
219 iter != images_disk_cache_.end(); | 221 ++iter) { |
220 iter++) { | 222 FilePath image_path = iter->first; |
221 FilePath image_path = (*iter).first; | 223 BrowserThemeProvider::ImageCache::const_iterator themed_iter = |
222 BrowserThemeProvider::ImageCache::const_iterator found = | 224 themed_image_cache_.find(iter->second); |
223 themed_image_cache_.find((*iter).second); | 225 if (themed_iter != themed_image_cache_.end()) { |
224 if (found != themed_image_cache_.end()) { | 226 SkBitmap* bitmap = themed_iter->second; |
225 SkBitmap* bitmap = found->second; | |
226 std::vector<unsigned char> image_data; | 227 std::vector<unsigned char> image_data; |
227 if (!gfx::PNGCodec::EncodeBGRASkBitmap(*bitmap, false, &image_data)) { | 228 if (!gfx::PNGCodec::EncodeBGRASkBitmap(*bitmap, false, &image_data)) { |
228 NOTREACHED() << "Image file could not be encoded."; | 229 NOTREACHED() << "Image file could not be encoded."; |
229 return; | 230 return; |
230 } | 231 } |
231 const char* image_data_ptr = | 232 const char* image_data_ptr = |
232 reinterpret_cast<const char*>(&image_data[0]); | 233 reinterpret_cast<const char*>(&image_data[0]); |
233 if (!file_util::WriteFile(image_path, | 234 if (!file_util::WriteFile(image_path, |
234 image_data_ptr, image_data.size())) { | 235 image_data_ptr, image_data.size())) { |
235 NOTREACHED() << "Image file could not be written to disk."; | 236 NOTREACHED() << "Image file could not be written to disk."; |
(...skipping 12 matching lines...) Expand all Loading... |
248 const BrowserThemeProvider::ImageCache& themed_image_cache_; | 249 const BrowserThemeProvider::ImageCache& themed_image_cache_; |
249 }; | 250 }; |
250 } | 251 } |
251 | 252 |
252 BrowserThemeProvider::BrowserThemeProvider() | 253 BrowserThemeProvider::BrowserThemeProvider() |
253 : rb_(ResourceBundle::GetSharedInstance()), | 254 : rb_(ResourceBundle::GetSharedInstance()), |
254 profile_(NULL), | 255 profile_(NULL), |
255 process_images_(false) { | 256 process_images_(false) { |
256 static bool initialized = false; | 257 static bool initialized = false; |
257 if (!initialized) { | 258 if (!initialized) { |
258 for (size_t i = 0; i < arraysize(kToolbarButtonIDs); ++i) { | 259 for (size_t i = 0; i < arraysize(kToolbarButtonIDs); ++i) |
259 button_images_[kToolbarButtonIDs[i]] = true; | 260 button_images_[kToolbarButtonIDs[i]] = true; |
260 } | 261 for (size_t i = 0; i < arraysize(kThemeableImages); ++i) |
261 for (size_t i = 0; i < arraysize(kThemeableImages); ++i) { | 262 themeable_images[kThemeableImages[i]] = true; |
262 themeable_images_[kThemeableImages[i]] = true; | 263 frame_tints[IDR_THEME_FRAME] = TINT_FRAME; |
263 } | 264 frame_tints[IDR_THEME_FRAME_INACTIVE] = TINT_FRAME_INACTIVE; |
264 frame_tints_[IDR_THEME_FRAME] = TINT_FRAME; | 265 frame_tints[IDR_THEME_FRAME_OVERLAY] = TINT_FRAME; |
265 frame_tints_[IDR_THEME_FRAME_INACTIVE] = TINT_FRAME_INACTIVE; | 266 frame_tints[IDR_THEME_FRAME_OVERLAY_INACTIVE] = TINT_FRAME_INACTIVE; |
266 frame_tints_[IDR_THEME_FRAME_OVERLAY] = TINT_FRAME; | 267 frame_tints[IDR_THEME_FRAME_INCOGNITO] = TINT_FRAME_INCOGNITO; |
267 frame_tints_[IDR_THEME_FRAME_OVERLAY_INACTIVE] = TINT_FRAME_INACTIVE; | 268 frame_tints[IDR_THEME_FRAME_INCOGNITO_INACTIVE] = |
268 frame_tints_[IDR_THEME_FRAME_INCOGNITO] = TINT_FRAME_INCOGNITO; | |
269 frame_tints_[IDR_THEME_FRAME_INCOGNITO_INACTIVE] = | |
270 TINT_FRAME_INCOGNITO_INACTIVE; | 269 TINT_FRAME_INCOGNITO_INACTIVE; |
271 | 270 |
272 resource_names_[IDR_THEME_FRAME] = "theme_frame"; | 271 resource_names_[IDR_THEME_FRAME] = "theme_frame"; |
273 resource_names_[IDR_THEME_FRAME_INACTIVE] = "theme_frame_inactive"; | 272 resource_names_[IDR_THEME_FRAME_INACTIVE] = "theme_frame_inactive"; |
274 resource_names_[IDR_THEME_FRAME_OVERLAY] = "theme_frame_overlay"; | 273 resource_names_[IDR_THEME_FRAME_OVERLAY] = "theme_frame_overlay"; |
275 resource_names_[IDR_THEME_FRAME_OVERLAY_INACTIVE] = | 274 resource_names_[IDR_THEME_FRAME_OVERLAY_INACTIVE] = |
276 "theme_frame_overlay_inactive"; | 275 "theme_frame_overlay_inactive"; |
277 resource_names_[IDR_THEME_FRAME_INCOGNITO] = "theme_frame_incognito"; | 276 resource_names_[IDR_THEME_FRAME_INCOGNITO] = "theme_frame_incognito"; |
278 resource_names_[IDR_THEME_FRAME_INCOGNITO_INACTIVE] = | 277 resource_names_[IDR_THEME_FRAME_INCOGNITO_INACTIVE] = |
279 "theme_frame_incognito_inactive"; | 278 "theme_frame_incognito_inactive"; |
(...skipping 23 matching lines...) Expand all Loading... |
303 file_util::CreateDirectory(image_dir_); | 302 file_util::CreateDirectory(image_dir_); |
304 | 303 |
305 LoadThemePrefs(); | 304 LoadThemePrefs(); |
306 } | 305 } |
307 | 306 |
308 SkBitmap* BrowserThemeProvider::GetBitmapNamed(int id) { | 307 SkBitmap* BrowserThemeProvider::GetBitmapNamed(int id) { |
309 DCHECK(CalledOnValidThread()); | 308 DCHECK(CalledOnValidThread()); |
310 | 309 |
311 // First check to see if the Skia image is in the themed cache. The themed | 310 // First check to see if the Skia image is in the themed cache. The themed |
312 // cache is not changed in this method, so it can remain unlocked. | 311 // cache is not changed in this method, so it can remain unlocked. |
313 ImageCache::const_iterator t_found = themed_image_cache_.find(id); | 312 ImageCache::const_iterator themed_iter = themed_image_cache_.find(id); |
314 if (t_found != themed_image_cache_.end()) | 313 if (themed_iter != themed_image_cache_.end()) |
315 return t_found->second; | 314 return themed_iter->second; |
316 | 315 |
317 // If Skia image is not in themed cache, check regular cache, and possibly | 316 // If Skia image is not in themed cache, check regular cache, and possibly |
318 // generate and store. | 317 // generate and store. |
319 ImageCache::const_iterator found = image_cache_.find(id); | 318 ImageCache::const_iterator image_iter = image_cache_.find(id); |
320 if (found != image_cache_.end()) | 319 if (image_iter != image_cache_.end()) |
321 return found->second; | 320 return image_iter->second; |
322 | 321 |
323 scoped_ptr<SkBitmap> result; | 322 scoped_ptr<SkBitmap> result; |
324 | 323 |
325 // Try to load the image from the extension. | 324 // Try to load the image from the extension. |
326 result.reset(LoadThemeBitmap(id)); | 325 result.reset(LoadThemeBitmap(id)); |
327 | 326 |
328 // If we still don't have an image, load it from resourcebundle. | 327 // If we still don't have an image, load it from resourcebundle. |
329 if (!result.get()) | 328 if (!result.get()) |
330 result.reset(new SkBitmap(*rb_.GetBitmapNamed(id))); | 329 result.reset(new SkBitmap(*rb_.GetBitmapNamed(id))); |
331 | 330 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 | 370 |
372 if (id == COLOR_NTP_LINK_UNDERLINE) { | 371 if (id == COLOR_NTP_LINK_UNDERLINE) { |
373 if (colors_.find(kColorNTPLinkUnderline) != colors_.end()) | 372 if (colors_.find(kColorNTPLinkUnderline) != colors_.end()) |
374 return colors_[kColorNTPLinkUnderline]; | 373 return colors_[kColorNTPLinkUnderline]; |
375 SkColor color_link = GetColor(COLOR_NTP_LINK); | 374 SkColor color_link = GetColor(COLOR_NTP_LINK); |
376 return SkColorSetA(color_link, SkColorGetA(color_link) / 3); | 375 return SkColorSetA(color_link, SkColorGetA(color_link) / 3); |
377 } | 376 } |
378 | 377 |
379 // TODO(glen): Figure out if we need to tint these. http://crbug.com/11578 | 378 // TODO(glen): Figure out if we need to tint these. http://crbug.com/11578 |
380 ColorMap::iterator color_iter = colors_.find(GetColorKey(id)); | 379 ColorMap::iterator color_iter = colors_.find(GetColorKey(id)); |
381 if (color_iter != colors_.end()) | 380 return (color_iter == colors_.end()) ? |
382 return color_iter->second; | 381 GetDefaultColor(id) : color_iter->second; |
383 else | |
384 return GetDefaultColor(id); | |
385 } | 382 } |
386 | 383 |
387 bool BrowserThemeProvider::GetDisplayProperty(int id, int* result) { | 384 bool BrowserThemeProvider::GetDisplayProperty(int id, int* result) { |
388 switch (id) { | 385 switch (id) { |
389 case NTP_BACKGROUND_ALIGNMENT: | 386 case NTP_BACKGROUND_ALIGNMENT: { |
390 if (display_properties_.find(kDisplayPropertyNTPAlignment) != | 387 DisplayPropertyMap::const_iterator display_iter = |
391 display_properties_.end()) { | 388 display_properties_.find(kDisplayPropertyNTPAlignment); |
392 *result = display_properties_[kDisplayPropertyNTPAlignment]; | 389 *result = (display_iter == display_properties_.end()) ? |
393 } else { | 390 kDefaultDisplayPropertyNTPAlignment : display_iter->second; |
394 *result = kDefaultDisplayPropertyNTPAlignment; | |
395 } | |
396 return true; | 391 return true; |
397 case NTP_BACKGROUND_TILING: | 392 } |
398 if (display_properties_.find(kDisplayPropertyNTPTiling) != | 393 case NTP_BACKGROUND_TILING: { |
399 display_properties_.end()) { | 394 DisplayPropertyMap::const_iterator display_iter = |
400 *result = display_properties_[kDisplayPropertyNTPTiling]; | 395 display_properties_.find(kDisplayPropertyNTPTiling); |
401 } else { | 396 *result = (display_iter == display_properties_.end()) ? |
402 *result = kDefaultDisplayPropertyNTPTiling; | 397 kDefaultDisplayPropertyNTPTiling : display_iter->second; |
403 } | |
404 return true; | 398 return true; |
405 case NTP_LOGO_ALTERNATE: | 399 } |
406 if (display_properties_.find(kDisplayPropertyNTPInverseLogo) != | 400 case NTP_LOGO_ALTERNATE: { |
407 display_properties_.end()) { | 401 DisplayPropertyMap::const_iterator display_iter = |
408 *result = display_properties_[kDisplayPropertyNTPInverseLogo]; | 402 display_properties_.find(kDisplayPropertyNTPInverseLogo); |
409 } else { | 403 *result = (display_iter == display_properties_.end()) ? |
410 *result = kDefaultDisplayPropertyNTPInverseLogo; | 404 kDefaultDisplayPropertyNTPInverseLogo : display_iter->second; |
411 } | |
412 return true; | 405 return true; |
| 406 } |
413 default: | 407 default: |
414 NOTREACHED() << "Unknown property requested"; | 408 NOTREACHED() << "Unknown property requested"; |
415 } | 409 } |
416 return false; | 410 return false; |
417 } | 411 } |
418 | 412 |
419 bool BrowserThemeProvider::ShouldUseNativeFrame() { | 413 bool BrowserThemeProvider::ShouldUseNativeFrame() { |
420 if (HasCustomImage(IDR_THEME_FRAME)) | 414 if (HasCustomImage(IDR_THEME_FRAME)) |
421 return false; | 415 return false; |
422 #if defined(OS_WIN) | 416 #if defined(OS_WIN) |
423 return win_util::ShouldUseVistaFrame(); | 417 return win_util::ShouldUseVistaFrame(); |
424 #else | 418 #else |
425 return false; | 419 return false; |
426 #endif | 420 #endif |
427 } | 421 } |
428 | 422 |
429 bool BrowserThemeProvider::HasCustomImage(int id) { | 423 bool BrowserThemeProvider::HasCustomImage(int id) { |
430 if (!themeable_images_[id]) | 424 if (!themeable_images[id]) |
431 return false; | 425 return false; |
432 | 426 |
433 // A custom image = base name is NOT equal to resource name. See note in | 427 // A custom image = base name is NOT equal to resource name. See note in |
434 // SaveThemeBitmap describing the process by which an original image is | 428 // SaveThemeBitmap describing the process by which an original image is |
435 // tagged. | 429 // tagged. |
436 if (images_.find(id) != images_.end() && | 430 if ((images_.find(id) == images_.end()) || |
437 resource_names_.find(id) != resource_names_.end()) | 431 (resource_names_.find(id) == resource_names_.end())) |
438 return !EndsWith(UTF8ToWide(images_[id]), | |
439 UTF8ToWide(resource_names_[id]), false); | |
440 else | |
441 return false; | 432 return false; |
| 433 return !EndsWith(UTF8ToWide(images_[id]), |
| 434 UTF8ToWide(resource_names_[id]), false); |
442 } | 435 } |
443 | 436 |
444 bool BrowserThemeProvider::GetRawData(int id, | 437 bool BrowserThemeProvider::GetRawData(int id, |
445 std::vector<unsigned char>* raw_data) { | 438 std::vector<unsigned char>* raw_data) { |
446 // Check to see whether we should substitute some images. | 439 // Check to see whether we should substitute some images. |
447 int ntp_alternate; | 440 int ntp_alternate; |
448 GetDisplayProperty(NTP_LOGO_ALTERNATE, &ntp_alternate); | 441 GetDisplayProperty(NTP_LOGO_ALTERNATE, &ntp_alternate); |
449 if (id == IDR_PRODUCT_LOGO && ntp_alternate != 0) | 442 if (id == IDR_PRODUCT_LOGO && ntp_alternate != 0) |
450 id = IDR_PRODUCT_LOGO_WHITE; | 443 id = IDR_PRODUCT_LOGO_WHITE; |
451 | 444 |
452 if (raw_data_.find(id) != raw_data_.end()) { | 445 if (raw_data_.find(id) != raw_data_.end()) { |
453 *raw_data = raw_data_[id]; | 446 *raw_data = raw_data_[id]; |
454 return true; | 447 return true; |
455 } | 448 } |
456 | 449 |
457 if (!ReadThemeFileData(id, raw_data)) { | 450 if (!ReadThemeFileData(id, raw_data) && |
458 if (!rb_.LoadImageResourceBytes(id, raw_data)) | 451 !rb_.LoadImageResourceBytes(id, raw_data)) |
459 return false; | 452 return false; |
460 } | |
461 | 453 |
462 raw_data_[id] = *raw_data; | 454 raw_data_[id] = *raw_data; |
463 return true; | 455 return true; |
464 } | 456 } |
465 | 457 |
466 void BrowserThemeProvider::SetTheme(Extension* extension) { | 458 void BrowserThemeProvider::SetTheme(Extension* extension) { |
467 // Clear our image cache. | 459 // Clear our image cache. |
468 ClearCaches(); | 460 ClearCaches(); |
469 | 461 |
470 DCHECK(extension); | 462 DCHECK(extension); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 if (alignment & BrowserThemeProvider::ALIGN_TOP) | 538 if (alignment & BrowserThemeProvider::ALIGN_TOP) |
547 vertical_string = kAlignmentTop; | 539 vertical_string = kAlignmentTop; |
548 else if (alignment & BrowserThemeProvider::ALIGN_BOTTOM) | 540 else if (alignment & BrowserThemeProvider::ALIGN_BOTTOM) |
549 vertical_string = kAlignmentBottom; | 541 vertical_string = kAlignmentBottom; |
550 | 542 |
551 if (alignment & BrowserThemeProvider::ALIGN_LEFT) | 543 if (alignment & BrowserThemeProvider::ALIGN_LEFT) |
552 horizontal_string = kAlignmentLeft; | 544 horizontal_string = kAlignmentLeft; |
553 else if (alignment & BrowserThemeProvider::ALIGN_RIGHT) | 545 else if (alignment & BrowserThemeProvider::ALIGN_RIGHT) |
554 horizontal_string = kAlignmentRight; | 546 horizontal_string = kAlignmentRight; |
555 | 547 |
556 if (!vertical_string.empty() && !horizontal_string.empty()) | 548 if (vertical_string.empty()) |
557 return vertical_string + " " + horizontal_string; | |
558 else if (vertical_string.empty()) | |
559 return horizontal_string; | 549 return horizontal_string; |
560 else | 550 if (horizontal_string.empty()) |
561 return vertical_string; | 551 return vertical_string; |
| 552 return vertical_string + " " + horizontal_string; |
562 } | 553 } |
563 | 554 |
564 // static | 555 // static |
565 int BrowserThemeProvider::StringToAlignment(const std::string& alignment) { | 556 int BrowserThemeProvider::StringToAlignment(const std::string& alignment) { |
566 std::vector<std::wstring> split; | 557 std::vector<std::wstring> split; |
567 SplitStringAlongWhitespace(UTF8ToWide(alignment), &split); | 558 SplitStringAlongWhitespace(UTF8ToWide(alignment), &split); |
568 | 559 |
569 std::vector<std::wstring>::iterator alignments = split.begin(); | |
570 int alignment_mask = 0; | 560 int alignment_mask = 0; |
571 while (alignments != split.end()) { | 561 for (std::vector<std::wstring>::iterator alignments(split.begin()); |
| 562 alignments != split.end(); ++alignments) { |
572 std::string comp = WideToUTF8(*alignments); | 563 std::string comp = WideToUTF8(*alignments); |
573 const char* component = comp.c_str(); | 564 const char* component = comp.c_str(); |
574 | 565 |
575 if (base::strcasecmp(component, kAlignmentTop) == 0) | 566 if (base::strcasecmp(component, kAlignmentTop) == 0) |
576 alignment_mask |= BrowserThemeProvider::ALIGN_TOP; | 567 alignment_mask |= BrowserThemeProvider::ALIGN_TOP; |
577 else if (base::strcasecmp(component, kAlignmentBottom) == 0) | 568 else if (base::strcasecmp(component, kAlignmentBottom) == 0) |
578 alignment_mask |= BrowserThemeProvider::ALIGN_BOTTOM; | 569 alignment_mask |= BrowserThemeProvider::ALIGN_BOTTOM; |
579 | 570 |
580 if (base::strcasecmp(component, kAlignmentLeft) == 0) | 571 if (base::strcasecmp(component, kAlignmentLeft) == 0) |
581 alignment_mask |= BrowserThemeProvider::ALIGN_LEFT; | 572 alignment_mask |= BrowserThemeProvider::ALIGN_LEFT; |
582 else if (base::strcasecmp(component, kAlignmentRight) == 0) | 573 else if (base::strcasecmp(component, kAlignmentRight) == 0) |
583 alignment_mask |= BrowserThemeProvider::ALIGN_RIGHT; | 574 alignment_mask |= BrowserThemeProvider::ALIGN_RIGHT; |
584 alignments++; | |
585 } | 575 } |
586 return alignment_mask; | 576 return alignment_mask; |
587 } | 577 } |
588 | 578 |
589 // static | 579 // static |
590 std::string BrowserThemeProvider::TilingToString(int tiling) { | 580 std::string BrowserThemeProvider::TilingToString(int tiling) { |
591 // Convert from a TilingProperty back into a string. | 581 // Convert from a TilingProperty back into a string. |
592 if (tiling == BrowserThemeProvider::REPEAT_X) | 582 if (tiling == BrowserThemeProvider::REPEAT_X) |
593 return kTilingRepeatX; | 583 return kTilingRepeatX; |
594 else if (tiling == BrowserThemeProvider::REPEAT_Y) | 584 if (tiling == BrowserThemeProvider::REPEAT_Y) |
595 return kTilingRepeatY; | 585 return kTilingRepeatY; |
596 else if (tiling == BrowserThemeProvider::REPEAT) | 586 if (tiling == BrowserThemeProvider::REPEAT) |
597 return kTilingRepeat; | 587 return kTilingRepeat; |
598 else | 588 return kTilingNoRepeat; |
599 return kTilingNoRepeat; | |
600 } | 589 } |
601 | 590 |
602 // static | 591 // static |
603 int BrowserThemeProvider::StringToTiling(const std::string &tiling) { | 592 int BrowserThemeProvider::StringToTiling(const std::string &tiling) { |
604 const char* component = tiling.c_str(); | 593 const char* component = tiling.c_str(); |
605 | 594 |
606 if (base::strcasecmp(component, kTilingRepeatX) == 0) | 595 if (base::strcasecmp(component, kTilingRepeatX) == 0) |
607 return BrowserThemeProvider::REPEAT_X; | 596 return BrowserThemeProvider::REPEAT_X; |
608 else if (base::strcasecmp(component, kTilingRepeatY) == 0) | 597 if (base::strcasecmp(component, kTilingRepeatY) == 0) |
609 return BrowserThemeProvider::REPEAT_Y; | 598 return BrowserThemeProvider::REPEAT_Y; |
610 else if (base::strcasecmp(component, kTilingRepeat) == 0) | 599 if (base::strcasecmp(component, kTilingRepeat) == 0) |
611 return BrowserThemeProvider::REPEAT; | 600 return BrowserThemeProvider::REPEAT; |
612 // NO_REPEAT is the default choice. | 601 // NO_REPEAT is the default choice. |
613 return BrowserThemeProvider::NO_REPEAT; | 602 return BrowserThemeProvider::NO_REPEAT; |
614 } | 603 } |
615 | 604 |
616 void BrowserThemeProvider::SetColor(const char* key, const SkColor& color) { | 605 void BrowserThemeProvider::SetColor(const char* key, const SkColor& color) { |
617 colors_[key] = color; | 606 colors_[key] = color; |
618 } | 607 } |
619 | 608 |
620 void BrowserThemeProvider::SetTint(const char* key, | 609 void BrowserThemeProvider::SetTint(const char* key, |
(...skipping 22 matching lines...) Expand all Loading... |
643 colors_[kColorFrameIncognito] = | 632 colors_[kColorFrameIncognito] = |
644 HSLShift(frame, GetTint(TINT_FRAME_INCOGNITO)); | 633 HSLShift(frame, GetTint(TINT_FRAME_INCOGNITO)); |
645 } | 634 } |
646 if (colors_.find(kColorFrameIncognitoInactive) == colors_.end()) { | 635 if (colors_.find(kColorFrameIncognitoInactive) == colors_.end()) { |
647 colors_[kColorFrameIncognitoInactive] = | 636 colors_[kColorFrameIncognitoInactive] = |
648 HSLShift(frame, GetTint(TINT_FRAME_INCOGNITO_INACTIVE)); | 637 HSLShift(frame, GetTint(TINT_FRAME_INCOGNITO_INACTIVE)); |
649 } | 638 } |
650 } | 639 } |
651 | 640 |
652 void BrowserThemeProvider::GenerateFrameImages() { | 641 void BrowserThemeProvider::GenerateFrameImages() { |
653 std::map<const int, int>::iterator iter = frame_tints_.begin(); | 642 for (FrameTintMap::iterator iter(frame_tints.begin()); |
654 while (iter != frame_tints_.end()) { | 643 iter != frame_tints.end(); ++iter) { |
655 int id = iter->first; | 644 int id = iter->first; |
656 scoped_ptr<SkBitmap> frame; | 645 scoped_ptr<SkBitmap> frame; |
657 // If there's no frame image provided for the specified id, then load | 646 // If there's no frame image provided for the specified id, then load |
658 // the default provided frame. If that's not provided, skip this whole | 647 // the default provided frame. If that's not provided, skip this whole |
659 // thing and just use the default images. | 648 // thing and just use the default images. |
660 int base_id; | 649 int base_id; |
661 std::string resource_name; | 650 std::string resource_name; |
662 | 651 |
663 // If we've already processed the images for this theme, they're all | 652 // If we've already processed the images for this theme, they're all |
664 // waiting on disk -- just load them in. | 653 // waiting on disk -- just load them in. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 // the default frame. | 686 // the default frame. |
698 frame.reset(new SkBitmap(*rb_.GetBitmapNamed(IDR_THEME_FRAME))); | 687 frame.reset(new SkBitmap(*rb_.GetBitmapNamed(IDR_THEME_FRAME))); |
699 } | 688 } |
700 | 689 |
701 if (frame.get()) { | 690 if (frame.get()) { |
702 SkBitmap* tinted = new SkBitmap(TintBitmap(*frame, iter->second)); | 691 SkBitmap* tinted = new SkBitmap(TintBitmap(*frame, iter->second)); |
703 themed_image_cache_[id] = tinted; | 692 themed_image_cache_[id] = tinted; |
704 SaveThemeBitmap(resource_name, id); | 693 SaveThemeBitmap(resource_name, id); |
705 } | 694 } |
706 } | 695 } |
707 ++iter; | |
708 } | 696 } |
709 } | 697 } |
710 | 698 |
711 void BrowserThemeProvider::GenerateTabImages() { | 699 void BrowserThemeProvider::GenerateTabImages() { |
712 GenerateTabBackgroundBitmap(IDR_THEME_TAB_BACKGROUND); | 700 GenerateTabBackgroundBitmap(IDR_THEME_TAB_BACKGROUND); |
713 GenerateTabBackgroundBitmap(IDR_THEME_TAB_BACKGROUND_INCOGNITO); | 701 GenerateTabBackgroundBitmap(IDR_THEME_TAB_BACKGROUND_INCOGNITO); |
714 } | 702 } |
715 | 703 |
716 void BrowserThemeProvider::ClearAllThemeData() { | 704 void BrowserThemeProvider::ClearAllThemeData() { |
717 // Clear our image cache. | 705 // Clear our image cache. |
718 ClearCaches(); | 706 ClearCaches(); |
719 | 707 |
720 images_.clear(); | 708 images_.clear(); |
721 colors_.clear(); | 709 colors_.clear(); |
722 tints_.clear(); | 710 tints_.clear(); |
723 display_properties_.clear(); | 711 display_properties_.clear(); |
724 raw_data_.clear(); | 712 raw_data_.clear(); |
725 | 713 |
726 SaveImageData(NULL); | 714 SaveImageData(NULL); |
727 SaveColorData(); | 715 SaveColorData(); |
728 SaveTintData(); | 716 SaveTintData(); |
729 SaveDisplayPropertyData(); | 717 SaveDisplayPropertyData(); |
730 SaveThemeID(kDefaultThemeID); | 718 SaveThemeID(kDefaultThemeID); |
731 } | 719 } |
732 | 720 |
733 void BrowserThemeProvider::LoadThemePrefs() { | 721 void BrowserThemeProvider::LoadThemePrefs() { |
734 process_images_ = false; | 722 process_images_ = false; |
735 PrefService* prefs = profile_->GetPrefs(); | 723 PrefService* prefs = profile_->GetPrefs(); |
736 | 724 |
737 // TODO(glen): Figure out if any custom prefs were loaded, and if so | 725 // TODO(glen): Figure out if any custom prefs were loaded, and if so UMA-log |
738 // UMA-log the fact that a theme was loaded. | 726 // the fact that a theme was loaded. |
739 if (prefs->HasPrefPath(prefs::kCurrentThemeImages) || | 727 if (!prefs->HasPrefPath(prefs::kCurrentThemeImages) && |
740 prefs->HasPrefPath(prefs::kCurrentThemeColors) || | 728 !prefs->HasPrefPath(prefs::kCurrentThemeColors) && |
741 prefs->HasPrefPath(prefs::kCurrentThemeTints)) { | 729 !prefs->HasPrefPath(prefs::kCurrentThemeTints)) |
742 // Our prefs already have the extension path baked in, so we don't need | 730 return; |
743 // to provide it. | |
744 SetImageData(prefs->GetMutableDictionary(prefs::kCurrentThemeImages), | |
745 FilePath()); | |
746 SetColorData(prefs->GetMutableDictionary(prefs::kCurrentThemeColors)); | |
747 SetTintData(prefs->GetMutableDictionary(prefs::kCurrentThemeTints)); | |
748 SetDisplayPropertyData( | |
749 prefs->GetMutableDictionary(prefs::kCurrentThemeDisplayProperties)); | |
750 | 731 |
751 // If we're not loading the frame from the cached image dir, we are using | 732 // Our prefs already have the extension path baked in, so we don't need to |
752 // an old preferences file, or the processed images were not saved | 733 // provide it. |
753 // correctly. Force image reprocessing and caching. | 734 SetImageData(prefs->GetMutableDictionary(prefs::kCurrentThemeImages), |
754 if (images_.count(IDR_THEME_FRAME) > 0) { | 735 FilePath()); |
| 736 SetColorData(prefs->GetMutableDictionary(prefs::kCurrentThemeColors)); |
| 737 SetTintData(prefs->GetMutableDictionary(prefs::kCurrentThemeTints)); |
| 738 SetDisplayPropertyData( |
| 739 prefs->GetMutableDictionary(prefs::kCurrentThemeDisplayProperties)); |
| 740 |
| 741 // If we're not loading the frame from the cached image dir, we are using an |
| 742 // old preferences file, or the processed images were not saved correctly. |
| 743 // Force image reprocessing and caching. |
| 744 if (images_.count(IDR_THEME_FRAME) > 0) { |
755 #if defined(OS_WIN) | 745 #if defined(OS_WIN) |
756 FilePath cache_path = FilePath(UTF8ToWide(images_[IDR_THEME_FRAME])); | 746 FilePath cache_path = FilePath(UTF8ToWide(images_[IDR_THEME_FRAME])); |
757 #else | 747 #else |
758 FilePath cache_path = FilePath(images_[IDR_THEME_FRAME]); | 748 FilePath cache_path = FilePath(images_[IDR_THEME_FRAME]); |
759 #endif | 749 #endif |
760 process_images_ = !file_util::ContainsPath(image_dir_, cache_path); | 750 process_images_ = !file_util::ContainsPath(image_dir_, cache_path); |
761 } | 751 } |
762 | 752 |
763 GenerateFrameColors(); | 753 GenerateFrameColors(); |
764 // Scope for AutoLock on themed_image_cache. | 754 // Scope for AutoLock on themed_image_cache. |
765 { | 755 { |
766 AutoLock lock(themed_image_cache_lock_); | 756 AutoLock lock(themed_image_cache_lock_); |
767 GenerateFrameImages(); | 757 GenerateFrameImages(); |
768 GenerateTabImages(); | 758 GenerateTabImages(); |
769 } | 759 } |
770 | 760 |
771 if (process_images_) { | 761 if (process_images_) { |
772 WriteImagesToDisk(); | 762 WriteImagesToDisk(); |
773 UserMetrics::RecordAction(L"Migrated noncached to cached theme.", | 763 UserMetrics::RecordAction(L"Migrated noncached to cached theme.", profile_); |
774 profile_); | |
775 } | |
776 UserMetrics::RecordAction(L"Themes_loaded", profile_); | |
777 } | 764 } |
| 765 UserMetrics::RecordAction(L"Themes_loaded", profile_); |
778 } | 766 } |
779 | 767 |
780 void BrowserThemeProvider::NotifyThemeChanged() { | 768 void BrowserThemeProvider::NotifyThemeChanged() { |
781 // Redraw! | 769 // Redraw! |
782 NotificationService* service = NotificationService::current(); | 770 NotificationService* service = NotificationService::current(); |
783 service->Notify(NotificationType::BROWSER_THEME_CHANGED, | 771 service->Notify(NotificationType::BROWSER_THEME_CHANGED, |
784 Source<BrowserThemeProvider>(this), | 772 Source<BrowserThemeProvider>(this), |
785 NotificationService::NoDetails()); | 773 NotificationService::NoDetails()); |
786 } | 774 } |
787 | 775 |
788 SkBitmap* BrowserThemeProvider::LoadThemeBitmap(int id) { | 776 SkBitmap* BrowserThemeProvider::LoadThemeBitmap(int id) { |
789 DCHECK(CalledOnValidThread()); | 777 DCHECK(CalledOnValidThread()); |
790 | 778 |
791 if (!themeable_images_[id]) | 779 if (!themeable_images[id]) |
792 return NULL; | 780 return NULL; |
793 | 781 |
794 // Attempt to find the image in our theme bundle. | 782 // Attempt to find the image in our theme bundle. |
795 std::vector<unsigned char> raw_data, png_data; | 783 std::vector<unsigned char> raw_data, png_data; |
796 if (ReadThemeFileData(id, &raw_data)) { | 784 if (ReadThemeFileData(id, &raw_data)) { |
797 // Decode the PNG. | 785 // Decode the PNG. |
798 int image_width = 0; | 786 int image_width = 0; |
799 int image_height = 0; | 787 int image_height = 0; |
800 | 788 |
801 if (!gfx::PNGCodec::Decode(&raw_data.front(), raw_data.size(), | 789 if (!gfx::PNGCodec::Decode(&raw_data.front(), raw_data.size(), |
802 gfx::PNGCodec::FORMAT_BGRA, &png_data, | 790 gfx::PNGCodec::FORMAT_BGRA, &png_data, |
803 &image_width, &image_height)) { | 791 &image_width, &image_height)) { |
804 NOTREACHED() << "Unable to decode theme image resource " << id; | 792 NOTREACHED() << "Unable to decode theme image resource " << id; |
805 return NULL; | 793 return NULL; |
806 } | 794 } |
807 | 795 |
808 return gfx::PNGCodec::CreateSkBitmapFromBGRAFormat(png_data, | 796 return gfx::PNGCodec::CreateSkBitmapFromBGRAFormat(png_data, |
809 image_width, | 797 image_width, |
810 image_height); | 798 image_height); |
811 } else { | 799 } else { |
812 // TODO(glen): File no-longer exists, we're out of date. We should | 800 // TODO(glen): File no-longer exists, we're out of date. We should |
813 // clear the theme (or maybe just the pref that points to this | 801 // clear the theme (or maybe just the pref that points to this |
(...skipping 29 matching lines...) Expand all Loading... |
843 images_disk_cache_[image_path] = id; | 831 images_disk_cache_[image_path] = id; |
844 } | 832 } |
845 | 833 |
846 #if defined(OS_WIN) | 834 #if defined(OS_WIN) |
847 void BrowserThemeProvider::FreePlatformCaches() { | 835 void BrowserThemeProvider::FreePlatformCaches() { |
848 // Views (Skia) has no platform image cache to clear. | 836 // Views (Skia) has no platform image cache to clear. |
849 } | 837 } |
850 #endif | 838 #endif |
851 | 839 |
852 SkBitmap* BrowserThemeProvider::GenerateTabBackgroundBitmapImpl(int id) { | 840 SkBitmap* BrowserThemeProvider::GenerateTabBackgroundBitmapImpl(int id) { |
853 int base_id; | 841 int base_id = (id == IDR_THEME_TAB_BACKGROUND) ? |
854 if (id == IDR_THEME_TAB_BACKGROUND) { | 842 IDR_THEME_FRAME : IDR_THEME_FRAME_INCOGNITO; |
855 base_id = IDR_THEME_FRAME; | 843 // According to Miranda, it is safe to read from the themed_image_cache_ here |
856 } else { | |
857 base_id = IDR_THEME_FRAME_INCOGNITO; | |
858 } | |
859 // According to Miranda, it is safe to read from the themed-image_cache_ here | |
860 // because we only lock to write on the UI thread, and we only lock to read | 844 // because we only lock to write on the UI thread, and we only lock to read |
861 // on the cache writing thread. | 845 // on the cache writing thread. |
862 std::map<int, SkBitmap*>::iterator it = themed_image_cache_.find(base_id); | 846 ImageCache::iterator it = themed_image_cache_.find(base_id); |
863 if (it != themed_image_cache_.end()) { | 847 if (it != themed_image_cache_.end()) |
864 SkBitmap bg_tint = TintBitmap(*(it->second), TINT_BACKGROUND_TAB); | 848 return NULL; |
865 int vertical_offset = HasCustomImage(id) ? | |
866 kRestoredTabVerticalOffset : 0; | |
867 SkBitmap* bg_tab = new SkBitmap(SkBitmapOperations::CreateTiledBitmap( | |
868 bg_tint, 0, vertical_offset, bg_tint.width(), bg_tint.height())); | |
869 | 849 |
870 // If they've provided a custom image, overlay it. | 850 SkBitmap bg_tint = TintBitmap(*(it->second), TINT_BACKGROUND_TAB); |
871 if (HasCustomImage(id)) { | 851 int vertical_offset = HasCustomImage(id) ? kRestoredTabVerticalOffset : 0; |
872 SkBitmap* overlay = LoadThemeBitmap(id); | 852 SkBitmap* bg_tab = new SkBitmap(SkBitmapOperations::CreateTiledBitmap( |
873 if (overlay) { | 853 bg_tint, 0, vertical_offset, bg_tint.width(), bg_tint.height())); |
874 SkCanvas canvas(*bg_tab); | 854 |
875 for (int x = 0; x < bg_tab->width(); x += overlay->width()) | 855 // If they've provided a custom image, overlay it. |
876 canvas.drawBitmap(*overlay, static_cast<SkScalar>(x), 0, NULL); | 856 if (HasCustomImage(id)) { |
877 } | 857 SkBitmap* overlay = LoadThemeBitmap(id); |
| 858 if (overlay) { |
| 859 SkCanvas canvas(*bg_tab); |
| 860 for (int x = 0; x < bg_tab->width(); x += overlay->width()) |
| 861 canvas.drawBitmap(*overlay, static_cast<SkScalar>(x), 0, NULL); |
878 } | 862 } |
879 | |
880 return bg_tab; | |
881 } | 863 } |
882 | 864 |
883 return NULL; | 865 return bg_tab; |
884 } | 866 } |
885 | 867 |
886 const std::string BrowserThemeProvider::GetTintKey(int id) { | 868 const std::string BrowserThemeProvider::GetTintKey(int id) { |
887 switch (id) { | 869 switch (id) { |
888 case TINT_FRAME: | 870 case TINT_FRAME: |
889 return kTintFrame; | 871 return kTintFrame; |
890 case TINT_FRAME_INACTIVE: | 872 case TINT_FRAME_INACTIVE: |
891 return kTintFrameInactive; | 873 return kTintFrameInactive; |
892 case TINT_FRAME_INCOGNITO: | 874 case TINT_FRAME_INCOGNITO: |
893 return kTintFrameIncognito; | 875 return kTintFrameIncognito; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1015 return SkBitmapOperations::CreateHSLShiftedBitmap(bitmap, GetTint(hsl_id)); | 997 return SkBitmapOperations::CreateHSLShiftedBitmap(bitmap, GetTint(hsl_id)); |
1016 } | 998 } |
1017 | 999 |
1018 void BrowserThemeProvider::SetImageData(DictionaryValue* images_value, | 1000 void BrowserThemeProvider::SetImageData(DictionaryValue* images_value, |
1019 FilePath images_path) { | 1001 FilePath images_path) { |
1020 images_.clear(); | 1002 images_.clear(); |
1021 | 1003 |
1022 if (!images_value) | 1004 if (!images_value) |
1023 return; | 1005 return; |
1024 | 1006 |
1025 DictionaryValue::key_iterator iter = images_value->begin_keys(); | 1007 for (DictionaryValue::key_iterator iter(images_value->begin_keys()); |
1026 while (iter != images_value->end_keys()) { | 1008 iter != images_value->end_keys(); ++iter) { |
1027 std::string val; | 1009 std::string val; |
1028 if (images_value->GetString(*iter, &val)) { | 1010 if (images_value->GetString(*iter, &val)) { |
1029 int id = ThemeResourcesUtil::GetId(WideToUTF8(*iter)); | 1011 int id = ThemeResourcesUtil::GetId(WideToUTF8(*iter)); |
1030 if (id != -1) { | 1012 if (id != -1) { |
1031 if (!images_path.empty()) { | 1013 if (!images_path.empty()) { |
1032 images_[id] = WideToUTF8(images_path.AppendASCII(val) | 1014 images_[id] = WideToUTF8(images_path.AppendASCII(val) |
1033 .ToWStringHack()); | 1015 .ToWStringHack()); |
1034 resource_names_[id] = WideToASCII(*iter); | 1016 resource_names_[id] = WideToASCII(*iter); |
1035 } else { | 1017 } else { |
1036 images_[id] = val; | 1018 images_[id] = val; |
1037 } | 1019 } |
1038 } | 1020 } |
1039 } | 1021 } |
1040 ++iter; | |
1041 } | 1022 } |
1042 } | 1023 } |
1043 | 1024 |
1044 void BrowserThemeProvider::SetColorData(DictionaryValue* colors_value) { | 1025 void BrowserThemeProvider::SetColorData(DictionaryValue* colors_value) { |
1045 colors_.clear(); | 1026 colors_.clear(); |
1046 | 1027 |
1047 if (!colors_value) | 1028 if (!colors_value) |
1048 return; | 1029 return; |
1049 | 1030 |
1050 DictionaryValue::key_iterator iter = colors_value->begin_keys(); | 1031 for (DictionaryValue::key_iterator iter(colors_value->begin_keys()); |
1051 while (iter != colors_value->end_keys()) { | 1032 iter != colors_value->end_keys(); ++iter) { |
1052 ListValue* color_list; | 1033 ListValue* color_list; |
1053 if (colors_value->GetList(*iter, &color_list) && | 1034 if (colors_value->GetList(*iter, &color_list) && |
1054 (color_list->GetSize() == 3 || color_list->GetSize() == 4)) { | 1035 ((color_list->GetSize() == 3) || (color_list->GetSize() == 4))) { |
1055 int r, g, b; | 1036 int r, g, b; |
1056 color_list->GetInteger(0, &r); | 1037 color_list->GetInteger(0, &r); |
1057 color_list->GetInteger(1, &g); | 1038 color_list->GetInteger(1, &g); |
1058 color_list->GetInteger(2, &b); | 1039 color_list->GetInteger(2, &b); |
1059 if (color_list->GetSize() == 4) { | 1040 if (color_list->GetSize() == 4) { |
1060 double alpha; | 1041 double alpha; |
1061 int alpha_int; | 1042 int alpha_int; |
1062 if (color_list->GetReal(3, &alpha)) { | 1043 if (color_list->GetReal(3, &alpha)) { |
1063 colors_[WideToUTF8(*iter)] = SkColorSetARGB( | 1044 colors_[WideToUTF8(*iter)] = |
1064 static_cast<int>(alpha * 255), r, g, b); | 1045 SkColorSetARGB(static_cast<int>(alpha * 255), r, g, b); |
1065 } else if (color_list->GetInteger(3, &alpha_int)) { | 1046 } else if (color_list->GetInteger(3, &alpha_int)) { |
1066 colors_[WideToUTF8(*iter)] = SkColorSetARGB( | 1047 colors_[WideToUTF8(*iter)] = |
1067 alpha_int * 255, r, g, b); | 1048 SkColorSetARGB(alpha_int * 255, r, g, b); |
1068 } | 1049 } |
1069 } else { | 1050 } else { |
1070 colors_[WideToUTF8(*iter)] = SkColorSetRGB(r, g, b); | 1051 colors_[WideToUTF8(*iter)] = SkColorSetRGB(r, g, b); |
1071 } | 1052 } |
1072 } | 1053 } |
1073 ++iter; | |
1074 } | 1054 } |
1075 } | 1055 } |
1076 | 1056 |
1077 void BrowserThemeProvider::SetTintData(DictionaryValue* tints_value) { | 1057 void BrowserThemeProvider::SetTintData(DictionaryValue* tints_value) { |
1078 tints_.clear(); | 1058 tints_.clear(); |
1079 | 1059 |
1080 if (!tints_value) | 1060 if (!tints_value) |
1081 return; | 1061 return; |
1082 | 1062 |
1083 DictionaryValue::key_iterator iter = tints_value->begin_keys(); | 1063 for (DictionaryValue::key_iterator iter(tints_value->begin_keys()); |
1084 while (iter != tints_value->end_keys()) { | 1064 iter != tints_value->end_keys(); ++iter) { |
1085 ListValue* tint_list; | 1065 ListValue* tint_list; |
1086 if (tints_value->GetList(*iter, &tint_list) && | 1066 if (tints_value->GetList(*iter, &tint_list) && |
1087 tint_list->GetSize() == 3) { | 1067 (tint_list->GetSize() == 3)) { |
1088 color_utils::HSL hsl = { -1, -1, -1 }; | 1068 color_utils::HSL hsl = { -1, -1, -1 }; |
1089 int value = 0; | 1069 int value = 0; |
1090 if (!tint_list->GetReal(0, &hsl.h) && tint_list->GetInteger(0, &value)) | 1070 if (!tint_list->GetReal(0, &hsl.h) && tint_list->GetInteger(0, &value)) |
1091 hsl.h = value; | 1071 hsl.h = value; |
1092 if (!tint_list->GetReal(1, &hsl.s) && tint_list->GetInteger(1, &value)) | 1072 if (!tint_list->GetReal(1, &hsl.s) && tint_list->GetInteger(1, &value)) |
1093 hsl.s = value; | 1073 hsl.s = value; |
1094 if (!tint_list->GetReal(2, &hsl.l) && tint_list->GetInteger(2, &value)) | 1074 if (!tint_list->GetReal(2, &hsl.l) && tint_list->GetInteger(2, &value)) |
1095 hsl.l = value; | 1075 hsl.l = value; |
1096 | 1076 |
1097 tints_[WideToUTF8(*iter)] = hsl; | 1077 tints_[WideToUTF8(*iter)] = hsl; |
1098 } | 1078 } |
1099 ++iter; | |
1100 } | 1079 } |
1101 } | 1080 } |
1102 | 1081 |
1103 void BrowserThemeProvider::SetDisplayPropertyData( | 1082 void BrowserThemeProvider::SetDisplayPropertyData( |
1104 DictionaryValue* display_properties_value) { | 1083 DictionaryValue* display_properties_value) { |
1105 display_properties_.clear(); | 1084 display_properties_.clear(); |
1106 | 1085 |
1107 if (!display_properties_value) | 1086 if (!display_properties_value) |
1108 return; | 1087 return; |
1109 | 1088 |
1110 DictionaryValue::key_iterator iter = display_properties_value->begin_keys(); | 1089 for (DictionaryValue::key_iterator iter( |
1111 while (iter != display_properties_value->end_keys()) { | 1090 display_properties_value->begin_keys()); |
| 1091 iter != display_properties_value->end_keys(); ++iter) { |
1112 // New tab page alignment and background tiling. | 1092 // New tab page alignment and background tiling. |
1113 if (base::strcasecmp(WideToUTF8(*iter).c_str(), | 1093 if (base::strcasecmp(WideToUTF8(*iter).c_str(), |
1114 kDisplayPropertyNTPAlignment) == 0) { | 1094 kDisplayPropertyNTPAlignment) == 0) { |
1115 std::string val; | 1095 std::string val; |
1116 if (display_properties_value->GetString(*iter, &val)) | 1096 if (display_properties_value->GetString(*iter, &val)) { |
1117 display_properties_[kDisplayPropertyNTPAlignment] = | 1097 display_properties_[kDisplayPropertyNTPAlignment] = |
1118 StringToAlignment(val); | 1098 StringToAlignment(val); |
| 1099 } |
1119 } else if (base::strcasecmp(WideToUTF8(*iter).c_str(), | 1100 } else if (base::strcasecmp(WideToUTF8(*iter).c_str(), |
1120 kDisplayPropertyNTPTiling) == 0) { | 1101 kDisplayPropertyNTPTiling) == 0) { |
1121 std::string val; | 1102 std::string val; |
1122 if (display_properties_value->GetString(*iter, &val)) | 1103 if (display_properties_value->GetString(*iter, &val)) { |
1123 display_properties_[kDisplayPropertyNTPTiling] = | 1104 display_properties_[kDisplayPropertyNTPTiling] = |
1124 StringToTiling(val); | 1105 StringToTiling(val); |
| 1106 } |
1125 } | 1107 } |
1126 if (base::strcasecmp(WideToUTF8(*iter).c_str(), | 1108 if (base::strcasecmp(WideToUTF8(*iter).c_str(), |
1127 kDisplayPropertyNTPInverseLogo) == 0) { | 1109 kDisplayPropertyNTPInverseLogo) == 0) { |
1128 int val = 0; | 1110 int val = 0; |
1129 if (display_properties_value->GetInteger(*iter, &val)) | 1111 if (display_properties_value->GetInteger(*iter, &val)) |
1130 display_properties_[kDisplayPropertyNTPInverseLogo] = val; | 1112 display_properties_[kDisplayPropertyNTPInverseLogo] = val; |
1131 } | 1113 } |
1132 ++iter; | |
1133 } | 1114 } |
1134 } | 1115 } |
1135 | 1116 |
1136 SkBitmap* BrowserThemeProvider::GenerateTabBackgroundBitmap(int id) { | 1117 SkBitmap* BrowserThemeProvider::GenerateTabBackgroundBitmap(int id) { |
1137 if (id == IDR_THEME_TAB_BACKGROUND || | 1118 if (id == IDR_THEME_TAB_BACKGROUND || |
1138 id == IDR_THEME_TAB_BACKGROUND_INCOGNITO) { | 1119 id == IDR_THEME_TAB_BACKGROUND_INCOGNITO) { |
1139 // The requested image is a background tab. Get a frame to create the | 1120 // The requested image is a background tab. Get a frame to create the |
1140 // tab against. As themes don't use the glass frame, we don't have to | 1121 // tab against. As themes don't use the glass frame, we don't have to |
1141 // worry about compositing them together, as our default theme provides | 1122 // worry about compositing them together, as our default theme provides |
1142 // the necessary bitmaps. | 1123 // the necessary bitmaps. |
1143 if (!process_images_) { | 1124 if (!process_images_) { |
1144 scoped_ptr<SkBitmap> frame; | 1125 scoped_ptr<SkBitmap> frame; |
1145 frame.reset(LoadThemeBitmap(id)); | 1126 frame.reset(LoadThemeBitmap(id)); |
1146 if (frame.get()) | 1127 if (frame.get()) |
1147 themed_image_cache_[id] = new SkBitmap(*frame.get()); | 1128 themed_image_cache_[id] = new SkBitmap(*frame.get()); |
1148 } else { | 1129 } else { |
1149 SkBitmap* bg_tab = GenerateTabBackgroundBitmapImpl(id); | 1130 SkBitmap* bg_tab = GenerateTabBackgroundBitmapImpl(id); |
1150 | 1131 |
1151 if (bg_tab) { | 1132 if (bg_tab) { |
1152 std::string resource_name; | 1133 std::string resource_name((id == IDR_THEME_TAB_BACKGROUND) ? |
1153 if (id == IDR_THEME_TAB_BACKGROUND) { | 1134 "theme_tab_background" : "theme_tab_background_incognito"); |
1154 resource_name = "theme_tab_background"; | |
1155 } else { | |
1156 resource_name = "theme_tab_background_incognito"; | |
1157 } | |
1158 | 1135 |
1159 themed_image_cache_[id] = bg_tab; | 1136 themed_image_cache_[id] = bg_tab; |
1160 SaveThemeBitmap(resource_name, id); | 1137 SaveThemeBitmap(resource_name, id); |
1161 return bg_tab; | 1138 return bg_tab; |
1162 } | 1139 } |
1163 } | 1140 } |
1164 } | 1141 } |
1165 return NULL; | 1142 return NULL; |
1166 } | 1143 } |
1167 | 1144 |
1168 void BrowserThemeProvider::SaveImageData(DictionaryValue* images_value) { | 1145 void BrowserThemeProvider::SaveImageData(DictionaryValue* images_value) { |
1169 // Save our images data. | 1146 // Save our images data. |
1170 DictionaryValue* pref_images = | 1147 DictionaryValue* pref_images = |
1171 profile_->GetPrefs()->GetMutableDictionary(prefs::kCurrentThemeImages); | 1148 profile_->GetPrefs()->GetMutableDictionary(prefs::kCurrentThemeImages); |
1172 pref_images->Clear(); | 1149 pref_images->Clear(); |
1173 | 1150 |
1174 if (images_value) { | 1151 if (!images_value) |
1175 DictionaryValue::key_iterator iter = images_value->begin_keys(); | 1152 return; |
1176 while (iter != images_value->end_keys()) { | 1153 |
1177 std::string val; | 1154 for (DictionaryValue::key_iterator iter(images_value->begin_keys()); |
1178 if (images_value->GetString(*iter, &val)) { | 1155 iter != images_value->end_keys(); ++iter) { |
1179 int id = ThemeResourcesUtil::GetId(WideToUTF8(*iter)); | 1156 std::string val; |
1180 if (id != -1) | 1157 if (images_value->GetString(*iter, &val)) { |
1181 pref_images->SetString(*iter, images_[id]); | 1158 int id = ThemeResourcesUtil::GetId(WideToUTF8(*iter)); |
1182 } | 1159 if (id != -1) |
1183 ++iter; | 1160 pref_images->SetString(*iter, images_[id]); |
1184 } | 1161 } |
1185 } | 1162 } |
1186 } | 1163 } |
1187 | 1164 |
1188 void BrowserThemeProvider::SaveColorData() { | 1165 void BrowserThemeProvider::SaveColorData() { |
1189 // Save our color data. | 1166 // Save our color data. |
1190 DictionaryValue* pref_colors = | 1167 DictionaryValue* pref_colors = |
1191 profile_->GetPrefs()->GetMutableDictionary(prefs::kCurrentThemeColors); | 1168 profile_->GetPrefs()->GetMutableDictionary(prefs::kCurrentThemeColors); |
1192 pref_colors->Clear(); | 1169 pref_colors->Clear(); |
1193 if (colors_.size()) { | 1170 |
1194 ColorMap::iterator iter = colors_.begin(); | 1171 if (colors_.empty()) |
1195 while (iter != colors_.end()) { | 1172 return; |
1196 SkColor rgba = (*iter).second; | 1173 |
1197 ListValue* rgb_list = new ListValue(); | 1174 for (ColorMap::iterator iter(colors_.begin()); iter != colors_.end(); |
1198 rgb_list->Set(0, Value::CreateIntegerValue(SkColorGetR(rgba))); | 1175 ++iter) { |
1199 rgb_list->Set(1, Value::CreateIntegerValue(SkColorGetG(rgba))); | 1176 SkColor rgba = iter->second; |
1200 rgb_list->Set(2, Value::CreateIntegerValue(SkColorGetB(rgba))); | 1177 ListValue* rgb_list = new ListValue(); |
1201 if (SkColorGetA(rgba) != 255) | 1178 rgb_list->Set(0, Value::CreateIntegerValue(SkColorGetR(rgba))); |
1202 rgb_list->Set(3, Value::CreateRealValue(SkColorGetA(rgba) / 255.0)); | 1179 rgb_list->Set(1, Value::CreateIntegerValue(SkColorGetG(rgba))); |
1203 pref_colors->Set(UTF8ToWide((*iter).first), rgb_list); | 1180 rgb_list->Set(2, Value::CreateIntegerValue(SkColorGetB(rgba))); |
1204 ++iter; | 1181 if (SkColorGetA(rgba) != 255) |
1205 } | 1182 rgb_list->Set(3, Value::CreateRealValue(SkColorGetA(rgba) / 255.0)); |
| 1183 pref_colors->Set(UTF8ToWide(iter->first), rgb_list); |
1206 } | 1184 } |
1207 } | 1185 } |
1208 | 1186 |
1209 void BrowserThemeProvider::SaveTintData() { | 1187 void BrowserThemeProvider::SaveTintData() { |
1210 // Save our tint data. | 1188 // Save our tint data. |
1211 DictionaryValue* pref_tints = | 1189 DictionaryValue* pref_tints = |
1212 profile_->GetPrefs()->GetMutableDictionary(prefs::kCurrentThemeTints); | 1190 profile_->GetPrefs()->GetMutableDictionary(prefs::kCurrentThemeTints); |
1213 pref_tints->Clear(); | 1191 pref_tints->Clear(); |
1214 if (tints_.size()) { | 1192 |
1215 TintMap::iterator iter = tints_.begin(); | 1193 if (tints_.empty()) |
1216 while (iter != tints_.end()) { | 1194 return; |
1217 color_utils::HSL hsl = (*iter).second; | 1195 |
1218 ListValue* hsl_list = new ListValue(); | 1196 for (TintMap::iterator iter(tints_.begin()); iter != tints_.end(); ++iter) { |
1219 hsl_list->Set(0, Value::CreateRealValue(hsl.h)); | 1197 color_utils::HSL hsl = iter->second; |
1220 hsl_list->Set(1, Value::CreateRealValue(hsl.s)); | 1198 ListValue* hsl_list = new ListValue(); |
1221 hsl_list->Set(2, Value::CreateRealValue(hsl.l)); | 1199 hsl_list->Set(0, Value::CreateRealValue(hsl.h)); |
1222 pref_tints->Set(UTF8ToWide((*iter).first), hsl_list); | 1200 hsl_list->Set(1, Value::CreateRealValue(hsl.s)); |
1223 ++iter; | 1201 hsl_list->Set(2, Value::CreateRealValue(hsl.l)); |
1224 } | 1202 pref_tints->Set(UTF8ToWide(iter->first), hsl_list); |
1225 } | 1203 } |
1226 } | 1204 } |
1227 | 1205 |
1228 void BrowserThemeProvider::SaveDisplayPropertyData() { | 1206 void BrowserThemeProvider::SaveDisplayPropertyData() { |
1229 // Save our display property data. | 1207 // Save our display property data. |
1230 DictionaryValue* pref_display_properties = | 1208 DictionaryValue* pref_display_properties = |
1231 profile_->GetPrefs()-> | 1209 profile_->GetPrefs()-> |
1232 GetMutableDictionary(prefs::kCurrentThemeDisplayProperties); | 1210 GetMutableDictionary(prefs::kCurrentThemeDisplayProperties); |
1233 pref_display_properties->Clear(); | 1211 pref_display_properties->Clear(); |
1234 | 1212 |
1235 if (display_properties_.size()) { | 1213 if (display_properties_.empty()) |
1236 DisplayPropertyMap::iterator iter = display_properties_.begin(); | 1214 return; |
1237 while (iter != display_properties_.end()) { | 1215 |
1238 if (base::strcasecmp((*iter).first.c_str(), | 1216 for (DisplayPropertyMap::iterator iter(display_properties_.begin()); |
1239 kDisplayPropertyNTPAlignment) == 0) { | 1217 iter != display_properties_.end(); ++iter) { |
1240 pref_display_properties-> | 1218 if (base::strcasecmp(iter->first.c_str(), |
1241 SetString(UTF8ToWide((*iter).first), AlignmentToString( | 1219 kDisplayPropertyNTPAlignment) == 0) { |
1242 (*iter).second)); | 1220 pref_display_properties->SetString(UTF8ToWide(iter->first), |
1243 } else if (base::strcasecmp((*iter).first.c_str(), | 1221 AlignmentToString(iter->second)); |
1244 kDisplayPropertyNTPTiling) == 0) { | 1222 } else if (base::strcasecmp(iter->first.c_str(), |
1245 pref_display_properties-> | 1223 kDisplayPropertyNTPTiling) == 0) { |
1246 SetString(UTF8ToWide((*iter).first), TilingToString( | 1224 pref_display_properties->SetString(UTF8ToWide(iter->first), |
1247 (*iter).second)); | 1225 TilingToString(iter->second)); |
1248 } | 1226 } |
1249 if (base::strcasecmp((*iter).first.c_str(), | 1227 if (base::strcasecmp(iter->first.c_str(), |
1250 kDisplayPropertyNTPInverseLogo) == 0) { | 1228 kDisplayPropertyNTPInverseLogo) == 0) { |
1251 pref_display_properties-> | 1229 pref_display_properties->SetInteger(UTF8ToWide(iter->first), |
1252 SetInteger(UTF8ToWide((*iter).first), (*iter).second); | 1230 iter->second); |
1253 } | |
1254 ++iter; | |
1255 } | 1231 } |
1256 } | 1232 } |
1257 } | 1233 } |
1258 | 1234 |
1259 void BrowserThemeProvider::SaveCachedImageData() { | 1235 void BrowserThemeProvider::SaveCachedImageData() { |
1260 DictionaryValue* pref_images = | 1236 DictionaryValue* pref_images = |
1261 profile_->GetPrefs()->GetMutableDictionary(prefs::kCurrentThemeImages); | 1237 profile_->GetPrefs()->GetMutableDictionary(prefs::kCurrentThemeImages); |
1262 | 1238 |
1263 for (ImagesDiskCache::iterator it = images_disk_cache_.begin(); | 1239 for (ImagesDiskCache::iterator it(images_disk_cache_.begin()); |
1264 it != images_disk_cache_.end(); it++) { | 1240 it != images_disk_cache_.end(); ++it) { |
1265 std::wstring disk_path = it->first.ToWStringHack(); | 1241 std::wstring disk_path = it->first.ToWStringHack(); |
1266 std::string pref_name = resource_names_[it->second]; | 1242 std::string pref_name = resource_names_[it->second]; |
1267 pref_images->SetString(UTF8ToWide(pref_name), | 1243 pref_images->SetString(UTF8ToWide(pref_name), WideToUTF8(disk_path)); |
1268 WideToUTF8(disk_path)); | |
1269 } | 1244 } |
1270 profile_->GetPrefs()->SavePersistentPrefs(); | 1245 profile_->GetPrefs()->SavePersistentPrefs(); |
1271 } | 1246 } |
1272 | 1247 |
1273 void BrowserThemeProvider::SaveThemeID(const std::string& id) { | 1248 void BrowserThemeProvider::SaveThemeID(const std::string& id) { |
1274 profile_->GetPrefs()->SetString(prefs::kCurrentThemeID, UTF8ToWide(id)); | 1249 profile_->GetPrefs()->SetString(prefs::kCurrentThemeID, UTF8ToWide(id)); |
1275 } | 1250 } |
1276 | 1251 |
1277 void BrowserThemeProvider::ClearCaches() { | 1252 void BrowserThemeProvider::ClearCaches() { |
1278 FreePlatformCaches(); | 1253 FreePlatformCaches(); |
1279 for (ImageCache::iterator i = image_cache_.begin(); | 1254 STLDeleteValues(&image_cache_); |
1280 i != image_cache_.end(); i++) { | |
1281 delete i->second; | |
1282 } | |
1283 | 1255 |
1284 // Scope for AutoLock on themed_image_cache. | 1256 // Scope for AutoLock on themed_image_cache. |
1285 { | 1257 { |
1286 AutoLock lock(themed_image_cache_lock_); | 1258 AutoLock lock(themed_image_cache_lock_); |
1287 for (ImageCache::iterator i = themed_image_cache_.begin(); | 1259 STLDeleteValues(&themed_image_cache_); |
1288 i != themed_image_cache_.end(); i++) { | |
1289 delete i->second; | |
1290 } | |
1291 themed_image_cache_.clear(); | |
1292 } | 1260 } |
1293 image_cache_.clear(); | 1261 |
1294 images_disk_cache_.clear(); | 1262 images_disk_cache_.clear(); |
1295 } | 1263 } |
1296 | 1264 |
1297 void BrowserThemeProvider::WriteImagesToDisk() { | 1265 void BrowserThemeProvider::WriteImagesToDisk() { |
1298 g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE, | 1266 g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE, |
1299 new WriteImagesToDiskTask(images_disk_cache_, themed_image_cache_)); | 1267 new WriteImagesToDiskTask(images_disk_cache_, themed_image_cache_)); |
1300 SaveCachedImageData(); | 1268 SaveCachedImageData(); |
1301 } | 1269 } |
1302 | 1270 |
1303 bool BrowserThemeProvider::ShouldTintFrames() { | 1271 bool BrowserThemeProvider::ShouldTintFrames() { |
1304 return (HasCustomImage(IDR_THEME_FRAME) || | 1272 return (HasCustomImage(IDR_THEME_FRAME) || |
1305 tints_.find(GetTintKey(TINT_BACKGROUND_TAB)) != tints_.end() || | 1273 tints_.find(GetTintKey(TINT_BACKGROUND_TAB)) != tints_.end() || |
1306 tints_.find(GetTintKey(TINT_FRAME)) != tints_.end() || | 1274 tints_.find(GetTintKey(TINT_FRAME)) != tints_.end() || |
1307 tints_.find(GetTintKey(TINT_FRAME_INACTIVE)) != tints_.end() || | 1275 tints_.find(GetTintKey(TINT_FRAME_INACTIVE)) != tints_.end() || |
1308 tints_.find(GetTintKey(TINT_FRAME_INCOGNITO)) != tints_.end() || | 1276 tints_.find(GetTintKey(TINT_FRAME_INCOGNITO)) != tints_.end() || |
1309 tints_.find(GetTintKey(TINT_FRAME_INCOGNITO_INACTIVE)) != tints_.end()); | 1277 tints_.find(GetTintKey(TINT_FRAME_INCOGNITO_INACTIVE)) != tints_.end()); |
1310 } | 1278 } |
OLD | NEW |