| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "extensions/common/extension_messages.h" | 5 #include "extensions/common/extension_messages.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 57 |
| 58 ExtensionMsg_Loaded_Params::~ExtensionMsg_Loaded_Params() {} | 58 ExtensionMsg_Loaded_Params::~ExtensionMsg_Loaded_Params() {} |
| 59 | 59 |
| 60 ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params( | 60 ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params( |
| 61 const Extension* extension, | 61 const Extension* extension, |
| 62 bool include_tab_permissions) | 62 bool include_tab_permissions) |
| 63 : manifest(extension->manifest()->value()->DeepCopy()), | 63 : manifest(extension->manifest()->value()->DeepCopy()), |
| 64 location(extension->location()), | 64 location(extension->location()), |
| 65 path(extension->path()), | 65 path(extension->path()), |
| 66 active_permissions(extension->permissions_data()->active_permissions()), | 66 active_permissions(extension->permissions_data()->active_permissions()), |
| 67 withheld_permissions( | 67 withheld_permissions(extension->permissions_data() |
| 68 extension->permissions_data()->withheld_permissions()), | 68 ->withheld_permissions()), |
| 69 policy_blocked_hosts( | |
| 70 extension->permissions_data()->policy_blocked_hosts()), | |
| 71 policy_allowed_hosts( | |
| 72 extension->permissions_data()->policy_allowed_hosts()), | |
| 73 uses_default_policy_blocked_allowed_hosts( | |
| 74 extension->permissions_data()->UsesDefaultPolicyHostRestrictions()), | |
| 75 id(extension->id()), | 69 id(extension->id()), |
| 76 creation_flags(extension->creation_flags()) { | 70 creation_flags(extension->creation_flags()) { |
| 77 if (include_tab_permissions) { | 71 if (include_tab_permissions) { |
| 78 for (const auto& pair : | 72 for (const auto& pair : |
| 79 extension->permissions_data()->tab_specific_permissions()) { | 73 extension->permissions_data()->tab_specific_permissions()) { |
| 80 tab_specific_permissions[pair.first] = | 74 tab_specific_permissions[pair.first] = |
| 81 ExtensionMsg_PermissionSetStruct(*pair.second); | 75 ExtensionMsg_PermissionSetStruct(*pair.second); |
| 82 } | 76 } |
| 83 } | 77 } |
| 84 } | 78 } |
| 85 | 79 |
| 86 ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params( | 80 ExtensionMsg_Loaded_Params::ExtensionMsg_Loaded_Params( |
| 87 const ExtensionMsg_Loaded_Params& other) = default; | 81 const ExtensionMsg_Loaded_Params& other) = default; |
| 88 | 82 |
| 89 scoped_refptr<Extension> ExtensionMsg_Loaded_Params::ConvertToExtension( | 83 scoped_refptr<Extension> ExtensionMsg_Loaded_Params::ConvertToExtension( |
| 90 std::string* error) const { | 84 std::string* error) const { |
| 91 // We pass in the |id| to the create call because it will save work in the | 85 // We pass in the |id| to the create call because it will save work in the |
| 92 // normal case, and because in tests, extensions may not have paths or keys, | 86 // normal case, and because in tests, extensions may not have paths or keys, |
| 93 // but it's important to retain the same id. | 87 // but it's important to retain the same id. |
| 94 scoped_refptr<Extension> extension = | 88 scoped_refptr<Extension> extension = |
| 95 Extension::Create(path, location, *manifest, creation_flags, id, error); | 89 Extension::Create(path, location, *manifest, creation_flags, id, error); |
| 96 if (extension.get()) { | 90 if (extension.get()) { |
| 97 const extensions::PermissionsData* permissions_data = | 91 const extensions::PermissionsData* permissions_data = |
| 98 extension->permissions_data(); | 92 extension->permissions_data(); |
| 99 permissions_data->SetPermissions(active_permissions.ToPermissionSet(), | 93 permissions_data->SetPermissions(active_permissions.ToPermissionSet(), |
| 100 withheld_permissions.ToPermissionSet()); | 94 withheld_permissions.ToPermissionSet()); |
| 101 if (uses_default_policy_blocked_allowed_hosts) { | |
| 102 permissions_data->SetUsesDefaultHostRestrictions(); | |
| 103 } else { | |
| 104 permissions_data->SetPolicyHostRestrictions(policy_blocked_hosts, | |
| 105 policy_allowed_hosts); | |
| 106 } | |
| 107 for (const auto& pair : tab_specific_permissions) { | 95 for (const auto& pair : tab_specific_permissions) { |
| 108 permissions_data->UpdateTabSpecificPermissions( | 96 permissions_data->UpdateTabSpecificPermissions( |
| 109 pair.first, *pair.second.ToPermissionSet()); | 97 pair.first, *pair.second.ToPermissionSet()); |
| 110 } | 98 } |
| 111 } | 99 } |
| 112 return extension; | 100 return extension; |
| 113 } | 101 } |
| 114 | 102 |
| 115 namespace IPC { | 103 namespace IPC { |
| 116 | 104 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 LogParam(p.type(), l); | 314 LogParam(p.type(), l); |
| 327 LogParam(p.id(), l); | 315 LogParam(p.id(), l); |
| 328 } | 316 } |
| 329 | 317 |
| 330 void ParamTraits<ExtensionMsg_PermissionSetStruct>::GetSize( | 318 void ParamTraits<ExtensionMsg_PermissionSetStruct>::GetSize( |
| 331 base::PickleSizer* s, const param_type& p) { | 319 base::PickleSizer* s, const param_type& p) { |
| 332 GetParamSize(s, p.apis); | 320 GetParamSize(s, p.apis); |
| 333 GetParamSize(s, p.manifest_permissions); | 321 GetParamSize(s, p.manifest_permissions); |
| 334 GetParamSize(s, p.explicit_hosts); | 322 GetParamSize(s, p.explicit_hosts); |
| 335 GetParamSize(s, p.scriptable_hosts); | 323 GetParamSize(s, p.scriptable_hosts); |
| 336 GetParamSize(s, p.policy_blocked_hosts); | |
| 337 GetParamSize(s, p.policy_allowed_hosts); | |
| 338 GetParamSize(s, p.uses_default_policy_host_restrictions); | |
| 339 } | 324 } |
| 340 | 325 |
| 341 void ParamTraits<ExtensionMsg_PermissionSetStruct>::Write(base::Pickle* m, | 326 void ParamTraits<ExtensionMsg_PermissionSetStruct>::Write(base::Pickle* m, |
| 342 const param_type& p) { | 327 const param_type& p) { |
| 343 WriteParam(m, p.apis); | 328 WriteParam(m, p.apis); |
| 344 WriteParam(m, p.manifest_permissions); | 329 WriteParam(m, p.manifest_permissions); |
| 345 WriteParam(m, p.explicit_hosts); | 330 WriteParam(m, p.explicit_hosts); |
| 346 WriteParam(m, p.scriptable_hosts); | 331 WriteParam(m, p.scriptable_hosts); |
| 347 WriteParam(m, p.policy_blocked_hosts); | |
| 348 WriteParam(m, p.policy_allowed_hosts); | |
| 349 WriteParam(m, p.uses_default_policy_host_restrictions); | |
| 350 } | 332 } |
| 351 | 333 |
| 352 bool ParamTraits<ExtensionMsg_PermissionSetStruct>::Read( | 334 bool ParamTraits<ExtensionMsg_PermissionSetStruct>::Read( |
| 353 const base::Pickle* m, | 335 const base::Pickle* m, |
| 354 base::PickleIterator* iter, | 336 base::PickleIterator* iter, |
| 355 param_type* p) { | 337 param_type* p) { |
| 356 return ReadParam(m, iter, &p->apis) && | 338 return ReadParam(m, iter, &p->apis) && |
| 357 ReadParam(m, iter, &p->manifest_permissions) && | 339 ReadParam(m, iter, &p->manifest_permissions) && |
| 358 ReadParam(m, iter, &p->explicit_hosts) && | 340 ReadParam(m, iter, &p->explicit_hosts) && |
| 359 ReadParam(m, iter, &p->scriptable_hosts) && | 341 ReadParam(m, iter, &p->scriptable_hosts); |
| 360 ReadParam(m, iter, &p->policy_blocked_hosts) && | |
| 361 ReadParam(m, iter, &p->policy_allowed_hosts) && | |
| 362 ReadParam(m, iter, &p->uses_default_policy_host_restrictions); | |
| 363 } | 342 } |
| 364 | 343 |
| 365 void ParamTraits<ExtensionMsg_PermissionSetStruct>::Log(const param_type& p, | 344 void ParamTraits<ExtensionMsg_PermissionSetStruct>::Log(const param_type& p, |
| 366 std::string* l) { | 345 std::string* l) { |
| 367 LogParam(p.apis, l); | 346 LogParam(p.apis, l); |
| 368 LogParam(p.manifest_permissions, l); | 347 LogParam(p.manifest_permissions, l); |
| 369 LogParam(p.explicit_hosts, l); | 348 LogParam(p.explicit_hosts, l); |
| 370 LogParam(p.scriptable_hosts, l); | 349 LogParam(p.scriptable_hosts, l); |
| 371 LogParam(p.policy_blocked_hosts, l); | |
| 372 LogParam(p.policy_allowed_hosts, l); | |
| 373 LogParam(p.uses_default_policy_host_restrictions, l); | |
| 374 } | 350 } |
| 375 | 351 |
| 376 void ParamTraits<ExtensionMsg_Loaded_Params>::Write(base::Pickle* m, | 352 void ParamTraits<ExtensionMsg_Loaded_Params>::Write(base::Pickle* m, |
| 377 const param_type& p) { | 353 const param_type& p) { |
| 378 WriteParam(m, p.location); | 354 WriteParam(m, p.location); |
| 379 WriteParam(m, p.path); | 355 WriteParam(m, p.path); |
| 380 WriteParam(m, *(p.manifest)); | 356 WriteParam(m, *(p.manifest)); |
| 381 WriteParam(m, p.creation_flags); | 357 WriteParam(m, p.creation_flags); |
| 382 WriteParam(m, p.id); | 358 WriteParam(m, p.id); |
| 383 WriteParam(m, p.active_permissions); | 359 WriteParam(m, p.active_permissions); |
| 384 WriteParam(m, p.withheld_permissions); | 360 WriteParam(m, p.withheld_permissions); |
| 385 WriteParam(m, p.tab_specific_permissions); | 361 WriteParam(m, p.tab_specific_permissions); |
| 386 WriteParam(m, p.policy_blocked_hosts); | |
| 387 WriteParam(m, p.policy_allowed_hosts); | |
| 388 WriteParam(m, p.uses_default_policy_blocked_allowed_hosts); | |
| 389 } | 362 } |
| 390 | 363 |
| 391 bool ParamTraits<ExtensionMsg_Loaded_Params>::Read(const base::Pickle* m, | 364 bool ParamTraits<ExtensionMsg_Loaded_Params>::Read(const base::Pickle* m, |
| 392 base::PickleIterator* iter, | 365 base::PickleIterator* iter, |
| 393 param_type* p) { | 366 param_type* p) { |
| 394 p->manifest.reset(new base::DictionaryValue()); | 367 p->manifest.reset(new base::DictionaryValue()); |
| 395 return ReadParam(m, iter, &p->location) && ReadParam(m, iter, &p->path) && | 368 return ReadParam(m, iter, &p->location) && ReadParam(m, iter, &p->path) && |
| 396 ReadParam(m, iter, p->manifest.get()) && | 369 ReadParam(m, iter, p->manifest.get()) && |
| 397 ReadParam(m, iter, &p->creation_flags) && ReadParam(m, iter, &p->id) && | 370 ReadParam(m, iter, &p->creation_flags) && ReadParam(m, iter, &p->id) && |
| 398 ReadParam(m, iter, &p->active_permissions) && | 371 ReadParam(m, iter, &p->active_permissions) && |
| 399 ReadParam(m, iter, &p->withheld_permissions) && | 372 ReadParam(m, iter, &p->withheld_permissions) && |
| 400 ReadParam(m, iter, &p->tab_specific_permissions) && | 373 ReadParam(m, iter, &p->tab_specific_permissions); |
| 401 ReadParam(m, iter, &p->policy_blocked_hosts) && | |
| 402 ReadParam(m, iter, &p->policy_allowed_hosts) && | |
| 403 ReadParam(m, iter, &p->uses_default_policy_blocked_allowed_hosts); | |
| 404 } | 374 } |
| 405 | 375 |
| 406 void ParamTraits<ExtensionMsg_Loaded_Params>::Log(const param_type& p, | 376 void ParamTraits<ExtensionMsg_Loaded_Params>::Log(const param_type& p, |
| 407 std::string* l) { | 377 std::string* l) { |
| 408 l->append(p.id); | 378 l->append(p.id); |
| 409 } | 379 } |
| 410 | 380 |
| 411 } // namespace IPC | 381 } // namespace IPC |
| OLD | NEW |