| 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" |
| 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 Loading... |
| 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 gfx::ImageSkia final_icon = |
| 136 gfx::ImageSkiaOperations::CreateImageWithFallbackResizeMethod( |
| 137 icon, skia::ImageOperations::RESIZE_LANCZOS3); |
| 138 action->SetIcon(kTabId, gfx::Image(final_icon)); |
| 134 } | 139 } |
| 135 } | 140 } |
| 136 | 141 |
| 137 // Store |action|'s default values in a DictionaryValue for use in storing to | 142 // Store |action|'s default values in a DictionaryValue for use in storing to |
| 138 // disk. | 143 // disk. |
| 139 scoped_ptr<base::DictionaryValue> DefaultsToValue(ExtensionAction* action) { | 144 scoped_ptr<base::DictionaryValue> DefaultsToValue(ExtensionAction* action) { |
| 140 const int kTabId = ExtensionAction::kDefaultTabId; | 145 const int kTabId = ExtensionAction::kDefaultTabId; |
| 141 scoped_ptr<base::DictionaryValue> dict(new DictionaryValue()); | 146 scoped_ptr<base::DictionaryValue> dict(new DictionaryValue()); |
| 142 | 147 |
| 143 dict->SetString(kPopupUrlStorageKey, action->GetPopupUrl(kTabId).spec()); | 148 dict->SetString(kPopupUrlStorageKey, action->GetPopupUrl(kTabId).spec()); |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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::CreateImageWithFallbackResizeMethod( |
| 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 Loading... |
| 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 } |
| OLD | NEW |