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/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" | |
31 | 30 |
32 namespace { | 31 namespace { |
33 | 32 |
34 const char kBrowserActionStorageKey[] = "browser_action"; | 33 const char kBrowserActionStorageKey[] = "browser_action"; |
35 const char kPopupUrlStorageKey[] = "poupup_url"; | 34 const char kPopupUrlStorageKey[] = "poupup_url"; |
36 const char kTitleStorageKey[] = "title"; | 35 const char kTitleStorageKey[] = "title"; |
37 const char kIconStorageKey[] = "icon"; | 36 const char kIconStorageKey[] = "icon"; |
38 const char kBadgeTextStorageKey[] = "badge_text"; | 37 const char kBadgeTextStorageKey[] = "badge_text"; |
39 const char kBadgeBackgroundColorStorageKey[] = "badge_background_color"; | 38 const char kBadgeBackgroundColorStorageKey[] = "badge_background_color"; |
40 const char kBadgeTextColorStorageKey[] = "badge_text_color"; | 39 const char kBadgeTextColorStorageKey[] = "badge_text_color"; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 | 123 |
125 const base::DictionaryValue* icon_value = NULL; | 124 const base::DictionaryValue* icon_value = NULL; |
126 if (dict->GetDictionary(kIconStorageKey, &icon_value)) { | 125 if (dict->GetDictionary(kIconStorageKey, &icon_value)) { |
127 for (size_t i = 0; i < arraysize(kIconSizes); i++) { | 126 for (size_t i = 0; i < arraysize(kIconSizes); i++) { |
128 if (icon_value->GetString(kIconSizes[i].size_string, &str_value) && | 127 if (icon_value->GetString(kIconSizes[i].size_string, &str_value) && |
129 StringToSkBitmap(str_value, &bitmap)) { | 128 StringToSkBitmap(str_value, &bitmap)) { |
130 CHECK(!bitmap.isNull()); | 129 CHECK(!bitmap.isNull()); |
131 icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, kIconSizes[i].scale)); | 130 icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, kIconSizes[i].scale)); |
132 } | 131 } |
133 } | 132 } |
134 | 133 action->SetIcon(kTabId, gfx::Image(icon)); |
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 } | |
141 } | 134 } |
142 } | 135 } |
143 | 136 |
144 // Store |action|'s default values in a DictionaryValue for use in storing to | 137 // Store |action|'s default values in a DictionaryValue for use in storing to |
145 // disk. | 138 // disk. |
146 scoped_ptr<base::DictionaryValue> DefaultsToValue(ExtensionAction* action) { | 139 scoped_ptr<base::DictionaryValue> DefaultsToValue(ExtensionAction* action) { |
147 const int kTabId = ExtensionAction::kDefaultTabId; | 140 const int kTabId = ExtensionAction::kDefaultTabId; |
148 scoped_ptr<base::DictionaryValue> dict(new DictionaryValue()); | 141 scoped_ptr<base::DictionaryValue> dict(new DictionaryValue()); |
149 | 142 |
150 dict->SetString(kPopupUrlStorageKey, action->GetPopupUrl(kTabId).spec()); | 143 dict->SetString(kPopupUrlStorageKey, action->GetPopupUrl(kTabId).spec()); |
151 dict->SetString(kTitleStorageKey, action->GetTitle(kTabId)); | 144 dict->SetString(kTitleStorageKey, action->GetTitle(kTabId)); |
152 dict->SetString(kBadgeTextStorageKey, action->GetBadgeText(kTabId)); | 145 dict->SetString(kBadgeTextStorageKey, action->GetBadgeText(kTabId)); |
153 dict->SetString(kBadgeBackgroundColorStorageKey, | 146 dict->SetString(kBadgeBackgroundColorStorageKey, |
154 SkColorToRawString(action->GetBadgeBackgroundColor(kTabId))); | 147 SkColorToRawString(action->GetBadgeBackgroundColor(kTabId))); |
155 dict->SetString(kBadgeTextColorStorageKey, | 148 dict->SetString(kBadgeTextColorStorageKey, |
156 SkColorToRawString(action->GetBadgeTextColor(kTabId))); | 149 SkColorToRawString(action->GetBadgeTextColor(kTabId))); |
157 dict->SetInteger(kAppearanceStorageKey, | 150 dict->SetInteger(kAppearanceStorageKey, |
158 action->GetIsVisible(kTabId) ? | 151 action->GetIsVisible(kTabId) ? |
159 ExtensionAction::ACTIVE : ExtensionAction::INVISIBLE); | 152 ExtensionAction::ACTIVE : ExtensionAction::INVISIBLE); |
160 | 153 |
161 gfx::ImageSkia icon = action->GetExplicitlySetIcon(kTabId); | 154 gfx::ImageSkia icon = action->GetExplicitlySetIcon(kTabId); |
162 if (!icon.isNull()) { | 155 if (!icon.isNull()) { |
163 base::DictionaryValue* icon_value = new base::DictionaryValue(); | 156 base::DictionaryValue* icon_value = new base::DictionaryValue(); |
164 for (size_t i = 0; i < arraysize(kIconSizes); i++) { | 157 for (size_t i = 0; i < arraysize(kIconSizes); i++) { |
165 icon_value->SetString( | 158 if (icon.HasRepresentation(kIconSizes[i].scale)) { |
166 kIconSizes[i].size_string, | 159 icon_value->SetString( |
167 RepresentationToString(icon, kIconSizes[i].scale)); | 160 kIconSizes[i].size_string, |
| 161 RepresentationToString(icon, kIconSizes[i].scale)); |
| 162 } |
168 } | 163 } |
169 dict->Set(kIconStorageKey, icon_value); | 164 dict->Set(kIconStorageKey, icon_value); |
170 } | 165 } |
171 return dict.Pass(); | 166 return dict.Pass(); |
172 } | 167 } |
173 | 168 |
174 } // namespace | 169 } // namespace |
175 | 170 |
176 namespace extensions { | 171 namespace extensions { |
177 | 172 |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 if (canvas_set->GetBinary(kIconSizes[i].size_string, &binary)) { | 462 if (canvas_set->GetBinary(kIconSizes[i].size_string, &binary)) { |
468 IPC::Message pickle(binary->GetBuffer(), binary->GetSize()); | 463 IPC::Message pickle(binary->GetBuffer(), binary->GetSize()); |
469 PickleIterator iter(pickle); | 464 PickleIterator iter(pickle); |
470 SkBitmap bitmap; | 465 SkBitmap bitmap; |
471 EXTENSION_FUNCTION_VALIDATE(IPC::ReadParam(&pickle, &iter, &bitmap)); | 466 EXTENSION_FUNCTION_VALIDATE(IPC::ReadParam(&pickle, &iter, &bitmap)); |
472 CHECK(!bitmap.isNull()); | 467 CHECK(!bitmap.isNull()); |
473 icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, kIconSizes[i].scale)); | 468 icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, kIconSizes[i].scale)); |
474 } | 469 } |
475 } | 470 } |
476 | 471 |
477 gfx::ImageSkia final_icon = | 472 extension_action_->SetIcon(tab_id_, gfx::Image(icon)); |
478 gfx::ImageSkiaOperations::CreateImageWithCustomResizeMethod( | |
479 icon, skia::ImageOperations::RESIZE_LANCZOS3); | |
480 extension_action_->SetIcon(tab_id_, gfx::Image(final_icon)); | |
481 } else if (details_->GetInteger("iconIndex", &icon_index)) { | 473 } else if (details_->GetInteger("iconIndex", &icon_index)) { |
482 // Obsolete argument: ignore it. | 474 // Obsolete argument: ignore it. |
483 return true; | 475 return true; |
484 } else { | 476 } else { |
485 EXTENSION_FUNCTION_VALIDATE(false); | 477 EXTENSION_FUNCTION_VALIDATE(false); |
486 } | 478 } |
487 NotifyChange(); | 479 NotifyChange(); |
488 return true; | 480 return true; |
489 } | 481 } |
490 | 482 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 bool ExtensionActionGetBadgeBackgroundColorFunction::RunExtensionAction() { | 556 bool ExtensionActionGetBadgeBackgroundColorFunction::RunExtensionAction() { |
565 ListValue* list = new ListValue(); | 557 ListValue* list = new ListValue(); |
566 SkColor color = extension_action_->GetBadgeBackgroundColor(tab_id_); | 558 SkColor color = extension_action_->GetBadgeBackgroundColor(tab_id_); |
567 list->Append(Value::CreateIntegerValue(SkColorGetR(color))); | 559 list->Append(Value::CreateIntegerValue(SkColorGetR(color))); |
568 list->Append(Value::CreateIntegerValue(SkColorGetG(color))); | 560 list->Append(Value::CreateIntegerValue(SkColorGetG(color))); |
569 list->Append(Value::CreateIntegerValue(SkColorGetB(color))); | 561 list->Append(Value::CreateIntegerValue(SkColorGetB(color))); |
570 list->Append(Value::CreateIntegerValue(SkColorGetA(color))); | 562 list->Append(Value::CreateIntegerValue(SkColorGetA(color))); |
571 SetResult(list); | 563 SetResult(list); |
572 return true; | 564 return true; |
573 } | 565 } |
OLD | NEW |