| Index: chrome/common/extensions/permissions/socket_permission_data.cc
|
| diff --git a/chrome/common/extensions/permissions/socket_permission_data.cc b/chrome/common/extensions/permissions/socket_permission_data.cc
|
| index 4b8b689223d91052abe4381eecd1a3a1b7b2ab1d..bd9f041d02706268a90c6857b325e1427f9309c3 100644
|
| --- a/chrome/common/extensions/permissions/socket_permission_data.cc
|
| +++ b/chrome/common/extensions/permissions/socket_permission_data.cc
|
| @@ -16,6 +16,7 @@
|
|
|
| namespace {
|
|
|
| +using content::SocketPermissionRequest;
|
| using extensions::SocketPermissionData;
|
|
|
| const char kColon = ':';
|
| @@ -29,27 +30,27 @@ const char kUDPSendTo[] = "udp-send-to";
|
| const int kAnyPort = 0;
|
| const int kInvalidPort = -1;
|
|
|
| -SocketPermissionData::OperationType StringToType(const std::string& s) {
|
| +SocketPermissionRequest::OperationType StringToType(const std::string& s) {
|
| if (s == kTCPConnect)
|
| - return SocketPermissionData::TCP_CONNECT;
|
| + return SocketPermissionRequest::TCP_CONNECT;
|
| if (s == kTCPListen)
|
| - return SocketPermissionData::TCP_LISTEN;
|
| + return SocketPermissionRequest::TCP_LISTEN;
|
| if (s == kUDPBind)
|
| - return SocketPermissionData::UDP_BIND;
|
| + return SocketPermissionRequest::UDP_BIND;
|
| if (s == kUDPSendTo)
|
| - return SocketPermissionData::UDP_SEND_TO;
|
| - return SocketPermissionData::NONE;
|
| + return SocketPermissionRequest::UDP_SEND_TO;
|
| + return SocketPermissionRequest::NONE;
|
| }
|
|
|
| -const char* TypeToString(SocketPermissionData::OperationType type) {
|
| +const char* TypeToString(SocketPermissionRequest::OperationType type) {
|
| switch (type) {
|
| - case SocketPermissionData::TCP_CONNECT:
|
| + case SocketPermissionRequest::TCP_CONNECT:
|
| return kTCPConnect;
|
| - case SocketPermissionData::TCP_LISTEN:
|
| + case SocketPermissionRequest::TCP_LISTEN:
|
| return kTCPListen;
|
| - case SocketPermissionData::UDP_BIND:
|
| + case SocketPermissionRequest::UDP_BIND:
|
| return kUDPBind;
|
| - case SocketPermissionData::UDP_SEND_TO:
|
| + case SocketPermissionRequest::UDP_SEND_TO:
|
| return kUDPSendTo;
|
| default:
|
| return kInvalid;
|
| @@ -68,7 +69,8 @@ bool StartsOrEndsWithWhitespace(const std::string& str) {
|
|
|
| namespace extensions {
|
|
|
| -SocketPermissionData::SocketPermissionData() {
|
| +SocketPermissionData::SocketPermissionData()
|
| + : pattern_(SocketPermissionRequest::NONE, std::string(), kInvalidPort) {
|
| Reset();
|
| }
|
|
|
| @@ -76,14 +78,14 @@ SocketPermissionData::~SocketPermissionData() {
|
| }
|
|
|
| bool SocketPermissionData::operator<(const SocketPermissionData& rhs) const {
|
| - if (type_ < rhs.type_)
|
| + if (pattern_.type < rhs.pattern_.type)
|
| return true;
|
| - if (type_ > rhs.type_)
|
| + if (pattern_.type > rhs.pattern_.type)
|
| return false;
|
|
|
| - if (host_ < rhs.host_)
|
| + if (pattern_.host < rhs.pattern_.host)
|
| return true;
|
| - if (host_ > rhs.host_)
|
| + if (pattern_.host > rhs.pattern_.host)
|
| return false;
|
|
|
| if (match_subdomains_ < rhs.match_subdomains_)
|
| @@ -91,28 +93,28 @@ bool SocketPermissionData::operator<(const SocketPermissionData& rhs) const {
|
| if (match_subdomains_ > rhs.match_subdomains_)
|
| return false;
|
|
|
| - if (port_ < rhs.port_)
|
| + if (pattern_.port < rhs.pattern_.port)
|
| return true;
|
| return false;
|
| }
|
|
|
| bool SocketPermissionData::operator==(const SocketPermissionData& rhs) const {
|
| - return (type_ == rhs.type_) && (host_ == rhs.host_) &&
|
| - (match_subdomains_ == rhs.match_subdomains_) &&
|
| - (port_ == rhs.port_);
|
| + return (pattern_.type == rhs.pattern_.type) &&
|
| + (pattern_.host == rhs.pattern_.host) &&
|
| + (match_subdomains_ == rhs.match_subdomains_) &&
|
| + (pattern_.port == rhs.pattern_.port);
|
| }
|
|
|
| -bool SocketPermissionData::Match(
|
| - OperationType type, const std::string& host, int port) const {
|
| - if (type_ != type)
|
| +bool SocketPermissionData::Match(SocketPermissionRequest request) const {
|
| + if (pattern_.type != request.type)
|
| return false;
|
|
|
| - std::string lhost = StringToLowerASCII(host);
|
| - if (host_ != lhost) {
|
| + std::string lhost = StringToLowerASCII(request.host);
|
| + if (pattern_.host != lhost) {
|
| if (!match_subdomains_)
|
| return false;
|
|
|
| - if (!host_.empty()) {
|
| + if (!pattern_.host.empty()) {
|
| // Do not wildcard part of IP address.
|
| url_parse::Component component(0, lhost.length());
|
| url_canon::RawCanonOutputT<char, 128> ignored_output;
|
| @@ -123,11 +125,11 @@ bool SocketPermissionData::Match(
|
| return false;
|
|
|
| // host should equal one or more chars + "." + host_.
|
| - int i = lhost.length() - host_.length();
|
| + int i = lhost.length() - pattern_.host.length();
|
| if (i < 2)
|
| return false;
|
|
|
| - if (lhost.compare(i, host_.length(), host_) != 0)
|
| + if (lhost.compare(i, pattern_.host.length(), pattern_.host) != 0)
|
| return false;
|
|
|
| if (lhost[i - 1] != kDot)
|
| @@ -135,7 +137,7 @@ bool SocketPermissionData::Match(
|
| }
|
| }
|
|
|
| - if (port_ != port && port_ != kAnyPort)
|
| + if (pattern_.port != request.port && pattern_.port != kAnyPort)
|
| return false;
|
|
|
| return true;
|
| @@ -143,9 +145,9 @@ bool SocketPermissionData::Match(
|
|
|
| bool SocketPermissionData::Parse(const std::string& permission) {
|
| do {
|
| - host_.clear();
|
| + pattern_.host.clear();
|
| match_subdomains_ = true;
|
| - port_ = kAnyPort;
|
| + pattern_.port = kAnyPort;
|
| spec_.clear();
|
|
|
| std::vector<std::string> tokens;
|
| @@ -154,22 +156,22 @@ bool SocketPermissionData::Parse(const std::string& permission) {
|
| if (tokens.empty() || tokens.size() > 3)
|
| break;
|
|
|
| - type_ = StringToType(tokens[0]);
|
| - if (type_ == NONE)
|
| + pattern_.type = StringToType(tokens[0]);
|
| + if (pattern_.type == SocketPermissionRequest::NONE)
|
| break;
|
|
|
| if (tokens.size() == 1)
|
| return true;
|
|
|
| - host_ = tokens[1];
|
| - if (!host_.empty()) {
|
| - if (StartsOrEndsWithWhitespace(host_))
|
| + pattern_.host = tokens[1];
|
| + if (!pattern_.host.empty()) {
|
| + if (StartsOrEndsWithWhitespace(pattern_.host))
|
| break;
|
| - host_ = StringToLowerASCII(host_);
|
| + pattern_.host = StringToLowerASCII(pattern_.host);
|
|
|
| // The first component can optionally be '*' to match all subdomains.
|
| std::vector<std::string> host_components;
|
| - base::SplitString(host_, kDot, &host_components);
|
| + base::SplitString(pattern_.host, kDot, &host_components);
|
| DCHECK(!host_components.empty());
|
|
|
| if (host_components[0] == kWildcard || host_components[0].empty()) {
|
| @@ -178,7 +180,7 @@ bool SocketPermissionData::Parse(const std::string& permission) {
|
| } else {
|
| match_subdomains_ = false;
|
| }
|
| - host_ = JoinString(host_components, kDot);
|
| + pattern_.host = JoinString(host_components, kDot);
|
| }
|
|
|
| if (tokens.size() == 2 || tokens[2].empty() || tokens[2] == kWildcard)
|
| @@ -187,8 +189,8 @@ bool SocketPermissionData::Parse(const std::string& permission) {
|
| if (StartsOrEndsWithWhitespace(tokens[2]))
|
| break;
|
|
|
| - if (!base::StringToInt(tokens[2], &port_) ||
|
| - port_ < 1 || port_ > 65535)
|
| + if (!base::StringToInt(tokens[2], &pattern_.port) ||
|
| + pattern_.port < 1 || pattern_.port > 65535)
|
| break;
|
| return true;
|
| } while (false);
|
| @@ -198,13 +200,13 @@ bool SocketPermissionData::Parse(const std::string& permission) {
|
| }
|
|
|
| SocketPermissionData::HostType SocketPermissionData::GetHostType() const {
|
| - return host_.empty() ? SocketPermissionData::ANY_HOST :
|
| - match_subdomains_ ? SocketPermissionData::HOSTS_IN_DOMAINS :
|
| - SocketPermissionData::SPECIFIC_HOSTS;
|
| + return pattern_.host.empty() ? SocketPermissionData::ANY_HOST :
|
| + match_subdomains_ ? SocketPermissionData::HOSTS_IN_DOMAINS :
|
| + SocketPermissionData::SPECIFIC_HOSTS;
|
| }
|
|
|
| const std::string SocketPermissionData::GetHost() const {
|
| - return host_;
|
| + return pattern_.host;
|
| }
|
|
|
| const std::string& SocketPermissionData::GetAsString() const {
|
| @@ -212,29 +214,29 @@ const std::string& SocketPermissionData::GetAsString() const {
|
| return spec_;
|
|
|
| spec_.reserve(64);
|
| - spec_.append(TypeToString(type_));
|
| + spec_.append(TypeToString(pattern_.type));
|
|
|
| if (match_subdomains_) {
|
| spec_.append(1, kColon).append(kWildcard);
|
| - if (!host_.empty())
|
| - spec_.append(1, kDot).append(host_);
|
| + if (!pattern_.host.empty())
|
| + spec_.append(1, kDot).append(pattern_.host);
|
| } else {
|
| - spec_.append(1, kColon).append(host_);
|
| + spec_.append(1, kColon).append(pattern_.host);
|
| }
|
|
|
| - if (port_ == kAnyPort)
|
| + if (pattern_.port == kAnyPort)
|
| spec_.append(1, kColon).append(kWildcard);
|
| else
|
| - spec_.append(1, kColon).append(base::IntToString(port_));
|
| + spec_.append(1, kColon).append(base::IntToString(pattern_.port));
|
|
|
| return spec_;
|
| }
|
|
|
| void SocketPermissionData::Reset() {
|
| - type_ = NONE;
|
| - host_.clear();
|
| + pattern_.type = SocketPermissionRequest::NONE;
|
| + pattern_.host.clear();
|
| match_subdomains_ = false;
|
| - port_ = kInvalidPort;
|
| + pattern_.port = kInvalidPort;
|
| spec_.clear();
|
| }
|
|
|
|
|