OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "extensions/common/manifest_handlers/kiosk_mode_info.h" | 5 #include "extensions/common/manifest_handlers/kiosk_mode_info.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
9 #include "base/strings/string_number_conversions.h" | |
10 #include "base/strings/string_tokenizer.h" | |
9 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
11 #include "base/values.h" | 13 #include "base/values.h" |
12 #include "extensions/common/api/extensions_manifest_types.h" | 14 #include "extensions/common/api/extensions_manifest_types.h" |
13 #include "extensions/common/manifest_constants.h" | 15 #include "extensions/common/manifest_constants.h" |
14 | 16 |
17 namespace { | |
18 | |
19 // Whether the given |version| is a valid platform version. The acceptable | |
20 // format is major[.minor[.micro]], where major, minor and micro are decimals. | |
21 bool IsValidPlatformVersion(const std::string& version) { | |
22 int count = 0; | |
23 | |
24 base::StringTokenizer tokenizer(version, "."); | |
25 while (tokenizer.GetNext()) { | |
26 int version_number; | |
27 if (!base::StringToInt( | |
28 base::StringPiece(tokenizer.token_begin(), tokenizer.token_end()), | |
29 &version_number)) { | |
30 return false; | |
31 } | |
32 ++count; | |
33 if (count > 3) | |
34 return false; | |
35 } | |
36 | |
37 return count > 0; | |
38 } | |
asargent_no_longer_on_chrome
2016/01/15 23:27:33
could you just use base::Version for this instead
xiyuan
2016/01/19 23:40:52
Good call. Done.
| |
39 | |
40 } // namespace | |
41 | |
15 namespace extensions { | 42 namespace extensions { |
16 | 43 |
17 namespace keys = manifest_keys; | 44 namespace keys = manifest_keys; |
18 | 45 |
19 using api::extensions_manifest_types::KioskSecondaryAppsType; | 46 using api::extensions_manifest_types::KioskSecondaryAppsType; |
20 | 47 |
21 KioskModeInfo::KioskModeInfo(KioskStatus kiosk_status, | 48 KioskModeInfo::KioskModeInfo(KioskStatus kiosk_status, |
22 const std::vector<std::string>& secondary_app_ids) | 49 const std::vector<std::string>& secondary_app_ids, |
23 : kiosk_status(kiosk_status), secondary_app_ids(secondary_app_ids) {} | 50 const std::string& required_platform_version) |
51 : kiosk_status(kiosk_status), | |
52 secondary_app_ids(secondary_app_ids), | |
53 required_platform_version(required_platform_version) {} | |
24 | 54 |
25 KioskModeInfo::~KioskModeInfo() { | 55 KioskModeInfo::~KioskModeInfo() { |
26 } | 56 } |
27 | 57 |
28 // static | 58 // static |
29 KioskModeInfo* KioskModeInfo::Get(const Extension* extension) { | 59 KioskModeInfo* KioskModeInfo::Get(const Extension* extension) { |
30 return static_cast<KioskModeInfo*>( | 60 return static_cast<KioskModeInfo*>( |
31 extension->GetManifestData(keys::kKioskMode)); | 61 extension->GetManifestData(keys::kKioskMode)); |
32 } | 62 } |
33 | 63 |
(...skipping 12 matching lines...) Expand all Loading... | |
46 // static | 76 // static |
47 bool KioskModeInfo::HasSecondaryApps(const Extension* extension) { | 77 bool KioskModeInfo::HasSecondaryApps(const Extension* extension) { |
48 KioskModeInfo* info = Get(extension); | 78 KioskModeInfo* info = Get(extension); |
49 return info && !info->secondary_app_ids.empty(); | 79 return info && !info->secondary_app_ids.empty(); |
50 } | 80 } |
51 | 81 |
52 KioskModeHandler::KioskModeHandler() { | 82 KioskModeHandler::KioskModeHandler() { |
53 supported_keys_.push_back(keys::kKioskEnabled); | 83 supported_keys_.push_back(keys::kKioskEnabled); |
54 supported_keys_.push_back(keys::kKioskOnly); | 84 supported_keys_.push_back(keys::kKioskOnly); |
55 supported_keys_.push_back(keys::kKioskSecondaryApps); | 85 supported_keys_.push_back(keys::kKioskSecondaryApps); |
86 supported_keys_.push_back(keys::kRequiredPlatformVersion); | |
56 } | 87 } |
57 | 88 |
58 KioskModeHandler::~KioskModeHandler() { | 89 KioskModeHandler::~KioskModeHandler() { |
59 } | 90 } |
60 | 91 |
61 bool KioskModeHandler::Parse(Extension* extension, base::string16* error) { | 92 bool KioskModeHandler::Parse(Extension* extension, base::string16* error) { |
62 const Manifest* manifest = extension->manifest(); | 93 const Manifest* manifest = extension->manifest(); |
63 DCHECK(manifest->HasKey(keys::kKioskEnabled) || | 94 DCHECK(manifest->HasKey(keys::kKioskEnabled) || |
64 manifest->HasKey(keys::kKioskOnly)); | 95 manifest->HasKey(keys::kKioskOnly)); |
65 | 96 |
(...skipping 20 matching lines...) Expand all Loading... | |
86 // All other use cases should be already filtered out by manifest feature | 117 // All other use cases should be already filtered out by manifest feature |
87 // checks. | 118 // checks. |
88 DCHECK(extension->is_platform_app()); | 119 DCHECK(extension->is_platform_app()); |
89 | 120 |
90 KioskModeInfo::KioskStatus kiosk_status = KioskModeInfo::NONE; | 121 KioskModeInfo::KioskStatus kiosk_status = KioskModeInfo::NONE; |
91 if (kiosk_enabled) | 122 if (kiosk_enabled) |
92 kiosk_status = kiosk_only ? KioskModeInfo::ONLY : KioskModeInfo::ENABLED; | 123 kiosk_status = kiosk_only ? KioskModeInfo::ONLY : KioskModeInfo::ENABLED; |
93 | 124 |
94 // Kiosk secondary apps key is optional. | 125 // Kiosk secondary apps key is optional. |
95 std::vector<std::string> ids; | 126 std::vector<std::string> ids; |
96 if (extension->manifest()->HasKey(keys::kKioskSecondaryApps)) { | 127 if (manifest->HasKey(keys::kKioskSecondaryApps)) { |
97 const base::Value* secondary_apps = nullptr; | 128 const base::Value* secondary_apps = nullptr; |
98 const base::ListValue* list = nullptr; | 129 const base::ListValue* list = nullptr; |
99 if (!extension->manifest()->Get(keys::kKioskSecondaryApps, | 130 if (!manifest->Get(keys::kKioskSecondaryApps, &secondary_apps) || |
100 &secondary_apps) || | |
101 !secondary_apps->GetAsList(&list)) { | 131 !secondary_apps->GetAsList(&list)) { |
102 *error = base::ASCIIToUTF16(manifest_errors::kInvalidKioskSecondaryApps); | 132 *error = base::ASCIIToUTF16(manifest_errors::kInvalidKioskSecondaryApps); |
103 return false; | 133 return false; |
104 } | 134 } |
105 | 135 |
106 for (const base::Value* value : *list) { | 136 for (const base::Value* value : *list) { |
107 scoped_ptr<KioskSecondaryAppsType> app = | 137 scoped_ptr<KioskSecondaryAppsType> app = |
108 KioskSecondaryAppsType::FromValue(*value, error); | 138 KioskSecondaryAppsType::FromValue(*value, error); |
109 if (!app) { | 139 if (!app) { |
110 *error = base::ASCIIToUTF16( | 140 *error = base::ASCIIToUTF16( |
111 manifest_errors::kInvalidKioskSecondaryAppsBadAppId); | 141 manifest_errors::kInvalidKioskSecondaryAppsBadAppId); |
112 return false; | 142 return false; |
113 } | 143 } |
114 ids.push_back(app->id); | 144 ids.push_back(app->id); |
115 } | 145 } |
116 } | 146 } |
117 | 147 |
118 extension->SetManifestData(keys::kKioskMode, | 148 // Optional required_platform_version key. |
119 new KioskModeInfo(kiosk_status, ids)); | 149 std::string required_platform_version; |
150 if (manifest->HasKey(keys::kRequiredPlatformVersion) && | |
151 (!manifest->GetString(keys::kRequiredPlatformVersion, | |
152 &required_platform_version) || | |
153 !IsValidPlatformVersion(required_platform_version))) { | |
154 *error = | |
155 base::ASCIIToUTF16(manifest_errors::kInvalidRequiredPlatformVersion); | |
156 return false; | |
157 } | |
158 | |
159 extension->SetManifestData( | |
160 keys::kKioskMode, | |
161 new KioskModeInfo(kiosk_status, ids, required_platform_version)); | |
120 | 162 |
121 return true; | 163 return true; |
122 } | 164 } |
123 | 165 |
124 const std::vector<std::string> KioskModeHandler::Keys() const { | 166 const std::vector<std::string> KioskModeHandler::Keys() const { |
125 return supported_keys_; | 167 return supported_keys_; |
126 } | 168 } |
127 | 169 |
128 } // namespace extensions | 170 } // namespace extensions |
OLD | NEW |