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

Side by Side Diff: extensions/common/manifest_handlers/background_info.cc

Issue 107803004: Add base:: to string16 in extensions/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove a using Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "extensions/common/manifest_handlers/background_info.h" 5 #include "extensions/common/manifest_handlers/background_info.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 // static 86 // static
87 bool BackgroundInfo::HasPersistentBackgroundPage(const Extension* extension) { 87 bool BackgroundInfo::HasPersistentBackgroundPage(const Extension* extension) {
88 return GetBackgroundInfo(extension).has_persistent_background_page(); 88 return GetBackgroundInfo(extension).has_persistent_background_page();
89 } 89 }
90 90
91 // static 91 // static
92 bool BackgroundInfo::HasLazyBackgroundPage(const Extension* extension) { 92 bool BackgroundInfo::HasLazyBackgroundPage(const Extension* extension) {
93 return GetBackgroundInfo(extension).has_lazy_background_page(); 93 return GetBackgroundInfo(extension).has_lazy_background_page();
94 } 94 }
95 95
96 bool BackgroundInfo::Parse(const Extension* extension, string16* error) { 96 bool BackgroundInfo::Parse(const Extension* extension, base::string16* error) {
97 const std::string& bg_scripts_key = extension->is_platform_app() ? 97 const std::string& bg_scripts_key = extension->is_platform_app() ?
98 keys::kPlatformAppBackgroundScripts : keys::kBackgroundScripts; 98 keys::kPlatformAppBackgroundScripts : keys::kBackgroundScripts;
99 if (!LoadBackgroundScripts(extension, bg_scripts_key, error) || 99 if (!LoadBackgroundScripts(extension, bg_scripts_key, error) ||
100 !LoadBackgroundPage(extension, error) || 100 !LoadBackgroundPage(extension, error) ||
101 !LoadBackgroundPersistent(extension, error) || 101 !LoadBackgroundPersistent(extension, error) ||
102 !LoadAllowJSAccess(extension, error)) { 102 !LoadAllowJSAccess(extension, error)) {
103 return false; 103 return false;
104 } 104 }
105 return true; 105 return true;
106 } 106 }
107 107
108 bool BackgroundInfo::LoadBackgroundScripts(const Extension* extension, 108 bool BackgroundInfo::LoadBackgroundScripts(const Extension* extension,
109 const std::string& key, 109 const std::string& key,
110 string16* error) { 110 base::string16* error) {
111 const base::Value* background_scripts_value = NULL; 111 const base::Value* background_scripts_value = NULL;
112 if (!extension->manifest()->Get(key, &background_scripts_value)) 112 if (!extension->manifest()->Get(key, &background_scripts_value))
113 return true; 113 return true;
114 114
115 CHECK(background_scripts_value); 115 CHECK(background_scripts_value);
116 if (background_scripts_value->GetType() != base::Value::TYPE_LIST) { 116 if (background_scripts_value->GetType() != base::Value::TYPE_LIST) {
117 *error = ASCIIToUTF16(errors::kInvalidBackgroundScripts); 117 *error = ASCIIToUTF16(errors::kInvalidBackgroundScripts);
118 return false; 118 return false;
119 } 119 }
120 120
121 const base::ListValue* background_scripts = NULL; 121 const base::ListValue* background_scripts = NULL;
122 background_scripts_value->GetAsList(&background_scripts); 122 background_scripts_value->GetAsList(&background_scripts);
123 for (size_t i = 0; i < background_scripts->GetSize(); ++i) { 123 for (size_t i = 0; i < background_scripts->GetSize(); ++i) {
124 std::string script; 124 std::string script;
125 if (!background_scripts->GetString(i, &script)) { 125 if (!background_scripts->GetString(i, &script)) {
126 *error = ErrorUtils::FormatErrorMessageUTF16( 126 *error = ErrorUtils::FormatErrorMessageUTF16(
127 errors::kInvalidBackgroundScript, base::IntToString(i)); 127 errors::kInvalidBackgroundScript, base::IntToString(i));
128 return false; 128 return false;
129 } 129 }
130 background_scripts_.push_back(script); 130 background_scripts_.push_back(script);
131 } 131 }
132 132
133 return true; 133 return true;
134 } 134 }
135 135
136 bool BackgroundInfo::LoadBackgroundPage(const Extension* extension, 136 bool BackgroundInfo::LoadBackgroundPage(const Extension* extension,
137 const std::string& key, 137 const std::string& key,
138 string16* error) { 138 base::string16* error) {
139 const base::Value* background_page_value = NULL; 139 const base::Value* background_page_value = NULL;
140 if (!extension->manifest()->Get(key, &background_page_value)) 140 if (!extension->manifest()->Get(key, &background_page_value))
141 return true; 141 return true;
142 142
143 if (!background_scripts_.empty()) { 143 if (!background_scripts_.empty()) {
144 *error = ASCIIToUTF16(errors::kInvalidBackgroundCombination); 144 *error = ASCIIToUTF16(errors::kInvalidBackgroundCombination);
145 return false; 145 return false;
146 } 146 }
147 147
148 std::string background_str; 148 std::string background_str;
(...skipping 24 matching lines...) Expand all
173 return false; 173 return false;
174 } 174 }
175 } else { 175 } else {
176 background_url_ = extension->GetResourceURL(background_str); 176 background_url_ = extension->GetResourceURL(background_str);
177 } 177 }
178 178
179 return true; 179 return true;
180 } 180 }
181 181
182 bool BackgroundInfo::LoadBackgroundPage(const Extension* extension, 182 bool BackgroundInfo::LoadBackgroundPage(const Extension* extension,
183 string16* error) { 183 base::string16* error) {
184 if (extension->is_platform_app()) { 184 if (extension->is_platform_app()) {
185 return LoadBackgroundPage( 185 return LoadBackgroundPage(
186 extension, keys::kPlatformAppBackgroundPage, error); 186 extension, keys::kPlatformAppBackgroundPage, error);
187 } 187 }
188 188
189 if (!LoadBackgroundPage(extension, keys::kBackgroundPage, error)) 189 if (!LoadBackgroundPage(extension, keys::kBackgroundPage, error))
190 return false; 190 return false;
191 if (background_url_.is_empty()) 191 if (background_url_.is_empty())
192 return LoadBackgroundPage(extension, keys::kBackgroundPageLegacy, error); 192 return LoadBackgroundPage(extension, keys::kBackgroundPageLegacy, error);
193 return true; 193 return true;
194 } 194 }
195 195
196 bool BackgroundInfo::LoadBackgroundPersistent(const Extension* extension, 196 bool BackgroundInfo::LoadBackgroundPersistent(const Extension* extension,
197 string16* error) { 197 base::string16* error) {
198 if (extension->is_platform_app()) { 198 if (extension->is_platform_app()) {
199 is_persistent_ = false; 199 is_persistent_ = false;
200 return true; 200 return true;
201 } 201 }
202 202
203 const base::Value* background_persistent = NULL; 203 const base::Value* background_persistent = NULL;
204 if (!extension->manifest()->Get(keys::kBackgroundPersistent, 204 if (!extension->manifest()->Get(keys::kBackgroundPersistent,
205 &background_persistent)) 205 &background_persistent))
206 return true; 206 return true;
207 207
208 if (!background_persistent->GetAsBoolean(&is_persistent_)) { 208 if (!background_persistent->GetAsBoolean(&is_persistent_)) {
209 *error = ASCIIToUTF16(errors::kInvalidBackgroundPersistent); 209 *error = ASCIIToUTF16(errors::kInvalidBackgroundPersistent);
210 return false; 210 return false;
211 } 211 }
212 212
213 if (!has_background_page()) { 213 if (!has_background_page()) {
214 *error = ASCIIToUTF16(errors::kInvalidBackgroundPersistentNoPage); 214 *error = ASCIIToUTF16(errors::kInvalidBackgroundPersistentNoPage);
215 return false; 215 return false;
216 } 216 }
217 217
218 return true; 218 return true;
219 } 219 }
220 220
221 bool BackgroundInfo::LoadAllowJSAccess(const Extension* extension, 221 bool BackgroundInfo::LoadAllowJSAccess(const Extension* extension,
222 string16* error) { 222 base::string16* error) {
223 const base::Value* allow_js_access = NULL; 223 const base::Value* allow_js_access = NULL;
224 if (!extension->manifest()->Get(keys::kBackgroundAllowJsAccess, 224 if (!extension->manifest()->Get(keys::kBackgroundAllowJsAccess,
225 &allow_js_access)) 225 &allow_js_access))
226 return true; 226 return true;
227 227
228 if (!allow_js_access->IsType(base::Value::TYPE_BOOLEAN) || 228 if (!allow_js_access->IsType(base::Value::TYPE_BOOLEAN) ||
229 !allow_js_access->GetAsBoolean(&allow_js_access_)) { 229 !allow_js_access->GetAsBoolean(&allow_js_access_)) {
230 *error = ASCIIToUTF16(errors::kInvalidBackgroundAllowJsAccess); 230 *error = ASCIIToUTF16(errors::kInvalidBackgroundAllowJsAccess);
231 return false; 231 return false;
232 } 232 }
233 233
234 return true; 234 return true;
235 } 235 }
236 236
237 BackgroundManifestHandler::BackgroundManifestHandler() { 237 BackgroundManifestHandler::BackgroundManifestHandler() {
238 } 238 }
239 239
240 BackgroundManifestHandler::~BackgroundManifestHandler() { 240 BackgroundManifestHandler::~BackgroundManifestHandler() {
241 } 241 }
242 242
243 bool BackgroundManifestHandler::Parse(Extension* extension, string16* error) { 243 bool BackgroundManifestHandler::Parse(Extension* extension,
244 base::string16* error) {
244 scoped_ptr<BackgroundInfo> info(new BackgroundInfo); 245 scoped_ptr<BackgroundInfo> info(new BackgroundInfo);
245 if (!info->Parse(extension, error)) 246 if (!info->Parse(extension, error))
246 return false; 247 return false;
247 248
248 // Platform apps must have background pages. 249 // Platform apps must have background pages.
249 if (extension->is_platform_app() && !info->has_background_page()) { 250 if (extension->is_platform_app() && !info->has_background_page()) {
250 *error = ASCIIToUTF16(errors::kBackgroundRequiredForPlatformApps); 251 *error = ASCIIToUTF16(errors::kBackgroundRequiredForPlatformApps);
251 return false; 252 return false;
252 } 253 }
253 // Lazy background pages are incompatible with the webRequest API. 254 // Lazy background pages are incompatible with the webRequest API.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 keys::kBackgroundPageLegacy, 310 keys::kBackgroundPageLegacy,
310 keys::kBackgroundPersistent, 311 keys::kBackgroundPersistent,
311 keys::kBackgroundScripts, 312 keys::kBackgroundScripts,
312 keys::kPlatformAppBackgroundPage, 313 keys::kPlatformAppBackgroundPage,
313 keys::kPlatformAppBackgroundScripts 314 keys::kPlatformAppBackgroundScripts
314 }; 315 };
315 return std::vector<std::string>(keys, keys + arraysize(keys)); 316 return std::vector<std::string>(keys, keys + arraysize(keys));
316 } 317 }
317 318
318 } // namespace extensions 319 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/manifest_handlers/background_info.h ('k') | extensions/common/manifest_handlers/csp_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698