Chromium Code Reviews| 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/manifest_constants.h" | |
| 13 | |
| 14 namespace extensions { | |
| 15 | |
| 16 namespace keys = manifest_keys; | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 const char kKioskSecondaryAppInfo[] = "kiosk_secondary_app_info"; | |
| 21 const char kAppId[] = "id"; | |
| 22 } | |
|
xiyuan
2015/08/26 18:16:17
nit: insert an empty line before. And append "// n
jennyz
2015/08/28 18:24:08
Done.
| |
| 23 | |
| 24 KioskSecondaryAppsInfo::KioskSecondaryAppsInfo( | |
| 25 const std::vector<std::string>& app_ids) | |
| 26 : ids(app_ids) {} | |
| 27 | |
| 28 KioskSecondaryAppsInfo::~KioskSecondaryAppsInfo() {} | |
| 29 | |
| 30 // static | |
| 31 bool KioskSecondaryAppsInfo::HaveSecondaryApps(const Extension* extension) { | |
| 32 return KioskSecondaryAppsInfo::Get(extension) != nullptr; | |
| 33 } | |
| 34 | |
| 35 // static | |
| 36 KioskSecondaryAppsInfo* KioskSecondaryAppsInfo::Get( | |
| 37 const Extension* extension) { | |
| 38 return static_cast<KioskSecondaryAppsInfo*>( | |
| 39 extension->GetManifestData(kKioskSecondaryAppInfo)); | |
| 40 } | |
| 41 | |
| 42 KioskSecondaryAppsHandler::KioskSecondaryAppsHandler() {} | |
| 43 | |
| 44 KioskSecondaryAppsHandler::~KioskSecondaryAppsHandler() {} | |
| 45 | |
| 46 bool KioskSecondaryAppsHandler::Parse(Extension* extension, | |
| 47 base::string16* error) { | |
|
not at google - send to devlin
2015/08/26 17:53:59
It's easier to use a manifest type than hand-writi
jennyz
2015/08/28 18:24:08
Yes, I applied the patch you suggested to tools/js
| |
| 48 // Kiosk secondary apps key is optional. | |
| 49 if (!extension->manifest()->HasKey(keys::kKioskSecondaryApps)) { | |
| 50 return true; | |
| 51 } | |
| 52 | |
| 53 const base::Value* secondary_app_ids = nullptr; | |
| 54 if (!extension->manifest()->Get(keys::kKioskSecondaryApps, | |
| 55 &secondary_app_ids)) { | |
| 56 *error = base::ASCIIToUTF16(manifest_errors::kInvalidKioskSecondaryApps); | |
| 57 return false; | |
| 58 } | |
| 59 | |
| 60 const base::ListValue* list = nullptr; | |
| 61 if (!secondary_app_ids->GetAsList(&list)) { | |
| 62 *error = base::ASCIIToUTF16(manifest_errors::kInvalidKioskSecondaryApps); | |
| 63 return false; | |
| 64 } | |
| 65 | |
| 66 std::vector<std::string> app_ids; | |
| 67 for (size_t i = 0; i < list->GetSize(); ++i) { | |
| 68 const base::DictionaryValue* app_id_entry = nullptr; | |
| 69 if (!list->GetDictionary(i, &app_id_entry)) { | |
| 70 *error = base::ASCIIToUTF16( | |
| 71 manifest_errors::kInvalidKioskSecondaryAppsBadAppEntry); | |
| 72 return false; | |
| 73 } | |
| 74 std::string app_id; | |
| 75 if (!app_id_entry->GetStringWithoutPathExpansion(kAppId, &app_id)) { | |
| 76 *error = base::ASCIIToUTF16( | |
| 77 manifest_errors::kInvalidKioskSecondaryAppsBadAppId); | |
| 78 return false; | |
| 79 } | |
| 80 app_ids.push_back(app_id); | |
| 81 } | |
| 82 if (!app_ids.empty()) { | |
| 83 extension->SetManifestData(kKioskSecondaryAppInfo, | |
| 84 new KioskSecondaryAppsInfo(app_ids)); | |
| 85 } | |
| 86 return true; | |
| 87 } | |
| 88 | |
| 89 const std::vector<std::string> KioskSecondaryAppsHandler::Keys() const { | |
| 90 return SingleKey(keys::kKioskSecondaryApps); | |
| 91 } | |
| 92 | |
| 93 } // namespace extensions | |
| OLD | NEW |