Properly attach InfoBarContainer when it is swapped to a new WebContents
[chromium-blink-merge.git] / chrome / common / extensions / api / supervised_user_private / supervised_user_handler.cc
blob486ed723180d77ecaca793f0eadf7568a7466367
1 // Copyright 2014 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 "chrome/common/extensions/api/supervised_user_private/supervised_user_handler.h"
7 #include "base/lazy_instance.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "base/values.h"
11 #include "extensions/common/error_utils.h"
12 #include "extensions/common/manifest_constants.h"
14 namespace extensions {
16 namespace keys = manifest_keys;
18 SupervisedUserInfo::SupervisedUserInfo() {
21 SupervisedUserInfo::~SupervisedUserInfo() {
24 // static
25 bool SupervisedUserInfo::IsContentPack(const Extension* extension) {
26 SupervisedUserInfo* info = static_cast<SupervisedUserInfo*>(
27 extension->GetManifestData(keys::kContentPack));
28 return info ? !info->site_list.empty() : false;
31 // static
32 ExtensionResource SupervisedUserInfo::GetContentPackSiteList(
33 const Extension* extension) {
34 SupervisedUserInfo* info = static_cast<SupervisedUserInfo*>(
35 extension->GetManifestData(keys::kContentPack));
36 return info && !info->site_list.empty()
37 ? extension->GetResource(info->site_list)
38 : ExtensionResource();
41 SupervisedUserHandler::SupervisedUserHandler() {
44 SupervisedUserHandler::~SupervisedUserHandler() {
47 bool SupervisedUserHandler::Parse(Extension* extension, base::string16* error) {
48 if (!extension->manifest()->HasKey(keys::kContentPack))
49 return true;
51 scoped_ptr<SupervisedUserInfo> info(new SupervisedUserInfo);
52 const base::DictionaryValue* content_pack_value = NULL;
53 if (!extension->manifest()->GetDictionary(keys::kContentPack,
54 &content_pack_value)) {
55 *error = base::ASCIIToUTF16(manifest_errors::kInvalidContentPack);
56 return false;
59 if (!LoadSites(info.get(), content_pack_value, error) ||
60 !LoadConfigurations(info.get(), content_pack_value, error)) {
61 return false;
64 extension->SetManifestData(keys::kContentPack, info.release());
65 return true;
68 const std::vector<std::string> SupervisedUserHandler::Keys() const {
69 return SingleKey(keys::kContentPack);
72 bool SupervisedUserHandler::LoadSites(
73 SupervisedUserInfo* info,
74 const base::DictionaryValue* content_pack_value,
75 base::string16* error) {
76 if (!content_pack_value->HasKey(keys::kContentPackSites))
77 return true;
79 base::FilePath::StringType site_list_string;
80 if (!content_pack_value->GetString(keys::kContentPackSites,
81 &site_list_string)) {
82 *error = base::ASCIIToUTF16(manifest_errors::kInvalidContentPackSites);
83 return false;
86 info->site_list = base::FilePath(site_list_string);
88 return true;
91 bool SupervisedUserHandler::LoadConfigurations(
92 SupervisedUserInfo* info,
93 const base::DictionaryValue* content_pack_value,
94 base::string16* error) {
95 NOTIMPLEMENTED();
96 return true;
99 } // namespace extensions