1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "extensions/common/manifest_handlers/requirements_info.h"
#include "base/lazy_instance.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "extensions/common/error_utils.h"
#include "extensions/common/manifest_constants.h"
namespace extensions {
namespace keys = manifest_keys;
namespace errors = manifest_errors;
RequirementsInfo::RequirementsInfo(const Manifest* manifest)
: webgl(false),
npapi(false),
window_shape(false) {
// Before parsing requirements from the manifest, automatically default the
// NPAPI plugin requirement based on whether it includes NPAPI plugins.
const base::ListValue* list_value = NULL;
npapi = manifest->GetList(keys::kPlugins, &list_value) &&
!list_value->empty();
}
RequirementsInfo::~RequirementsInfo() {
}
// static
const RequirementsInfo& RequirementsInfo::GetRequirements(
const Extension* extension) {
RequirementsInfo* info = static_cast<RequirementsInfo*>(
extension->GetManifestData(keys::kRequirements));
// We should be guaranteed to have requirements, since they are parsed for all
// extension types.
CHECK(info);
return *info;
}
RequirementsHandler::RequirementsHandler() {
}
RequirementsHandler::~RequirementsHandler() {
}
const std::vector<std::string> RequirementsHandler::PrerequisiteKeys() const {
return SingleKey(keys::kPlugins);
}
const std::vector<std::string> RequirementsHandler::Keys() const {
return SingleKey(keys::kRequirements);
}
bool RequirementsHandler::AlwaysParseForType(Manifest::Type type) const {
return true;
}
bool RequirementsHandler::Parse(Extension* extension, base::string16* error) {
scoped_ptr<RequirementsInfo> requirements(
new RequirementsInfo(extension->manifest()));
if (!extension->manifest()->HasKey(keys::kRequirements)) {
extension->SetManifestData(keys::kRequirements, requirements.release());
return true;
}
const base::DictionaryValue* requirements_value = NULL;
if (!extension->manifest()->GetDictionary(keys::kRequirements,
&requirements_value)) {
*error = base::ASCIIToUTF16(errors::kInvalidRequirements);
return false;
}
for (base::DictionaryValue::Iterator iter(*requirements_value);
!iter.IsAtEnd();
iter.Advance()) {
const base::DictionaryValue* requirement_value;
if (!iter.value().GetAsDictionary(&requirement_value)) {
*error = ErrorUtils::FormatErrorMessageUTF16(
errors::kInvalidRequirement, iter.key());
return false;
}
if (iter.key() == "plugins") {
for (base::DictionaryValue::Iterator plugin_iter(*requirement_value);
!plugin_iter.IsAtEnd(); plugin_iter.Advance()) {
bool plugin_required = false;
if (!plugin_iter.value().GetAsBoolean(&plugin_required)) {
*error = ErrorUtils::FormatErrorMessageUTF16(
errors::kInvalidRequirement, iter.key());
return false;
}
if (plugin_iter.key() == "npapi") {
requirements->npapi = plugin_required;
} else {
*error = ErrorUtils::FormatErrorMessageUTF16(
errors::kInvalidRequirement, iter.key());
return false;
}
}
} else if (iter.key() == "3D") {
const base::ListValue* features = NULL;
if (!requirement_value->GetListWithoutPathExpansion("features",
&features) ||
!features) {
*error = ErrorUtils::FormatErrorMessageUTF16(
errors::kInvalidRequirement, iter.key());
return false;
}
for (base::ListValue::const_iterator feature_iter = features->begin();
feature_iter != features->end(); ++feature_iter) {
std::string feature;
if ((*feature_iter)->GetAsString(&feature)) {
if (feature == "webgl") {
requirements->webgl = true;
} else if (feature == "css3d") {
// css3d is always available, so no check is needed, but no error is
// generated.
} else {
*error = ErrorUtils::FormatErrorMessageUTF16(
errors::kInvalidRequirement, iter.key());
return false;
}
}
}
} else if (iter.key() == "window") {
for (base::DictionaryValue::Iterator feature_iter(*requirement_value);
!feature_iter.IsAtEnd(); feature_iter.Advance()) {
bool feature_required = false;
if (!feature_iter.value().GetAsBoolean(&feature_required)) {
*error = ErrorUtils::FormatErrorMessageUTF16(
errors::kInvalidRequirement, iter.key());
return false;
}
if (feature_iter.key() == "shape") {
requirements->window_shape = feature_required;
} else {
*error = ErrorUtils::FormatErrorMessageUTF16(
errors::kInvalidRequirement, iter.key());
return false;
}
}
} else {
*error = base::ASCIIToUTF16(errors::kInvalidRequirements);
return false;
}
}
extension->SetManifestData(keys::kRequirements, requirements.release());
return true;
}
} // namespace extensions
|