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

Side by Side Diff: chrome/browser/extensions/api/extension_action/extension_actions_api.cc

Issue 11017046: Use LANCZOS3 resize algorithm to generate missing image reps for extension action icons. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 2 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 | Annotate | Revision Log
OLDNEW
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/extensions/api/extension_action/extension_actions_api.h " 5 #include "chrome/browser/extensions/api/extension_action/extension_actions_api.h "
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
11 #include "base/string_piece.h" 11 #include "base/string_piece.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/extensions/api/extension_action/extension_page_actions_ api_constants.h" 13 #include "chrome/browser/extensions/api/extension_action/extension_page_actions_ api_constants.h"
14 #include "chrome/browser/extensions/extension_action.h" 14 #include "chrome/browser/extensions/extension_action.h"
15 #include "chrome/browser/extensions/extension_action_manager.h" 15 #include "chrome/browser/extensions/extension_action_manager.h"
16 #include "chrome/browser/extensions/extension_service.h" 16 #include "chrome/browser/extensions/extension_service.h"
17 #include "chrome/browser/extensions/extension_system.h" 17 #include "chrome/browser/extensions/extension_system.h"
18 #include "chrome/browser/extensions/extension_tab_util.h" 18 #include "chrome/browser/extensions/extension_tab_util.h"
19 #include "chrome/browser/extensions/location_bar_controller.h" 19 #include "chrome/browser/extensions/location_bar_controller.h"
20 #include "chrome/browser/extensions/state_store.h" 20 #include "chrome/browser/extensions/state_store.h"
21 #include "chrome/browser/extensions/tab_helper.h" 21 #include "chrome/browser/extensions/tab_helper.h"
22 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/ui/tab_contents/tab_contents.h" 23 #include "chrome/browser/ui/tab_contents/tab_contents.h"
24 #include "chrome/common/chrome_notification_types.h" 24 #include "chrome/common/chrome_notification_types.h"
25 #include "chrome/common/extensions/extension.h" 25 #include "chrome/common/extensions/extension.h"
26 #include "chrome/common/extensions/extension_error_utils.h" 26 #include "chrome/common/extensions/extension_error_utils.h"
27 #include "chrome/common/render_messages.h" 27 #include "chrome/common/render_messages.h"
28 #include "content/public/browser/navigation_entry.h" 28 #include "content/public/browser/navigation_entry.h"
29 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
30 #include "ui/gfx/image/image_skia_operations.h"
30 31
31 namespace { 32 namespace {
32 33
33 const char kBrowserActionStorageKey[] = "browser_action"; 34 const char kBrowserActionStorageKey[] = "browser_action";
34 const char kPopupUrlStorageKey[] = "poupup_url"; 35 const char kPopupUrlStorageKey[] = "poupup_url";
35 const char kTitleStorageKey[] = "title"; 36 const char kTitleStorageKey[] = "title";
36 const char kIconStorageKey[] = "icon"; 37 const char kIconStorageKey[] = "icon";
37 const char kBadgeTextStorageKey[] = "badge_text"; 38 const char kBadgeTextStorageKey[] = "badge_text";
38 const char kBadgeBackgroundColorStorageKey[] = "badge_background_color"; 39 const char kBadgeBackgroundColorStorageKey[] = "badge_background_color";
39 const char kBadgeTextColorStorageKey[] = "badge_text_color"; 40 const char kBadgeTextColorStorageKey[] = "badge_text_color";
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 124
124 const base::DictionaryValue* icon_value = NULL; 125 const base::DictionaryValue* icon_value = NULL;
125 if (dict->GetDictionary(kIconStorageKey, &icon_value)) { 126 if (dict->GetDictionary(kIconStorageKey, &icon_value)) {
126 for (size_t i = 0; i < arraysize(kIconSizes); i++) { 127 for (size_t i = 0; i < arraysize(kIconSizes); i++) {
127 if (icon_value->GetString(kIconSizes[i].size_string, &str_value) && 128 if (icon_value->GetString(kIconSizes[i].size_string, &str_value) &&
128 StringToSkBitmap(str_value, &bitmap)) { 129 StringToSkBitmap(str_value, &bitmap)) {
129 CHECK(!bitmap.isNull()); 130 CHECK(!bitmap.isNull());
130 icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, kIconSizes[i].scale)); 131 icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, kIconSizes[i].scale));
131 } 132 }
132 } 133 }
133 action->SetIcon(kTabId, gfx::Image(icon)); 134
135 if (!icon.isNull()) {
136 gfx::ImageSkia final_icon =
137 gfx::ImageSkiaOperations::CreateImageWithCustomResizeMethod(
138 icon, skia::ImageOperations::RESIZE_LANCZOS3);
139 action->SetIcon(kTabId, gfx::Image(final_icon));
140 }
134 } 141 }
135 } 142 }
136 143
137 // Store |action|'s default values in a DictionaryValue for use in storing to 144 // Store |action|'s default values in a DictionaryValue for use in storing to
138 // disk. 145 // disk.
139 scoped_ptr<base::DictionaryValue> DefaultsToValue(ExtensionAction* action) { 146 scoped_ptr<base::DictionaryValue> DefaultsToValue(ExtensionAction* action) {
140 const int kTabId = ExtensionAction::kDefaultTabId; 147 const int kTabId = ExtensionAction::kDefaultTabId;
141 scoped_ptr<base::DictionaryValue> dict(new DictionaryValue()); 148 scoped_ptr<base::DictionaryValue> dict(new DictionaryValue());
142 149
143 dict->SetString(kPopupUrlStorageKey, action->GetPopupUrl(kTabId).spec()); 150 dict->SetString(kPopupUrlStorageKey, action->GetPopupUrl(kTabId).spec());
144 dict->SetString(kTitleStorageKey, action->GetTitle(kTabId)); 151 dict->SetString(kTitleStorageKey, action->GetTitle(kTabId));
145 dict->SetString(kBadgeTextStorageKey, action->GetBadgeText(kTabId)); 152 dict->SetString(kBadgeTextStorageKey, action->GetBadgeText(kTabId));
146 dict->SetString(kBadgeBackgroundColorStorageKey, 153 dict->SetString(kBadgeBackgroundColorStorageKey,
147 SkColorToRawString(action->GetBadgeBackgroundColor(kTabId))); 154 SkColorToRawString(action->GetBadgeBackgroundColor(kTabId)));
148 dict->SetString(kBadgeTextColorStorageKey, 155 dict->SetString(kBadgeTextColorStorageKey,
149 SkColorToRawString(action->GetBadgeTextColor(kTabId))); 156 SkColorToRawString(action->GetBadgeTextColor(kTabId)));
150 dict->SetInteger(kAppearanceStorageKey, 157 dict->SetInteger(kAppearanceStorageKey,
151 action->GetIsVisible(kTabId) ? 158 action->GetIsVisible(kTabId) ?
152 ExtensionAction::ACTIVE : ExtensionAction::INVISIBLE); 159 ExtensionAction::ACTIVE : ExtensionAction::INVISIBLE);
153 160
154 gfx::ImageSkia icon = action->GetExplicitlySetIcon(kTabId); 161 gfx::ImageSkia icon = action->GetExplicitlySetIcon(kTabId);
155 if (!icon.isNull()) { 162 if (!icon.isNull()) {
156 base::DictionaryValue* icon_value = new base::DictionaryValue(); 163 base::DictionaryValue* icon_value = new base::DictionaryValue();
157 for (size_t i = 0; i < arraysize(kIconSizes); i++) { 164 for (size_t i = 0; i < arraysize(kIconSizes); i++) {
158 if (icon.HasRepresentation(kIconSizes[i].scale)) { 165 icon_value->SetString(
159 icon_value->SetString( 166 kIconSizes[i].size_string,
160 kIconSizes[i].size_string, 167 RepresentationToString(icon, kIconSizes[i].scale));
161 RepresentationToString(icon, kIconSizes[i].scale));
162 }
163 } 168 }
164 dict->Set(kIconStorageKey, icon_value); 169 dict->Set(kIconStorageKey, icon_value);
165 } 170 }
166 return dict.Pass(); 171 return dict.Pass();
167 } 172 }
168 173
169 } // namespace 174 } // namespace
170 175
171 namespace extensions { 176 namespace extensions {
172 177
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 if (canvas_set->GetBinary(kIconSizes[i].size_string, &binary)) { 467 if (canvas_set->GetBinary(kIconSizes[i].size_string, &binary)) {
463 IPC::Message pickle(binary->GetBuffer(), binary->GetSize()); 468 IPC::Message pickle(binary->GetBuffer(), binary->GetSize());
464 PickleIterator iter(pickle); 469 PickleIterator iter(pickle);
465 SkBitmap bitmap; 470 SkBitmap bitmap;
466 EXTENSION_FUNCTION_VALIDATE(IPC::ReadParam(&pickle, &iter, &bitmap)); 471 EXTENSION_FUNCTION_VALIDATE(IPC::ReadParam(&pickle, &iter, &bitmap));
467 CHECK(!bitmap.isNull()); 472 CHECK(!bitmap.isNull());
468 icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, kIconSizes[i].scale)); 473 icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, kIconSizes[i].scale));
469 } 474 }
470 } 475 }
471 476
472 extension_action_->SetIcon(tab_id_, gfx::Image(icon)); 477 gfx::ImageSkia final_icon =
478 gfx::ImageSkiaOperations::CreateImageWithCustomResizeMethod(
479 icon, skia::ImageOperations::RESIZE_LANCZOS3);
480 extension_action_->SetIcon(tab_id_, gfx::Image(final_icon));
473 } else if (details_->GetInteger("iconIndex", &icon_index)) { 481 } else if (details_->GetInteger("iconIndex", &icon_index)) {
474 // Obsolete argument: ignore it. 482 // Obsolete argument: ignore it.
475 return true; 483 return true;
476 } else { 484 } else {
477 EXTENSION_FUNCTION_VALIDATE(false); 485 EXTENSION_FUNCTION_VALIDATE(false);
478 } 486 }
479 NotifyChange(); 487 NotifyChange();
480 return true; 488 return true;
481 } 489 }
482 490
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 bool ExtensionActionGetBadgeBackgroundColorFunction::RunExtensionAction() { 564 bool ExtensionActionGetBadgeBackgroundColorFunction::RunExtensionAction() {
557 ListValue* list = new ListValue(); 565 ListValue* list = new ListValue();
558 SkColor color = extension_action_->GetBadgeBackgroundColor(tab_id_); 566 SkColor color = extension_action_->GetBadgeBackgroundColor(tab_id_);
559 list->Append(Value::CreateIntegerValue(SkColorGetR(color))); 567 list->Append(Value::CreateIntegerValue(SkColorGetR(color)));
560 list->Append(Value::CreateIntegerValue(SkColorGetG(color))); 568 list->Append(Value::CreateIntegerValue(SkColorGetG(color)));
561 list->Append(Value::CreateIntegerValue(SkColorGetB(color))); 569 list->Append(Value::CreateIntegerValue(SkColorGetB(color)));
562 list->Append(Value::CreateIntegerValue(SkColorGetA(color))); 570 list->Append(Value::CreateIntegerValue(SkColorGetA(color)));
563 SetResult(list); 571 SetResult(list);
564 return true; 572 return true;
565 } 573 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/extension_action/browser_action_apitest.cc ('k') | ui/gfx/image/image_skia_operations.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698