Index: extensions/common/manifest_handlers/background_info.cc |
diff --git a/extensions/common/manifest_handlers/background_info.cc b/extensions/common/manifest_handlers/background_info.cc |
index c7aee9053aa49e8ef61bb91c370e50347eeda705..b3a17e0b583ad620985d4e3cbdd4b5e224f3c222 100644 |
--- a/extensions/common/manifest_handlers/background_info.cc |
+++ b/extensions/common/manifest_handlers/background_info.cc |
@@ -63,25 +63,19 @@ GURL BackgroundInfo::GetBackgroundURL(const Extension* extension) { |
} |
// static |
-bool BackgroundInfo::HasGeneratedBackgroundPage(const Extension* extension) { |
- const BackgroundInfo& info = GetBackgroundInfo(extension); |
- return !info.background_scripts_.empty(); |
-} |
- |
-// static |
const std::vector<std::string>& BackgroundInfo::GetBackgroundScripts( |
const Extension* extension) { |
return GetBackgroundInfo(extension).background_scripts_; |
} |
// static |
-bool BackgroundInfo::HasBackgroundPage(const Extension* extension) { |
- return GetBackgroundInfo(extension).has_background_page(); |
+std::string BackgroundInfo::GetServiceWorkerScript(const Extension* extension) { |
+ return GetBackgroundInfo(extension).service_worker_script_; |
} |
// static |
-bool BackgroundInfo::AllowJSAccess(const Extension* extension) { |
- return GetBackgroundInfo(extension).allow_js_access_; |
+bool BackgroundInfo::HasBackgroundPage(const Extension* extension) { |
+ return GetBackgroundInfo(extension).has_background_page(); |
} |
// static |
@@ -94,10 +88,31 @@ bool BackgroundInfo::HasLazyBackgroundPage(const Extension* extension) { |
return GetBackgroundInfo(extension).has_lazy_background_page(); |
} |
+// static |
+bool BackgroundInfo::HasGeneratedBackgroundPage(const Extension* extension) { |
+ const BackgroundInfo& info = GetBackgroundInfo(extension); |
+ return !info.background_scripts_.empty(); |
+} |
+ |
+// static |
+bool BackgroundInfo::HasServiceWorker(const Extension* extension) { |
+ return GetBackgroundInfo(extension).has_service_worker(); |
+} |
+ |
+// static |
+bool BackgroundInfo::AllowJSAccess(const Extension* extension) { |
+ return GetBackgroundInfo(extension).allow_js_access_; |
+} |
+ |
bool BackgroundInfo::Parse(const Extension* extension, base::string16* error) { |
const std::string& bg_scripts_key = extension->is_platform_app() ? |
keys::kPlatformAppBackgroundScripts : keys::kBackgroundScripts; |
- if (!LoadBackgroundScripts(extension, bg_scripts_key, error) || |
+ const std::string& sw_scripts_key = |
+ extension->is_platform_app() |
+ ? keys::kPlatformAppServiceWorkerScript |
+ : ""; // TODO(scheib): Support extensions crbug.com/346885 |
+ if (!LoadServiceWorkerScript(extension, sw_scripts_key, error) || |
+ !LoadBackgroundScripts(extension, bg_scripts_key, error) || |
!LoadBackgroundPage(extension, error) || |
!LoadBackgroundPersistent(extension, error) || |
!LoadAllowJSAccess(extension, error)) { |
@@ -106,6 +121,21 @@ bool BackgroundInfo::Parse(const Extension* extension, base::string16* error) { |
return true; |
} |
+bool BackgroundInfo::LoadServiceWorkerScript(const Extension* extension, |
Jeffrey Yasskin
2014/02/28 01:54:37
The Service Worker is only going to actually work
Yoyo Zhou
2014/02/28 17:59:09
Set *error to a relevant message.
By the way, you
scheib
2014/03/03 19:54:00
Done.
|
+ const std::string& key, |
+ base::string16* error) { |
+ const base::Value* service_worker_script_value = NULL; |
+ if (!extension->manifest()->Get(key, &service_worker_script_value)) |
+ return true; |
+ |
+ CHECK(service_worker_script_value); |
+ if (!service_worker_script_value->GetAsString(&service_worker_script_)) { |
+ *error = ASCIIToUTF16(errors::kInvalidServiceWorkerScript); |
+ return false; |
+ } |
+ return true; |
+} |
+ |
bool BackgroundInfo::LoadBackgroundScripts(const Extension* extension, |
const std::string& key, |
base::string16* error) { |
@@ -113,6 +143,11 @@ bool BackgroundInfo::LoadBackgroundScripts(const Extension* extension, |
if (!extension->manifest()->Get(key, &background_scripts_value)) |
return true; |
+ if (has_service_worker()) { |
Jeffrey Yasskin
2014/02/28 01:54:37
Could you put this in BgInfo::Parse so that its co
scheib
2014/03/03 19:54:00
Done.
|
+ *error = ASCIIToUTF16(errors::kInvalidBackgroundCombination); |
+ return false; |
+ } |
+ |
CHECK(background_scripts_value); |
if (background_scripts_value->GetType() != base::Value::TYPE_LIST) { |
*error = ASCIIToUTF16(errors::kInvalidBackgroundScripts); |
@@ -141,7 +176,7 @@ bool BackgroundInfo::LoadBackgroundPage(const Extension* extension, |
if (!extension->manifest()->Get(key, &background_page_value)) |
return true; |
- if (!background_scripts_.empty()) { |
+ if (!background_scripts_.empty() || has_service_worker()) { |
*error = ASCIIToUTF16(errors::kInvalidBackgroundCombination); |
return false; |
} |
@@ -247,8 +282,9 @@ bool BackgroundManifestHandler::Parse(Extension* extension, |
if (!info->Parse(extension, error)) |
return false; |
- // Platform apps must have background pages. |
- if (extension->is_platform_app() && !info->has_background_page()) { |
+ // Platform apps must have background pages or service workers. |
+ if (extension->is_platform_app() && !info->has_background_page() && |
+ !info->has_service_worker()) { |
*error = ASCIIToUTF16(errors::kBackgroundRequiredForPlatformApps); |
return false; |
} |