| 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/api/themes/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 "grit/theme_resources.h" | 21 #include "grit/theme_resources.h" |
| 21 #include "grit/ui_resources.h" | 22 #include "grit/ui_resources.h" |
| 22 #include "net/base/file_stream.h" | 23 #include "net/base/file_stream.h" |
| 23 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
| 24 #include "third_party/skia/include/core/SkCanvas.h" | 25 #include "third_party/skia/include/core/SkCanvas.h" |
| 25 #include "ui/base/resource/data_pack.h" | 26 #include "ui/base/resource/data_pack.h" |
| 26 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
| 27 #include "ui/gfx/canvas.h" | 28 #include "ui/gfx/canvas.h" |
| 28 #include "ui/gfx/codec/png_codec.h" | 29 #include "ui/gfx/codec/png_codec.h" |
| 29 #include "ui/gfx/image/canvas_image_source.h" | 30 #include "ui/gfx/image/canvas_image_source.h" |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 return NULL; | 563 return NULL; |
| 563 pack->header_ = reinterpret_cast<BrowserThemePackHeader*>(const_cast<char*>( | 564 pack->header_ = reinterpret_cast<BrowserThemePackHeader*>(const_cast<char*>( |
| 564 pointer.data())); | 565 pointer.data())); |
| 565 | 566 |
| 566 if (pack->header_->version != kThemePackVersion) { | 567 if (pack->header_->version != kThemePackVersion) { |
| 567 DLOG(ERROR) << "BuildFromDataPack failure! Version mismatch!"; | 568 DLOG(ERROR) << "BuildFromDataPack failure! Version mismatch!"; |
| 568 return NULL; | 569 return NULL; |
| 569 } | 570 } |
| 570 // TODO(erg): Check endianess once DataPack works on the other endian. | 571 // TODO(erg): Check endianess once DataPack works on the other endian. |
| 571 std::string theme_id(reinterpret_cast<char*>(pack->header_->theme_id), | 572 std::string theme_id(reinterpret_cast<char*>(pack->header_->theme_id), |
| 572 Extension::kIdSize); | 573 extensions::id_util::kIdSize); |
| 573 std::string truncated_id = expected_id.substr(0, Extension::kIdSize); | 574 std::string truncated_id = |
| 575 expected_id.substr(0, extensions::id_util::kIdSize); |
| 574 if (theme_id != truncated_id) { | 576 if (theme_id != truncated_id) { |
| 575 DLOG(ERROR) << "Wrong id: " << theme_id << " vs " << expected_id; | 577 DLOG(ERROR) << "Wrong id: " << theme_id << " vs " << expected_id; |
| 576 return NULL; | 578 return NULL; |
| 577 } | 579 } |
| 578 | 580 |
| 579 if (!pack->data_pack_->GetStringPiece(kTintsID, &pointer)) | 581 if (!pack->data_pack_->GetStringPiece(kTintsID, &pointer)) |
| 580 return NULL; | 582 return NULL; |
| 581 pack->tints_ = reinterpret_cast<TintEntry*>(const_cast<char*>( | 583 pack->tints_ = reinterpret_cast<TintEntry*>(const_cast<char*>( |
| 582 pointer.data())); | 584 pointer.data())); |
| 583 | 585 |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 // Linux check | 797 // Linux check |
| 796 COMPILE_ASSERT(__BYTE_ORDER == __LITTLE_ENDIAN, | 798 COMPILE_ASSERT(__BYTE_ORDER == __LITTLE_ENDIAN, |
| 797 datapack_assumes_little_endian); | 799 datapack_assumes_little_endian); |
| 798 #elif defined(__BIG_ENDIAN__) | 800 #elif defined(__BIG_ENDIAN__) |
| 799 // Mac check | 801 // Mac check |
| 800 #error DataPack assumes little endian | 802 #error DataPack assumes little endian |
| 801 #endif | 803 #endif |
| 802 header_->little_endian = 1; | 804 header_->little_endian = 1; |
| 803 | 805 |
| 804 const std::string& id = extension->id(); | 806 const std::string& id = extension->id(); |
| 805 memcpy(header_->theme_id, id.c_str(), Extension::kIdSize); | 807 memcpy(header_->theme_id, id.c_str(), extensions::id_util::kIdSize); |
| 806 } | 808 } |
| 807 | 809 |
| 808 void BrowserThemePack::BuildTintsFromJSON(DictionaryValue* tints_value) { | 810 void BrowserThemePack::BuildTintsFromJSON(DictionaryValue* tints_value) { |
| 809 tints_ = new TintEntry[kTintTableLength]; | 811 tints_ = new TintEntry[kTintTableLength]; |
| 810 for (size_t i = 0; i < kTintTableLength; ++i) { | 812 for (size_t i = 0; i < kTintTableLength; ++i) { |
| 811 tints_[i].id = -1; | 813 tints_[i].id = -1; |
| 812 tints_[i].h = -1; | 814 tints_[i].h = -1; |
| 813 tints_[i].s = -1; | 815 tints_[i].s = -1; |
| 814 tints_[i].l = -1; | 816 tints_[i].l = -1; |
| 815 } | 817 } |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1312 ui::ScaleFactor scale_factor) const { | 1314 ui::ScaleFactor scale_factor) const { |
| 1313 if (prs_id < 0) | 1315 if (prs_id < 0) |
| 1314 return -1; | 1316 return -1; |
| 1315 | 1317 |
| 1316 for (size_t i = 0; i < scale_factors_.size(); ++i) { | 1318 for (size_t i = 0; i < scale_factors_.size(); ++i) { |
| 1317 if (scale_factors_[i] == scale_factor) | 1319 if (scale_factors_[i] == scale_factor) |
| 1318 return static_cast<int>(kPersistingImagesLength * i) + prs_id; | 1320 return static_cast<int>(kPersistingImagesLength * i) + prs_id; |
| 1319 } | 1321 } |
| 1320 return -1; | 1322 return -1; |
| 1321 } | 1323 } |
| OLD | NEW |