[content shell] implement testRunner.overridePreference
[chromium-blink-merge.git] / net / socket / ssl_client_socket.cc
blob7f2325846e0bce50c3d4f5fafa73bc2226883e82
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
3 // found in the LICENSE file.
5 #include "net/socket/ssl_client_socket.h"
7 #include "base/string_util.h"
9 namespace net {
11 SSLClientSocket::SSLClientSocket()
12 : was_npn_negotiated_(false),
13 was_spdy_negotiated_(false),
14 protocol_negotiated_(kProtoUnknown),
15 channel_id_sent_(false) {
18 // static
19 NextProto SSLClientSocket::NextProtoFromString(
20 const std::string& proto_string) {
21 if (proto_string == "http1.1" || proto_string == "http/1.1") {
22 return kProtoHTTP11;
23 } else if (proto_string == "spdy/1") {
24 return kProtoSPDY1;
25 } else if (proto_string == "spdy/2") {
26 return kProtoSPDY2;
27 } else if (proto_string == "spdy/3") {
28 return kProtoSPDY3;
29 } else {
30 return kProtoUnknown;
34 // static
35 const char* SSLClientSocket::NextProtoToString(NextProto next_proto) {
36 switch (next_proto) {
37 case kProtoHTTP11:
38 return "http/1.1";
39 case kProtoSPDY1:
40 return "spdy/1";
41 case kProtoSPDY2:
42 return "spdy/2";
43 case kProtoSPDY3:
44 return "spdy/3";
45 default:
46 break;
48 return "unknown";
51 // static
52 const char* SSLClientSocket::NextProtoStatusToString(
53 const SSLClientSocket::NextProtoStatus status) {
54 switch (status) {
55 case kNextProtoUnsupported:
56 return "unsupported";
57 case kNextProtoNegotiated:
58 return "negotiated";
59 case kNextProtoNoOverlap:
60 return "no-overlap";
62 return NULL;
65 // static
66 std::string SSLClientSocket::ServerProtosToString(
67 const std::string& server_protos) {
68 const char* protos = server_protos.c_str();
69 size_t protos_len = server_protos.length();
70 std::vector<std::string> server_protos_with_commas;
71 for (size_t i = 0; i < protos_len; ) {
72 const size_t len = protos[i];
73 std::string proto_str(&protos[i + 1], len);
74 server_protos_with_commas.push_back(proto_str);
75 i += len + 1;
77 return JoinString(server_protos_with_commas, ',');
80 bool SSLClientSocket::WasNpnNegotiated() const {
81 return was_npn_negotiated_;
84 NextProto SSLClientSocket::GetNegotiatedProtocol() const {
85 return protocol_negotiated_;
88 bool SSLClientSocket::IgnoreCertError(int error, int load_flags) {
89 if (error == OK || load_flags & LOAD_IGNORE_ALL_CERT_ERRORS)
90 return true;
92 if (error == ERR_CERT_COMMON_NAME_INVALID &&
93 (load_flags & LOAD_IGNORE_CERT_COMMON_NAME_INVALID))
94 return true;
96 if (error == ERR_CERT_DATE_INVALID &&
97 (load_flags & LOAD_IGNORE_CERT_DATE_INVALID))
98 return true;
100 if (error == ERR_CERT_AUTHORITY_INVALID &&
101 (load_flags & LOAD_IGNORE_CERT_AUTHORITY_INVALID))
102 return true;
104 return false;
107 bool SSLClientSocket::set_was_npn_negotiated(bool negotiated) {
108 return was_npn_negotiated_ = negotiated;
111 bool SSLClientSocket::was_spdy_negotiated() const {
112 return was_spdy_negotiated_;
115 bool SSLClientSocket::set_was_spdy_negotiated(bool negotiated) {
116 return was_spdy_negotiated_ = negotiated;
119 void SSLClientSocket::set_protocol_negotiated(NextProto protocol_negotiated) {
120 protocol_negotiated_ = protocol_negotiated;
123 bool SSLClientSocket::WasChannelIDSent() const {
124 return channel_id_sent_;
127 void SSLClientSocket::set_channel_id_sent(bool channel_id_sent) {
128 channel_id_sent_ = channel_id_sent;
131 } // namespace net