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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 // http://crbug.com/140546 is fixed. | 93 // http://crbug.com/140546 is fixed. |
94 std::string raw_str; | 94 std::string raw_str; |
95 if (!base::Base64Decode(str, &raw_str)) | 95 if (!base::Base64Decode(str, &raw_str)) |
96 return false; | 96 return false; |
97 IPC::Message bitmap_pickle(raw_str.data(), raw_str.size()); | 97 IPC::Message bitmap_pickle(raw_str.data(), raw_str.size()); |
98 PickleIterator iter(bitmap_pickle); | 98 PickleIterator iter(bitmap_pickle); |
99 return IPC::ReadParam(&bitmap_pickle, &iter, bitmap); | 99 return IPC::ReadParam(&bitmap_pickle, &iter, bitmap); |
100 } | 100 } |
101 | 101 |
102 // Conversion function for reading/writing to storage. | 102 // Conversion function for reading/writing to storage. |
103 std::string RepresentationToString(const gfx::ImageSkia& image, | 103 std::string RepresentationToString(const gfx::ImageSkia& image, float scale) { |
104 ui::ScaleFactor scale) { | |
105 SkBitmap bitmap = image.GetRepresentation(scale).sk_bitmap(); | 104 SkBitmap bitmap = image.GetRepresentation(scale).sk_bitmap(); |
106 IPC::Message bitmap_pickle; | 105 IPC::Message bitmap_pickle; |
107 // Clear the header values so they don't vary in serialization. | 106 // Clear the header values so they don't vary in serialization. |
108 bitmap_pickle.SetHeaderValues(0, 0, 0); | 107 bitmap_pickle.SetHeaderValues(0, 0, 0); |
109 IPC::WriteParam(&bitmap_pickle, bitmap); | 108 IPC::WriteParam(&bitmap_pickle, bitmap); |
110 std::string raw_str(static_cast<const char*>(bitmap_pickle.data()), | 109 std::string raw_str(static_cast<const char*>(bitmap_pickle.data()), |
111 bitmap_pickle.size()); | 110 bitmap_pickle.size()); |
112 std::string base64_str; | 111 std::string base64_str; |
113 if (!base::Base64Encode(raw_str, &base64_str)) | 112 if (!base::Base64Encode(raw_str, &base64_str)) |
114 return std::string(); | 113 return std::string(); |
(...skipping 22 matching lines...) Expand all Loading... |
137 if (dict->GetInteger(kAppearanceStorageKey, &int_value)) | 136 if (dict->GetInteger(kAppearanceStorageKey, &int_value)) |
138 action->SetAppearance(kTabId, | 137 action->SetAppearance(kTabId, |
139 static_cast<ExtensionAction::Appearance>(int_value)); | 138 static_cast<ExtensionAction::Appearance>(int_value)); |
140 | 139 |
141 const base::DictionaryValue* icon_value = NULL; | 140 const base::DictionaryValue* icon_value = NULL; |
142 if (dict->GetDictionary(kIconStorageKey, &icon_value)) { | 141 if (dict->GetDictionary(kIconStorageKey, &icon_value)) { |
143 for (size_t i = 0; i < arraysize(kIconSizes); i++) { | 142 for (size_t i = 0; i < arraysize(kIconSizes); i++) { |
144 if (icon_value->GetString(kIconSizes[i].size_string, &str_value) && | 143 if (icon_value->GetString(kIconSizes[i].size_string, &str_value) && |
145 StringToSkBitmap(str_value, &bitmap)) { | 144 StringToSkBitmap(str_value, &bitmap)) { |
146 CHECK(!bitmap.isNull()); | 145 CHECK(!bitmap.isNull()); |
147 icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, kIconSizes[i].scale)); | 146 float scale = ui::GetImageScale(kIconSizes[i].scale); |
| 147 icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale)); |
148 } | 148 } |
149 } | 149 } |
150 action->SetIcon(kTabId, gfx::Image(icon)); | 150 action->SetIcon(kTabId, gfx::Image(icon)); |
151 } | 151 } |
152 } | 152 } |
153 | 153 |
154 // Store |action|'s default values in a DictionaryValue for use in storing to | 154 // Store |action|'s default values in a DictionaryValue for use in storing to |
155 // disk. | 155 // disk. |
156 scoped_ptr<base::DictionaryValue> DefaultsToValue(ExtensionAction* action) { | 156 scoped_ptr<base::DictionaryValue> DefaultsToValue(ExtensionAction* action) { |
157 const int kTabId = ExtensionAction::kDefaultTabId; | 157 const int kTabId = ExtensionAction::kDefaultTabId; |
158 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 158 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
159 | 159 |
160 dict->SetString(kPopupUrlStorageKey, action->GetPopupUrl(kTabId).spec()); | 160 dict->SetString(kPopupUrlStorageKey, action->GetPopupUrl(kTabId).spec()); |
161 dict->SetString(kTitleStorageKey, action->GetTitle(kTabId)); | 161 dict->SetString(kTitleStorageKey, action->GetTitle(kTabId)); |
162 dict->SetString(kBadgeTextStorageKey, action->GetBadgeText(kTabId)); | 162 dict->SetString(kBadgeTextStorageKey, action->GetBadgeText(kTabId)); |
163 dict->SetString(kBadgeBackgroundColorStorageKey, | 163 dict->SetString(kBadgeBackgroundColorStorageKey, |
164 SkColorToRawString(action->GetBadgeBackgroundColor(kTabId))); | 164 SkColorToRawString(action->GetBadgeBackgroundColor(kTabId))); |
165 dict->SetString(kBadgeTextColorStorageKey, | 165 dict->SetString(kBadgeTextColorStorageKey, |
166 SkColorToRawString(action->GetBadgeTextColor(kTabId))); | 166 SkColorToRawString(action->GetBadgeTextColor(kTabId))); |
167 dict->SetInteger(kAppearanceStorageKey, | 167 dict->SetInteger(kAppearanceStorageKey, |
168 action->GetIsVisible(kTabId) ? | 168 action->GetIsVisible(kTabId) ? |
169 ExtensionAction::ACTIVE : ExtensionAction::INVISIBLE); | 169 ExtensionAction::ACTIVE : ExtensionAction::INVISIBLE); |
170 | 170 |
171 gfx::ImageSkia icon = action->GetExplicitlySetIcon(kTabId); | 171 gfx::ImageSkia icon = action->GetExplicitlySetIcon(kTabId); |
172 if (!icon.isNull()) { | 172 if (!icon.isNull()) { |
173 base::DictionaryValue* icon_value = new base::DictionaryValue(); | 173 base::DictionaryValue* icon_value = new base::DictionaryValue(); |
174 for (size_t i = 0; i < arraysize(kIconSizes); i++) { | 174 for (size_t i = 0; i < arraysize(kIconSizes); i++) { |
175 if (icon.HasRepresentation(kIconSizes[i].scale)) { | 175 float scale = ui::GetImageScale(kIconSizes[i].scale); |
| 176 if (icon.HasRepresentation(scale)) { |
176 icon_value->SetString( | 177 icon_value->SetString( |
177 kIconSizes[i].size_string, | 178 kIconSizes[i].size_string, |
178 RepresentationToString(icon, kIconSizes[i].scale)); | 179 RepresentationToString(icon, scale)); |
179 } | 180 } |
180 } | 181 } |
181 dict->Set(kIconStorageKey, icon_value); | 182 dict->Set(kIconStorageKey, icon_value); |
182 } | 183 } |
183 return dict.Pass(); | 184 return dict.Pass(); |
184 } | 185 } |
185 | 186 |
186 } // namespace | 187 } // namespace |
187 | 188 |
188 // | 189 // |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 gfx::ImageSkia icon; | 690 gfx::ImageSkia icon; |
690 // Extract icon representations from the ImageDataSet dictionary. | 691 // Extract icon representations from the ImageDataSet dictionary. |
691 for (size_t i = 0; i < arraysize(kIconSizes); i++) { | 692 for (size_t i = 0; i < arraysize(kIconSizes); i++) { |
692 base::BinaryValue* binary; | 693 base::BinaryValue* binary; |
693 if (canvas_set->GetBinary(kIconSizes[i].size_string, &binary)) { | 694 if (canvas_set->GetBinary(kIconSizes[i].size_string, &binary)) { |
694 IPC::Message pickle(binary->GetBuffer(), binary->GetSize()); | 695 IPC::Message pickle(binary->GetBuffer(), binary->GetSize()); |
695 PickleIterator iter(pickle); | 696 PickleIterator iter(pickle); |
696 SkBitmap bitmap; | 697 SkBitmap bitmap; |
697 EXTENSION_FUNCTION_VALIDATE(IPC::ReadParam(&pickle, &iter, &bitmap)); | 698 EXTENSION_FUNCTION_VALIDATE(IPC::ReadParam(&pickle, &iter, &bitmap)); |
698 CHECK(!bitmap.isNull()); | 699 CHECK(!bitmap.isNull()); |
699 icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, kIconSizes[i].scale)); | 700 float scale = ui::GetImageScale(kIconSizes[i].scale); |
| 701 icon.AddRepresentation(gfx::ImageSkiaRep(bitmap, scale)); |
700 } | 702 } |
701 } | 703 } |
702 | 704 |
703 extension_action_->SetIcon(tab_id_, gfx::Image(icon)); | 705 extension_action_->SetIcon(tab_id_, gfx::Image(icon)); |
704 } else if (details_->GetInteger("iconIndex", &icon_index)) { | 706 } else if (details_->GetInteger("iconIndex", &icon_index)) { |
705 // Obsolete argument: ignore it. | 707 // Obsolete argument: ignore it. |
706 return true; | 708 return true; |
707 } else { | 709 } else { |
708 EXTENSION_FUNCTION_VALIDATE(false); | 710 EXTENSION_FUNCTION_VALIDATE(false); |
709 } | 711 } |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
882 return true; | 884 return true; |
883 } | 885 } |
884 | 886 |
885 bool EnablePageActionsFunction::RunImpl() { | 887 bool EnablePageActionsFunction::RunImpl() { |
886 return SetPageActionEnabled(true); | 888 return SetPageActionEnabled(true); |
887 } | 889 } |
888 | 890 |
889 bool DisablePageActionsFunction::RunImpl() { | 891 bool DisablePageActionsFunction::RunImpl() { |
890 return SetPageActionEnabled(false); | 892 return SetPageActionEnabled(false); |
891 } | 893 } |
OLD | NEW |