summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-16 21:11:55 +0000
committeryoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-16 21:11:55 +0000
commit1abdf4f00771d35feddd9f204b6ea46470f31f21 (patch)
tree0143e940a4148912045de61785bf4b30491b40fc
parent2e5b90c3b35ef01872bb68aae1f8928602159fff (diff)
downloadchromium_src-1abdf4f00771d35feddd9f204b6ea46470f31f21.zip
chromium_src-1abdf4f00771d35feddd9f204b6ea46470f31f21.tar.gz
chromium_src-1abdf4f00771d35feddd9f204b6ea46470f31f21.tar.bz2
Add offline_enabled field in manifest.
Packaged apps (and extensions) can declare themselves to be offline-enabled. BUG=89655 TEST=added ExtensionManifestTest.OfflineEnabled Review URL: http://codereview.chromium.org/7645033 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97024 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/common/extensions/extension.cc14
-rw-r--r--chrome/common/extensions/extension.h4
-rw-r--r--chrome/common/extensions/extension_constants.cc3
-rw-r--r--chrome/common/extensions/extension_constants.h2
-rw-r--r--chrome/common/extensions/extension_manifests_unittest.cc22
-rw-r--r--chrome/test/data/extensions/manifest_tests/offline_default_packaged_app.json9
-rw-r--r--chrome/test/data/extensions/manifest_tests/offline_disabled_packaged_app.json10
-rw-r--r--chrome/test/data/extensions/manifest_tests/offline_enabled_extension.json5
-rw-r--r--chrome/test/data/extensions/manifest_tests/offline_enabled_hosted_app.json14
-rw-r--r--chrome/test/data/extensions/manifest_tests/offline_enabled_invalid.json10
-rw-r--r--chrome/test/data/extensions/manifest_tests/offline_enabled_packaged_app.json10
11 files changed, 100 insertions, 3 deletions
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index 1b62353..c91b568 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -1190,7 +1190,8 @@ bool Extension::EnsureNotHybridApp(const DictionaryValue* manifest,
*key != keys::kPermissions &&
*key != keys::kOptionalPermissions &&
*key != keys::kOptionsPage &&
- *key != keys::kBackground) {
+ *key != keys::kBackground &&
+ *key != keys::kOfflineEnabled) {
*error = ExtensionErrorUtils::FormatErrorMessage(
errors::kHostedAppsCannotIncludeExtensionFeatures, *key);
return false;
@@ -1208,6 +1209,7 @@ bool Extension::IsTrustedId(const std::string& id) {
Extension::Extension(const FilePath& path, Location location)
: incognito_split_mode_(false),
+ offline_enabled_(false),
location_(location),
converted_from_user_script_(false),
is_theme_(false),
@@ -1870,7 +1872,7 @@ bool Extension::InitFromValue(const DictionaryValue& source, int flags,
}
// Initialize options page url (optional).
- // Funtion LoadIsApp() set is_app_ above.
+ // Function LoadIsApp() set is_app_ above.
if (source.HasKey(keys::kOptionsPage)) {
std::string options_str;
if (!source.GetString(keys::kOptionsPage, &options_str)) {
@@ -2305,6 +2307,14 @@ bool Extension::InitFromValue(const DictionaryValue& source, int flags,
}
}
+ // Initialize offline-enabled status. Defaults to false.
+ if (source.HasKey(keys::kOfflineEnabled)) {
+ if (!source.GetBoolean(keys::kOfflineEnabled, &offline_enabled_)) {
+ *error = errors::kInvalidOfflineEnabled;
+ return false;
+ }
+ }
+
if (HasMultipleUISurfaces()) {
*error = errors::kOneUISurfaceOnly;
return false;
diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h
index d5801f5..79e5837 100644
--- a/chrome/common/extensions/extension.h
+++ b/chrome/common/extensions/extension.h
@@ -532,6 +532,7 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
}
const std::string omnibox_keyword() const { return omnibox_keyword_; }
bool incognito_split_mode() const { return incognito_split_mode_; }
+ bool offline_enabled() const { return offline_enabled_; }
const std::vector<TtsVoice>& tts_voices() const { return tts_voices_; }
bool wants_file_access() const { return wants_file_access_; }
@@ -708,6 +709,9 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
// mode.
bool incognito_split_mode_;
+ // Whether the extension or app should be enabled when offline.
+ bool offline_enabled_;
+
// Defines the set of URLs in the extension's web content.
URLPatternSet extent_;
diff --git a/chrome/common/extensions/extension_constants.cc b/chrome/common/extensions/extension_constants.cc
index a0eb53f..77d8bf6 100644
--- a/chrome/common/extensions/extension_constants.cc
+++ b/chrome/common/extensions/extension_constants.cc
@@ -48,6 +48,7 @@ const char* kName = "name";
const char* kNaClModules = "nacl_modules";
const char* kNaClModulesMIMEType = "mime_type";
const char* kNaClModulesPath = "path";
+const char* kOfflineEnabled = "offline_enabled";
const char* kOmnibox = "omnibox";
const char* kOmniboxKeyword = "omnibox.keyword";
const char* kOptionalPermissions = "optional_permissions";
@@ -261,6 +262,8 @@ const char* kInvalidNaClModulesPath =
"Invalid value for 'nacl_modules[*].path'.";
const char* kInvalidNaClModulesMIMEType =
"Invalid value for 'nacl_modules[*].mime_type'.";
+const char* kInvalidOfflineEnabled =
+ "Invalid value for 'offline_enabled'.";
const char* kInvalidOmniboxKeyword =
"Invalid value for 'omnibox.keyword'.";
const char* kInvalidOptionsPage =
diff --git a/chrome/common/extensions/extension_constants.h b/chrome/common/extensions/extension_constants.h
index 983e0b7..f94bc5c6 100644
--- a/chrome/common/extensions/extension_constants.h
+++ b/chrome/common/extensions/extension_constants.h
@@ -53,6 +53,7 @@ namespace extension_manifest_keys {
extern const char* kNaClModulesMIMEType;
extern const char* kNaClModulesPath;
extern const char* kName;
+ extern const char* kOfflineEnabled;
extern const char* kOmnibox;
extern const char* kOmniboxKeyword;
extern const char* kOptionalPermissions;
@@ -193,6 +194,7 @@ namespace extension_manifest_errors {
extern const char* kInvalidNaClModulesMIMEType;
extern const char* kInvalidNaClModulesPath;
extern const char* kInvalidName;
+ extern const char* kInvalidOfflineEnabled;
extern const char* kInvalidOmniboxKeyword;
extern const char* kInvalidOptionsPage;
extern const char* kInvalidOptionsPageExpectUrlInPackage;
diff --git a/chrome/common/extensions/extension_manifests_unittest.cc b/chrome/common/extensions/extension_manifests_unittest.cc
index 2fd647c..3d7ed44 100644
--- a/chrome/common/extensions/extension_manifests_unittest.cc
+++ b/chrome/common/extensions/extension_manifests_unittest.cc
@@ -600,7 +600,7 @@ TEST_F(ExtensionManifestTest, DisallowHybridApps) {
TEST_F(ExtensionManifestTest, OptionsPageInApps) {
scoped_refptr<Extension> extension;
- // Allow options page with absolute URL in hosed apps.
+ // Allow options page with absolute URL in hosted apps.
extension = LoadAndExpectSuccess("hosted_app_absolute_options.json");
EXPECT_STREQ("http",
extension->options_url().scheme().c_str());
@@ -826,3 +826,23 @@ TEST_F(ExtensionManifestTest, FileManagerURLOverride) {
LoadAndExpectError("filebrowser_url_override.json",
errors::kInvalidChromeURLOverrides);
}
+
+TEST_F(ExtensionManifestTest, OfflineEnabled) {
+ LoadAndExpectError("offline_enabled_invalid.json",
+ errors::kInvalidOfflineEnabled);
+ scoped_refptr<Extension> extension_0(
+ LoadAndExpectSuccess("offline_enabled_extension.json"));
+ EXPECT_TRUE(extension_0->offline_enabled());
+ scoped_refptr<Extension> extension_1(
+ LoadAndExpectSuccess("offline_enabled_packaged_app.json"));
+ EXPECT_TRUE(extension_1->offline_enabled());
+ scoped_refptr<Extension> extension_2(
+ LoadAndExpectSuccess("offline_disabled_packaged_app.json"));
+ EXPECT_FALSE(extension_2->offline_enabled());
+ scoped_refptr<Extension> extension_3(
+ LoadAndExpectSuccess("offline_default_packaged_app.json"));
+ EXPECT_FALSE(extension_3->offline_enabled());
+ scoped_refptr<Extension> extension_4(
+ LoadAndExpectSuccess("offline_enabled_hosted_app.json"));
+ EXPECT_TRUE(extension_4->offline_enabled());
+}
diff --git a/chrome/test/data/extensions/manifest_tests/offline_default_packaged_app.json b/chrome/test/data/extensions/manifest_tests/offline_default_packaged_app.json
new file mode 100644
index 0000000..cbbf0071
--- /dev/null
+++ b/chrome/test/data/extensions/manifest_tests/offline_default_packaged_app.json
@@ -0,0 +1,9 @@
+{
+ "name": "offline packaged app",
+ "version": "1",
+ "app": {
+ "launch": {
+ "local_path": "loco.html"
+ }
+ }
+}
diff --git a/chrome/test/data/extensions/manifest_tests/offline_disabled_packaged_app.json b/chrome/test/data/extensions/manifest_tests/offline_disabled_packaged_app.json
new file mode 100644
index 0000000..d029bdc
--- /dev/null
+++ b/chrome/test/data/extensions/manifest_tests/offline_disabled_packaged_app.json
@@ -0,0 +1,10 @@
+{
+ "name": "offline false packaged app",
+ "version": "1",
+ "app": {
+ "launch": {
+ "local_path": "loco.html"
+ }
+ },
+ "offline_enabled": false
+}
diff --git a/chrome/test/data/extensions/manifest_tests/offline_enabled_extension.json b/chrome/test/data/extensions/manifest_tests/offline_enabled_extension.json
new file mode 100644
index 0000000..262fe7d1
--- /dev/null
+++ b/chrome/test/data/extensions/manifest_tests/offline_enabled_extension.json
@@ -0,0 +1,5 @@
+{
+ "name": "offline enabled extension",
+ "version": "1",
+ "offline_enabled": true
+}
diff --git a/chrome/test/data/extensions/manifest_tests/offline_enabled_hosted_app.json b/chrome/test/data/extensions/manifest_tests/offline_enabled_hosted_app.json
new file mode 100644
index 0000000..3bb569c
--- /dev/null
+++ b/chrome/test/data/extensions/manifest_tests/offline_enabled_hosted_app.json
@@ -0,0 +1,14 @@
+{
+ "name": "offline hosted app",
+ "version": "1",
+ "app": {
+ "urls": [
+ "http://www.google.com/mail/",
+ "http://www.google.com/foobar/"
+ ],
+ "launch": {
+ "web_url": "http://www.google.com/mail/"
+ }
+ },
+ "offline_enabled": true
+}
diff --git a/chrome/test/data/extensions/manifest_tests/offline_enabled_invalid.json b/chrome/test/data/extensions/manifest_tests/offline_enabled_invalid.json
new file mode 100644
index 0000000..32e2e0b
--- /dev/null
+++ b/chrome/test/data/extensions/manifest_tests/offline_enabled_invalid.json
@@ -0,0 +1,10 @@
+{
+ "name": "invalid offline enabled",
+ "version": "1",
+ "app": {
+ "launch": {
+ "local_path": "loco.html"
+ }
+ },
+ "offline_enabled": "nope"
+}
diff --git a/chrome/test/data/extensions/manifest_tests/offline_enabled_packaged_app.json b/chrome/test/data/extensions/manifest_tests/offline_enabled_packaged_app.json
new file mode 100644
index 0000000..2afecd6
--- /dev/null
+++ b/chrome/test/data/extensions/manifest_tests/offline_enabled_packaged_app.json
@@ -0,0 +1,10 @@
+{
+ "name": "offline true packaged app",
+ "version": "1",
+ "app": {
+ "launch": {
+ "local_path": "loco.html"
+ }
+ },
+ "offline_enabled": true
+}