OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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_secondary_apps_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/api/extensions_manifest_types.h" | |
13 #include "extensions/common/manifest_constants.h" | |
14 #include "tools/json_schema_compiler/util.h" | |
15 | |
16 namespace extensions { | |
17 | |
18 namespace keys = manifest_keys; | |
19 | |
20 using api::extensions_manifest_types::KioskSecondaryAppsType; | |
21 | |
22 namespace { | |
23 | |
24 const char kKioskSecondaryAppInfo[] = "kiosk_secondary_app_info"; | |
25 | |
26 } // namespace | |
27 | |
28 KioskSecondaryAppsInfo::KioskSecondaryAppsInfo( | |
29 const std::vector<std::string>& app_ids) | |
30 : ids(app_ids) {} | |
31 | |
32 KioskSecondaryAppsInfo::~KioskSecondaryAppsInfo() {} | |
33 | |
34 // static | |
35 bool KioskSecondaryAppsInfo::HaveSecondaryApps(const Extension* extension) { | |
36 return KioskSecondaryAppsInfo::Get(extension) != nullptr; | |
37 } | |
38 | |
39 // static | |
40 KioskSecondaryAppsInfo* KioskSecondaryAppsInfo::Get( | |
41 const Extension* extension) { | |
42 return static_cast<KioskSecondaryAppsInfo*>( | |
43 extension->GetManifestData(kKioskSecondaryAppInfo)); | |
44 } | |
45 | |
46 // static | |
47 scoped_ptr<KioskSecondaryAppsInfo> KioskSecondaryAppsInfo::Create( | |
48 Extension* extension, | |
49 base::string16* error) { | |
50 const base::Value* secondary_apps = nullptr; | |
51 const base::ListValue* list = nullptr; | |
52 if (!extension->manifest()->Get(keys::kKioskSecondaryApps, &secondary_apps) || | |
53 !secondary_apps->GetAsList(&list)) { | |
54 *error = base::ASCIIToUTF16(manifest_errors::kInvalidKioskSecondaryApps); | |
55 return scoped_ptr<KioskSecondaryAppsInfo>(); | |
56 } | |
57 | |
58 std::vector<linked_ptr<KioskSecondaryAppsType>> id_list; | |
59 if (!json_schema_compiler::util::PopulateArrayFromList(*list, &id_list, | |
not at google - send to devlin
2015/08/31 18:11:52
This shouldn't be needed. It should be possible fo
jennyz
2015/08/31 23:57:25
Done.
| |
60 error) || | |
61 id_list.empty()) { | |
62 return scoped_ptr<KioskSecondaryAppsInfo>(); | |
63 } | |
64 | |
65 std::vector<std::string> ids; | |
66 for (const auto& it : id_list) | |
67 ids.push_back(it->id); | |
68 return make_scoped_ptr(new KioskSecondaryAppsInfo(ids)); | |
69 } | |
70 | |
71 KioskSecondaryAppsHandler::KioskSecondaryAppsHandler() {} | |
72 | |
73 KioskSecondaryAppsHandler::~KioskSecondaryAppsHandler() {} | |
74 | |
75 bool KioskSecondaryAppsHandler::Parse(Extension* extension, | |
76 base::string16* error) { | |
77 // Kiosk secondary apps key is optional. | |
78 if (!extension->manifest()->HasKey(keys::kKioskSecondaryApps)) { | |
79 return true; | |
80 } | |
not at google - send to devlin
2015/08/31 18:11:52
This isn't actually needed because the code will o
jennyz
2015/08/31 23:57:25
Acknowledged.
| |
81 | |
82 scoped_ptr<KioskSecondaryAppsInfo> info = | |
83 KioskSecondaryAppsInfo::Create(extension, error); | |
84 if (!info) | |
85 return false; | |
86 extension->SetManifestData(kKioskSecondaryAppInfo, info.release()); | |
87 return true; | |
88 } | |
89 | |
90 const std::vector<std::string> KioskSecondaryAppsHandler::Keys() const { | |
91 return SingleKey(keys::kKioskSecondaryApps); | |
92 } | |
93 | |
94 } // namespace extensions | |
OLD | NEW |