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

Side by Side Diff: chrome/common/extensions/api/extension_action/action_info.cc

Issue 1492073003: Handle more scale factors for extension Browser Action icons (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: test catches real bug! Created 5 years 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/common/extensions/api/extension_action/action_info.h" 5 #include "chrome/common/extensions/api/extension_action/action_info.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/common/extensions/api/commands/commands_handler.h" 9 #include "chrome/common/extensions/api/commands/commands_handler.h"
10 #include "extensions/common/constants.h" 10 #include "extensions/common/constants.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 } 84 }
85 } 85 }
86 86
87 // Read the page action |default_icon| (optional). 87 // Read the page action |default_icon| (optional).
88 // The |default_icon| value can be either dictionary {icon size -> icon path} 88 // The |default_icon| value can be either dictionary {icon size -> icon path}
89 // or non empty string value. 89 // or non empty string value.
90 if (dict->HasKey(keys::kPageActionDefaultIcon)) { 90 if (dict->HasKey(keys::kPageActionDefaultIcon)) {
91 const base::DictionaryValue* icons_value = NULL; 91 const base::DictionaryValue* icons_value = NULL;
92 std::string default_icon; 92 std::string default_icon;
93 if (dict->GetDictionary(keys::kPageActionDefaultIcon, &icons_value)) { 93 if (dict->GetDictionary(keys::kPageActionDefaultIcon, &icons_value)) {
94 int icon_sizes[extension_misc::kNumExtensionActionIconSizes]; 94 if (!manifest_handler_helpers::LoadAllIconsFromDictionary(
95 for (size_t i = 0u; i < extension_misc::kNumExtensionActionIconSizes; ++i) 95 icons_value, &result->default_icon, error)) {
96 icon_sizes[i] = extension_misc::kExtensionActionIconSizes[i].size;
97 if (!manifest_handler_helpers::LoadIconsFromDictionary(
98 icons_value,
99 icon_sizes,
100 extension_misc::kNumExtensionActionIconSizes,
101 &result->default_icon,
102 error)) {
103 return scoped_ptr<ActionInfo>(); 96 return scoped_ptr<ActionInfo>();
104 } 97 }
105 } else if (dict->GetString(keys::kPageActionDefaultIcon, &default_icon) && 98 } else if (dict->GetString(keys::kPageActionDefaultIcon, &default_icon) &&
106 manifest_handler_helpers::NormalizeAndValidatePath( 99 manifest_handler_helpers::NormalizeAndValidatePath(
107 &default_icon)) { 100 &default_icon)) {
108 // Choose the most optimistic (highest) icon density - e.g. 38 not 19 - 101 // Choose the most optimistic (highest) icon density regardless of the
109 // regardless of the actual icon resolution, whatever that happens to be. 102 // actual icon resolution, whatever that happens to be. Code elsewhere
110 // Code elsewhere knows how to scale 38 down to 19. 103 // knows how to scale down to 19.
111 result->default_icon.Add(extension_misc::EXTENSION_ICON_ACTION * 104 result->default_icon.Add(extension_misc::EXTENSION_ICON_GIGANTOR,
112 extension_misc::kNumExtensionActionIconSizes,
113 default_icon); 105 default_icon);
114 } else { 106 } else {
115 *error = base::ASCIIToUTF16(errors::kInvalidPageActionIconPath); 107 *error = base::ASCIIToUTF16(errors::kInvalidPageActionIconPath);
116 return scoped_ptr<ActionInfo>(); 108 return scoped_ptr<ActionInfo>();
117 } 109 }
118 } 110 }
119 111
120 // Read the page action title from |default_title| if present, |name| if not 112 // Read the page action title from |default_title| if present, |name| if not
121 // (both optional). 113 // (both optional).
122 if (dict->HasKey(keys::kPageActionDefaultTitle)) { 114 if (dict->HasKey(keys::kPageActionDefaultTitle)) {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 212
221 // static 213 // static
222 bool ActionInfo::IsVerboseInstallMessage(const Extension* extension) { 214 bool ActionInfo::IsVerboseInstallMessage(const Extension* extension) {
223 const ActionInfo* page_action_info = GetPageActionInfo(extension); 215 const ActionInfo* page_action_info = GetPageActionInfo(extension);
224 return page_action_info && 216 return page_action_info &&
225 (CommandsInfo::GetPageActionCommand(extension) || 217 (CommandsInfo::GetPageActionCommand(extension) ||
226 !page_action_info->default_icon.empty()); 218 !page_action_info->default_icon.empty());
227 } 219 }
228 220
229 } // namespace extensions 221 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698