OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/common/extensions/extension_messages.h" | 5 #include "chrome/common/extensions/extension_messages.h" |
6 | 6 |
7 #include "chrome/common/extensions/extension.h" | 7 #include "chrome/common/extensions/extension.h" |
8 #include "chrome/common/extensions/extension_constants.h" | 8 #include "chrome/common/extensions/extension_constants.h" |
9 #include "chrome/common/extensions/permissions/permissions_data.h" | 9 #include "chrome/common/extensions/permissions/permissions_data.h" |
10 #include "content/public/common/common_param_traits.h" | 10 #include "content/public/common/common_param_traits.h" |
11 #include "extensions/common/manifest.h" | 11 #include "extensions/common/manifest.h" |
| 12 #include "extensions/common/manifest_handler.h" |
12 #include "extensions/common/permissions/permissions_info.h" | 13 #include "extensions/common/permissions/permissions_info.h" |
13 | 14 |
14 using extensions::APIPermission; | 15 using extensions::APIPermission; |
15 using extensions::APIPermissionInfo; | 16 using extensions::APIPermissionInfo; |
16 using extensions::APIPermissionMap; | |
17 using extensions::APIPermissionSet; | 17 using extensions::APIPermissionSet; |
18 using extensions::Extension; | 18 using extensions::Extension; |
19 using extensions::Manifest; | 19 using extensions::Manifest; |
| 20 using extensions::ManifestHandler; |
| 21 using extensions::ManifestPermission; |
| 22 using extensions::ManifestPermissionSet; |
20 using extensions::PermissionSet; | 23 using extensions::PermissionSet; |
21 using extensions::URLPatternSet; | 24 using extensions::URLPatternSet; |
22 | 25 |
23 ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params() | 26 ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params() |
24 : location(Manifest::INVALID_LOCATION), | 27 : location(Manifest::INVALID_LOCATION), |
25 creation_flags(Extension::NO_FLAGS){} | 28 creation_flags(Extension::NO_FLAGS){} |
26 | 29 |
27 ExtensionMsg_Loaded_Params::~ExtensionMsg_Loaded_Params() {} | 30 ExtensionMsg_Loaded_Params::~ExtensionMsg_Loaded_Params() {} |
28 | 31 |
29 ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params( | 32 ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params( |
30 const Extension* extension) | 33 const Extension* extension) |
31 : manifest(extension->manifest()->value()->DeepCopy()), | 34 : manifest(extension->manifest()->value()->DeepCopy()), |
32 location(extension->location()), | 35 location(extension->location()), |
33 path(extension->path()), | 36 path(extension->path()), |
34 apis(extension->GetActivePermissions()->apis()), | 37 apis(extension->GetActivePermissions()->apis()), |
| 38 manifest_permissions( |
| 39 extension->GetActivePermissions()->manifest_permissions()), |
35 explicit_hosts(extension->GetActivePermissions()->explicit_hosts()), | 40 explicit_hosts(extension->GetActivePermissions()->explicit_hosts()), |
36 scriptable_hosts(extension->GetActivePermissions()->scriptable_hosts()), | 41 scriptable_hosts(extension->GetActivePermissions()->scriptable_hosts()), |
37 id(extension->id()), | 42 id(extension->id()), |
38 creation_flags(extension->creation_flags()) { | 43 creation_flags(extension->creation_flags()) { |
39 } | 44 } |
40 | 45 |
41 scoped_refptr<Extension> ExtensionMsg_Loaded_Params::ConvertToExtension( | 46 scoped_refptr<Extension> ExtensionMsg_Loaded_Params::ConvertToExtension( |
42 std::string* error) const { | 47 std::string* error) const { |
43 scoped_refptr<Extension> extension = | 48 scoped_refptr<Extension> extension = |
44 Extension::Create(path, location, *manifest, creation_flags, error); | 49 Extension::Create(path, location, *manifest, creation_flags, error); |
45 if (extension.get()) { | 50 if (extension.get()) { |
46 extensions::PermissionsData::SetActivePermissions( | 51 extensions::PermissionsData::SetActivePermissions( |
47 extension.get(), | 52 extension.get(), |
48 new PermissionSet(apis, explicit_hosts, scriptable_hosts)); | 53 new PermissionSet(apis, manifest_permissions, |
| 54 explicit_hosts, scriptable_hosts)); |
49 } | 55 } |
50 return extension; | 56 return extension; |
51 } | 57 } |
52 | 58 |
53 namespace IPC { | 59 namespace IPC { |
54 | 60 |
55 template <> | 61 template <> |
56 struct ParamTraits<Manifest::Location> { | 62 struct ParamTraits<Manifest::Location> { |
57 typedef Manifest::Location param_type; | 63 typedef Manifest::Location param_type; |
58 static void Write(Message* m, const param_type& p) { | 64 static void Write(Message* m, const param_type& p) { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 r->insert(p.release()); | 182 r->insert(p.release()); |
177 } | 183 } |
178 return true; | 184 return true; |
179 } | 185 } |
180 | 186 |
181 void ParamTraits<APIPermissionSet>::Log( | 187 void ParamTraits<APIPermissionSet>::Log( |
182 const param_type& p, std::string* l) { | 188 const param_type& p, std::string* l) { |
183 LogParam(p.map(), l); | 189 LogParam(p.map(), l); |
184 } | 190 } |
185 | 191 |
| 192 void ParamTraits<ManifestPermissionSet>::Write( |
| 193 Message* m, const param_type& p) { |
| 194 ManifestPermissionSet::const_iterator it = p.begin(); |
| 195 const ManifestPermissionSet::const_iterator end = p.end(); |
| 196 WriteParam(m, p.size()); |
| 197 for (; it != end; ++it) { |
| 198 WriteParam(m, it->name()); |
| 199 it->Write(m); |
| 200 } |
| 201 } |
| 202 |
| 203 bool ParamTraits<ManifestPermissionSet>::Read( |
| 204 const Message* m, PickleIterator* iter, param_type* r) { |
| 205 size_t size; |
| 206 if (!ReadParam(m, iter, &size)) |
| 207 return false; |
| 208 for (size_t i = 0; i < size; ++i) { |
| 209 std::string name; |
| 210 if (!ReadParam(m, iter, &name)) |
| 211 return false; |
| 212 scoped_ptr<ManifestPermission> p(ManifestHandler::CreatePermission(name)); |
| 213 if (!p) |
| 214 return false; |
| 215 if (!p->Read(m, iter)) |
| 216 return false; |
| 217 r->insert(p.release()); |
| 218 } |
| 219 return true; |
| 220 } |
| 221 |
| 222 void ParamTraits<ManifestPermissionSet>::Log( |
| 223 const param_type& p, std::string* l) { |
| 224 LogParam(p.map(), l); |
| 225 } |
| 226 |
186 void ParamTraits<ExtensionMsg_Loaded_Params>::Write(Message* m, | 227 void ParamTraits<ExtensionMsg_Loaded_Params>::Write(Message* m, |
187 const param_type& p) { | 228 const param_type& p) { |
188 WriteParam(m, p.location); | 229 WriteParam(m, p.location); |
189 WriteParam(m, p.path); | 230 WriteParam(m, p.path); |
190 WriteParam(m, *(p.manifest)); | 231 WriteParam(m, *(p.manifest)); |
191 WriteParam(m, p.creation_flags); | 232 WriteParam(m, p.creation_flags); |
192 WriteParam(m, p.apis); | 233 WriteParam(m, p.apis); |
193 WriteParam(m, p.explicit_hosts); | 234 WriteParam(m, p.explicit_hosts); |
194 WriteParam(m, p.scriptable_hosts); | 235 WriteParam(m, p.scriptable_hosts); |
195 } | 236 } |
(...skipping 10 matching lines...) Expand all Loading... |
206 ReadParam(m, iter, &p->explicit_hosts) && | 247 ReadParam(m, iter, &p->explicit_hosts) && |
207 ReadParam(m, iter, &p->scriptable_hosts); | 248 ReadParam(m, iter, &p->scriptable_hosts); |
208 } | 249 } |
209 | 250 |
210 void ParamTraits<ExtensionMsg_Loaded_Params>::Log(const param_type& p, | 251 void ParamTraits<ExtensionMsg_Loaded_Params>::Log(const param_type& p, |
211 std::string* l) { | 252 std::string* l) { |
212 l->append(p.id); | 253 l->append(p.id); |
213 } | 254 } |
214 | 255 |
215 } // namespace IPC | 256 } // namespace IPC |
OLD | NEW |