| 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_action_api.h" | 5 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 } | 179 } |
| 180 } | 180 } |
| 181 | 181 |
| 182 const base::DictionaryValue* icon_value = NULL; | 182 const base::DictionaryValue* icon_value = NULL; |
| 183 if (dict->GetDictionary(kIconStorageKey, &icon_value) && | 183 if (dict->GetDictionary(kIconStorageKey, &icon_value) && |
| 184 !action->HasIcon(kDefaultTabId)) { | 184 !action->HasIcon(kDefaultTabId)) { |
| 185 for (size_t i = 0; i < arraysize(kIconSizes); i++) { | 185 for (size_t i = 0; i < arraysize(kIconSizes); i++) { |
| 186 if (icon_value->GetString(kIconSizes[i].size_string, &str_value) && | 186 if (icon_value->GetString(kIconSizes[i].size_string, &str_value) && |
| 187 StringToSkBitmap(str_value, &bitmap)) { | 187 StringToSkBitmap(str_value, &bitmap)) { |
| 188 CHECK(!bitmap.isNull()); | 188 CHECK(!bitmap.isNull()); |
| 189 float scale = ui::GetImageScale(kIconSizes[i].scale); | 189 float scale = ui::GetScaleForScaleFactor(kIconSizes[i].scale); |
| 190 icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale)); | 190 icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale)); |
| 191 } | 191 } |
| 192 } | 192 } |
| 193 action->SetIcon(kDefaultTabId, gfx::Image(icon)); | 193 action->SetIcon(kDefaultTabId, gfx::Image(icon)); |
| 194 } | 194 } |
| 195 } | 195 } |
| 196 | 196 |
| 197 // Store |action|'s default values in a DictionaryValue for use in storing to | 197 // Store |action|'s default values in a DictionaryValue for use in storing to |
| 198 // disk. | 198 // disk. |
| 199 scoped_ptr<base::DictionaryValue> DefaultsToValue(ExtensionAction* action) { | 199 scoped_ptr<base::DictionaryValue> DefaultsToValue(ExtensionAction* action) { |
| 200 const int kDefaultTabId = ExtensionAction::kDefaultTabId; | 200 const int kDefaultTabId = ExtensionAction::kDefaultTabId; |
| 201 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 201 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 202 | 202 |
| 203 dict->SetString(kPopupUrlStorageKey, | 203 dict->SetString(kPopupUrlStorageKey, |
| 204 action->GetPopupUrl(kDefaultTabId).spec()); | 204 action->GetPopupUrl(kDefaultTabId).spec()); |
| 205 dict->SetString(kTitleStorageKey, action->GetTitle(kDefaultTabId)); | 205 dict->SetString(kTitleStorageKey, action->GetTitle(kDefaultTabId)); |
| 206 dict->SetString(kBadgeTextStorageKey, action->GetBadgeText(kDefaultTabId)); | 206 dict->SetString(kBadgeTextStorageKey, action->GetBadgeText(kDefaultTabId)); |
| 207 dict->SetString( | 207 dict->SetString( |
| 208 kBadgeBackgroundColorStorageKey, | 208 kBadgeBackgroundColorStorageKey, |
| 209 SkColorToRawString(action->GetBadgeBackgroundColor(kDefaultTabId))); | 209 SkColorToRawString(action->GetBadgeBackgroundColor(kDefaultTabId))); |
| 210 dict->SetString(kBadgeTextColorStorageKey, | 210 dict->SetString(kBadgeTextColorStorageKey, |
| 211 SkColorToRawString(action->GetBadgeTextColor(kDefaultTabId))); | 211 SkColorToRawString(action->GetBadgeTextColor(kDefaultTabId))); |
| 212 dict->SetInteger(kAppearanceStorageKey, | 212 dict->SetInteger(kAppearanceStorageKey, |
| 213 action->GetIsVisible(kDefaultTabId) ? ACTIVE : INVISIBLE); | 213 action->GetIsVisible(kDefaultTabId) ? ACTIVE : INVISIBLE); |
| 214 | 214 |
| 215 gfx::ImageSkia icon = action->GetExplicitlySetIcon(kDefaultTabId); | 215 gfx::ImageSkia icon = action->GetExplicitlySetIcon(kDefaultTabId); |
| 216 if (!icon.isNull()) { | 216 if (!icon.isNull()) { |
| 217 base::DictionaryValue* icon_value = new base::DictionaryValue(); | 217 base::DictionaryValue* icon_value = new base::DictionaryValue(); |
| 218 for (size_t i = 0; i < arraysize(kIconSizes); i++) { | 218 for (size_t i = 0; i < arraysize(kIconSizes); i++) { |
| 219 float scale = ui::GetImageScale(kIconSizes[i].scale); | 219 float scale = ui::GetScaleForScaleFactor(kIconSizes[i].scale); |
| 220 if (icon.HasRepresentation(scale)) { | 220 if (icon.HasRepresentation(scale)) { |
| 221 icon_value->SetString( | 221 icon_value->SetString( |
| 222 kIconSizes[i].size_string, | 222 kIconSizes[i].size_string, |
| 223 RepresentationToString(icon, scale)); | 223 RepresentationToString(icon, scale)); |
| 224 } | 224 } |
| 225 } | 225 } |
| 226 dict->Set(kIconStorageKey, icon_value); | 226 dict->Set(kIconStorageKey, icon_value); |
| 227 } | 227 } |
| 228 return dict.Pass(); | 228 return dict.Pass(); |
| 229 } | 229 } |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 gfx::ImageSkia icon; | 674 gfx::ImageSkia icon; |
| 675 // Extract icon representations from the ImageDataSet dictionary. | 675 // Extract icon representations from the ImageDataSet dictionary. |
| 676 for (size_t i = 0; i < arraysize(kIconSizes); i++) { | 676 for (size_t i = 0; i < arraysize(kIconSizes); i++) { |
| 677 base::BinaryValue* binary; | 677 base::BinaryValue* binary; |
| 678 if (canvas_set->GetBinary(kIconSizes[i].size_string, &binary)) { | 678 if (canvas_set->GetBinary(kIconSizes[i].size_string, &binary)) { |
| 679 IPC::Message pickle(binary->GetBuffer(), binary->GetSize()); | 679 IPC::Message pickle(binary->GetBuffer(), binary->GetSize()); |
| 680 PickleIterator iter(pickle); | 680 PickleIterator iter(pickle); |
| 681 SkBitmap bitmap; | 681 SkBitmap bitmap; |
| 682 EXTENSION_FUNCTION_VALIDATE(IPC::ReadParam(&pickle, &iter, &bitmap)); | 682 EXTENSION_FUNCTION_VALIDATE(IPC::ReadParam(&pickle, &iter, &bitmap)); |
| 683 CHECK(!bitmap.isNull()); | 683 CHECK(!bitmap.isNull()); |
| 684 float scale = ui::GetImageScale(kIconSizes[i].scale); | 684 float scale = ui::GetScaleForScaleFactor(kIconSizes[i].scale); |
| 685 icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale)); | 685 icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale)); |
| 686 } | 686 } |
| 687 } | 687 } |
| 688 | 688 |
| 689 extension_action_->SetIcon(tab_id_, gfx::Image(icon)); | 689 extension_action_->SetIcon(tab_id_, gfx::Image(icon)); |
| 690 } else if (details_->GetInteger("iconIndex", &icon_index)) { | 690 } else if (details_->GetInteger("iconIndex", &icon_index)) { |
| 691 // Obsolete argument: ignore it. | 691 // Obsolete argument: ignore it. |
| 692 return true; | 692 return true; |
| 693 } else { | 693 } else { |
| 694 EXTENSION_FUNCTION_VALIDATE(false); | 694 EXTENSION_FUNCTION_VALIDATE(false); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 return true; | 913 return true; |
| 914 } | 914 } |
| 915 | 915 |
| 916 bool EnablePageActionsFunction::RunSync() { | 916 bool EnablePageActionsFunction::RunSync() { |
| 917 return SetPageActionEnabled(true); | 917 return SetPageActionEnabled(true); |
| 918 } | 918 } |
| 919 | 919 |
| 920 bool DisablePageActionsFunction::RunSync() { | 920 bool DisablePageActionsFunction::RunSync() { |
| 921 return SetPageActionEnabled(false); | 921 return SetPageActionEnabled(false); |
| 922 } | 922 } |
| OLD | NEW |