Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: chrome/browser/extensions/extension_action.cc

Issue 1647903003: Fix the dynamic browser action setIcon path to work with any size icon. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2623
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
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; 132 int icon_size = 0;
133 if (!base::StringToInt(iter.key(), &icon_size)) 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) {
134 continue; 137 continue;
138 }
135 139
136 const base::BinaryValue* image_data; 140 const base::BinaryValue* image_data;
137 std::string binary_string64; 141 std::string binary_string64;
138 IPC::Message pickle; 142 IPC::Message pickle;
139 if (iter.value().GetAsBinary(&image_data)) { 143 if (iter.value().GetAsBinary(&image_data)) {
140 pickle = IPC::Message(image_data->GetBuffer(), image_data->GetSize()); 144 pickle = IPC::Message(image_data->GetBuffer(), image_data->GetSize());
141 } else if (iter.value().GetAsString(&binary_string64)) { 145 } else if (iter.value().GetAsString(&binary_string64)) {
142 std::string binary_string; 146 std::string binary_string;
143 if (!base::Base64Decode(binary_string64, &binary_string)) 147 if (!base::Base64Decode(binary_string64, &binary_string))
144 return false; 148 return false;
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 // If there is a default icon, the icon width will be set depending on our 328 // If there is a default icon, the icon width will be set depending on our
325 // action type. 329 // action type.
326 if (default_icon_) 330 if (default_icon_)
327 return ActionIconSize(); 331 return ActionIconSize();
328 332
329 // If no icon has been set and there is no default icon, we need favicon 333 // If no icon has been set and there is no default icon, we need favicon
330 // width. 334 // width.
331 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( 335 return ui::ResourceBundle::GetSharedInstance().GetImageNamed(
332 IDR_EXTENSIONS_FAVICON).Width(); 336 IDR_EXTENSIONS_FAVICON).Width();
333 } 337 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698