| 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 "content/public/common/common_param_traits.h" | 7 #include "content/public/common/common_param_traits.h" |
| 8 #include "extensions/common/extension.h" | 8 #include "extensions/common/extension.h" |
| 9 #include "extensions/common/manifest.h" | 9 #include "extensions/common/manifest.h" |
| 10 #include "extensions/common/manifest_handler.h" | 10 #include "extensions/common/manifest_handler.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 88 |
| 89 namespace IPC { | 89 namespace IPC { |
| 90 | 90 |
| 91 template <> | 91 template <> |
| 92 struct ParamTraits<Manifest::Location> { | 92 struct ParamTraits<Manifest::Location> { |
| 93 typedef Manifest::Location param_type; | 93 typedef Manifest::Location param_type; |
| 94 static void Write(Message* m, const param_type& p) { | 94 static void Write(Message* m, const param_type& p) { |
| 95 int val = static_cast<int>(p); | 95 int val = static_cast<int>(p); |
| 96 WriteParam(m, val); | 96 WriteParam(m, val); |
| 97 } | 97 } |
| 98 static bool Read(const Message* m, PickleIterator* iter, param_type* p) { | 98 static bool Read(const Message* m, |
| 99 base::PickleIterator* iter, |
| 100 param_type* p) { |
| 99 int val = 0; | 101 int val = 0; |
| 100 if (!ReadParam(m, iter, &val) || | 102 if (!ReadParam(m, iter, &val) || |
| 101 val < Manifest::INVALID_LOCATION || | 103 val < Manifest::INVALID_LOCATION || |
| 102 val >= Manifest::NUM_LOCATIONS) | 104 val >= Manifest::NUM_LOCATIONS) |
| 103 return false; | 105 return false; |
| 104 *p = static_cast<param_type>(val); | 106 *p = static_cast<param_type>(val); |
| 105 return true; | 107 return true; |
| 106 } | 108 } |
| 107 static void Log(const param_type& p, std::string* l) { | 109 static void Log(const param_type& p, std::string* l) { |
| 108 ParamTraits<int>::Log(static_cast<int>(p), l); | 110 ParamTraits<int>::Log(static_cast<int>(p), l); |
| 109 } | 111 } |
| 110 }; | 112 }; |
| 111 | 113 |
| 112 void ParamTraits<URLPattern>::Write(Message* m, const param_type& p) { | 114 void ParamTraits<URLPattern>::Write(Message* m, const param_type& p) { |
| 113 WriteParam(m, p.valid_schemes()); | 115 WriteParam(m, p.valid_schemes()); |
| 114 WriteParam(m, p.GetAsString()); | 116 WriteParam(m, p.GetAsString()); |
| 115 } | 117 } |
| 116 | 118 |
| 117 bool ParamTraits<URLPattern>::Read(const Message* m, PickleIterator* iter, | 119 bool ParamTraits<URLPattern>::Read(const Message* m, |
| 120 base::PickleIterator* iter, |
| 118 param_type* p) { | 121 param_type* p) { |
| 119 int valid_schemes; | 122 int valid_schemes; |
| 120 std::string spec; | 123 std::string spec; |
| 121 if (!ReadParam(m, iter, &valid_schemes) || | 124 if (!ReadParam(m, iter, &valid_schemes) || |
| 122 !ReadParam(m, iter, &spec)) | 125 !ReadParam(m, iter, &spec)) |
| 123 return false; | 126 return false; |
| 124 | 127 |
| 125 // TODO(jstritar): We don't want the URLPattern to fail parsing when the | 128 // TODO(jstritar): We don't want the URLPattern to fail parsing when the |
| 126 // scheme is invalid. Instead, the pattern should parse but it should not | 129 // scheme is invalid. Instead, the pattern should parse but it should not |
| 127 // match the invalid patterns. We get around this by setting the valid | 130 // match the invalid patterns. We get around this by setting the valid |
| 128 // schemes after parsing the pattern. Update these method calls once we can | 131 // schemes after parsing the pattern. Update these method calls once we can |
| 129 // ignore scheme validation with URLPattern parse options. crbug.com/90544 | 132 // ignore scheme validation with URLPattern parse options. crbug.com/90544 |
| 130 p->SetValidSchemes(URLPattern::SCHEME_ALL); | 133 p->SetValidSchemes(URLPattern::SCHEME_ALL); |
| 131 URLPattern::ParseResult result = p->Parse(spec); | 134 URLPattern::ParseResult result = p->Parse(spec); |
| 132 p->SetValidSchemes(valid_schemes); | 135 p->SetValidSchemes(valid_schemes); |
| 133 return URLPattern::PARSE_SUCCESS == result; | 136 return URLPattern::PARSE_SUCCESS == result; |
| 134 } | 137 } |
| 135 | 138 |
| 136 void ParamTraits<URLPattern>::Log(const param_type& p, std::string* l) { | 139 void ParamTraits<URLPattern>::Log(const param_type& p, std::string* l) { |
| 137 LogParam(p.GetAsString(), l); | 140 LogParam(p.GetAsString(), l); |
| 138 } | 141 } |
| 139 | 142 |
| 140 void ParamTraits<URLPatternSet>::Write(Message* m, const param_type& p) { | 143 void ParamTraits<URLPatternSet>::Write(Message* m, const param_type& p) { |
| 141 WriteParam(m, p.patterns()); | 144 WriteParam(m, p.patterns()); |
| 142 } | 145 } |
| 143 | 146 |
| 144 bool ParamTraits<URLPatternSet>::Read(const Message* m, PickleIterator* iter, | 147 bool ParamTraits<URLPatternSet>::Read(const Message* m, |
| 145 param_type* p) { | 148 base::PickleIterator* iter, |
| 149 param_type* p) { |
| 146 std::set<URLPattern> patterns; | 150 std::set<URLPattern> patterns; |
| 147 if (!ReadParam(m, iter, &patterns)) | 151 if (!ReadParam(m, iter, &patterns)) |
| 148 return false; | 152 return false; |
| 149 | 153 |
| 150 for (std::set<URLPattern>::iterator i = patterns.begin(); | 154 for (std::set<URLPattern>::iterator i = patterns.begin(); |
| 151 i != patterns.end(); ++i) | 155 i != patterns.end(); ++i) |
| 152 p->AddPattern(*i); | 156 p->AddPattern(*i); |
| 153 return true; | 157 return true; |
| 154 } | 158 } |
| 155 | 159 |
| 156 void ParamTraits<URLPatternSet>::Log(const param_type& p, std::string* l) { | 160 void ParamTraits<URLPatternSet>::Log(const param_type& p, std::string* l) { |
| 157 LogParam(p.patterns(), l); | 161 LogParam(p.patterns(), l); |
| 158 } | 162 } |
| 159 | 163 |
| 160 void ParamTraits<APIPermission::ID>::Write( | 164 void ParamTraits<APIPermission::ID>::Write( |
| 161 Message* m, const param_type& p) { | 165 Message* m, const param_type& p) { |
| 162 WriteParam(m, static_cast<int>(p)); | 166 WriteParam(m, static_cast<int>(p)); |
| 163 } | 167 } |
| 164 | 168 |
| 165 bool ParamTraits<APIPermission::ID>::Read( | 169 bool ParamTraits<APIPermission::ID>::Read(const Message* m, |
| 166 const Message* m, PickleIterator* iter, param_type* p) { | 170 base::PickleIterator* iter, |
| 171 param_type* p) { |
| 167 int api_id = -2; | 172 int api_id = -2; |
| 168 if (!ReadParam(m, iter, &api_id)) | 173 if (!ReadParam(m, iter, &api_id)) |
| 169 return false; | 174 return false; |
| 170 | 175 |
| 171 *p = static_cast<APIPermission::ID>(api_id); | 176 *p = static_cast<APIPermission::ID>(api_id); |
| 172 return true; | 177 return true; |
| 173 } | 178 } |
| 174 | 179 |
| 175 void ParamTraits<APIPermission::ID>::Log( | 180 void ParamTraits<APIPermission::ID>::Log( |
| 176 const param_type& p, std::string* l) { | 181 const param_type& p, std::string* l) { |
| 177 LogParam(static_cast<int>(p), l); | 182 LogParam(static_cast<int>(p), l); |
| 178 } | 183 } |
| 179 | 184 |
| 180 void ParamTraits<APIPermissionSet>::Write( | 185 void ParamTraits<APIPermissionSet>::Write( |
| 181 Message* m, const param_type& p) { | 186 Message* m, const param_type& p) { |
| 182 APIPermissionSet::const_iterator it = p.begin(); | 187 APIPermissionSet::const_iterator it = p.begin(); |
| 183 const APIPermissionSet::const_iterator end = p.end(); | 188 const APIPermissionSet::const_iterator end = p.end(); |
| 184 WriteParam(m, p.size()); | 189 WriteParam(m, p.size()); |
| 185 for (; it != end; ++it) { | 190 for (; it != end; ++it) { |
| 186 WriteParam(m, it->id()); | 191 WriteParam(m, it->id()); |
| 187 it->Write(m); | 192 it->Write(m); |
| 188 } | 193 } |
| 189 } | 194 } |
| 190 | 195 |
| 191 bool ParamTraits<APIPermissionSet>::Read( | 196 bool ParamTraits<APIPermissionSet>::Read(const Message* m, |
| 192 const Message* m, PickleIterator* iter, param_type* r) { | 197 base::PickleIterator* iter, |
| 198 param_type* r) { |
| 193 size_t size; | 199 size_t size; |
| 194 if (!ReadParam(m, iter, &size)) | 200 if (!ReadParam(m, iter, &size)) |
| 195 return false; | 201 return false; |
| 196 for (size_t i = 0; i < size; ++i) { | 202 for (size_t i = 0; i < size; ++i) { |
| 197 APIPermission::ID id; | 203 APIPermission::ID id; |
| 198 if (!ReadParam(m, iter, &id)) | 204 if (!ReadParam(m, iter, &id)) |
| 199 return false; | 205 return false; |
| 200 const APIPermissionInfo* permission_info = | 206 const APIPermissionInfo* permission_info = |
| 201 extensions::PermissionsInfo::GetInstance()->GetByID(id); | 207 extensions::PermissionsInfo::GetInstance()->GetByID(id); |
| 202 if (!permission_info) | 208 if (!permission_info) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 218 Message* m, const param_type& p) { | 224 Message* m, const param_type& p) { |
| 219 ManifestPermissionSet::const_iterator it = p.begin(); | 225 ManifestPermissionSet::const_iterator it = p.begin(); |
| 220 const ManifestPermissionSet::const_iterator end = p.end(); | 226 const ManifestPermissionSet::const_iterator end = p.end(); |
| 221 WriteParam(m, p.size()); | 227 WriteParam(m, p.size()); |
| 222 for (; it != end; ++it) { | 228 for (; it != end; ++it) { |
| 223 WriteParam(m, it->name()); | 229 WriteParam(m, it->name()); |
| 224 it->Write(m); | 230 it->Write(m); |
| 225 } | 231 } |
| 226 } | 232 } |
| 227 | 233 |
| 228 bool ParamTraits<ManifestPermissionSet>::Read( | 234 bool ParamTraits<ManifestPermissionSet>::Read(const Message* m, |
| 229 const Message* m, PickleIterator* iter, param_type* r) { | 235 base::PickleIterator* iter, |
| 236 param_type* r) { |
| 230 size_t size; | 237 size_t size; |
| 231 if (!ReadParam(m, iter, &size)) | 238 if (!ReadParam(m, iter, &size)) |
| 232 return false; | 239 return false; |
| 233 for (size_t i = 0; i < size; ++i) { | 240 for (size_t i = 0; i < size; ++i) { |
| 234 std::string name; | 241 std::string name; |
| 235 if (!ReadParam(m, iter, &name)) | 242 if (!ReadParam(m, iter, &name)) |
| 236 return false; | 243 return false; |
| 237 scoped_ptr<ManifestPermission> p(ManifestHandler::CreatePermission(name)); | 244 scoped_ptr<ManifestPermission> p(ManifestHandler::CreatePermission(name)); |
| 238 if (!p) | 245 if (!p) |
| 239 return false; | 246 return false; |
| 240 if (!p->Read(m, iter)) | 247 if (!p->Read(m, iter)) |
| 241 return false; | 248 return false; |
| 242 r->insert(p.release()); | 249 r->insert(p.release()); |
| 243 } | 250 } |
| 244 return true; | 251 return true; |
| 245 } | 252 } |
| 246 | 253 |
| 247 void ParamTraits<ManifestPermissionSet>::Log( | 254 void ParamTraits<ManifestPermissionSet>::Log( |
| 248 const param_type& p, std::string* l) { | 255 const param_type& p, std::string* l) { |
| 249 LogParam(p.map(), l); | 256 LogParam(p.map(), l); |
| 250 } | 257 } |
| 251 | 258 |
| 252 void ParamTraits<HostID>::Write( | 259 void ParamTraits<HostID>::Write( |
| 253 Message* m, const param_type& p) { | 260 Message* m, const param_type& p) { |
| 254 WriteParam(m, p.type()); | 261 WriteParam(m, p.type()); |
| 255 WriteParam(m, p.id()); | 262 WriteParam(m, p.id()); |
| 256 } | 263 } |
| 257 | 264 |
| 258 bool ParamTraits<HostID>::Read( | 265 bool ParamTraits<HostID>::Read(const Message* m, |
| 259 const Message* m, PickleIterator* iter, param_type* r) { | 266 base::PickleIterator* iter, |
| 267 param_type* r) { |
| 260 HostID::HostType type; | 268 HostID::HostType type; |
| 261 std::string id; | 269 std::string id; |
| 262 if (!ReadParam(m, iter, &type)) | 270 if (!ReadParam(m, iter, &type)) |
| 263 return false; | 271 return false; |
| 264 if (!ReadParam(m, iter, &id)) | 272 if (!ReadParam(m, iter, &id)) |
| 265 return false; | 273 return false; |
| 266 *r = HostID(type, id); | 274 *r = HostID(type, id); |
| 267 return true; | 275 return true; |
| 268 } | 276 } |
| 269 | 277 |
| 270 void ParamTraits<HostID>::Log( | 278 void ParamTraits<HostID>::Log( |
| 271 const param_type& p, std::string* l) { | 279 const param_type& p, std::string* l) { |
| 272 LogParam(p.type(), l); | 280 LogParam(p.type(), l); |
| 273 LogParam(p.id(), l); | 281 LogParam(p.id(), l); |
| 274 } | 282 } |
| 275 | 283 |
| 276 void ParamTraits<ExtensionMsg_PermissionSetStruct>::Write(Message* m, | 284 void ParamTraits<ExtensionMsg_PermissionSetStruct>::Write(Message* m, |
| 277 const param_type& p) { | 285 const param_type& p) { |
| 278 WriteParam(m, p.apis); | 286 WriteParam(m, p.apis); |
| 279 WriteParam(m, p.manifest_permissions); | 287 WriteParam(m, p.manifest_permissions); |
| 280 WriteParam(m, p.explicit_hosts); | 288 WriteParam(m, p.explicit_hosts); |
| 281 WriteParam(m, p.scriptable_hosts); | 289 WriteParam(m, p.scriptable_hosts); |
| 282 } | 290 } |
| 283 | 291 |
| 284 bool ParamTraits<ExtensionMsg_PermissionSetStruct>::Read(const Message* m, | 292 bool ParamTraits<ExtensionMsg_PermissionSetStruct>::Read( |
| 285 PickleIterator* iter, | 293 const Message* m, |
| 286 param_type* p) { | 294 base::PickleIterator* iter, |
| 295 param_type* p) { |
| 287 return ReadParam(m, iter, &p->apis) && | 296 return ReadParam(m, iter, &p->apis) && |
| 288 ReadParam(m, iter, &p->manifest_permissions) && | 297 ReadParam(m, iter, &p->manifest_permissions) && |
| 289 ReadParam(m, iter, &p->explicit_hosts) && | 298 ReadParam(m, iter, &p->explicit_hosts) && |
| 290 ReadParam(m, iter, &p->scriptable_hosts); | 299 ReadParam(m, iter, &p->scriptable_hosts); |
| 291 } | 300 } |
| 292 | 301 |
| 293 void ParamTraits<ExtensionMsg_PermissionSetStruct>::Log(const param_type& p, | 302 void ParamTraits<ExtensionMsg_PermissionSetStruct>::Log(const param_type& p, |
| 294 std::string* l) { | 303 std::string* l) { |
| 295 LogParam(p.apis, l); | 304 LogParam(p.apis, l); |
| 296 LogParam(p.manifest_permissions, l); | 305 LogParam(p.manifest_permissions, l); |
| 297 LogParam(p.explicit_hosts, l); | 306 LogParam(p.explicit_hosts, l); |
| 298 LogParam(p.scriptable_hosts, l); | 307 LogParam(p.scriptable_hosts, l); |
| 299 } | 308 } |
| 300 | 309 |
| 301 void ParamTraits<ExtensionMsg_Loaded_Params>::Write(Message* m, | 310 void ParamTraits<ExtensionMsg_Loaded_Params>::Write(Message* m, |
| 302 const param_type& p) { | 311 const param_type& p) { |
| 303 WriteParam(m, p.location); | 312 WriteParam(m, p.location); |
| 304 WriteParam(m, p.path); | 313 WriteParam(m, p.path); |
| 305 WriteParam(m, *(p.manifest)); | 314 WriteParam(m, *(p.manifest)); |
| 306 WriteParam(m, p.creation_flags); | 315 WriteParam(m, p.creation_flags); |
| 307 WriteParam(m, p.active_permissions); | 316 WriteParam(m, p.active_permissions); |
| 308 WriteParam(m, p.withheld_permissions); | 317 WriteParam(m, p.withheld_permissions); |
| 309 } | 318 } |
| 310 | 319 |
| 311 bool ParamTraits<ExtensionMsg_Loaded_Params>::Read(const Message* m, | 320 bool ParamTraits<ExtensionMsg_Loaded_Params>::Read(const Message* m, |
| 312 PickleIterator* iter, | 321 base::PickleIterator* iter, |
| 313 param_type* p) { | 322 param_type* p) { |
| 314 p->manifest.reset(new base::DictionaryValue()); | 323 p->manifest.reset(new base::DictionaryValue()); |
| 315 return ReadParam(m, iter, &p->location) && ReadParam(m, iter, &p->path) && | 324 return ReadParam(m, iter, &p->location) && ReadParam(m, iter, &p->path) && |
| 316 ReadParam(m, iter, p->manifest.get()) && | 325 ReadParam(m, iter, p->manifest.get()) && |
| 317 ReadParam(m, iter, &p->creation_flags) && | 326 ReadParam(m, iter, &p->creation_flags) && |
| 318 ReadParam(m, iter, &p->active_permissions) && | 327 ReadParam(m, iter, &p->active_permissions) && |
| 319 ReadParam(m, iter, &p->withheld_permissions); | 328 ReadParam(m, iter, &p->withheld_permissions); |
| 320 } | 329 } |
| 321 | 330 |
| 322 void ParamTraits<ExtensionMsg_Loaded_Params>::Log(const param_type& p, | 331 void ParamTraits<ExtensionMsg_Loaded_Params>::Log(const param_type& p, |
| 323 std::string* l) { | 332 std::string* l) { |
| 324 l->append(p.id); | 333 l->append(p.id); |
| 325 } | 334 } |
| 326 | 335 |
| 327 } // namespace IPC | 336 } // namespace IPC |
| OLD | NEW |