| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 return GetBackgroundInfo(extension).has_background_page(); | 72 return GetBackgroundInfo(extension).has_background_page(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 // static | 75 // static |
| 76 bool BackgroundInfo::AllowJSAccess(const Extension* extension) { | 76 bool BackgroundInfo::AllowJSAccess(const Extension* extension) { |
| 77 return GetBackgroundInfo(extension).allow_js_access_; | 77 return GetBackgroundInfo(extension).allow_js_access_; |
| 78 } | 78 } |
| 79 | 79 |
| 80 // static | 80 // static |
| 81 bool BackgroundInfo::HasPersistentBackgroundPage(const Extension* extension) { | 81 bool BackgroundInfo::HasPersistentBackgroundPage(const Extension* extension) { |
| 82 const BackgroundInfo& info = GetBackgroundInfo(extension); | 82 return GetBackgroundInfo(extension).has_persistent_background_page(); |
| 83 return info.has_background_page() && info.is_persistent_; | |
| 84 } | 83 } |
| 85 | 84 |
| 86 // static | 85 // static |
| 87 bool BackgroundInfo::HasLazyBackgroundPage(const Extension* extension) { | 86 bool BackgroundInfo::HasLazyBackgroundPage(const Extension* extension) { |
| 88 const BackgroundInfo& info = GetBackgroundInfo(extension); | 87 return GetBackgroundInfo(extension).has_lazy_background_page(); |
| 89 return info.has_background_page() && !info.is_persistent_; | |
| 90 } | 88 } |
| 91 | 89 |
| 92 bool BackgroundInfo::Parse(const Extension* extension, string16* error) { | 90 bool BackgroundInfo::Parse(const Extension* extension, string16* error) { |
| 93 const std::string& bg_scripts_key = extension->is_platform_app() ? | 91 const std::string& bg_scripts_key = extension->is_platform_app() ? |
| 94 keys::kPlatformAppBackgroundScripts : keys::kBackgroundScripts; | 92 keys::kPlatformAppBackgroundScripts : keys::kBackgroundScripts; |
| 95 if (!LoadBackgroundScripts(extension, bg_scripts_key, error) || | 93 if (!LoadBackgroundScripts(extension, bg_scripts_key, error) || |
| 96 !LoadBackgroundPage(extension, error) || | 94 !LoadBackgroundPage(extension, error) || |
| 97 !LoadBackgroundPersistent(extension, error) || | 95 !LoadBackgroundPersistent(extension, error) || |
| 98 !LoadAllowJSAccess(extension, error)) { | 96 !LoadAllowJSAccess(extension, error)) { |
| 99 return false; | 97 return false; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 BackgroundManifestHandler::BackgroundManifestHandler() { | 231 BackgroundManifestHandler::BackgroundManifestHandler() { |
| 234 } | 232 } |
| 235 | 233 |
| 236 BackgroundManifestHandler::~BackgroundManifestHandler() { | 234 BackgroundManifestHandler::~BackgroundManifestHandler() { |
| 237 } | 235 } |
| 238 | 236 |
| 239 bool BackgroundManifestHandler::Parse(Extension* extension, string16* error) { | 237 bool BackgroundManifestHandler::Parse(Extension* extension, string16* error) { |
| 240 scoped_ptr<BackgroundInfo> info(new BackgroundInfo); | 238 scoped_ptr<BackgroundInfo> info(new BackgroundInfo); |
| 241 if (!info->Parse(extension, error)) | 239 if (!info->Parse(extension, error)) |
| 242 return false; | 240 return false; |
| 241 |
| 242 // Platform apps must have background pages. |
| 243 if (extension->is_platform_app() && !info->has_background_page()) { |
| 244 *error = ASCIIToUTF16(errors::kBackgroundRequiredForPlatformApps); |
| 245 return false; |
| 246 } |
| 247 // Lazy background pages are incompatible with the webRequest API. |
| 248 if (info->has_lazy_background_page() && |
| 249 PermissionsData::GetInitialAPIPermissions(extension)->count( |
| 250 APIPermission::kWebRequest)) { |
| 251 *error = ASCIIToUTF16(errors::kWebRequestConflictsWithLazyBackground); |
| 252 return false; |
| 253 } |
| 254 |
| 243 extension->SetManifestData(kBackground, info.release()); | 255 extension->SetManifestData(kBackground, info.release()); |
| 244 return true; | 256 return true; |
| 245 } | 257 } |
| 246 | 258 |
| 247 bool BackgroundManifestHandler::Validate( | 259 bool BackgroundManifestHandler::Validate( |
| 248 const Extension* extension, | 260 const Extension* extension, |
| 249 std::string* error, | 261 std::string* error, |
| 250 std::vector<InstallWarning>* warnings) const { | 262 std::vector<InstallWarning>* warnings) const { |
| 251 // Validate that background scripts exist. | 263 // Validate that background scripts exist. |
| 252 const std::vector<std::string>& background_scripts = | 264 const std::vector<std::string>& background_scripts = |
| (...skipping 21 matching lines...) Expand all Loading... |
| 274 *error = | 286 *error = |
| 275 l10n_util::GetStringFUTF8( | 287 l10n_util::GetStringFUTF8( |
| 276 IDS_EXTENSION_LOAD_BACKGROUND_PAGE_FAILED, | 288 IDS_EXTENSION_LOAD_BACKGROUND_PAGE_FAILED, |
| 277 page_path.LossyDisplayName()); | 289 page_path.LossyDisplayName()); |
| 278 return false; | 290 return false; |
| 279 } | 291 } |
| 280 } | 292 } |
| 281 return true; | 293 return true; |
| 282 } | 294 } |
| 283 | 295 |
| 296 bool BackgroundManifestHandler::AlwaysParseForType(Manifest::Type type) const { |
| 297 return type == Manifest::TYPE_PLATFORM_APP; |
| 298 } |
| 299 |
| 284 const std::vector<std::string> BackgroundManifestHandler::Keys() const { | 300 const std::vector<std::string> BackgroundManifestHandler::Keys() const { |
| 285 static const char* keys[] = { | 301 static const char* keys[] = { |
| 286 keys::kBackgroundAllowJsAccess, | 302 keys::kBackgroundAllowJsAccess, |
| 287 keys::kBackgroundPage, | 303 keys::kBackgroundPage, |
| 288 keys::kBackgroundPageLegacy, | 304 keys::kBackgroundPageLegacy, |
| 289 keys::kBackgroundPersistent, | 305 keys::kBackgroundPersistent, |
| 290 keys::kBackgroundScripts, | 306 keys::kBackgroundScripts, |
| 291 keys::kPlatformAppBackgroundPage, | 307 keys::kPlatformAppBackgroundPage, |
| 292 keys::kPlatformAppBackgroundScripts | 308 keys::kPlatformAppBackgroundScripts |
| 293 }; | 309 }; |
| 294 return std::vector<std::string>(keys, keys + arraysize(keys)); | 310 return std::vector<std::string>(keys, keys + arraysize(keys)); |
| 295 } | 311 } |
| 296 | 312 |
| 297 } // extensions | 313 } // namespace extensions |
| OLD | NEW |