OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/themes/browser_theme_pack.h" | 5 #include "chrome/browser/themes/browser_theme_pack.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/threading/sequenced_worker_pool.h" | 13 #include "base/threading/sequenced_worker_pool.h" |
14 #include "base/threading/thread_restrictions.h" | 14 #include "base/threading/thread_restrictions.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "base/values.h" | 16 #include "base/values.h" |
17 #include "chrome/browser/themes/theme_properties.h" | 17 #include "chrome/browser/themes/theme_properties.h" |
18 #include "chrome/common/extensions/api/themes/theme_handler.h" | 18 #include "chrome/common/extensions/manifest_handlers/theme_handler.h" |
19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
20 #include "extensions/common/id_util.h" | 20 #include "extensions/common/id_util.h" |
21 #include "grit/theme_resources.h" | 21 #include "grit/theme_resources.h" |
22 #include "grit/ui_resources.h" | 22 #include "grit/ui_resources.h" |
23 #include "net/base/file_stream.h" | 23 #include "net/base/file_stream.h" |
24 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
25 #include "third_party/skia/include/core/SkCanvas.h" | 25 #include "third_party/skia/include/core/SkCanvas.h" |
26 #include "ui/base/resource/data_pack.h" | 26 #include "ui/base/resource/data_pack.h" |
27 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
28 #include "ui/gfx/canvas.h" | 28 #include "ui/gfx/canvas.h" |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 | 535 |
536 // static | 536 // static |
537 scoped_refptr<BrowserThemePack> BrowserThemePack::BuildFromExtension( | 537 scoped_refptr<BrowserThemePack> BrowserThemePack::BuildFromExtension( |
538 const Extension* extension) { | 538 const Extension* extension) { |
539 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 539 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
540 DCHECK(extension); | 540 DCHECK(extension); |
541 DCHECK(extension->is_theme()); | 541 DCHECK(extension->is_theme()); |
542 | 542 |
543 scoped_refptr<BrowserThemePack> pack(new BrowserThemePack); | 543 scoped_refptr<BrowserThemePack> pack(new BrowserThemePack); |
544 pack->BuildHeader(extension); | 544 pack->BuildHeader(extension); |
545 pack->BuildTintsFromJSON(extensions::ThemeInfo::GetThemeTints(extension)); | 545 pack->BuildTintsFromJSON(extensions::ThemeInfo::GetTints(extension)); |
546 pack->BuildColorsFromJSON(extensions::ThemeInfo::GetThemeColors(extension)); | 546 pack->BuildColorsFromJSON(extensions::ThemeInfo::GetColors(extension)); |
547 pack->BuildDisplayPropertiesFromJSON( | 547 pack->BuildDisplayPropertiesFromJSON( |
548 extensions::ThemeInfo::GetThemeDisplayProperties(extension)); | 548 extensions::ThemeInfo::GetDisplayProperties(extension)); |
549 | 549 |
550 // Builds the images. (Image building is dependent on tints). | 550 // Builds the images. (Image building is dependent on tints). |
551 FilePathMap file_paths; | 551 FilePathMap file_paths; |
552 pack->ParseImageNamesFromJSON( | 552 pack->ParseImageNamesFromJSON( |
553 extensions::ThemeInfo::GetThemeImages(extension), | 553 extensions::ThemeInfo::GetImages(extension), |
554 extension->path(), | 554 extension->path(), |
555 &file_paths); | 555 &file_paths); |
556 pack->BuildSourceImagesArray(file_paths); | 556 pack->BuildSourceImagesArray(file_paths); |
557 | 557 |
558 if (!pack->LoadRawBitmapsTo(file_paths, &pack->images_on_ui_thread_)) | 558 if (!pack->LoadRawBitmapsTo(file_paths, &pack->images_on_ui_thread_)) |
559 return NULL; | 559 return NULL; |
560 | 560 |
561 pack->CreateImages(&pack->images_on_ui_thread_); | 561 pack->CreateImages(&pack->images_on_ui_thread_); |
562 | 562 |
563 // Make sure the |images_on_file_thread_| has bitmaps for supported | 563 // Make sure the |images_on_file_thread_| has bitmaps for supported |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 #elif defined(__BIG_ENDIAN__) | 834 #elif defined(__BIG_ENDIAN__) |
835 // Mac check | 835 // Mac check |
836 #error DataPack assumes little endian | 836 #error DataPack assumes little endian |
837 #endif | 837 #endif |
838 header_->little_endian = 1; | 838 header_->little_endian = 1; |
839 | 839 |
840 const std::string& id = extension->id(); | 840 const std::string& id = extension->id(); |
841 memcpy(header_->theme_id, id.c_str(), extensions::id_util::kIdSize); | 841 memcpy(header_->theme_id, id.c_str(), extensions::id_util::kIdSize); |
842 } | 842 } |
843 | 843 |
844 void BrowserThemePack::BuildTintsFromJSON(DictionaryValue* tints_value) { | 844 void BrowserThemePack::BuildTintsFromJSON( |
| 845 const base::DictionaryValue* tints_value) { |
845 tints_ = new TintEntry[kTintTableLength]; | 846 tints_ = new TintEntry[kTintTableLength]; |
846 for (size_t i = 0; i < kTintTableLength; ++i) { | 847 for (size_t i = 0; i < kTintTableLength; ++i) { |
847 tints_[i].id = -1; | 848 tints_[i].id = -1; |
848 tints_[i].h = -1; | 849 tints_[i].h = -1; |
849 tints_[i].s = -1; | 850 tints_[i].s = -1; |
850 tints_[i].l = -1; | 851 tints_[i].l = -1; |
851 } | 852 } |
852 | 853 |
853 if (!tints_value) | 854 if (!tints_value) |
854 return; | 855 return; |
(...skipping 24 matching lines...) Expand all Loading... |
879 temp_tints.begin(); | 880 temp_tints.begin(); |
880 it != temp_tints.end() && count < kTintTableLength; | 881 it != temp_tints.end() && count < kTintTableLength; |
881 ++it, ++count) { | 882 ++it, ++count) { |
882 tints_[count].id = it->first; | 883 tints_[count].id = it->first; |
883 tints_[count].h = it->second.h; | 884 tints_[count].h = it->second.h; |
884 tints_[count].s = it->second.s; | 885 tints_[count].s = it->second.s; |
885 tints_[count].l = it->second.l; | 886 tints_[count].l = it->second.l; |
886 } | 887 } |
887 } | 888 } |
888 | 889 |
889 void BrowserThemePack::BuildColorsFromJSON(DictionaryValue* colors_value) { | 890 void BrowserThemePack::BuildColorsFromJSON( |
| 891 const base::DictionaryValue* colors_value) { |
890 colors_ = new ColorPair[kColorTableLength]; | 892 colors_ = new ColorPair[kColorTableLength]; |
891 for (size_t i = 0; i < kColorTableLength; ++i) { | 893 for (size_t i = 0; i < kColorTableLength; ++i) { |
892 colors_[i].id = -1; | 894 colors_[i].id = -1; |
893 colors_[i].color = SkColorSetRGB(0, 0, 0); | 895 colors_[i].color = SkColorSetRGB(0, 0, 0); |
894 } | 896 } |
895 | 897 |
896 std::map<int, SkColor> temp_colors; | 898 std::map<int, SkColor> temp_colors; |
897 if (colors_value) | 899 if (colors_value) |
898 ReadColorsFromJSON(colors_value, &temp_colors); | 900 ReadColorsFromJSON(colors_value, &temp_colors); |
899 GenerateMissingColors(&temp_colors); | 901 GenerateMissingColors(&temp_colors); |
900 | 902 |
901 // Copy data from the intermediary data structure to the array. | 903 // Copy data from the intermediary data structure to the array. |
902 size_t count = 0; | 904 size_t count = 0; |
903 for (std::map<int, SkColor>::const_iterator it = temp_colors.begin(); | 905 for (std::map<int, SkColor>::const_iterator it = temp_colors.begin(); |
904 it != temp_colors.end() && count < kColorTableLength; ++it, ++count) { | 906 it != temp_colors.end() && count < kColorTableLength; ++it, ++count) { |
905 colors_[count].id = it->first; | 907 colors_[count].id = it->first; |
906 colors_[count].color = it->second; | 908 colors_[count].color = it->second; |
907 } | 909 } |
908 } | 910 } |
909 | 911 |
910 void BrowserThemePack::ReadColorsFromJSON( | 912 void BrowserThemePack::ReadColorsFromJSON( |
911 DictionaryValue* colors_value, | 913 const base::DictionaryValue* colors_value, |
912 std::map<int, SkColor>* temp_colors) { | 914 std::map<int, SkColor>* temp_colors) { |
913 // Parse the incoming data from |colors_value| into an intermediary structure. | 915 // Parse the incoming data from |colors_value| into an intermediary structure. |
914 for (DictionaryValue::Iterator iter(*colors_value); !iter.IsAtEnd(); | 916 for (DictionaryValue::Iterator iter(*colors_value); !iter.IsAtEnd(); |
915 iter.Advance()) { | 917 iter.Advance()) { |
916 const ListValue* color_list; | 918 const ListValue* color_list; |
917 if (iter.value().GetAsList(&color_list) && | 919 if (iter.value().GetAsList(&color_list) && |
918 ((color_list->GetSize() == 3) || (color_list->GetSize() == 4))) { | 920 ((color_list->GetSize() == 3) || (color_list->GetSize() == 4))) { |
919 SkColor color = SK_ColorWHITE; | 921 SkColor color = SK_ColorWHITE; |
920 int r, g, b; | 922 int r, g, b; |
921 if (color_list->GetInteger(0, &r) && | 923 if (color_list->GetInteger(0, &r) && |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
996 ThemeProperties::TINT_FRAME_INCOGNITO)); | 998 ThemeProperties::TINT_FRAME_INCOGNITO)); |
997 } | 999 } |
998 if (!colors->count(ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE)) { | 1000 if (!colors->count(ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE)) { |
999 (*colors)[ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE] = | 1001 (*colors)[ThemeProperties::COLOR_FRAME_INCOGNITO_INACTIVE] = |
1000 HSLShift(frame, GetTintInternal( | 1002 HSLShift(frame, GetTintInternal( |
1001 ThemeProperties::TINT_FRAME_INCOGNITO_INACTIVE)); | 1003 ThemeProperties::TINT_FRAME_INCOGNITO_INACTIVE)); |
1002 } | 1004 } |
1003 } | 1005 } |
1004 | 1006 |
1005 void BrowserThemePack::BuildDisplayPropertiesFromJSON( | 1007 void BrowserThemePack::BuildDisplayPropertiesFromJSON( |
1006 DictionaryValue* display_properties_value) { | 1008 const base::DictionaryValue* display_properties_value) { |
1007 display_properties_ = new DisplayPropertyPair[kDisplayPropertiesSize]; | 1009 display_properties_ = new DisplayPropertyPair[kDisplayPropertiesSize]; |
1008 for (size_t i = 0; i < kDisplayPropertiesSize; ++i) { | 1010 for (size_t i = 0; i < kDisplayPropertiesSize; ++i) { |
1009 display_properties_[i].id = -1; | 1011 display_properties_[i].id = -1; |
1010 display_properties_[i].property = 0; | 1012 display_properties_[i].property = 0; |
1011 } | 1013 } |
1012 | 1014 |
1013 if (!display_properties_value) | 1015 if (!display_properties_value) |
1014 return; | 1016 return; |
1015 | 1017 |
1016 std::map<int, int> temp_properties; | 1018 std::map<int, int> temp_properties; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1048 size_t count = 0; | 1050 size_t count = 0; |
1049 for (std::map<int, int>::const_iterator it = temp_properties.begin(); | 1051 for (std::map<int, int>::const_iterator it = temp_properties.begin(); |
1050 it != temp_properties.end() && count < kDisplayPropertiesSize; | 1052 it != temp_properties.end() && count < kDisplayPropertiesSize; |
1051 ++it, ++count) { | 1053 ++it, ++count) { |
1052 display_properties_[count].id = it->first; | 1054 display_properties_[count].id = it->first; |
1053 display_properties_[count].property = it->second; | 1055 display_properties_[count].property = it->second; |
1054 } | 1056 } |
1055 } | 1057 } |
1056 | 1058 |
1057 void BrowserThemePack::ParseImageNamesFromJSON( | 1059 void BrowserThemePack::ParseImageNamesFromJSON( |
1058 DictionaryValue* images_value, | 1060 const base::DictionaryValue* images_value, |
1059 const base::FilePath& images_path, | 1061 const base::FilePath& images_path, |
1060 FilePathMap* file_paths) const { | 1062 FilePathMap* file_paths) const { |
1061 if (!images_value) | 1063 if (!images_value) |
1062 return; | 1064 return; |
1063 | 1065 |
1064 for (DictionaryValue::Iterator iter(*images_value); !iter.IsAtEnd(); | 1066 for (DictionaryValue::Iterator iter(*images_value); !iter.IsAtEnd(); |
1065 iter.Advance()) { | 1067 iter.Advance()) { |
1066 std::string val; | 1068 std::string val; |
1067 if (iter.value().GetAsString(&val)) { | 1069 if (iter.value().GetAsString(&val)) { |
1068 int id = GetPersistentIDByName(iter.key()); | 1070 int id = GetPersistentIDByName(iter.key()); |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1355 ui::ScaleFactor scale_factor) const { | 1357 ui::ScaleFactor scale_factor) const { |
1356 if (prs_id < 0) | 1358 if (prs_id < 0) |
1357 return -1; | 1359 return -1; |
1358 | 1360 |
1359 for (size_t i = 0; i < scale_factors_.size(); ++i) { | 1361 for (size_t i = 0; i < scale_factors_.size(); ++i) { |
1360 if (scale_factors_[i] == scale_factor) | 1362 if (scale_factors_[i] == scale_factor) |
1361 return static_cast<int>(kPersistingImagesLength * i) + prs_id; | 1363 return static_cast<int>(kPersistingImagesLength * i) + prs_id; |
1362 } | 1364 } |
1363 return -1; | 1365 return -1; |
1364 } | 1366 } |
OLD | NEW |