Chromium Code Reviews| Index: extensions/common/manifest_handlers/kiosk_secondary_apps_info.cc |
| diff --git a/extensions/common/manifest_handlers/kiosk_secondary_apps_info.cc b/extensions/common/manifest_handlers/kiosk_secondary_apps_info.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c05e2f697ebea2d912b41682ee6a4730e70fead8 |
| --- /dev/null |
| +++ b/extensions/common/manifest_handlers/kiosk_secondary_apps_info.cc |
| @@ -0,0 +1,94 @@ |
| +// 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_handlers/kiosk_secondary_apps_info.h" |
| + |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/strings/string16.h" |
| +#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" |
| +#include "tools/json_schema_compiler/util.h" |
| + |
| +namespace extensions { |
| + |
| +namespace keys = manifest_keys; |
| + |
| +using api::extensions_manifest_types::KioskSecondaryAppsType; |
| + |
| +namespace { |
| + |
| +const char kKioskSecondaryAppInfo[] = "kiosk_secondary_app_info"; |
| + |
| +} // namespace |
| + |
| +KioskSecondaryAppsInfo::KioskSecondaryAppsInfo( |
| + const std::vector<std::string>& app_ids) |
| + : ids(app_ids) {} |
| + |
| +KioskSecondaryAppsInfo::~KioskSecondaryAppsInfo() {} |
| + |
| +// static |
| +bool KioskSecondaryAppsInfo::HaveSecondaryApps(const Extension* extension) { |
| + return KioskSecondaryAppsInfo::Get(extension) != nullptr; |
| +} |
| + |
| +// static |
| +KioskSecondaryAppsInfo* KioskSecondaryAppsInfo::Get( |
| + const Extension* extension) { |
| + return static_cast<KioskSecondaryAppsInfo*>( |
| + extension->GetManifestData(kKioskSecondaryAppInfo)); |
| +} |
| + |
| +// static |
| +scoped_ptr<KioskSecondaryAppsInfo> KioskSecondaryAppsInfo::Create( |
| + Extension* extension, |
| + base::string16* error) { |
| + 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 scoped_ptr<KioskSecondaryAppsInfo>(); |
| + } |
| + |
| + std::vector<linked_ptr<KioskSecondaryAppsType>> id_list; |
| + if (!json_schema_compiler::util::PopulateArrayFromList(*list, &id_list, |
|
not at google - send to devlin
2015/08/31 18:11:52
This shouldn't be needed. It should be possible fo
jennyz
2015/08/31 23:57:25
Done.
|
| + error) || |
| + id_list.empty()) { |
| + return scoped_ptr<KioskSecondaryAppsInfo>(); |
| + } |
| + |
| + std::vector<std::string> ids; |
| + for (const auto& it : id_list) |
| + ids.push_back(it->id); |
| + return make_scoped_ptr(new KioskSecondaryAppsInfo(ids)); |
| +} |
| + |
| +KioskSecondaryAppsHandler::KioskSecondaryAppsHandler() {} |
| + |
| +KioskSecondaryAppsHandler::~KioskSecondaryAppsHandler() {} |
| + |
| +bool KioskSecondaryAppsHandler::Parse(Extension* extension, |
| + base::string16* error) { |
| + // Kiosk secondary apps key is optional. |
| + if (!extension->manifest()->HasKey(keys::kKioskSecondaryApps)) { |
| + return true; |
| + } |
|
not at google - send to devlin
2015/08/31 18:11:52
This isn't actually needed because the code will o
jennyz
2015/08/31 23:57:25
Acknowledged.
|
| + |
| + scoped_ptr<KioskSecondaryAppsInfo> info = |
| + KioskSecondaryAppsInfo::Create(extension, error); |
| + if (!info) |
| + return false; |
| + extension->SetManifestData(kKioskSecondaryAppInfo, info.release()); |
| + return true; |
| +} |
| + |
| +const std::vector<std::string> KioskSecondaryAppsHandler::Keys() const { |
| + return SingleKey(keys::kKioskSecondaryApps); |
| +} |
| + |
| +} // namespace extensions |