OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "chrome/common/extensions/background_info.h" | 5 #include "chrome/common/extensions/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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 } | 257 } |
258 | 258 |
259 bool BackgroundManifestHandler::Validate( | 259 bool BackgroundManifestHandler::Validate( |
260 const Extension* extension, | 260 const Extension* extension, |
261 std::string* error, | 261 std::string* error, |
262 std::vector<InstallWarning>* warnings) const { | 262 std::vector<InstallWarning>* warnings) const { |
263 // Validate that background scripts exist. | 263 // Validate that background scripts exist. |
264 const std::vector<std::string>& background_scripts = | 264 const std::vector<std::string>& background_scripts = |
265 extensions::BackgroundInfo::GetBackgroundScripts(extension); | 265 extensions::BackgroundInfo::GetBackgroundScripts(extension); |
266 for (size_t i = 0; i < background_scripts.size(); ++i) { | 266 for (size_t i = 0; i < background_scripts.size(); ++i) { |
267 if (!file_util::PathExists( | 267 if (!base::PathExists( |
268 extension->GetResource(background_scripts[i]).GetFilePath())) { | 268 extension->GetResource(background_scripts[i]).GetFilePath())) { |
269 *error = l10n_util::GetStringFUTF8( | 269 *error = l10n_util::GetStringFUTF8( |
270 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, | 270 IDS_EXTENSION_LOAD_BACKGROUND_SCRIPT_FAILED, |
271 UTF8ToUTF16(background_scripts[i])); | 271 UTF8ToUTF16(background_scripts[i])); |
272 return false; | 272 return false; |
273 } | 273 } |
274 } | 274 } |
275 | 275 |
276 // Validate background page location, except for hosted apps, which should use | 276 // Validate background page location, except for hosted apps, which should use |
277 // an external URL. Background page for hosted apps are verified when the | 277 // an external URL. Background page for hosted apps are verified when the |
278 // extension is created (in Extension::InitFromValue) | 278 // extension is created (in Extension::InitFromValue) |
279 if (extensions::BackgroundInfo::HasBackgroundPage(extension) && | 279 if (extensions::BackgroundInfo::HasBackgroundPage(extension) && |
280 !extension->is_hosted_app() && background_scripts.empty()) { | 280 !extension->is_hosted_app() && background_scripts.empty()) { |
281 base::FilePath page_path = | 281 base::FilePath page_path = |
282 extension_file_util::ExtensionURLToRelativeFilePath( | 282 extension_file_util::ExtensionURLToRelativeFilePath( |
283 extensions::BackgroundInfo::GetBackgroundURL(extension)); | 283 extensions::BackgroundInfo::GetBackgroundURL(extension)); |
284 const base::FilePath path = extension->GetResource(page_path).GetFilePath(); | 284 const base::FilePath path = extension->GetResource(page_path).GetFilePath(); |
285 if (path.empty() || !file_util::PathExists(path)) { | 285 if (path.empty() || !base::PathExists(path)) { |
286 *error = | 286 *error = |
287 l10n_util::GetStringFUTF8( | 287 l10n_util::GetStringFUTF8( |
288 IDS_EXTENSION_LOAD_BACKGROUND_PAGE_FAILED, | 288 IDS_EXTENSION_LOAD_BACKGROUND_PAGE_FAILED, |
289 page_path.LossyDisplayName()); | 289 page_path.LossyDisplayName()); |
290 return false; | 290 return false; |
291 } | 291 } |
292 } | 292 } |
293 return true; | 293 return true; |
294 } | 294 } |
295 | 295 |
296 bool BackgroundManifestHandler::AlwaysParseForType(Manifest::Type type) const { | 296 bool BackgroundManifestHandler::AlwaysParseForType(Manifest::Type type) const { |
297 return type == Manifest::TYPE_PLATFORM_APP; | 297 return type == Manifest::TYPE_PLATFORM_APP; |
298 } | 298 } |
299 | 299 |
300 const std::vector<std::string> BackgroundManifestHandler::Keys() const { | 300 const std::vector<std::string> BackgroundManifestHandler::Keys() const { |
301 static const char* keys[] = { | 301 static const char* keys[] = { |
302 keys::kBackgroundAllowJsAccess, | 302 keys::kBackgroundAllowJsAccess, |
303 keys::kBackgroundPage, | 303 keys::kBackgroundPage, |
304 keys::kBackgroundPageLegacy, | 304 keys::kBackgroundPageLegacy, |
305 keys::kBackgroundPersistent, | 305 keys::kBackgroundPersistent, |
306 keys::kBackgroundScripts, | 306 keys::kBackgroundScripts, |
307 keys::kPlatformAppBackgroundPage, | 307 keys::kPlatformAppBackgroundPage, |
308 keys::kPlatformAppBackgroundScripts | 308 keys::kPlatformAppBackgroundScripts |
309 }; | 309 }; |
310 return std::vector<std::string>(keys, keys + arraysize(keys)); | 310 return std::vector<std::string>(keys, keys + arraysize(keys)); |
311 } | 311 } |
312 | 312 |
313 } // namespace extensions | 313 } // namespace extensions |
OLD | NEW |