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. 4 5 #include "extensions/common/manifest_handlers/kiosk_mode_info.h" 6 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" 13 14 namespace extensions { 15 16 namespace keys = manifest_keys; 17 18 KioskModeInfo::KioskModeInfo(KioskStatus kiosk_status) 19 : kiosk_status(kiosk_status) { 20 } 21 22 KioskModeInfo::~KioskModeInfo() { 23 } 24 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; 30 } 31 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; 37 } 38 39 KioskModeHandler::KioskModeHandler() { 40 supported_keys_.push_back(keys::kKioskEnabled); 41 supported_keys_.push_back(keys::kKioskOnly); 42 } 43 44 KioskModeHandler::~KioskModeHandler() { 45 } 46 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)); 51 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); 56 return false; 57 } 58 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); 63 return false; 64 } 65 66 if (kiosk_only && !kiosk_enabled) { 67 *error = base::ASCIIToUTF16( 68 manifest_errors::kInvalidKioskOnlyButNotEnabled); 69 return false; 70 } 71 72 // All other use cases should be already filtered out by manifest feature 73 // checks. 74 DCHECK(extension->is_platform_app()); 75 76 KioskModeInfo::KioskStatus kiosk_status = KioskModeInfo::NONE; 77 if (kiosk_enabled) 78 kiosk_status = kiosk_only ? KioskModeInfo::ONLY : KioskModeInfo::ENABLED; 79 80 extension->SetManifestData(keys::kKioskMode, 81 new KioskModeInfo(kiosk_status)); 82 83 return true; 84 } 85 86 const std::vector<std::string> KioskModeHandler::Keys() const { 87 return supported_keys_; 88 } 89 90 } // namespace extensions 91