| Index: chrome/common/extensions/manifest_handlers/kiosk_mode_info.cc
|
| diff --git a/chrome/common/extensions/manifest_handlers/kiosk_mode_info.cc b/chrome/common/extensions/manifest_handlers/kiosk_mode_info.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2957f3314bbabc02b83e365d954d6543e87d8590
|
| --- /dev/null
|
| +++ b/chrome/common/extensions/manifest_handlers/kiosk_mode_info.cc
|
| @@ -0,0 +1,94 @@
|
| +// Copyright (c) 2013 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 "chrome/common/extensions/manifest_handlers/kiosk_mode_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/manifest_constants.h"
|
| +
|
| +namespace extensions {
|
| +
|
| +namespace keys = manifest_keys;
|
| +
|
| +KioskEnabledInfo::KioskEnabledInfo(bool is_kiosk_enabled)
|
| + : kiosk_enabled(is_kiosk_enabled) {
|
| +}
|
| +
|
| +KioskEnabledInfo::~KioskEnabledInfo() {
|
| +}
|
| +
|
| +// static
|
| +bool KioskEnabledInfo::IsKioskEnabled(const Extension* extension) {
|
| + KioskEnabledInfo* info = static_cast<KioskEnabledInfo*>(
|
| + extension->GetManifestData(keys::kKioskEnabled));
|
| + return info ? info->kiosk_enabled : false;
|
| +}
|
| +
|
| +KioskOnlyInfo::KioskOnlyInfo(bool is_kiosk_only)
|
| + : kiosk_only(is_kiosk_only) {
|
| +}
|
| +
|
| +KioskOnlyInfo::~KioskOnlyInfo() {
|
| +}
|
| +
|
| +// static
|
| +bool KioskOnlyInfo::IsKioskOnly(const Extension* extension) {
|
| + KioskOnlyInfo* info = static_cast<KioskOnlyInfo*>(
|
| + extension->GetManifestData(keys::kKioskOnly));
|
| + return info ? info->kiosk_only : false;
|
| +}
|
| +
|
| +KioskModeHandler::KioskModeHandler() {
|
| + supported_keys_.push_back(keys::kKioskEnabled);
|
| + supported_keys_.push_back(keys::kKioskOnly);
|
| +}
|
| +
|
| +KioskModeHandler::~KioskModeHandler() {
|
| +}
|
| +
|
| +bool KioskModeHandler::Parse(Extension* extension, string16* error) {
|
| + const Manifest* manifest = extension->manifest();
|
| + DCHECK(manifest->HasKey(keys::kKioskEnabled) ||
|
| + manifest->HasKey(keys::kKioskOnly));
|
| +
|
| + bool kiosk_enabled = false;
|
| + if (manifest->HasKey(keys::kKioskEnabled) &&
|
| + !manifest->GetBoolean(keys::kKioskEnabled, &kiosk_enabled)) {
|
| + *error = ASCIIToUTF16(manifest_errors::kInvalidKioskEnabled);
|
| + return false;
|
| + }
|
| +
|
| + bool kiosk_only = false;
|
| + if (manifest->HasKey(keys::kKioskOnly) &&
|
| + !manifest->GetBoolean(keys::kKioskOnly, &kiosk_only)) {
|
| + *error = ASCIIToUTF16(manifest_errors::kInvalidKioskOnly);
|
| + return false;
|
| + }
|
| +
|
| + if (kiosk_only && !kiosk_enabled) {
|
| + *error = ASCIIToUTF16(manifest_errors::kInvalidKioskOnlyButNotEnabled);
|
| + return false;
|
| + }
|
| +
|
| + // All other use cases should be already filtered out by manifest feature
|
| + // checks.
|
| + DCHECK(extension->is_platform_app());
|
| +
|
| + extension->SetManifestData(keys::kKioskEnabled,
|
| + new KioskEnabledInfo(kiosk_enabled));
|
| + extension->SetManifestData(keys::kKioskOnly,
|
| + new KioskOnlyInfo(kiosk_only));
|
| +
|
| + return true;
|
| +}
|
| +
|
| +const std::vector<std::string> KioskModeHandler::Keys() const {
|
| + return supported_keys_;
|
| +}
|
| +
|
| +} // namespace extensions
|
|
|