Ignore non-active fullscreen windows for shelf state.
[chromium-blink-merge.git] / extensions / common / manifest_handlers / kiosk_mode_info.cc
blob92f406b01293a052c8d3563f60b76e80853c3fe4
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() {
25 // static
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;
32 // static
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, 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 = ASCIIToUTF16(manifest_errors::kInvalidKioskEnabled);
56 return false;
59 bool kiosk_only = false;
60 if (manifest->HasKey(keys::kKioskOnly) &&
61 !manifest->GetBoolean(keys::kKioskOnly, &kiosk_only)) {
62 *error = ASCIIToUTF16(manifest_errors::kInvalidKioskOnly);
63 return false;
66 if (kiosk_only && !kiosk_enabled) {
67 *error = ASCIIToUTF16(manifest_errors::kInvalidKioskOnlyButNotEnabled);
68 return false;
71 // All other use cases should be already filtered out by manifest feature
72 // checks.
73 DCHECK(extension->is_platform_app());
75 KioskModeInfo::KioskStatus kiosk_status = KioskModeInfo::NONE;
76 if (kiosk_enabled)
77 kiosk_status = kiosk_only ? KioskModeInfo::ONLY : KioskModeInfo::ENABLED;
79 extension->SetManifestData(keys::kKioskMode,
80 new KioskModeInfo(kiosk_status));
82 return true;
85 const std::vector<std::string> KioskModeHandler::Keys() const {
86 return supported_keys_;
89 } // namespace extensions