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/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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 } // namespace | 46 } // namespace |
47 | 47 |
48 ActionInfo::ActionInfo() { | 48 ActionInfo::ActionInfo() { |
49 } | 49 } |
50 | 50 |
51 ActionInfo::~ActionInfo() { | 51 ActionInfo::~ActionInfo() { |
52 } | 52 } |
53 | 53 |
54 // static | 54 // static |
55 scoped_ptr<ActionInfo> ActionInfo::Load(const Extension* extension, | 55 scoped_ptr<ActionInfo> ActionInfo::Load(Extension* extension, |
56 const base::DictionaryValue* dict, | 56 const base::DictionaryValue* dict, |
57 base::string16* error) { | 57 base::string16* error) { |
58 scoped_ptr<ActionInfo> result(new ActionInfo()); | 58 scoped_ptr<ActionInfo> result(new ActionInfo()); |
59 | 59 |
60 if (extension->manifest_version() == 1) { | 60 if (extension->manifest_version() == 1) { |
61 // kPageActionIcons is obsolete, and used by very few extensions. Continue | 61 // kPageActionIcons is obsolete, and used by very few extensions. Continue |
62 // loading it, but only take the first icon as the default_icon path. | 62 // loading it, but only take the first icon as the default_icon path. |
63 const base::ListValue* icons = NULL; | 63 const base::ListValue* icons = NULL; |
64 if (dict->HasKey(keys::kPageActionIcons) && | 64 if (dict->HasKey(keys::kPageActionIcons) && |
65 dict->GetList(keys::kPageActionIcons, &icons)) { | 65 dict->GetList(keys::kPageActionIcons, &icons)) { |
(...skipping 19 matching lines...) Expand all Loading... |
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 if (!manifest_handler_helpers::LoadIconsFromDictionary( | 94 if (!manifest_handler_helpers::LoadIconsFromDictionary( |
95 icons_value, &result->default_icon, error)) { | 95 extension, icons_value, &result->default_icon, error)) { |
96 return scoped_ptr<ActionInfo>(); | 96 return scoped_ptr<ActionInfo>(); |
97 } | 97 } |
98 } else if (dict->GetString(keys::kPageActionDefaultIcon, &default_icon) && | 98 } else if (dict->GetString(keys::kPageActionDefaultIcon, &default_icon) && |
99 manifest_handler_helpers::NormalizeAndValidatePath( | 99 manifest_handler_helpers::NormalizeAndValidatePath( |
100 &default_icon)) { | 100 &default_icon)) { |
101 // Choose the most optimistic (highest) icon density regardless of the | 101 // Choose the most optimistic (highest) icon density regardless of the |
102 // actual icon resolution, whatever that happens to be. Code elsewhere | 102 // actual icon resolution, whatever that happens to be. Code elsewhere |
103 // knows how to scale down to 19. | 103 // knows how to scale down to 19. |
104 result->default_icon.Add(extension_misc::EXTENSION_ICON_GIGANTOR, | 104 result->default_icon.Add(extension_misc::EXTENSION_ICON_GIGANTOR, |
105 default_icon); | 105 default_icon); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 | 212 |
213 // static | 213 // static |
214 bool ActionInfo::IsVerboseInstallMessage(const Extension* extension) { | 214 bool ActionInfo::IsVerboseInstallMessage(const Extension* extension) { |
215 const ActionInfo* page_action_info = GetPageActionInfo(extension); | 215 const ActionInfo* page_action_info = GetPageActionInfo(extension); |
216 return page_action_info && | 216 return page_action_info && |
217 (CommandsInfo::GetPageActionCommand(extension) || | 217 (CommandsInfo::GetPageActionCommand(extension) || |
218 !page_action_info->default_icon.empty()); | 218 !page_action_info->default_icon.empty()); |
219 } | 219 } |
220 | 220 |
221 } // namespace extensions | 221 } // namespace extensions |
OLD | NEW |