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