1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "extensions/common/manifest_handlers/kiosk_mode_info.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/string16.h"
9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "base/values.h"
12 #include "extensions/common/manifest_constants.h"
14 namespace extensions
{
16 namespace keys
= manifest_keys
;
18 KioskModeInfo::KioskModeInfo(KioskStatus kiosk_status
)
19 : kiosk_status(kiosk_status
) {
22 KioskModeInfo::~KioskModeInfo() {
26 bool KioskModeInfo::IsKioskEnabled(const Extension
* extension
) {
27 KioskModeInfo
* info
= static_cast<KioskModeInfo
*>(
28 extension
->GetManifestData(keys::kKioskMode
));
29 return info
? info
->kiosk_status
!= NONE
: false;
33 bool KioskModeInfo::IsKioskOnly(const Extension
* extension
) {
34 KioskModeInfo
* info
= static_cast<KioskModeInfo
*>(
35 extension
->GetManifestData(keys::kKioskMode
));
36 return info
? info
->kiosk_status
== ONLY
: false;
39 KioskModeHandler::KioskModeHandler() {
40 supported_keys_
.push_back(keys::kKioskEnabled
);
41 supported_keys_
.push_back(keys::kKioskOnly
);
44 KioskModeHandler::~KioskModeHandler() {
47 bool KioskModeHandler::Parse(Extension
* extension
, base::string16
* error
) {
48 const Manifest
* manifest
= extension
->manifest();
49 DCHECK(manifest
->HasKey(keys::kKioskEnabled
) ||
50 manifest
->HasKey(keys::kKioskOnly
));
52 bool kiosk_enabled
= false;
53 if (manifest
->HasKey(keys::kKioskEnabled
) &&
54 !manifest
->GetBoolean(keys::kKioskEnabled
, &kiosk_enabled
)) {
55 *error
= base::ASCIIToUTF16(manifest_errors::kInvalidKioskEnabled
);
59 bool kiosk_only
= false;
60 if (manifest
->HasKey(keys::kKioskOnly
) &&
61 !manifest
->GetBoolean(keys::kKioskOnly
, &kiosk_only
)) {
62 *error
= base::ASCIIToUTF16(manifest_errors::kInvalidKioskOnly
);
66 if (kiosk_only
&& !kiosk_enabled
) {
67 *error
= base::ASCIIToUTF16(
68 manifest_errors::kInvalidKioskOnlyButNotEnabled
);
72 // All other use cases should be already filtered out by manifest feature
74 DCHECK(extension
->is_platform_app());
76 KioskModeInfo::KioskStatus kiosk_status
= KioskModeInfo::NONE
;
78 kiosk_status
= kiosk_only
? KioskModeInfo::ONLY
: KioskModeInfo::ENABLED
;
80 extension
->SetManifestData(keys::kKioskMode
,
81 new KioskModeInfo(kiosk_status
));
86 const std::vector
<std::string
> KioskModeHandler::Keys() const {
87 return supported_keys_
;
90 } // namespace extensions