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

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

Issue 93793010: Update uses of UTF conversions in chrome/common to use the base:: namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 12 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 | Annotate | Revision Log
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 "chrome/common/extensions/extension_constants.h" 10 #include "chrome/common/extensions/extension_constants.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 // kPageActionIcons is obsolete, and used by very few extensions. Continue 62 // kPageActionIcons is obsolete, and used by very few extensions. Continue
63 // loading it, but only take the first icon as the default_icon path. 63 // loading it, but only take the first icon as the default_icon path.
64 const base::ListValue* icons = NULL; 64 const base::ListValue* icons = NULL;
65 if (dict->HasKey(keys::kPageActionIcons) && 65 if (dict->HasKey(keys::kPageActionIcons) &&
66 dict->GetList(keys::kPageActionIcons, &icons)) { 66 dict->GetList(keys::kPageActionIcons, &icons)) {
67 base::ListValue::const_iterator iter = icons->begin(); 67 base::ListValue::const_iterator iter = icons->begin();
68 std::string path; 68 std::string path;
69 if (iter == icons->end() || 69 if (iter == icons->end() ||
70 !(*iter)->GetAsString(&path) || 70 !(*iter)->GetAsString(&path) ||
71 !manifest_handler_helpers::NormalizeAndValidatePath(&path)) { 71 !manifest_handler_helpers::NormalizeAndValidatePath(&path)) {
72 *error = ASCIIToUTF16(errors::kInvalidPageActionIconPath); 72 *error = base::ASCIIToUTF16(errors::kInvalidPageActionIconPath);
73 return scoped_ptr<ActionInfo>(); 73 return scoped_ptr<ActionInfo>();
74 } 74 }
75 result->default_icon.Add(extension_misc::EXTENSION_ICON_ACTION, path); 75 result->default_icon.Add(extension_misc::EXTENSION_ICON_ACTION, path);
76 } 76 }
77 77
78 std::string id; 78 std::string id;
79 if (dict->HasKey(keys::kPageActionId)) { 79 if (dict->HasKey(keys::kPageActionId)) {
80 if (!dict->GetString(keys::kPageActionId, &id)) { 80 if (!dict->GetString(keys::kPageActionId, &id)) {
81 *error = ASCIIToUTF16(errors::kInvalidPageActionId); 81 *error = base::ASCIIToUTF16(errors::kInvalidPageActionId);
82 return scoped_ptr<ActionInfo>(); 82 return scoped_ptr<ActionInfo>();
83 } 83 }
84 result->id = id; 84 result->id = id;
85 } 85 }
86 } 86 }
87 87
88 // Read the page action |default_icon| (optional). 88 // Read the page action |default_icon| (optional).
89 // The |default_icon| value can be either dictionary {icon size -> icon path} 89 // The |default_icon| value can be either dictionary {icon size -> icon path}
90 // or non empty string value. 90 // or non empty string value.
91 if (dict->HasKey(keys::kPageActionDefaultIcon)) { 91 if (dict->HasKey(keys::kPageActionDefaultIcon)) {
92 const base::DictionaryValue* icons_value = NULL; 92 const base::DictionaryValue* icons_value = NULL;
93 std::string default_icon; 93 std::string default_icon;
94 if (dict->GetDictionary(keys::kPageActionDefaultIcon, &icons_value)) { 94 if (dict->GetDictionary(keys::kPageActionDefaultIcon, &icons_value)) {
95 if (!manifest_handler_helpers::LoadIconsFromDictionary( 95 if (!manifest_handler_helpers::LoadIconsFromDictionary(
96 icons_value, 96 icons_value,
97 extension_misc::kExtensionActionIconSizes, 97 extension_misc::kExtensionActionIconSizes,
98 extension_misc::kNumExtensionActionIconSizes, 98 extension_misc::kNumExtensionActionIconSizes,
99 &result->default_icon, 99 &result->default_icon,
100 error)) { 100 error)) {
101 return scoped_ptr<ActionInfo>(); 101 return scoped_ptr<ActionInfo>();
102 } 102 }
103 } else if (dict->GetString(keys::kPageActionDefaultIcon, &default_icon) && 103 } else if (dict->GetString(keys::kPageActionDefaultIcon, &default_icon) &&
104 manifest_handler_helpers::NormalizeAndValidatePath( 104 manifest_handler_helpers::NormalizeAndValidatePath(
105 &default_icon)) { 105 &default_icon)) {
106 result->default_icon.Add(extension_misc::EXTENSION_ICON_ACTION, 106 result->default_icon.Add(extension_misc::EXTENSION_ICON_ACTION,
107 default_icon); 107 default_icon);
108 } else { 108 } else {
109 *error = ASCIIToUTF16(errors::kInvalidPageActionIconPath); 109 *error = base::ASCIIToUTF16(errors::kInvalidPageActionIconPath);
110 return scoped_ptr<ActionInfo>(); 110 return scoped_ptr<ActionInfo>();
111 } 111 }
112 } 112 }
113 113
114 // Read the page action title from |default_title| if present, |name| if not 114 // Read the page action title from |default_title| if present, |name| if not
115 // (both optional). 115 // (both optional).
116 if (dict->HasKey(keys::kPageActionDefaultTitle)) { 116 if (dict->HasKey(keys::kPageActionDefaultTitle)) {
117 if (!dict->GetString(keys::kPageActionDefaultTitle, 117 if (!dict->GetString(keys::kPageActionDefaultTitle,
118 &result->default_title)) { 118 &result->default_title)) {
119 *error = ASCIIToUTF16(errors::kInvalidPageActionDefaultTitle); 119 *error = base::ASCIIToUTF16(errors::kInvalidPageActionDefaultTitle);
120 return scoped_ptr<ActionInfo>(); 120 return scoped_ptr<ActionInfo>();
121 } 121 }
122 } else if (extension->manifest_version() == 1 && dict->HasKey(keys::kName)) { 122 } else if (extension->manifest_version() == 1 && dict->HasKey(keys::kName)) {
123 if (!dict->GetString(keys::kName, &result->default_title)) { 123 if (!dict->GetString(keys::kName, &result->default_title)) {
124 *error = ASCIIToUTF16(errors::kInvalidPageActionName); 124 *error = base::ASCIIToUTF16(errors::kInvalidPageActionName);
125 return scoped_ptr<ActionInfo>(); 125 return scoped_ptr<ActionInfo>();
126 } 126 }
127 } 127 }
128 128
129 // Read the action's |popup| (optional). 129 // Read the action's |popup| (optional).
130 const char* popup_key = NULL; 130 const char* popup_key = NULL;
131 if (dict->HasKey(keys::kPageActionDefaultPopup)) 131 if (dict->HasKey(keys::kPageActionDefaultPopup))
132 popup_key = keys::kPageActionDefaultPopup; 132 popup_key = keys::kPageActionDefaultPopup;
133 133
134 if (extension->manifest_version() == 1 && 134 if (extension->manifest_version() == 1 &&
(...skipping 15 matching lines...) Expand all
150 if (dict->GetString(popup_key, &url_str)) { 150 if (dict->GetString(popup_key, &url_str)) {
151 // On success, |url_str| is set. Nothing else to do. 151 // On success, |url_str| is set. Nothing else to do.
152 } else if (extension->manifest_version() == 1 && 152 } else if (extension->manifest_version() == 1 &&
153 dict->GetDictionary(popup_key, &popup)) { 153 dict->GetDictionary(popup_key, &popup)) {
154 if (!popup->GetString(keys::kPageActionPopupPath, &url_str)) { 154 if (!popup->GetString(keys::kPageActionPopupPath, &url_str)) {
155 *error = ErrorUtils::FormatErrorMessageUTF16( 155 *error = ErrorUtils::FormatErrorMessageUTF16(
156 errors::kInvalidPageActionPopupPath, "<missing>"); 156 errors::kInvalidPageActionPopupPath, "<missing>");
157 return scoped_ptr<ActionInfo>(); 157 return scoped_ptr<ActionInfo>();
158 } 158 }
159 } else { 159 } else {
160 *error = ASCIIToUTF16(errors::kInvalidPageActionPopup); 160 *error = base::ASCIIToUTF16(errors::kInvalidPageActionPopup);
161 return scoped_ptr<ActionInfo>(); 161 return scoped_ptr<ActionInfo>();
162 } 162 }
163 163
164 if (!url_str.empty()) { 164 if (!url_str.empty()) {
165 // An empty string is treated as having no popup. 165 // An empty string is treated as having no popup.
166 result->default_popup_url = Extension::GetResourceURL(extension->url(), 166 result->default_popup_url = Extension::GetResourceURL(extension->url(),
167 url_str); 167 url_str);
168 if (!result->default_popup_url.is_valid()) { 168 if (!result->default_popup_url.is_valid()) {
169 *error = ErrorUtils::FormatErrorMessageUTF16( 169 *error = ErrorUtils::FormatErrorMessageUTF16(
170 errors::kInvalidPageActionPopupPath, url_str); 170 errors::kInvalidPageActionPopupPath, url_str);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 225
226 // static 226 // static
227 bool ActionInfo::IsVerboseInstallMessage(const Extension* extension) { 227 bool ActionInfo::IsVerboseInstallMessage(const Extension* extension) {
228 const ActionInfo* page_action_info = GetPageActionInfo(extension); 228 const ActionInfo* page_action_info = GetPageActionInfo(extension);
229 return page_action_info && 229 return page_action_info &&
230 (CommandsInfo::GetPageActionCommand(extension) || 230 (CommandsInfo::GetPageActionCommand(extension) ||
231 !page_action_info->default_icon.empty()); 231 !page_action_info->default_icon.empty());
232 } 232 }
233 233
234 } // namespace extensions 234 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698