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

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

Issue 1580983002: Fix the dynamic browser action setIcon path to work with any size icon. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move size validation Created 4 years, 11 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 if (!base::StringToInt(iter.key(), &icon_size) || icon_size <= 0 ||
134 icon_size > 1024) {
Devlin 2016/01/22 23:41:40 nit: in your other CL, you use GIGANTOR * 4. We s
Evan Stade 2016/01/23 00:03:25 Admittedly, 1024 is somewhat arbitrary. But why ma
134 continue; 135 continue;
136 }
135 137
136 const base::BinaryValue* image_data; 138 const base::BinaryValue* image_data;
137 std::string binary_string64; 139 std::string binary_string64;
138 IPC::Message pickle; 140 IPC::Message pickle;
139 if (iter.value().GetAsBinary(&image_data)) { 141 if (iter.value().GetAsBinary(&image_data)) {
140 pickle = IPC::Message(image_data->GetBuffer(), image_data->GetSize()); 142 pickle = IPC::Message(image_data->GetBuffer(), image_data->GetSize());
141 } else if (iter.value().GetAsString(&binary_string64)) { 143 } else if (iter.value().GetAsString(&binary_string64)) {
142 std::string binary_string; 144 std::string binary_string;
143 if (!base::Base64Decode(binary_string64, &binary_string)) 145 if (!base::Base64Decode(binary_string64, &binary_string))
144 return false; 146 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 326 // If there is a default icon, the icon width will be set depending on our
325 // action type. 327 // action type.
326 if (default_icon_) 328 if (default_icon_)
327 return ActionIconSize(); 329 return ActionIconSize();
328 330
329 // 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
330 // width. 332 // width.
331 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( 333 return ui::ResourceBundle::GetSharedInstance().GetImageNamed(
332 IDR_EXTENSIONS_FAVICON).Width(); 334 IDR_EXTENSIONS_FAVICON).Width();
333 } 335 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698