Commit 02ad1a72 authored by scheib's avatar scheib Committed by Commit bot

Remove service worker concepts from apps/extensions manifest parsing.

BUG=396340

Review URL: https://codereview.chromium.org/447783003

Cr-Commit-Position: refs/heads/master@{#292187}
parent 1760d49c
...@@ -1849,7 +1849,6 @@ ...@@ -1849,7 +1849,6 @@
'common/extensions/manifest_tests/extension_manifests_portsinpermissions_unittest.cc', 'common/extensions/manifest_tests/extension_manifests_portsinpermissions_unittest.cc',
'common/extensions/manifest_tests/extension_manifests_requirements_unittest.cc', 'common/extensions/manifest_tests/extension_manifests_requirements_unittest.cc',
'common/extensions/manifest_tests/extension_manifests_sandboxed_unittest.cc', 'common/extensions/manifest_tests/extension_manifests_sandboxed_unittest.cc',
'common/extensions/manifest_tests/extension_manifests_service_worker_unittest.cc',
'common/extensions/manifest_tests/extension_manifests_storage_unittest.cc', 'common/extensions/manifest_tests/extension_manifests_storage_unittest.cc',
'common/extensions/manifest_tests/extension_manifests_ui_unittest.cc', 'common/extensions/manifest_tests/extension_manifests_ui_unittest.cc',
'common/extensions/manifest_tests/extension_manifests_update_unittest.cc', 'common/extensions/manifest_tests/extension_manifests_update_unittest.cc',
......
...@@ -34,10 +34,6 @@ ...@@ -34,10 +34,6 @@
"channel": "stable", "channel": "stable",
"extension_types": ["legacy_packaged_app", "hosted_app"] "extension_types": ["legacy_packaged_app", "hosted_app"]
}, },
"app.service_worker": {
"channel": "trunk", // When changing update tests: http://crbug.com/353209
"extension_types": ["platform_app"]
},
"author": { "author": {
"channel": "stable", "channel": "stable",
"extension_types": "all" "extension_types": "all"
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/command_line.h"
#include "base/memory/scoped_ptr.h"
#include "base/test/values_test_util.h"
#include "base/values.h"
#include "chrome/common/extensions/features/feature_channel.h"
#include "chrome/common/extensions/manifest_tests/extension_manifest_test.h"
#include "content/public/common/content_switches.h"
#include "extensions/common/constants.h"
#include "extensions/common/error_utils.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest_constants.h"
#include "extensions/common/manifest_handlers/background_info.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace extensions {
class ExtensionManifestServiceWorkerTest : public ExtensionManifestTest {
public:
ExtensionManifestServiceWorkerTest()
: trunk_channel_(chrome::VersionInfo::CHANNEL_UNKNOWN) {}
void AddServiceWorkerCommandLineSwitch() {
CHECK(!CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableExperimentalWebPlatformFeatures));
CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableExperimentalWebPlatformFeatures);
}
// "app.service_worker" is restricted to trunk in _manifest_features.json.
extensions::ScopedCurrentChannel trunk_channel_;
};
// Checks that a service_worker key is ignored without
// enable-experimental-web-platform-features switch. When service workers are
// enabled by default please remove this test.
TEST_F(ExtensionManifestServiceWorkerTest, ServiceWorkerCommandLineRequired) {
CHECK(!CommandLine::ForCurrentProcess()->HasSwitch(
::switches::kEnableExperimentalWebPlatformFeatures));
LoadFromStringAndExpectError(
"{"
" 'name': '',"
" 'manifest_version': 2,"
" 'version': '1',"
" 'app': {"
" 'service_worker': {"
" 'script': 'service_worker.js'"
" }"
" }"
"}",
manifest_errors::kServiceWorkerRequiresFlag);
}
// Checks that an app manifest with a service_worker key but no script fails.
TEST_F(ExtensionManifestServiceWorkerTest, ServiceWorkerEmpty) {
AddServiceWorkerCommandLineSwitch();
LoadFromStringAndExpectError(
"{"
" 'name': '',"
" 'manifest_version': 2,"
" 'version': '1',"
" 'app': {"
" 'service_worker': {}" // No script specified.
" }"
"}",
manifest_errors::kBackgroundRequiredForPlatformApps);
LoadFromStringAndExpectError(
"{"
" 'name': '',"
" 'manifest_version': 2,"
" 'version': '1',"
" 'app': {"
" 'service_worker': {"
" 'script': ''" // Empty script.
" }"
" }"
"}",
manifest_errors::kBackgroundRequiredForPlatformApps);
}
// Checks that an app manifest with a single script is loaded.
TEST_F(ExtensionManifestServiceWorkerTest, ServiceWorkerScript) {
AddServiceWorkerCommandLineSwitch();
scoped_refptr<Extension> extension(LoadFromStringAndExpectSuccess(
"{"
" 'name': '',"
" 'manifest_version': 2,"
" 'version': '1',"
" 'app': {"
" 'service_worker': {"
" 'script': 'service_worker.js'"
" }"
" }"
"}"));
ASSERT_TRUE(extension.get());
// "app.service_worker" key exists and access is permitted.
EXPECT_TRUE(extension->manifest()->HasPath("app.service_worker"));
EXPECT_EQ("service_worker.js",
BackgroundInfo::GetServiceWorkerScript(extension.get()));
EXPECT_TRUE(BackgroundInfo::HasServiceWorker(extension.get()));
}
// Checks that an app manifest with service worker and background script fails.
TEST_F(ExtensionManifestServiceWorkerTest, ServiceWorkerWithBackgroundScript) {
AddServiceWorkerCommandLineSwitch();
LoadFromStringAndExpectError(
"{"
" 'name': '',"
" 'manifest_version': 2,"
" 'version': '1',"
" 'app': {"
" 'service_worker': {"
" 'script': 'service_worker.js'"
" },"
" 'background': {"
" 'scripts': [ 'background.js' ]"
" }"
" }"
"}",
manifest_errors::kInvalidBackgroundCombination);
}
} // namespace extensions
...@@ -159,12 +159,6 @@ TEST_F(ManifestTest, ExtensionTypes) { ...@@ -159,12 +159,6 @@ TEST_F(ManifestTest, ExtensionTypes) {
MutateManifest( MutateManifest(
&manifest, keys::kPlatformAppBackground, NULL); &manifest, keys::kPlatformAppBackground, NULL);
// Platform app with service worker.
MutateManifest(
&manifest, keys::kPlatformAppServiceWorker, new base::DictionaryValue());
AssertType(manifest.get(), Manifest::TYPE_PLATFORM_APP);
MutateManifest(&manifest, keys::kPlatformAppServiceWorker, NULL);
// Hosted app. // Hosted app.
MutateManifest( MutateManifest(
&manifest, keys::kWebURLs, new base::ListValue()); &manifest, keys::kWebURLs, new base::ListValue());
......
...@@ -120,8 +120,7 @@ Manifest::Manifest(Location location, scoped_ptr<base::DictionaryValue> value) ...@@ -120,8 +120,7 @@ Manifest::Manifest(Location location, scoped_ptr<base::DictionaryValue> value)
if (value_->Get(keys::kWebURLs, NULL) || if (value_->Get(keys::kWebURLs, NULL) ||
value_->Get(keys::kLaunchWebURL, NULL)) { value_->Get(keys::kLaunchWebURL, NULL)) {
type_ = TYPE_HOSTED_APP; type_ = TYPE_HOSTED_APP;
} else if (value_->Get(keys::kPlatformAppBackground, NULL) || } else if (value_->Get(keys::kPlatformAppBackground, NULL)) {
value_->Get(keys::kPlatformAppServiceWorker, NULL)) {
type_ = TYPE_PLATFORM_APP; type_ = TYPE_PLATFORM_APP;
} else { } else {
type_ = TYPE_LEGACY_PACKAGED_APP; type_ = TYPE_LEGACY_PACKAGED_APP;
......
...@@ -113,8 +113,6 @@ const char kPlatformAppBackground[] = "app.background"; ...@@ -113,8 +113,6 @@ const char kPlatformAppBackground[] = "app.background";
const char kPlatformAppBackgroundPage[] = "app.background.page"; const char kPlatformAppBackgroundPage[] = "app.background.page";
const char kPlatformAppBackgroundScripts[] = "app.background.scripts"; const char kPlatformAppBackgroundScripts[] = "app.background.scripts";
const char kPlatformAppContentSecurityPolicy[] = "app.content_security_policy"; const char kPlatformAppContentSecurityPolicy[] = "app.content_security_policy";
const char kPlatformAppServiceWorker[] = "app.service_worker";
const char kPlatformAppServiceWorkerScript[] = "app.service_worker.script";
const char kPlugins[] = "plugins"; const char kPlugins[] = "plugins";
const char kPluginsPath[] = "path"; const char kPluginsPath[] = "path";
const char kPluginsPublic[] = "public"; const char kPluginsPublic[] = "public";
...@@ -578,8 +576,6 @@ const char kInvalidSearchEngineMissingKeys[] = ...@@ -578,8 +576,6 @@ const char kInvalidSearchEngineMissingKeys[] =
"'chrome_settings_overrides.search_provider'."; "'chrome_settings_overrides.search_provider'.";
const char kInvalidSearchEngineURL[] = const char kInvalidSearchEngineURL[] =
"Invalid URL [*] for 'chrome_settings_overrides.search_provider'."; "Invalid URL [*] for 'chrome_settings_overrides.search_provider'.";
const char kInvalidServiceWorkerScript[] =
"Invalid value for 'service_worker.script'.";
const char kInvalidShortName[] = const char kInvalidShortName[] =
"Invalid value for 'short_name'."; "Invalid value for 'short_name'.";
const char kInvalidSignature[] = const char kInvalidSignature[] =
...@@ -722,9 +718,6 @@ const char kScriptBadgeIconIgnored[] = ...@@ -722,9 +718,6 @@ const char kScriptBadgeIconIgnored[] =
const char kScriptBadgeTitleIgnored[] = const char kScriptBadgeTitleIgnored[] =
"default_title specified in script_badge manifest section will not be " "default_title specified in script_badge manifest section will not be "
"used."; "used.";
const char kServiceWorkerRequiresFlag[] =
"Service worker features require "
"--enable-experimental-web-platform-features command-line flag.";
const char kUnrecognizedManifestKey[] = "Unrecognized manifest key '*'."; const char kUnrecognizedManifestKey[] = "Unrecognized manifest key '*'.";
const char kUnrecognizedManifestProperty[] = const char kUnrecognizedManifestProperty[] =
"Unrecognized property '*' of manifest key '*'."; "Unrecognized property '*' of manifest key '*'.";
......
...@@ -121,8 +121,6 @@ extern const char kPlatformAppBackground[]; ...@@ -121,8 +121,6 @@ extern const char kPlatformAppBackground[];
extern const char kPlatformAppBackgroundPage[]; extern const char kPlatformAppBackgroundPage[];
extern const char kPlatformAppBackgroundScripts[]; extern const char kPlatformAppBackgroundScripts[];
extern const char kPlatformAppContentSecurityPolicy[]; extern const char kPlatformAppContentSecurityPolicy[];
extern const char kPlatformAppServiceWorker[];
extern const char kPlatformAppServiceWorkerScript[];
extern const char kPlugins[]; extern const char kPlugins[];
extern const char kPluginsPath[]; extern const char kPluginsPath[];
extern const char kPluginsPublic[]; extern const char kPluginsPublic[];
...@@ -410,7 +408,6 @@ extern const char kInvalidSandboxedPagesCSP[]; ...@@ -410,7 +408,6 @@ extern const char kInvalidSandboxedPagesCSP[];
extern const char kInvalidScriptBadge[]; extern const char kInvalidScriptBadge[];
extern const char kInvalidSearchEngineMissingKeys[]; extern const char kInvalidSearchEngineMissingKeys[];
extern const char kInvalidSearchEngineURL[]; extern const char kInvalidSearchEngineURL[];
extern const char kInvalidServiceWorkerScript[];
extern const char kInvalidShortName[]; extern const char kInvalidShortName[];
extern const char kInvalidSignature[]; extern const char kInvalidSignature[];
extern const char kInvalidSpellcheck[]; extern const char kInvalidSpellcheck[];
...@@ -479,7 +476,6 @@ extern const char kUnrecognizedManifestProperty[]; ...@@ -479,7 +476,6 @@ extern const char kUnrecognizedManifestProperty[];
extern const char kScriptBadgeRequiresFlag[]; extern const char kScriptBadgeRequiresFlag[];
extern const char kScriptBadgeIconIgnored[]; extern const char kScriptBadgeIconIgnored[];
extern const char kScriptBadgeTitleIgnored[]; extern const char kScriptBadgeTitleIgnored[];
extern const char kServiceWorkerRequiresFlag[];
extern const char kWebRequestConflictsWithLazyBackground[]; extern const char kWebRequestConflictsWithLazyBackground[];
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
extern const char kIllegalPlugins[]; extern const char kIllegalPlugins[];
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "content/public/common/content_switches.h"
#include "extensions/common/constants.h" #include "extensions/common/constants.h"
#include "extensions/common/error_utils.h" #include "extensions/common/error_utils.h"
#include "extensions/common/file_util.h" #include "extensions/common/file_util.h"
...@@ -69,12 +68,6 @@ const std::vector<std::string>& BackgroundInfo::GetBackgroundScripts( ...@@ -69,12 +68,6 @@ const std::vector<std::string>& BackgroundInfo::GetBackgroundScripts(
return GetBackgroundInfo(extension).background_scripts_; return GetBackgroundInfo(extension).background_scripts_;
} }
// static
const std::string& BackgroundInfo::GetServiceWorkerScript(
const Extension* extension) {
return GetBackgroundInfo(extension).service_worker_script_;
}
// static // static
bool BackgroundInfo::HasBackgroundPage(const Extension* extension) { bool BackgroundInfo::HasBackgroundPage(const Extension* extension) {
return GetBackgroundInfo(extension).has_background_page(); return GetBackgroundInfo(extension).has_background_page();
...@@ -96,11 +89,6 @@ bool BackgroundInfo::HasGeneratedBackgroundPage(const Extension* extension) { ...@@ -96,11 +89,6 @@ bool BackgroundInfo::HasGeneratedBackgroundPage(const Extension* extension) {
return !info.background_scripts_.empty(); return !info.background_scripts_.empty();
} }
// static
bool BackgroundInfo::HasServiceWorker(const Extension* extension) {
return GetBackgroundInfo(extension).has_service_worker();
}
// static // static
bool BackgroundInfo::AllowJSAccess(const Extension* extension) { bool BackgroundInfo::AllowJSAccess(const Extension* extension) {
return GetBackgroundInfo(extension).allow_js_access_; return GetBackgroundInfo(extension).allow_js_access_;
...@@ -109,12 +97,7 @@ bool BackgroundInfo::AllowJSAccess(const Extension* extension) { ...@@ -109,12 +97,7 @@ bool BackgroundInfo::AllowJSAccess(const Extension* extension) {
bool BackgroundInfo::Parse(const Extension* extension, base::string16* error) { bool BackgroundInfo::Parse(const Extension* extension, base::string16* error) {
const std::string& bg_scripts_key = extension->is_platform_app() ? const std::string& bg_scripts_key = extension->is_platform_app() ?
keys::kPlatformAppBackgroundScripts : keys::kBackgroundScripts; keys::kPlatformAppBackgroundScripts : keys::kBackgroundScripts;
const std::string& sw_scripts_key = if (!LoadBackgroundScripts(extension, bg_scripts_key, error) ||
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) || !LoadBackgroundPage(extension, error) ||
!LoadBackgroundPersistent(extension, error) || !LoadBackgroundPersistent(extension, error) ||
!LoadAllowJSAccess(extension, error)) { !LoadAllowJSAccess(extension, error)) {
...@@ -122,8 +105,7 @@ bool BackgroundInfo::Parse(const Extension* extension, base::string16* error) { ...@@ -122,8 +105,7 @@ bool BackgroundInfo::Parse(const Extension* extension, base::string16* error) {
} }
int background_solution_sum = (background_url_.is_valid() ? 1 : 0) + int background_solution_sum = (background_url_.is_valid() ? 1 : 0) +
(!background_scripts_.empty() ? 1 : 0) + (!background_scripts_.empty() ? 1 : 0);
(has_service_worker() ? 1 : 0);
if (background_solution_sum > 1) { if (background_solution_sum > 1) {
*error = ASCIIToUTF16(errors::kInvalidBackgroundCombination); *error = ASCIIToUTF16(errors::kInvalidBackgroundCombination);
return false; return false;
...@@ -132,27 +114,6 @@ bool BackgroundInfo::Parse(const Extension* extension, base::string16* error) { ...@@ -132,27 +114,6 @@ bool BackgroundInfo::Parse(const Extension* extension, base::string16* error) {
return true; return true;
} }
bool BackgroundInfo::LoadServiceWorkerScript(const Extension* extension,
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;
if (!CommandLine::ForCurrentProcess()->HasSwitch(
::switches::kEnableExperimentalWebPlatformFeatures)) {
*error = ASCIIToUTF16(errors::kServiceWorkerRequiresFlag);
return false;
}
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, bool BackgroundInfo::LoadBackgroundScripts(const Extension* extension,
const std::string& key, const std::string& key,
base::string16* error) { base::string16* error) {
...@@ -289,9 +250,8 @@ bool BackgroundManifestHandler::Parse(Extension* extension, ...@@ -289,9 +250,8 @@ bool BackgroundManifestHandler::Parse(Extension* extension,
if (!info->Parse(extension, error)) if (!info->Parse(extension, error))
return false; return false;
// Platform apps must have background pages or service workers. // Platform apps must have background pages.
if (extension->is_platform_app() && !info->has_background_page() && if (extension->is_platform_app() && !info->has_background_page()) {
!info->has_service_worker()) {
*error = ASCIIToUTF16(errors::kBackgroundRequiredForPlatformApps); *error = ASCIIToUTF16(errors::kBackgroundRequiredForPlatformApps);
return false; return false;
} }
...@@ -348,14 +308,11 @@ bool BackgroundManifestHandler::AlwaysParseForType(Manifest::Type type) const { ...@@ -348,14 +308,11 @@ bool BackgroundManifestHandler::AlwaysParseForType(Manifest::Type type) const {
} }
const std::vector<std::string> BackgroundManifestHandler::Keys() const { const std::vector<std::string> BackgroundManifestHandler::Keys() const {
static const char* keys[] = {keys::kBackgroundAllowJsAccess, static const char* keys[] = {
keys::kBackgroundPage, keys::kBackgroundAllowJsAccess, keys::kBackgroundPage,
keys::kBackgroundPageLegacy, keys::kBackgroundPageLegacy, keys::kBackgroundPersistent,
keys::kBackgroundPersistent, keys::kBackgroundScripts, keys::kPlatformAppBackgroundPage,
keys::kBackgroundScripts, keys::kPlatformAppBackgroundScripts};
keys::kPlatformAppBackgroundPage,
keys::kPlatformAppBackgroundScripts,
keys::kPlatformAppServiceWorkerScript};
return std::vector<std::string>(keys, keys + arraysize(keys)); return std::vector<std::string>(keys, keys + arraysize(keys));
} }
......
...@@ -23,12 +23,10 @@ class BackgroundInfo : public Extension::ManifestData { ...@@ -23,12 +23,10 @@ class BackgroundInfo : public Extension::ManifestData {
static GURL GetBackgroundURL(const Extension* extension); static GURL GetBackgroundURL(const Extension* extension);
static const std::vector<std::string>& GetBackgroundScripts( static const std::vector<std::string>& GetBackgroundScripts(
const Extension* extension); const Extension* extension);
static const std::string& GetServiceWorkerScript(const Extension* extension);
static bool HasBackgroundPage(const Extension* extension); static bool HasBackgroundPage(const Extension* extension);
static bool HasPersistentBackgroundPage(const Extension* extension); static bool HasPersistentBackgroundPage(const Extension* extension);
static bool HasLazyBackgroundPage(const Extension* extension); static bool HasLazyBackgroundPage(const Extension* extension);
static bool HasGeneratedBackgroundPage(const Extension* extension); static bool HasGeneratedBackgroundPage(const Extension* extension);
static bool HasServiceWorker(const Extension* extension);
static bool AllowJSAccess(const Extension* extension); static bool AllowJSAccess(const Extension* extension);
bool has_background_page() const { bool has_background_page() const {
...@@ -43,14 +41,9 @@ class BackgroundInfo : public Extension::ManifestData { ...@@ -43,14 +41,9 @@ class BackgroundInfo : public Extension::ManifestData {
return has_background_page() && !is_persistent_; return has_background_page() && !is_persistent_;
} }
bool has_service_worker() const { return !service_worker_script_.empty(); }
bool Parse(const Extension* extension, base::string16* error); bool Parse(const Extension* extension, base::string16* error);
private: private:
bool LoadServiceWorkerScript(const Extension* extension,
const std::string& key,
base::string16* error);
bool LoadBackgroundScripts(const Extension* extension, bool LoadBackgroundScripts(const Extension* extension,
const std::string& key, const std::string& key,
base::string16* error); base::string16* error);
...@@ -74,10 +67,6 @@ class BackgroundInfo : public Extension::ManifestData { ...@@ -74,10 +67,6 @@ class BackgroundInfo : public Extension::ManifestData {
// load on-demand (when it needs to handle an event). Defaults to true. // load on-demand (when it needs to handle an event). Defaults to true.
bool is_persistent_; bool is_persistent_;
// Optional script to register as a service worker. This is mutually exclusive
// to the use of background_url_ or background_scripts_.
std::string service_worker_script_;
// True if the background page can be scripted by pages of the app or // True if the background page can be scripted by pages of the app or
// extension, in which case all such pages must run in the same process. // extension, in which case all such pages must run in the same process.
// False if such pages are not permitted to script the background page, // False if such pages are not permitted to script the background page,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment