summaryrefslogtreecommitdiffstats
path: root/extensions/common/manifest_handlers
diff options
context:
space:
mode:
authorxiyuan <xiyuan@chromium.org>2016-01-21 09:21:38 -0800
committerCommit bot <commit-bot@chromium.org>2016-01-21 17:23:34 +0000
commitc13cf9fa303adc690738c7acf6bdb2c934fb111b (patch)
treeeb61d768fc00a382fdeb69e0721ed82e5d9be8fb /extensions/common/manifest_handlers
parent98727ed4bcb6504e21b32a8c207c1998dc3a4429 (diff)
downloadchromium_src-c13cf9fa303adc690738c7acf6bdb2c934fb111b.zip
chromium_src-c13cf9fa303adc690738c7acf6bdb2c934fb111b.tar.gz
chromium_src-c13cf9fa303adc690738c7acf6bdb2c934fb111b.tar.bz2
kiosk: Add kiosk.required_platform_version manifest key
BUG=577779 TEST=KioskModeInfoManifestTest.RequiredPlatformVersion* Review URL: https://codereview.chromium.org/1595483004 Cr-Commit-Position: refs/heads/master@{#370722}
Diffstat (limited to 'extensions/common/manifest_handlers')
-rw-r--r--extensions/common/manifest_handlers/kiosk_mode_info.cc41
-rw-r--r--extensions/common/manifest_handlers/kiosk_mode_info.h5
-rw-r--r--extensions/common/manifest_handlers/kiosk_mode_info_unittest.cc21
3 files changed, 59 insertions, 8 deletions
diff --git a/extensions/common/manifest_handlers/kiosk_mode_info.cc b/extensions/common/manifest_handlers/kiosk_mode_info.cc
index d265c23..5ab5656 100644
--- a/extensions/common/manifest_handlers/kiosk_mode_info.cc
+++ b/extensions/common/manifest_handlers/kiosk_mode_info.cc
@@ -9,9 +9,21 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
+#include "base/version.h"
#include "extensions/common/api/extensions_manifest_types.h"
#include "extensions/common/manifest_constants.h"
+namespace {
+
+// Whether the given |version_string| is a valid ChromeOS platform version.
+// The acceptable format is major[.minor[.micro]].
+bool IsValidPlatformVersion(const std::string& version_string) {
+ const base::Version version(version_string);
+ return version.IsValid() && version.components().size() <= 3u;
+}
+
+} // namespace
+
namespace extensions {
namespace keys = manifest_keys;
@@ -19,8 +31,11 @@ namespace keys = manifest_keys;
using api::extensions_manifest_types::KioskSecondaryAppsType;
KioskModeInfo::KioskModeInfo(KioskStatus kiosk_status,
- const std::vector<std::string>& secondary_app_ids)
- : kiosk_status(kiosk_status), secondary_app_ids(secondary_app_ids) {}
+ const std::vector<std::string>& secondary_app_ids,
+ const std::string& required_platform_version)
+ : kiosk_status(kiosk_status),
+ secondary_app_ids(secondary_app_ids),
+ required_platform_version(required_platform_version) {}
KioskModeInfo::~KioskModeInfo() {
}
@@ -50,6 +65,7 @@ bool KioskModeInfo::HasSecondaryApps(const Extension* extension) {
}
KioskModeHandler::KioskModeHandler() {
+ supported_keys_.push_back(keys::kKiosk);
supported_keys_.push_back(keys::kKioskEnabled);
supported_keys_.push_back(keys::kKioskOnly);
supported_keys_.push_back(keys::kKioskSecondaryApps);
@@ -93,11 +109,10 @@ bool KioskModeHandler::Parse(Extension* extension, base::string16* error) {
// Kiosk secondary apps key is optional.
std::vector<std::string> ids;
- if (extension->manifest()->HasKey(keys::kKioskSecondaryApps)) {
+ if (manifest->HasKey(keys::kKioskSecondaryApps)) {
const base::Value* secondary_apps = nullptr;
const base::ListValue* list = nullptr;
- if (!extension->manifest()->Get(keys::kKioskSecondaryApps,
- &secondary_apps) ||
+ if (!manifest->Get(keys::kKioskSecondaryApps, &secondary_apps) ||
!secondary_apps->GetAsList(&list)) {
*error = base::ASCIIToUTF16(manifest_errors::kInvalidKioskSecondaryApps);
return false;
@@ -115,8 +130,20 @@ bool KioskModeHandler::Parse(Extension* extension, base::string16* error) {
}
}
- extension->SetManifestData(keys::kKioskMode,
- new KioskModeInfo(kiosk_status, ids));
+ // Optional kiosk.required_platform_version key.
+ std::string required_platform_version;
+ if (manifest->HasPath(keys::kKioskRequiredPlatformVersion) &&
+ (!manifest->GetString(keys::kKioskRequiredPlatformVersion,
+ &required_platform_version) ||
+ !IsValidPlatformVersion(required_platform_version))) {
+ *error = base::ASCIIToUTF16(
+ manifest_errors::kInvalidKioskRequiredPlatformVersion);
+ return false;
+ }
+
+ extension->SetManifestData(
+ keys::kKioskMode,
+ new KioskModeInfo(kiosk_status, ids, required_platform_version));
return true;
}
diff --git a/extensions/common/manifest_handlers/kiosk_mode_info.h b/extensions/common/manifest_handlers/kiosk_mode_info.h
index d23df60..514e78e 100644
--- a/extensions/common/manifest_handlers/kiosk_mode_info.h
+++ b/extensions/common/manifest_handlers/kiosk_mode_info.h
@@ -24,7 +24,8 @@ struct KioskModeInfo : public Extension::ManifestData {
};
KioskModeInfo(KioskStatus kiosk_status,
- const std::vector<std::string>& secondary_app_ids);
+ const std::vector<std::string>& secondary_app_ids,
+ const std::string& required_platform_version);
~KioskModeInfo() override;
// Gets the KioskModeInfo for |extension|, or NULL if none was
@@ -44,6 +45,8 @@ struct KioskModeInfo : public Extension::ManifestData {
// The IDs of the kiosk secondary apps.
const std::vector<std::string> secondary_app_ids;
+
+ const std::string required_platform_version;
};
// Parses the "kiosk_enabled" and "kiosk_only" manifest keys.
diff --git a/extensions/common/manifest_handlers/kiosk_mode_info_unittest.cc b/extensions/common/manifest_handlers/kiosk_mode_info_unittest.cc
index 9e42c18..444af63 100644
--- a/extensions/common/manifest_handlers/kiosk_mode_info_unittest.cc
+++ b/extensions/common/manifest_handlers/kiosk_mode_info_unittest.cc
@@ -32,4 +32,25 @@ TEST_F(KioskModeInfoManifestTest, MultipleSecondaryApps) {
std::equal(parsed_ids.begin(), parsed_ids.end(), expected_ids));
}
+TEST_F(KioskModeInfoManifestTest, RequiredPlatformVersionOptional) {
+ scoped_refptr<Extension> extension(
+ LoadAndExpectSuccess("kiosk_required_platform_version_not_present.json"));
+ KioskModeInfo* info = KioskModeInfo::Get(extension.get());
+ EXPECT_TRUE(info->required_platform_version.empty());
+}
+
+TEST_F(KioskModeInfoManifestTest, RequiredPlatformVersion) {
+ scoped_refptr<Extension> extension(
+ LoadAndExpectSuccess("kiosk_required_platform_version.json"));
+ KioskModeInfo* info = KioskModeInfo::Get(extension.get());
+ EXPECT_EQ("1234.0.0", info->required_platform_version);
+}
+
+TEST_F(KioskModeInfoManifestTest, RequiredPlatformVersionInvalid) {
+ LoadAndExpectError("kiosk_required_platform_version_empty.json",
+ manifest_errors::kInvalidKioskRequiredPlatformVersion);
+ LoadAndExpectError("kiosk_required_platform_version_invalid.json",
+ manifest_errors::kInvalidKioskRequiredPlatformVersion);
+}
+
} // namespace extensions