Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: chrome/browser/browser_theme_pack.cc

Issue 548207: Don't store IDR ids in ThemePack files as they change whenever the grd is modified. (Closed)
Patch Set: More tests and cleaner persistant id access Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/browser_theme_pack_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_pack.h" 5 #include "chrome/browser/browser_theme_pack.h"
6 6
7 #include <climits> 7 #include <climits>
8 8
9 #include "app/gfx/codec/png_codec.h" 9 #include "app/gfx/codec/png_codec.h"
10 #include "app/gfx/skbitmap_operations.h" 10 #include "app/gfx/skbitmap_operations.h"
(...skipping 18 matching lines...) Expand all
29 // No optimizations under windows until we know what's up with the crashing. 29 // No optimizations under windows until we know what's up with the crashing.
30 #if defined(OS_WIN) 30 #if defined(OS_WIN)
31 #pragma optimize("", off) 31 #pragma optimize("", off)
32 #pragma warning(disable:4748) 32 #pragma warning(disable:4748)
33 #endif 33 #endif
34 34
35 namespace { 35 namespace {
36 36
37 // Version number of the current theme pack. We just throw out and rebuild 37 // Version number of the current theme pack. We just throw out and rebuild
38 // theme packs that aren't int-equal to this. 38 // theme packs that aren't int-equal to this.
39 const int kThemePackVersion = 1; 39 const int kThemePackVersion = 2;
40 40
41 // IDs that are in the DataPack won't clash with the positive integer 41 // IDs that are in the DataPack won't clash with the positive integer
42 // int32_t. kHeaderID should always have the maximum value because we want the 42 // int32_t. kHeaderID should always have the maximum value because we want the
43 // "header" to be written last. That way we can detect whether the pack was 43 // "header" to be written last. That way we can detect whether the pack was
44 // successfully written and ignore and regenerate if it was only partially 44 // successfully written and ignore and regenerate if it was only partially
45 // written (i.e. chrome crashed on a different thread while writing the pack). 45 // written (i.e. chrome crashed on a different thread while writing the pack).
46 const int kHeaderID = UINT_MAX - 1; 46 const int kHeaderID = UINT_MAX - 1;
47 const int kTintsID = UINT_MAX - 2; 47 const int kTintsID = UINT_MAX - 2;
48 const int kColorsID = UINT_MAX - 3; 48 const int kColorsID = UINT_MAX - 3;
49 const int kDisplayPropertiesID = UINT_MAX - 4; 49 const int kDisplayPropertiesID = UINT_MAX - 4;
50 50
51 // Static size of the tint/color/display property arrays that are mmapped. 51 // Static size of the tint/color/display property arrays that are mmapped.
52 const int kTintArraySize = 6; 52 const int kTintArraySize = 6;
53 const int kColorArraySize = 19; 53 const int kColorArraySize = 19;
54 const int kDisplayPropertySize = 3; 54 const int kDisplayPropertySize = 3;
55 55
56 // The sum of kFrameBorderThickness and kNonClientRestoredExtraThickness from 56 // The sum of kFrameBorderThickness and kNonClientRestoredExtraThickness from
57 // OpaqueBrowserFrameView. 57 // OpaqueBrowserFrameView.
58 const int kRestoredTabVerticalOffset = 15; 58 const int kRestoredTabVerticalOffset = 15;
59 59
60 // Persistant constants for the main images that we need. These have the same
Miranda Callahan 2010/01/29 23:36:10 spelling nit (everywhere): "persistent".
61 // names as their IDR_* counterparts but these values will always stay the
62 // same.
63 const int PRS_THEME_FRAME = 1;
64 const int PRS_THEME_FRAME_INACTIVE = 2;
65 const int PRS_THEME_FRAME_INCOGNITO = 3;
66 const int PRS_THEME_FRAME_INCOGNITO_INACTIVE = 4;
67 const int PRS_THEME_TOOLBAR = 5;
68 const int PRS_THEME_TAB_BACKGROUND = 6;
69 const int PRS_THEME_TAB_BACKGROUND_INCOGNITO = 7;
70 const int PRS_THEME_TAB_BACKGROUND_V = 8;
71 const int PRS_THEME_NTP_BACKGROUND = 9;
72 const int PRS_THEME_FRAME_OVERLAY = 10;
73 const int PRS_THEME_FRAME_OVERLAY_INACTIVE = 11;
74 const int PRS_THEME_BUTTON_BACKGROUND = 12;
75 const int PRS_THEME_NTP_ATTRIBUTION = 13;
76 const int PRS_THEME_WINDOW_CONTROL_BACKGROUND = 14;
77
78 struct PersistingImagesTable {
79 // A non-changing integer ID meant to be saved in theme packs. This ID must
80 // not change between versions of chrome.
81 int persistant_id;
82
83 // The IDR that depends on the whims of GRIT and therefore changes whenever
84 // someone adds a new resource.
85 int idr_id;
86
87 // String to check for when parsing theme manifests or NULL if this isn't
88 // supposed to be changeable by the user.
89 const char* key;
90 };
91
92 // IDR_* resource names change whenever new resources are added; use persistant
93 // IDs when storing to a cached pack.
94 PersistingImagesTable kPersistingImages[] = {
95 { PRS_THEME_FRAME, IDR_THEME_FRAME,
96 "theme_frame" },
97 { PRS_THEME_FRAME_INACTIVE, IDR_THEME_FRAME_INACTIVE,
98 "theme_frame_inactive" },
99 { PRS_THEME_FRAME_INCOGNITO, IDR_THEME_FRAME_INCOGNITO,
100 "theme_frame_incognito" },
101 { PRS_THEME_FRAME_INCOGNITO_INACTIVE, IDR_THEME_FRAME_INCOGNITO_INACTIVE,
102 "theme_frame_incognito_inactive" },
103 { PRS_THEME_TOOLBAR, IDR_THEME_TOOLBAR,
104 "theme_toolbar" },
105 { PRS_THEME_TAB_BACKGROUND, IDR_THEME_TAB_BACKGROUND,
106 "theme_tab_background" },
107 { PRS_THEME_TAB_BACKGROUND_INCOGNITO, IDR_THEME_TAB_BACKGROUND_INCOGNITO,
108 "theme_tab_background_incognito" },
109 { PRS_THEME_TAB_BACKGROUND_V, IDR_THEME_TAB_BACKGROUND_V,
110 "theme_tab_background_v"},
111 { PRS_THEME_NTP_BACKGROUND, IDR_THEME_NTP_BACKGROUND,
112 "theme_ntp_background" },
113 { PRS_THEME_FRAME_OVERLAY, IDR_THEME_FRAME_OVERLAY,
114 "theme_frame_overlay" },
115 { PRS_THEME_FRAME_OVERLAY_INACTIVE, IDR_THEME_FRAME_OVERLAY_INACTIVE,
116 "theme_frame_overlay_inactive" },
117 { PRS_THEME_BUTTON_BACKGROUND, IDR_THEME_BUTTON_BACKGROUND,
118 "theme_button_background" },
119 { PRS_THEME_NTP_ATTRIBUTION, IDR_THEME_NTP_ATTRIBUTION,
120 "theme_ntp_attribution" },
121 { PRS_THEME_WINDOW_CONTROL_BACKGROUND, IDR_THEME_WINDOW_CONTROL_BACKGROUND,
122 "theme_window_control_background"},
123
124 // The rest of these entries have no key because they can't be overridden
125 // from the json manifest.
126 { 15, IDR_BACK, NULL },
127 { 16, IDR_BACK_D, NULL },
128 { 17, IDR_BACK_H, NULL },
129 { 18, IDR_BACK_P, NULL },
130 { 19, IDR_FORWARD, NULL },
131 { 20, IDR_FORWARD_D, NULL },
132 { 21, IDR_FORWARD_H, NULL },
133 { 22, IDR_FORWARD_P, NULL },
134 { 23, IDR_RELOAD, NULL },
135 { 24, IDR_RELOAD_H, NULL },
136 { 25, IDR_RELOAD_P, NULL },
137 { 26, IDR_HOME, NULL },
138 { 27, IDR_HOME_H, NULL },
139 { 28, IDR_HOME_P, NULL },
140 { 29, IDR_STAR, NULL },
141 { 30, IDR_STAR_NOBORDER, NULL },
142 { 31, IDR_STAR_NOBORDER_CENTER, NULL },
143 { 32, IDR_STAR_D, NULL },
144 { 33, IDR_STAR_H, NULL },
145 { 34, IDR_STAR_P, NULL },
146 { 35, IDR_STARRED, NULL },
147 { 36, IDR_STARRED_NOBORDER, NULL },
148 { 37, IDR_STARRED_NOBORDER_CENTER, NULL },
149 { 38, IDR_STARRED_H, NULL },
150 { 39, IDR_STARRED_P, NULL },
151 { 40, IDR_GO, NULL },
152 { 41, IDR_GO_NOBORDER, NULL },
153 { 42, IDR_GO_NOBORDER_CENTER, NULL },
154 { 43, IDR_GO_H, NULL },
155 { 44, IDR_GO_P, NULL },
156 { 45, IDR_STOP, NULL },
157 { 46, IDR_STOP_NOBORDER, NULL },
158 { 47, IDR_STOP_NOBORDER_CENTER, NULL },
159 { 48, IDR_STOP_H, NULL },
160 { 49, IDR_STOP_P, NULL },
161 { 50, IDR_MENU_BOOKMARK, NULL },
162 { 51, IDR_MENU_PAGE, NULL },
163 { 52, IDR_MENU_PAGE_RTL, NULL },
164 { 53, IDR_MENU_CHROME, NULL },
165 { 54, IDR_MENU_CHROME_RTL, NULL },
166 { 55, IDR_MENU_DROPARROW, NULL },
167 { 56, IDR_THROBBER, NULL },
168 { 57, IDR_THROBBER_WAITING, NULL },
169 { 58, IDR_THROBBER_LIGHT, NULL },
170 { 59, IDR_LOCATIONBG, NULL }
171 };
172
173 const int GetPersistantIDByName(const std::string& key) {
174 for (size_t i = 0; i < arraysize(kPersistingImages); ++i) {
175 if (kPersistingImages[i].key != NULL &&
176 base::strcasecmp(key.c_str(), kPersistingImages[i].key) == 0) {
177 return kPersistingImages[i].persistant_id;
178 }
179 }
180
181 return -1;
182 }
183
184 const int GetPersistantIDByIDR(int idr) {
185 for (size_t i = 0; i < arraysize(kPersistingImages); ++i) {
186 if (kPersistingImages[i].idr_id == idr) {
187 return kPersistingImages[i].persistant_id;
188 }
189 }
190
191 return -1;
192 }
60 193
61 struct StringToIntTable { 194 struct StringToIntTable {
62 const char* key; 195 const char* key;
63 int id; 196 int id;
64 }; 197 };
65 198
66 // Strings used by themes to identify tints in the JSON. 199 // Strings used by themes to identify tints in the JSON.
67 StringToIntTable kTintTable[] = { 200 StringToIntTable kTintTable[] = {
68 { "buttons", BrowserThemeProvider::TINT_BUTTONS }, 201 { "buttons", BrowserThemeProvider::TINT_BUTTONS },
69 { "frame", BrowserThemeProvider::TINT_FRAME }, 202 { "frame", BrowserThemeProvider::TINT_FRAME },
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } 262 }
130 263
131 struct IntToIntTable { 264 struct IntToIntTable {
132 int key; 265 int key;
133 int value; 266 int value;
134 }; 267 };
135 268
136 // Mapping used in GenerateFrameImages() to associate frame images with the 269 // Mapping used in GenerateFrameImages() to associate frame images with the
137 // tint ID that should maybe be applied to it. 270 // tint ID that should maybe be applied to it.
138 IntToIntTable kFrameTintMap[] = { 271 IntToIntTable kFrameTintMap[] = {
139 { IDR_THEME_FRAME, BrowserThemeProvider::TINT_FRAME }, 272 { PRS_THEME_FRAME, BrowserThemeProvider::TINT_FRAME },
140 { IDR_THEME_FRAME_INACTIVE, BrowserThemeProvider::TINT_FRAME_INACTIVE }, 273 { PRS_THEME_FRAME_INACTIVE, BrowserThemeProvider::TINT_FRAME_INACTIVE },
141 { IDR_THEME_FRAME_OVERLAY, BrowserThemeProvider::TINT_FRAME }, 274 { PRS_THEME_FRAME_OVERLAY, BrowserThemeProvider::TINT_FRAME },
142 { IDR_THEME_FRAME_OVERLAY_INACTIVE, 275 { PRS_THEME_FRAME_OVERLAY_INACTIVE,
143 BrowserThemeProvider::TINT_FRAME_INACTIVE }, 276 BrowserThemeProvider::TINT_FRAME_INACTIVE },
144 { IDR_THEME_FRAME_INCOGNITO, BrowserThemeProvider::TINT_FRAME_INCOGNITO }, 277 { PRS_THEME_FRAME_INCOGNITO, BrowserThemeProvider::TINT_FRAME_INCOGNITO },
145 { IDR_THEME_FRAME_INCOGNITO_INACTIVE, 278 { PRS_THEME_FRAME_INCOGNITO_INACTIVE,
146 BrowserThemeProvider::TINT_FRAME_INCOGNITO_INACTIVE } 279 BrowserThemeProvider::TINT_FRAME_INCOGNITO_INACTIVE }
147 }; 280 };
148 281
149 // Mapping used in GenerateTabBackgroundImages() to associate what frame image 282 // Mapping used in GenerateTabBackgroundImages() to associate what frame image
150 // goes with which tab background. 283 // goes with which tab background.
151 IntToIntTable kTabBackgroundMap[] = { 284 IntToIntTable kTabBackgroundMap[] = {
152 { IDR_THEME_TAB_BACKGROUND, IDR_THEME_FRAME }, 285 { PRS_THEME_TAB_BACKGROUND, PRS_THEME_FRAME },
153 { IDR_THEME_TAB_BACKGROUND_INCOGNITO, IDR_THEME_FRAME_INCOGNITO } 286 { PRS_THEME_TAB_BACKGROUND_INCOGNITO, PRS_THEME_FRAME_INCOGNITO }
154 }; 287 };
155 288
156 // A list of images that don't need tinting or any other modification and can 289 // A list of images that don't need tinting or any other modification and can
157 // be byte-copied directly into the finished DataPack. This should contain all 290 // be byte-copied directly into the finished DataPack. This should contain the
158 // themeable image IDs that aren't in kFrameTintMap or kTabBackgroundMap. 291 // persistant IDs for all themeable image IDs that aren't in kFrameTintMap or
292 // kTabBackgroundMap.
159 const int kPreloadIDs[] = { 293 const int kPreloadIDs[] = {
160 IDR_THEME_TOOLBAR, 294 PRS_THEME_TOOLBAR,
161 IDR_THEME_NTP_BACKGROUND, 295 PRS_THEME_NTP_BACKGROUND,
162 IDR_THEME_BUTTON_BACKGROUND, 296 PRS_THEME_BUTTON_BACKGROUND,
163 IDR_THEME_NTP_ATTRIBUTION, 297 PRS_THEME_NTP_ATTRIBUTION,
164 IDR_THEME_WINDOW_CONTROL_BACKGROUND 298 PRS_THEME_WINDOW_CONTROL_BACKGROUND
165 }; 299 };
166 300
167 // Returns a piece of memory with the contents of the file |path|. 301 // Returns a piece of memory with the contents of the file |path|.
168 RefCountedMemory* ReadFileData(const FilePath& path) { 302 RefCountedMemory* ReadFileData(const FilePath& path) {
169 if (!path.empty()) { 303 if (!path.empty()) {
170 net::FileStream file; 304 net::FileStream file;
171 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ; 305 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
172 if (file.Open(path, flags) == net::OK) { 306 if (file.Open(path, flags) == net::OK) {
173 int64 avail = file.Available(); 307 int64 avail = file.Available();
174 if (avail > 0 && avail < INT_MAX) { 308 if (avail > 0 && avail < INT_MAX) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 LOG(ERROR) << "Failed to load theme data pack."; 394 LOG(ERROR) << "Failed to load theme data pack.";
261 return NULL; 395 return NULL;
262 } 396 }
263 397
264 base::StringPiece pointer; 398 base::StringPiece pointer;
265 if (!pack->data_pack_->GetStringPiece(kHeaderID, &pointer)) 399 if (!pack->data_pack_->GetStringPiece(kHeaderID, &pointer))
266 return NULL; 400 return NULL;
267 pack->header_ = reinterpret_cast<BrowserThemePackHeader*>(const_cast<char*>( 401 pack->header_ = reinterpret_cast<BrowserThemePackHeader*>(const_cast<char*>(
268 pointer.data())); 402 pointer.data()));
269 403
270 if (pack->header_->version != kThemePackVersion) 404 if (pack->header_->version != kThemePackVersion) {
405 DLOG(ERROR) << "BuildFromDataPack failure! Version mismatch!";
271 return NULL; 406 return NULL;
407 }
272 // TODO(erg): Check endianess once DataPack works on the other endian. 408 // TODO(erg): Check endianess once DataPack works on the other endian.
273 std::string theme_id(reinterpret_cast<char*>(pack->header_->theme_id), 409 std::string theme_id(reinterpret_cast<char*>(pack->header_->theme_id),
274 Extension::kIdSize); 410 Extension::kIdSize);
275 std::string truncated_id = expected_id.substr(0, Extension::kIdSize); 411 std::string truncated_id = expected_id.substr(0, Extension::kIdSize);
276 if (theme_id != truncated_id) { 412 if (theme_id != truncated_id) {
277 DLOG(ERROR) << "Wrong id: " << theme_id << " vs " << expected_id; 413 DLOG(ERROR) << "Wrong id: " << theme_id << " vs " << expected_id;
278 return NULL; 414 return NULL;
279 } 415 }
280 416
281 if (!pack->data_pack_->GetStringPiece(kTintsID, &pointer)) 417 if (!pack->data_pack_->GetStringPiece(kTintsID, &pointer))
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 if (display_properties_[i].id == id) { 506 if (display_properties_[i].id == id) {
371 *result = display_properties_[i].property; 507 *result = display_properties_[i].property;
372 return true; 508 return true;
373 } 509 }
374 } 510 }
375 } 511 }
376 512
377 return false; 513 return false;
378 } 514 }
379 515
380 SkBitmap* BrowserThemePack::GetBitmapNamed(int id) const { 516 SkBitmap* BrowserThemePack::GetBitmapNamed(int idr_id) const {
517 int prs_id = GetPersistantIDByIDR(idr_id);
518
381 // Check our cache of prepared images, first. 519 // Check our cache of prepared images, first.
382 ImageCache::const_iterator image_iter = prepared_images_.find(id); 520 ImageCache::const_iterator image_iter = prepared_images_.find(prs_id);
383 if (image_iter != prepared_images_.end()) 521 if (image_iter != prepared_images_.end())
384 return image_iter->second; 522 return image_iter->second;
385 523
386 // Check if we've already loaded this image. 524 // Check if we've already loaded this image.
387 image_iter = loaded_images_.find(id); 525 image_iter = loaded_images_.find(prs_id);
388 if (image_iter != loaded_images_.end()) 526 if (image_iter != loaded_images_.end())
389 return image_iter->second; 527 return image_iter->second;
390 528
391 scoped_refptr<RefCountedMemory> memory; 529 scoped_refptr<RefCountedMemory> memory;
392 if (data_pack_.get()) { 530 if (data_pack_.get()) {
393 memory = data_pack_->GetStaticMemory(id); 531 memory = data_pack_->GetStaticMemory(prs_id);
394 } else { 532 } else {
395 RawImages::const_iterator it = image_memory_.find(id); 533 RawImages::const_iterator it = image_memory_.find(prs_id);
396 if (it != image_memory_.end()) { 534 if (it != image_memory_.end()) {
397 memory = it->second; 535 memory = it->second;
398 } 536 }
399 } 537 }
400 538
401 if (memory.get()) { 539 if (memory.get()) {
402 // Decode the PNG. 540 // Decode the PNG.
403 SkBitmap bitmap; 541 SkBitmap bitmap;
404 if (!gfx::PNGCodec::Decode(memory->front(), memory->size(), 542 if (!gfx::PNGCodec::Decode(memory->front(), memory->size(),
405 &bitmap)) { 543 &bitmap)) {
406 NOTREACHED() << "Unable to decode theme image resource " << id 544 NOTREACHED() << "Unable to decode theme image resource " << idr_id
407 << " from saved DataPack."; 545 << " from saved DataPack.";
408 return NULL; 546 return NULL;
409 } 547 }
410 548
411 SkBitmap* ret = new SkBitmap(bitmap); 549 SkBitmap* ret = new SkBitmap(bitmap);
412 loaded_images_[id] = ret; 550 loaded_images_[prs_id] = ret;
413 551
414 return ret; 552 return ret;
415 } 553 }
416 554
417 return NULL; 555 return NULL;
418 } 556 }
419 557
420 RefCountedMemory* BrowserThemePack::GetRawData(int id) const { 558 RefCountedMemory* BrowserThemePack::GetRawData(int idr_id) const {
421 RefCountedMemory* memory = NULL; 559 RefCountedMemory* memory = NULL;
560 int prs_id = GetPersistantIDByIDR(idr_id);
422 561
423 if (data_pack_.get()) { 562 if (prs_id != -1) {
424 memory = data_pack_->GetStaticMemory(id); 563 if (data_pack_.get()) {
425 } else { 564 memory = data_pack_->GetStaticMemory(prs_id);
426 RawImages::const_iterator it = image_memory_.find(id); 565 } else {
427 if (it != image_memory_.end()) { 566 RawImages::const_iterator it = image_memory_.find(prs_id);
428 memory = it->second; 567 if (it != image_memory_.end()) {
568 memory = it->second;
569 }
429 } 570 }
430 } 571 }
431 572
432 return memory; 573 return memory;
433 } 574 }
434 575
435 bool BrowserThemePack::HasCustomImage(int id) const { 576 bool BrowserThemePack::HasCustomImage(int idr_id) const {
577 int prs_id = GetPersistantIDByIDR(idr_id);
578 if (prs_id == -1)
579 return false;
580
436 if (data_pack_.get()) { 581 if (data_pack_.get()) {
437 base::StringPiece ignored; 582 base::StringPiece ignored;
438 return data_pack_->GetStringPiece(id, &ignored); 583 return data_pack_->GetStringPiece(prs_id, &ignored);
439 } else { 584 } else {
440 return prepared_images_.count(id) > 0 || 585 return prepared_images_.count(prs_id) > 0 ||
441 image_memory_.count(id) > 0; 586 image_memory_.count(prs_id) > 0;
442 } 587 }
443 } 588 }
444 589
445 // private: 590 // private:
446 591
447 BrowserThemePack::BrowserThemePack() 592 BrowserThemePack::BrowserThemePack()
448 : header_(NULL), 593 : header_(NULL),
449 tints_(NULL), 594 tints_(NULL),
450 colors_(NULL), 595 colors_(NULL),
451 display_properties_(NULL) { 596 display_properties_(NULL) {
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 DictionaryValue* images_value, 833 DictionaryValue* images_value,
689 FilePath images_path, 834 FilePath images_path,
690 std::map<int, FilePath>* file_paths) const { 835 std::map<int, FilePath>* file_paths) const {
691 if (!images_value) 836 if (!images_value)
692 return; 837 return;
693 838
694 for (DictionaryValue::key_iterator iter(images_value->begin_keys()); 839 for (DictionaryValue::key_iterator iter(images_value->begin_keys());
695 iter != images_value->end_keys(); ++iter) { 840 iter != images_value->end_keys(); ++iter) {
696 std::string val; 841 std::string val;
697 if (images_value->GetString(*iter, &val)) { 842 if (images_value->GetString(*iter, &val)) {
698 int id = ThemeResourcesUtil::GetId(WideToUTF8(*iter)); 843 int id = GetPersistantIDByName(WideToUTF8(*iter));
699 if (id != -1) 844 if (id != -1)
700 (*file_paths)[id] = images_path.AppendASCII(val); 845 (*file_paths)[id] = images_path.AppendASCII(val);
701 } 846 }
702 } 847 }
703 } 848 }
704 849
705 void BrowserThemePack::LoadRawBitmapsTo( 850 void BrowserThemePack::LoadRawBitmapsTo(
706 const std::map<int, FilePath>& file_paths, 851 const std::map<int, FilePath>& file_paths,
707 ImageCache* raw_bitmaps) { 852 ImageCache* raw_bitmaps) {
708 for (std::map<int, FilePath>::const_iterator it = file_paths.begin(); 853 for (std::map<int, FilePath>::const_iterator it = file_paths.begin();
(...skipping 27 matching lines...) Expand all
736 } 881 }
737 882
738 void BrowserThemePack::GenerateFrameImages(ImageCache* bitmaps) const { 883 void BrowserThemePack::GenerateFrameImages(ImageCache* bitmaps) const {
739 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 884 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
740 885
741 // Create all the output bitmaps in a separate cache and move them back into 886 // Create all the output bitmaps in a separate cache and move them back into
742 // the input bitmaps because there can be name collisions. 887 // the input bitmaps because there can be name collisions.
743 ImageCache temp_output; 888 ImageCache temp_output;
744 889
745 for (size_t i = 0; i < arraysize(kFrameTintMap); ++i) { 890 for (size_t i = 0; i < arraysize(kFrameTintMap); ++i) {
746 int id = kFrameTintMap[i].key; 891 int prs_id = kFrameTintMap[i].key;
747 scoped_ptr<SkBitmap> frame; 892 scoped_ptr<SkBitmap> frame;
748 // If there's no frame image provided for the specified id, then load 893 // If there's no frame image provided for the specified id, then load
749 // the default provided frame. If that's not provided, skip this whole 894 // the default provided frame. If that's not provided, skip this whole
750 // thing and just use the default images. 895 // thing and just use the default images.
751 int base_id; 896 int prs_base_id;
752 897
753 if (id == IDR_THEME_FRAME_INCOGNITO_INACTIVE) { 898 if (prs_id == PRS_THEME_FRAME_INCOGNITO_INACTIVE) {
754 base_id = bitmaps->count(IDR_THEME_FRAME_INCOGNITO) ? 899 prs_base_id = bitmaps->count(PRS_THEME_FRAME_INCOGNITO) ?
755 IDR_THEME_FRAME_INCOGNITO : IDR_THEME_FRAME; 900 PRS_THEME_FRAME_INCOGNITO : PRS_THEME_FRAME;
756 } else if (id == IDR_THEME_FRAME_OVERLAY_INACTIVE) { 901 } else if (prs_id == PRS_THEME_FRAME_OVERLAY_INACTIVE) {
757 base_id = IDR_THEME_FRAME_OVERLAY; 902 prs_base_id = PRS_THEME_FRAME_OVERLAY;
758 } else if (id == IDR_THEME_FRAME_INACTIVE) { 903 } else if (prs_id == PRS_THEME_FRAME_INACTIVE) {
759 base_id = IDR_THEME_FRAME; 904 prs_base_id = PRS_THEME_FRAME;
760 } else if (id == IDR_THEME_FRAME_INCOGNITO && 905 } else if (prs_id == PRS_THEME_FRAME_INCOGNITO &&
761 !bitmaps->count(IDR_THEME_FRAME_INCOGNITO)) { 906 !bitmaps->count(PRS_THEME_FRAME_INCOGNITO)) {
762 base_id = IDR_THEME_FRAME; 907 prs_base_id = PRS_THEME_FRAME;
763 } else { 908 } else {
764 base_id = id; 909 prs_base_id = prs_id;
765 } 910 }
766 911
767 if (bitmaps->count(id)) { 912 if (bitmaps->count(prs_id)) {
768 frame.reset(new SkBitmap(*(*bitmaps)[id])); 913 frame.reset(new SkBitmap(*(*bitmaps)[prs_id]));
769 } else if (base_id != id && bitmaps->count(base_id)) { 914 } else if (prs_base_id != prs_id && bitmaps->count(prs_base_id)) {
770 frame.reset(new SkBitmap(*(*bitmaps)[base_id])); 915 frame.reset(new SkBitmap(*(*bitmaps)[prs_base_id]));
771 } else if (base_id == IDR_THEME_FRAME_OVERLAY && 916 } else if (prs_base_id == PRS_THEME_FRAME_OVERLAY &&
772 bitmaps->count(IDR_THEME_FRAME)) { 917 bitmaps->count(PRS_THEME_FRAME)) {
773 // If there is no theme overlay, don't tint the default frame, 918 // If there is no theme overlay, don't tint the default frame,
774 // because it will overwrite the custom frame image when we cache and 919 // because it will overwrite the custom frame image when we cache and
775 // reload from disk. 920 // reload from disk.
776 frame.reset(NULL); 921 frame.reset(NULL);
777 } else { 922 } else {
778 // If the theme doesn't specify an image, then apply the tint to 923 // If the theme doesn't specify an image, then apply the tint to
779 // the default frame. 924 // the default frame.
780 frame.reset(new SkBitmap(*rb.GetBitmapNamed(IDR_THEME_FRAME))); 925 frame.reset(new SkBitmap(*rb.GetBitmapNamed(IDR_THEME_FRAME)));
781 } 926 }
782 927
783 if (frame.get()) { 928 if (frame.get()) {
784 temp_output[id] = new SkBitmap( 929 temp_output[prs_id] = new SkBitmap(
785 SkBitmapOperations::CreateHSLShiftedBitmap( 930 SkBitmapOperations::CreateHSLShiftedBitmap(
786 *frame, GetTintInternal(kFrameTintMap[i].value))); 931 *frame, GetTintInternal(kFrameTintMap[i].value)));
787 } 932 }
788 } 933 }
789 934
790 MergeImageCaches(temp_output, bitmaps); 935 MergeImageCaches(temp_output, bitmaps);
791 } 936 }
792 937
793 void BrowserThemePack::GenerateTintedButtons( 938 void BrowserThemePack::GenerateTintedButtons(
794 color_utils::HSL button_tint, 939 color_utils::HSL button_tint,
795 ImageCache* processed_bitmaps) const { 940 ImageCache* processed_bitmaps) const {
796 if (button_tint.h != -1 || button_tint.s != -1 || button_tint.l != -1) { 941 if (button_tint.h != -1 || button_tint.s != -1 || button_tint.l != -1) {
797 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 942 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
798 const std::set<int>& ids = 943 const std::set<int>& idr_ids =
799 BrowserThemeProvider::GetTintableToolbarButtons(); 944 BrowserThemeProvider::GetTintableToolbarButtons();
800 for (std::set<int>::const_iterator it = ids.begin(); it != ids.end(); 945 for (std::set<int>::const_iterator it = idr_ids.begin();
801 ++it) { 946 it != idr_ids.end(); ++it) {
947 int prs_id = GetPersistantIDByIDR(*it);
948
949 // Fetch the image by IDR...
802 scoped_ptr<SkBitmap> button(new SkBitmap(*rb.GetBitmapNamed(*it))); 950 scoped_ptr<SkBitmap> button(new SkBitmap(*rb.GetBitmapNamed(*it)));
803 (*processed_bitmaps)[*it] = new SkBitmap( 951
952 // but save a version with the persistant ID.
953 (*processed_bitmaps)[prs_id] = new SkBitmap(
804 SkBitmapOperations::CreateHSLShiftedBitmap(*button, button_tint)); 954 SkBitmapOperations::CreateHSLShiftedBitmap(*button, button_tint));
805 } 955 }
806 } 956 }
807 } 957 }
808 958
809 void BrowserThemePack::GenerateTabBackgroundImages(ImageCache* bitmaps) const { 959 void BrowserThemePack::GenerateTabBackgroundImages(ImageCache* bitmaps) const {
810 ImageCache temp_output; 960 ImageCache temp_output;
811 for (size_t i = 0; i < arraysize(kTabBackgroundMap); ++i) { 961 for (size_t i = 0; i < arraysize(kTabBackgroundMap); ++i) {
812 int id = kTabBackgroundMap[i].key; 962 int prs_id = kTabBackgroundMap[i].key;
813 int base_id = kTabBackgroundMap[i].value; 963 int prs_base_id = kTabBackgroundMap[i].value;
814 964
815 // We only need to generate the background tab images if we were provided 965 // We only need to generate the background tab images if we were provided
816 // with a IDR_THEME_FRAME. 966 // with a PRS_THEME_FRAME.
817 ImageCache::const_iterator it = bitmaps->find(base_id); 967 ImageCache::const_iterator it = bitmaps->find(prs_base_id);
818 if (it != bitmaps->end()) { 968 if (it != bitmaps->end()) {
819 SkBitmap bg_tint = SkBitmapOperations::CreateHSLShiftedBitmap( 969 SkBitmap bg_tint = SkBitmapOperations::CreateHSLShiftedBitmap(
820 *(it->second), GetTintInternal( 970 *(it->second), GetTintInternal(
821 BrowserThemeProvider::TINT_BACKGROUND_TAB)); 971 BrowserThemeProvider::TINT_BACKGROUND_TAB));
822 int vertical_offset = bitmaps->count(id) ? kRestoredTabVerticalOffset : 0; 972 int vertical_offset = bitmaps->count(prs_id)
973 ? kRestoredTabVerticalOffset : 0;
823 SkBitmap* bg_tab = new SkBitmap(SkBitmapOperations::CreateTiledBitmap( 974 SkBitmap* bg_tab = new SkBitmap(SkBitmapOperations::CreateTiledBitmap(
824 bg_tint, 0, vertical_offset, bg_tint.width(), bg_tint.height())); 975 bg_tint, 0, vertical_offset, bg_tint.width(), bg_tint.height()));
825 976
826 // If they've provided a custom image, overlay it. 977 // If they've provided a custom image, overlay it.
827 ImageCache::const_iterator overlay_it = bitmaps->find(id); 978 ImageCache::const_iterator overlay_it = bitmaps->find(prs_id);
828 if (overlay_it != bitmaps->end()) { 979 if (overlay_it != bitmaps->end()) {
829 SkBitmap* overlay = overlay_it->second; 980 SkBitmap* overlay = overlay_it->second;
830 SkCanvas canvas(*bg_tab); 981 SkCanvas canvas(*bg_tab);
831 for (int x = 0; x < bg_tab->width(); x += overlay->width()) 982 for (int x = 0; x < bg_tab->width(); x += overlay->width())
832 canvas.drawBitmap(*overlay, static_cast<SkScalar>(x), 0, NULL); 983 canvas.drawBitmap(*overlay, static_cast<SkScalar>(x), 0, NULL);
833 } 984 }
834 985
835 temp_output[id] = bg_tab; 986 temp_output[prs_id] = bg_tab;
836 } 987 }
837 } 988 }
838 989
839 MergeImageCaches(temp_output, bitmaps); 990 MergeImageCaches(temp_output, bitmaps);
840 } 991 }
841 992
842 void BrowserThemePack::RepackImages(const ImageCache& images, 993 void BrowserThemePack::RepackImages(const ImageCache& images,
843 RawImages* reencoded_images) const { 994 RawImages* reencoded_images) const {
844 for (ImageCache::const_iterator it = images.begin(); 995 for (ImageCache::const_iterator it = images.begin();
845 it != images.end(); ++it) { 996 it != images.end(); ++it) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 } 1050 }
900 1051
901 return BrowserThemeProvider::GetDefaultTint(id); 1052 return BrowserThemeProvider::GetDefaultTint(id);
902 } 1053 }
903 1054
904 // No optimizations under windows until we know what's up with the crashing. 1055 // No optimizations under windows until we know what's up with the crashing.
905 #if defined(OS_WIN) 1056 #if defined(OS_WIN)
906 #pragma warning(default:4748) 1057 #pragma warning(default:4748)
907 #pragma optimize("", on) 1058 #pragma optimize("", on)
908 #endif 1059 #endif
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/browser_theme_pack_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698