| 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" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "grit/theme_resources.h" | 22 #include "grit/theme_resources.h" |
| 23 #include "grit/ui_resources.h" | 23 #include "grit/ui_resources.h" |
| 24 #include "net/base/file_stream.h" | 24 #include "net/base/file_stream.h" |
| 25 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
| 26 #include "third_party/skia/include/core/SkCanvas.h" | 26 #include "third_party/skia/include/core/SkCanvas.h" |
| 27 #include "ui/base/resource/data_pack.h" | 27 #include "ui/base/resource/data_pack.h" |
| 28 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
| 29 #include "ui/gfx/canvas.h" | 29 #include "ui/gfx/canvas.h" |
| 30 #include "ui/gfx/codec/png_codec.h" | 30 #include "ui/gfx/codec/png_codec.h" |
| 31 #include "ui/gfx/image/canvas_image_source.h" | 31 #include "ui/gfx/image/canvas_image_source.h" |
| 32 #include "ui/gfx/image/image.h" |
| 32 #include "ui/gfx/image/image_skia.h" | 33 #include "ui/gfx/image/image_skia.h" |
| 33 #include "ui/gfx/image/image_skia_operations.h" | 34 #include "ui/gfx/image/image_skia_operations.h" |
| 34 #include "ui/gfx/screen.h" | 35 #include "ui/gfx/screen.h" |
| 35 #include "ui/gfx/size_conversions.h" | 36 #include "ui/gfx/size_conversions.h" |
| 36 #include "ui/gfx/skia_util.h" | 37 #include "ui/gfx/skia_util.h" |
| 37 | 38 |
| 38 using content::BrowserThread; | 39 using content::BrowserThread; |
| 39 using extensions::Extension; | 40 using extensions::Extension; |
| 40 | 41 |
| 41 namespace { | 42 namespace { |
| (...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 if (!pack->data_pack_->GetStringPiece(kScaleFactorsID, &pointer)) | 756 if (!pack->data_pack_->GetStringPiece(kScaleFactorsID, &pointer)) |
| 756 return NULL; | 757 return NULL; |
| 757 | 758 |
| 758 if (!InputScalesValid(pointer, pack->scale_factors_)) { | 759 if (!InputScalesValid(pointer, pack->scale_factors_)) { |
| 759 DLOG(ERROR) << "BuildFromDataPack failure! The pack scale factors differ " | 760 DLOG(ERROR) << "BuildFromDataPack failure! The pack scale factors differ " |
| 760 << "from those supported by platform."; | 761 << "from those supported by platform."; |
| 761 } | 762 } |
| 762 return pack; | 763 return pack; |
| 763 } | 764 } |
| 764 | 765 |
| 766 // static |
| 767 void BrowserThemePack::GetThemeableImageIDRs(std::set<int>* result) { |
| 768 if (!result) |
| 769 return; |
| 770 |
| 771 result->clear(); |
| 772 for (size_t i = 0; i < kPersistingImagesLength; ++i) |
| 773 result->insert(kPersistingImages[i].idr_id); |
| 774 |
| 775 #if defined(OS_WIN) && defined(USE_AURA) |
| 776 for (size_t i = 0; i < kPersistingImagesWinDesktopAuraLength; ++i) |
| 777 result->insert(kPersistingImagesWinDesktopAura[i].idr_id); |
| 778 #endif |
| 779 } |
| 780 |
| 765 bool BrowserThemePack::WriteToDisk(const base::FilePath& path) const { | 781 bool BrowserThemePack::WriteToDisk(const base::FilePath& path) const { |
| 766 // Add resources for each of the property arrays. | 782 // Add resources for each of the property arrays. |
| 767 RawDataForWriting resources; | 783 RawDataForWriting resources; |
| 768 resources[kHeaderID] = base::StringPiece( | 784 resources[kHeaderID] = base::StringPiece( |
| 769 reinterpret_cast<const char*>(header_), sizeof(BrowserThemePackHeader)); | 785 reinterpret_cast<const char*>(header_), sizeof(BrowserThemePackHeader)); |
| 770 resources[kTintsID] = base::StringPiece( | 786 resources[kTintsID] = base::StringPiece( |
| 771 reinterpret_cast<const char*>(tints_), | 787 reinterpret_cast<const char*>(tints_), |
| 772 sizeof(TintEntry[kTintTableLength])); | 788 sizeof(TintEntry[kTintTableLength])); |
| 773 resources[kColorsID] = base::StringPiece( | 789 resources[kColorsID] = base::StringPiece( |
| 774 reinterpret_cast<const char*>(colors_), | 790 reinterpret_cast<const char*>(colors_), |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 883 RawImages::const_iterator it = image_memory_.find(raw_id); | 899 RawImages::const_iterator it = image_memory_.find(raw_id); |
| 884 if (it != image_memory_.end()) { | 900 if (it != image_memory_.end()) { |
| 885 memory = it->second.get(); | 901 memory = it->second.get(); |
| 886 } | 902 } |
| 887 } | 903 } |
| 888 } | 904 } |
| 889 | 905 |
| 890 return memory; | 906 return memory; |
| 891 } | 907 } |
| 892 | 908 |
| 893 // static | |
| 894 void BrowserThemePack::GetThemeableImageIDRs(std::set<int>* result) { | |
| 895 if (!result) | |
| 896 return; | |
| 897 | |
| 898 result->clear(); | |
| 899 for (size_t i = 0; i < kPersistingImagesLength; ++i) | |
| 900 result->insert(kPersistingImages[i].idr_id); | |
| 901 | |
| 902 #if defined(OS_WIN) && defined(USE_AURA) | |
| 903 for (size_t i = 0; i < kPersistingImagesWinDesktopAuraLength; ++i) | |
| 904 result->insert(kPersistingImagesWinDesktopAura[i].idr_id); | |
| 905 #endif | |
| 906 } | |
| 907 | |
| 908 bool BrowserThemePack::HasCustomImage(int idr_id) const { | 909 bool BrowserThemePack::HasCustomImage(int idr_id) const { |
| 909 int prs_id = GetPersistentIDByIDR(idr_id); | 910 int prs_id = GetPersistentIDByIDR(idr_id); |
| 910 if (prs_id == -1) | 911 if (prs_id == -1) |
| 911 return false; | 912 return false; |
| 912 | 913 |
| 913 int* img = source_images_; | 914 int* img = source_images_; |
| 914 for (; *img != -1; ++img) { | 915 for (; *img != -1; ++img) { |
| 915 if (*img == prs_id) | 916 if (*img == prs_id) |
| 916 return true; | 917 return true; |
| 917 } | 918 } |
| 918 | 919 |
| 919 return false; | 920 return false; |
| 920 } | 921 } |
| 921 | 922 |
| 922 // private: | 923 // private: |
| 923 | 924 |
| 924 BrowserThemePack::BrowserThemePack() | 925 BrowserThemePack::BrowserThemePack() |
| 925 : header_(NULL), | 926 : CustomThemeSupplier(EXTENSION), |
| 927 header_(NULL), |
| 926 tints_(NULL), | 928 tints_(NULL), |
| 927 colors_(NULL), | 929 colors_(NULL), |
| 928 display_properties_(NULL), | 930 display_properties_(NULL), |
| 929 source_images_(NULL) { | 931 source_images_(NULL) { |
| 930 scale_factors_ = ui::GetSupportedScaleFactors(); | 932 scale_factors_ = ui::GetSupportedScaleFactors(); |
| 931 } | 933 } |
| 932 | 934 |
| 933 void BrowserThemePack::BuildHeader(const Extension* extension) { | 935 void BrowserThemePack::BuildHeader(const Extension* extension) { |
| 934 header_ = new BrowserThemePackHeader; | 936 header_ = new BrowserThemePackHeader; |
| 935 header_->version = kThemePackVersion; | 937 header_->version = kThemePackVersion; |
| (...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1604 false, | 1606 false, |
| 1605 &bitmap_data)) { | 1607 &bitmap_data)) { |
| 1606 NOTREACHED() << "Unable to encode theme image for prs_id=" | 1608 NOTREACHED() << "Unable to encode theme image for prs_id=" |
| 1607 << prs_id << " for scale_factor=" << scale_factors_[i]; | 1609 << prs_id << " for scale_factor=" << scale_factors_[i]; |
| 1608 break; | 1610 break; |
| 1609 } | 1611 } |
| 1610 image_memory_[scaled_raw_id] = | 1612 image_memory_[scaled_raw_id] = |
| 1611 base::RefCountedBytes::TakeVector(&bitmap_data); | 1613 base::RefCountedBytes::TakeVector(&bitmap_data); |
| 1612 } | 1614 } |
| 1613 } | 1615 } |
| OLD | NEW |