| 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/api/sockets/sockets_manifest_permission.h" | 5 #include "extensions/common/api/sockets/sockets_manifest_permission.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 sockets.tcp_server.reset(new Sockets::TcpServer()); | 216 sockets.tcp_server.reset(new Sockets::TcpServer()); |
| 217 SetHostPatterns( | 217 SetHostPatterns( |
| 218 sockets.tcp_server->listen, this, SocketPermissionRequest::TCP_LISTEN); | 218 sockets.tcp_server->listen, this, SocketPermissionRequest::TCP_LISTEN); |
| 219 if (sockets.tcp_server->listen->as_strings->size() == 0) { | 219 if (sockets.tcp_server->listen->as_strings->size() == 0) { |
| 220 sockets.tcp_server.reset(NULL); | 220 sockets.tcp_server.reset(NULL); |
| 221 } | 221 } |
| 222 | 222 |
| 223 return scoped_ptr<base::Value>(sockets.ToValue().release()).Pass(); | 223 return scoped_ptr<base::Value>(sockets.ToValue().release()).Pass(); |
| 224 } | 224 } |
| 225 | 225 |
| 226 ManifestPermission* SocketsManifestPermission::Clone() const { | |
| 227 scoped_ptr<SocketsManifestPermission> result(new SocketsManifestPermission()); | |
| 228 result->permissions_ = permissions_; | |
| 229 return result.release(); | |
| 230 } | |
| 231 | |
| 232 ManifestPermission* SocketsManifestPermission::Diff( | 226 ManifestPermission* SocketsManifestPermission::Diff( |
| 233 const ManifestPermission* rhs) const { | 227 const ManifestPermission* rhs) const { |
| 234 const SocketsManifestPermission* other = | 228 const SocketsManifestPermission* other = |
| 235 static_cast<const SocketsManifestPermission*>(rhs); | 229 static_cast<const SocketsManifestPermission*>(rhs); |
| 236 | 230 |
| 237 scoped_ptr<SocketsManifestPermission> result(new SocketsManifestPermission()); | 231 scoped_ptr<SocketsManifestPermission> result(new SocketsManifestPermission()); |
| 238 result->permissions_ = base::STLSetDifference<SocketPermissionEntrySet>( | 232 result->permissions_ = base::STLSetDifference<SocketPermissionEntrySet>( |
| 239 permissions_, other->permissions_); | 233 permissions_, other->permissions_); |
| 240 return result.release(); | 234 return result.release(); |
| 241 } | 235 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 255 const ManifestPermission* rhs) const { | 249 const ManifestPermission* rhs) const { |
| 256 const SocketsManifestPermission* other = | 250 const SocketsManifestPermission* other = |
| 257 static_cast<const SocketsManifestPermission*>(rhs); | 251 static_cast<const SocketsManifestPermission*>(rhs); |
| 258 | 252 |
| 259 scoped_ptr<SocketsManifestPermission> result(new SocketsManifestPermission()); | 253 scoped_ptr<SocketsManifestPermission> result(new SocketsManifestPermission()); |
| 260 result->permissions_ = base::STLSetIntersection<SocketPermissionEntrySet>( | 254 result->permissions_ = base::STLSetIntersection<SocketPermissionEntrySet>( |
| 261 permissions_, other->permissions_); | 255 permissions_, other->permissions_); |
| 262 return result.release(); | 256 return result.release(); |
| 263 } | 257 } |
| 264 | 258 |
| 265 bool SocketsManifestPermission::Contains(const ManifestPermission* rhs) const { | |
| 266 const SocketsManifestPermission* other = | |
| 267 static_cast<const SocketsManifestPermission*>(rhs); | |
| 268 | |
| 269 return base::STLIncludes<SocketPermissionEntrySet>(permissions_, | |
| 270 other->permissions_); | |
| 271 } | |
| 272 | |
| 273 bool SocketsManifestPermission::Equal(const ManifestPermission* rhs) const { | |
| 274 const SocketsManifestPermission* other = | |
| 275 static_cast<const SocketsManifestPermission*>(rhs); | |
| 276 | |
| 277 return (permissions_ == other->permissions_); | |
| 278 } | |
| 279 | |
| 280 void SocketsManifestPermission::Write(IPC::Message* m) const { | |
| 281 IPC::WriteParam(m, permissions_); | |
| 282 } | |
| 283 | |
| 284 bool SocketsManifestPermission::Read(const IPC::Message* m, | |
| 285 PickleIterator* iter) { | |
| 286 return IPC::ReadParam(m, iter, &permissions_); | |
| 287 } | |
| 288 | |
| 289 void SocketsManifestPermission::Log(std::string* log) const { | |
| 290 IPC::LogParam(permissions_, log); | |
| 291 } | |
| 292 | |
| 293 void SocketsManifestPermission::AddPermission( | 259 void SocketsManifestPermission::AddPermission( |
| 294 const SocketPermissionEntry& entry) { | 260 const SocketPermissionEntry& entry) { |
| 295 permissions_.insert(entry); | 261 permissions_.insert(entry); |
| 296 } | 262 } |
| 297 | 263 |
| 298 bool SocketsManifestPermission::AddAnyHostMessage( | 264 bool SocketsManifestPermission::AddAnyHostMessage( |
| 299 PermissionMessages& messages) const { | 265 PermissionMessages& messages) const { |
| 300 for (SocketPermissionEntrySet::const_iterator it = permissions_.begin(); | 266 for (SocketPermissionEntrySet::const_iterator it = permissions_.begin(); |
| 301 it != permissions_.end(); | 267 it != permissions_.end(); |
| 302 ++it) { | 268 ++it) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 if (it->pattern().type == SocketPermissionRequest::NETWORK_STATE) { | 332 if (it->pattern().type == SocketPermissionRequest::NETWORK_STATE) { |
| 367 messages.push_back( | 333 messages.push_back( |
| 368 PermissionMessage(PermissionMessage::kNetworkState, | 334 PermissionMessage(PermissionMessage::kNetworkState, |
| 369 l10n_util::GetStringUTF16( | 335 l10n_util::GetStringUTF16( |
| 370 IDS_EXTENSION_PROMPT_WARNING_NETWORK_STATE))); | 336 IDS_EXTENSION_PROMPT_WARNING_NETWORK_STATE))); |
| 371 } | 337 } |
| 372 } | 338 } |
| 373 } | 339 } |
| 374 | 340 |
| 375 } // namespace extensions | 341 } // namespace extensions |
| OLD | NEW |