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/extension_action.h" | 5 #include "chrome/browser/extensions/extension_action.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 | 122 |
123 void ExtensionAction::SetIcon(int tab_id, const gfx::Image& image) { | 123 void ExtensionAction::SetIcon(int tab_id, const gfx::Image& image) { |
124 SetValue(&icon_, tab_id, image); | 124 SetValue(&icon_, tab_id, image); |
125 } | 125 } |
126 | 126 |
127 bool ExtensionAction::ParseIconFromCanvasDictionary( | 127 bool ExtensionAction::ParseIconFromCanvasDictionary( |
128 const base::DictionaryValue& dict, | 128 const base::DictionaryValue& dict, |
129 gfx::ImageSkia* icon) { | 129 gfx::ImageSkia* icon) { |
130 for (base::DictionaryValue::Iterator iter(dict); !iter.IsAtEnd(); | 130 for (base::DictionaryValue::Iterator iter(dict); !iter.IsAtEnd(); |
131 iter.Advance()) { | 131 iter.Advance()) { |
132 int icon_size = 0; | |
133 // Chrome helpfully scales the provided icon(s), but let's not go overboard. | |
134 const int kActionIconMaxSize = 10 * extension_misc::EXTENSION_ICON_ACTION; | |
135 if (!base::StringToInt(iter.key(), &icon_size) || icon_size <= 0 || | |
136 icon_size > kActionIconMaxSize) { | |
Devlin
2016/01/26 19:08:48
Do we not want any checks for ridiculous scaling?
Evan Stade
2016/01/26 19:50:07
righto, baby rescued from bathwater
| |
137 continue; | |
138 } | |
139 | |
140 const base::BinaryValue* image_data; | 132 const base::BinaryValue* image_data; |
141 std::string binary_string64; | 133 std::string binary_string64; |
142 IPC::Message pickle; | 134 IPC::Message pickle; |
143 if (iter.value().GetAsBinary(&image_data)) { | 135 if (iter.value().GetAsBinary(&image_data)) { |
144 pickle = IPC::Message(image_data->GetBuffer(), image_data->GetSize()); | 136 pickle = IPC::Message(image_data->GetBuffer(), image_data->GetSize()); |
145 } else if (iter.value().GetAsString(&binary_string64)) { | 137 } else if (iter.value().GetAsString(&binary_string64)) { |
146 std::string binary_string; | 138 std::string binary_string; |
147 if (!base::Base64Decode(binary_string64, &binary_string)) | 139 if (!base::Base64Decode(binary_string64, &binary_string)) |
148 return false; | 140 return false; |
149 pickle = IPC::Message(binary_string.c_str(), binary_string.length()); | 141 pickle = IPC::Message(binary_string.c_str(), binary_string.length()); |
150 } else { | 142 } else { |
151 continue; | 143 continue; |
152 } | 144 } |
153 base::PickleIterator pickle_iter(pickle); | 145 base::PickleIterator pickle_iter(pickle); |
154 SkBitmap bitmap; | 146 SkBitmap bitmap; |
155 if (!IPC::ReadParam(&pickle, &pickle_iter, &bitmap)) | 147 if (!IPC::ReadParam(&pickle, &pickle_iter, &bitmap)) |
156 return false; | 148 return false; |
157 CHECK(!bitmap.isNull()); | 149 CHECK(!bitmap.isNull()); |
150 if (bitmap.width() != bitmap.height()) | |
Devlin
2016/01/26 19:08:48
I wonder if we really *need* this to be a square.
Evan Stade
2016/01/26 19:50:07
Why would we want to let developers do that? Is th
Devlin
2016/01/26 19:58:25
Well, we can scale it to be proportionate and main
Evan Stade
2016/01/26 22:33:50
IMO, better not to save them that step. It adds co
| |
151 continue; | |
158 float scale = | 152 float scale = |
159 static_cast<float>(icon_size) / ExtensionAction::ActionIconSize(); | 153 static_cast<float>(bitmap.width()) / ExtensionAction::ActionIconSize(); |
160 icon->AddRepresentation(gfx::ImageSkiaRep(bitmap, scale)); | 154 icon->AddRepresentation(gfx::ImageSkiaRep(bitmap, scale)); |
161 } | 155 } |
162 return true; | 156 return true; |
163 } | 157 } |
164 | 158 |
165 gfx::Image ExtensionAction::GetExplicitlySetIcon(int tab_id) const { | 159 gfx::Image ExtensionAction::GetExplicitlySetIcon(int tab_id) const { |
166 return GetValue(&icon_, tab_id); | 160 return GetValue(&icon_, tab_id); |
167 } | 161 } |
168 | 162 |
169 bool ExtensionAction::SetIsVisible(int tab_id, bool new_visibility) { | 163 bool ExtensionAction::SetIsVisible(int tab_id, bool new_visibility) { |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
328 // If there is a default icon, the icon width will be set depending on our | 322 // If there is a default icon, the icon width will be set depending on our |
329 // action type. | 323 // action type. |
330 if (default_icon_) | 324 if (default_icon_) |
331 return ActionIconSize(); | 325 return ActionIconSize(); |
332 | 326 |
333 // If no icon has been set and there is no default icon, we need favicon | 327 // If no icon has been set and there is no default icon, we need favicon |
334 // width. | 328 // width. |
335 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 329 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
336 IDR_EXTENSIONS_FAVICON).Width(); | 330 IDR_EXTENSIONS_FAVICON).Width(); |
337 } | 331 } |
OLD | NEW |