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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 continue; | 143 continue; |
144 } | 144 } |
145 base::PickleIterator pickle_iter(pickle); | 145 base::PickleIterator pickle_iter(pickle); |
146 SkBitmap bitmap; | 146 SkBitmap bitmap; |
147 if (!IPC::ReadParam(&pickle, &pickle_iter, &bitmap)) | 147 if (!IPC::ReadParam(&pickle, &pickle_iter, &bitmap)) |
148 return false; | 148 return false; |
149 CHECK(!bitmap.isNull()); | 149 CHECK(!bitmap.isNull()); |
150 | 150 |
151 // Chrome helpfully scales the provided icon(s), but let's not go overboard. | 151 // Chrome helpfully scales the provided icon(s), but let's not go overboard. |
152 const int kActionIconMaxSize = 10 * extension_misc::EXTENSION_ICON_ACTION; | 152 const int kActionIconMaxSize = 10 * extension_misc::EXTENSION_ICON_ACTION; |
153 if (bitmap.drawsNothing() || bitmap.width() != bitmap.height() || | 153 if (bitmap.drawsNothing() || bitmap.width() > kActionIconMaxSize) |
154 bitmap.width() > kActionIconMaxSize) { | |
155 continue; | 154 continue; |
156 } | |
157 | 155 |
158 float scale = | 156 float scale = |
159 static_cast<float>(bitmap.width()) / ExtensionAction::ActionIconSize(); | 157 static_cast<float>(bitmap.width()) / ExtensionAction::ActionIconSize(); |
160 icon->AddRepresentation(gfx::ImageSkiaRep(bitmap, scale)); | 158 icon->AddRepresentation(gfx::ImageSkiaRep(bitmap, scale)); |
161 } | 159 } |
162 return true; | 160 return true; |
163 } | 161 } |
164 | 162 |
165 gfx::Image ExtensionAction::GetExplicitlySetIcon(int tab_id) const { | 163 gfx::Image ExtensionAction::GetExplicitlySetIcon(int tab_id) const { |
166 return GetValue(&icon_, tab_id); | 164 return GetValue(&icon_, tab_id); |
(...skipping 161 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 | 326 // If there is a default icon, the icon width will be set depending on our |
329 // action type. | 327 // action type. |
330 if (default_icon_) | 328 if (default_icon_) |
331 return ActionIconSize(); | 329 return ActionIconSize(); |
332 | 330 |
333 // If no icon has been set and there is no default icon, we need favicon | 331 // If no icon has been set and there is no default icon, we need favicon |
334 // width. | 332 // width. |
335 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 333 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
336 IDR_EXTENSIONS_FAVICON).Width(); | 334 IDR_EXTENSIONS_FAVICON).Width(); |
337 } | 335 } |
OLD | NEW |