diff options
author | jennyz <jennyz@chromium.org> | 2015-09-03 13:59:27 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-03 21:00:03 +0000 |
commit | 26b7f4356b905831f152cebb28c08a16ad72d80c (patch) | |
tree | 3a0acf791ae608ab0601bfa412405ee82c9e933a /extensions/common/manifest_handlers | |
parent | fb833eca8993b1210f530fcfa09cd3e72d2d45fe (diff) | |
download | chromium_src-26b7f4356b905831f152cebb28c08a16ad72d80c.zip chromium_src-26b7f4356b905831f152cebb28c08a16ad72d80c.tar.gz chromium_src-26b7f4356b905831f152cebb28c08a16ad72d80c.tar.bz2 |
Implement kiosk multiple apps feature. This includes:
1. Add new manifest keys in the manifest file of the primary kiosk app to configure secondary kiosk apps.
2. Implement the work flow for primary kiosk to download and install secondary apps before its first time launch.
3. Expand FakeCWS to support multiple kiosk apps' update check.
4. Move the hard coded local extension cache director to chromeos path service so that it can be created in testing environment.
BUG=510217
TBR=stevenjb
Review URL: https://codereview.chromium.org/1301323005
Cr-Commit-Position: refs/heads/master@{#347237}
Diffstat (limited to 'extensions/common/manifest_handlers')
3 files changed, 94 insertions, 10 deletions
diff --git a/extensions/common/manifest_handlers/kiosk_mode_info.cc b/extensions/common/manifest_handlers/kiosk_mode_info.cc index f5d36af..d265c23 100644 --- a/extensions/common/manifest_handlers/kiosk_mode_info.cc +++ b/extensions/common/manifest_handlers/kiosk_mode_info.cc @@ -9,36 +9,50 @@ #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "base/values.h" +#include "extensions/common/api/extensions_manifest_types.h" #include "extensions/common/manifest_constants.h" namespace extensions { namespace keys = manifest_keys; -KioskModeInfo::KioskModeInfo(KioskStatus kiosk_status) - : kiosk_status(kiosk_status) { -} +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) {} KioskModeInfo::~KioskModeInfo() { } // static -bool KioskModeInfo::IsKioskEnabled(const Extension* extension) { - KioskModeInfo* info = static_cast<KioskModeInfo*>( +KioskModeInfo* KioskModeInfo::Get(const Extension* extension) { + return static_cast<KioskModeInfo*>( extension->GetManifestData(keys::kKioskMode)); +} + +// static +bool KioskModeInfo::IsKioskEnabled(const Extension* extension) { + KioskModeInfo* info = Get(extension); return info ? info->kiosk_status != NONE : false; } // static bool KioskModeInfo::IsKioskOnly(const Extension* extension) { - KioskModeInfo* info = static_cast<KioskModeInfo*>( - extension->GetManifestData(keys::kKioskMode)); + KioskModeInfo* info = Get(extension); return info ? info->kiosk_status == ONLY : false; } +// static +bool KioskModeInfo::HasSecondaryApps(const Extension* extension) { + KioskModeInfo* info = Get(extension); + return info && !info->secondary_app_ids.empty(); +} + KioskModeHandler::KioskModeHandler() { supported_keys_.push_back(keys::kKioskEnabled); supported_keys_.push_back(keys::kKioskOnly); + supported_keys_.push_back(keys::kKioskSecondaryApps); } KioskModeHandler::~KioskModeHandler() { @@ -77,8 +91,32 @@ bool KioskModeHandler::Parse(Extension* extension, base::string16* error) { if (kiosk_enabled) kiosk_status = kiosk_only ? KioskModeInfo::ONLY : KioskModeInfo::ENABLED; + // Kiosk secondary apps key is optional. + std::vector<std::string> ids; + if (extension->manifest()->HasKey(keys::kKioskSecondaryApps)) { + const base::Value* secondary_apps = nullptr; + const base::ListValue* list = nullptr; + if (!extension->manifest()->Get(keys::kKioskSecondaryApps, + &secondary_apps) || + !secondary_apps->GetAsList(&list)) { + *error = base::ASCIIToUTF16(manifest_errors::kInvalidKioskSecondaryApps); + return false; + } + + for (const base::Value* value : *list) { + scoped_ptr<KioskSecondaryAppsType> app = + KioskSecondaryAppsType::FromValue(*value, error); + if (!app) { + *error = base::ASCIIToUTF16( + manifest_errors::kInvalidKioskSecondaryAppsBadAppId); + return false; + } + ids.push_back(app->id); + } + } + extension->SetManifestData(keys::kKioskMode, - new KioskModeInfo(kiosk_status)); + new KioskModeInfo(kiosk_status, ids)); return true; } diff --git a/extensions/common/manifest_handlers/kiosk_mode_info.h b/extensions/common/manifest_handlers/kiosk_mode_info.h index cf02b0d..9de03a3 100644 --- a/extensions/common/manifest_handlers/kiosk_mode_info.h +++ b/extensions/common/manifest_handlers/kiosk_mode_info.h @@ -22,16 +22,27 @@ struct KioskModeInfo : public Extension::ManifestData { ONLY }; - explicit KioskModeInfo(KioskStatus kiosk_status); + KioskModeInfo(KioskStatus kiosk_status, + const std::vector<std::string>& secondary_app_ids); ~KioskModeInfo() override; - KioskStatus kiosk_status; + // Gets the KioskModeInfo for |extension|, or NULL if none was + // specified. + static KioskModeInfo* Get(const Extension* extension); // Whether the extension or app is enabled for app kiosk mode. static bool IsKioskEnabled(const Extension* extension); // Whether the extension or app should only be available in kiosk mode. static bool IsKioskOnly(const Extension* extension); + + // Returns true if |extension| declares kiosk secondary apps. + static bool HasSecondaryApps(const Extension* extension); + + KioskStatus kiosk_status; + + // The IDs of the kiosk secondary apps. + const std::vector<std::string> secondary_app_ids; }; // 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 new file mode 100644 index 0000000..9e42c18 --- /dev/null +++ b/extensions/common/manifest_handlers/kiosk_mode_info_unittest.cc @@ -0,0 +1,35 @@ +// Copyright 2015 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 "extensions/common/manifest_constants.h" +#include "extensions/common/manifest_handlers/kiosk_mode_info.h" +#include "extensions/common/manifest_test.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace extensions { + +using KioskModeInfoManifestTest = ManifestTest; + +TEST_F(KioskModeInfoManifestTest, NoSecondaryApps) { + scoped_refptr<Extension> extension( + LoadAndExpectSuccess("kiosk_secondary_app_no_secondary_app.json")); + EXPECT_FALSE(KioskModeInfo::HasSecondaryApps(extension.get())); +} + +TEST_F(KioskModeInfoManifestTest, MultipleSecondaryApps) { + const std::string expected_ids[] = { + "fiehokkcgaojmbhfhlpiheggjhaedjoc", + "ihplaomghjbeafnpnjkhppmfpnmdihgd"}; + scoped_refptr<Extension> extension( + LoadAndExpectSuccess("kiosk_secondary_app_multi_apps.json")); + EXPECT_TRUE(KioskModeInfo::HasSecondaryApps(extension.get())); + KioskModeInfo* info = KioskModeInfo::Get(extension.get()); + EXPECT_NE(nullptr, info); + std::vector<std::string> parsed_ids(info->secondary_app_ids); + std::sort(parsed_ids.begin(), parsed_ids.end()); + EXPECT_TRUE( + std::equal(parsed_ids.begin(), parsed_ids.end(), expected_ids)); +} + +} // namespace extensions |