OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "net/socket_stream/socket_stream_job.h" | 5 #include "net/socket_stream/socket_stream_job.h" |
6 | 6 |
7 #include "base/memory/singleton.h" | 7 #include "base/memory/singleton.h" |
| 8 #include "net/base/transport_security_state.h" |
8 #include "net/socket_stream/socket_stream_job_manager.h" | 9 #include "net/socket_stream/socket_stream_job_manager.h" |
| 10 #include "net/url_request/url_request_context.h" |
9 | 11 |
10 namespace net { | 12 namespace net { |
11 | 13 |
12 // static | 14 // static |
13 SocketStreamJob::ProtocolFactory* SocketStreamJob::RegisterProtocolFactory( | 15 SocketStreamJob::ProtocolFactory* SocketStreamJob::RegisterProtocolFactory( |
14 const std::string& scheme, ProtocolFactory* factory) { | 16 const std::string& scheme, ProtocolFactory* factory) { |
15 return SocketStreamJobManager::GetInstance()->RegisterProtocolFactory( | 17 return SocketStreamJobManager::GetInstance()->RegisterProtocolFactory( |
16 scheme, factory); | 18 scheme, factory); |
17 } | 19 } |
18 | 20 |
19 // static | 21 // static |
20 SocketStreamJob* SocketStreamJob::CreateSocketStreamJob( | 22 SocketStreamJob* SocketStreamJob::CreateSocketStreamJob( |
21 const GURL& url, SocketStream::Delegate* delegate) { | 23 const GURL& url, |
22 return SocketStreamJobManager::GetInstance()->CreateJob(url, delegate); | 24 SocketStream::Delegate* delegate, |
| 25 const URLRequestContext& context) { |
| 26 GURL socket_url(url); |
| 27 TransportSecurityState::DomainState domain_state; |
| 28 if (url.scheme() == "ws" && |
| 29 context.transport_security_state() && |
| 30 context.transport_security_state()->IsEnabledForHost( |
| 31 &domain_state, url.host(), context.IsSNIAvailable()) && |
| 32 domain_state.mode == TransportSecurityState::DomainState::MODE_STRICT) { |
| 33 url_canon::Replacements<char> replacements; |
| 34 static const char kNewScheme[] = "wss"; |
| 35 replacements.SetScheme(kNewScheme, |
| 36 url_parse::Component(0, strlen(kNewScheme))); |
| 37 socket_url = url.ReplaceComponents(replacements); |
| 38 } |
| 39 return SocketStreamJobManager::GetInstance()->CreateJob(socket_url, delegate); |
23 } | 40 } |
24 | 41 |
25 SocketStreamJob::SocketStreamJob() {} | 42 SocketStreamJob::SocketStreamJob() {} |
26 | 43 |
27 SocketStream::UserData* SocketStreamJob::GetUserData(const void* key) const { | 44 SocketStream::UserData* SocketStreamJob::GetUserData(const void* key) const { |
28 return socket_->GetUserData(key); | 45 return socket_->GetUserData(key); |
29 } | 46 } |
30 | 47 |
31 void SocketStreamJob::SetUserData(const void* key, | 48 void SocketStreamJob::SetUserData(const void* key, |
32 SocketStream::UserData* data) { | 49 SocketStream::UserData* data) { |
(...skipping 17 matching lines...) Expand all Loading... |
50 socket_->RestartWithAuth(username, password); | 67 socket_->RestartWithAuth(username, password); |
51 } | 68 } |
52 | 69 |
53 void SocketStreamJob::DetachDelegate() { | 70 void SocketStreamJob::DetachDelegate() { |
54 socket_->DetachDelegate(); | 71 socket_->DetachDelegate(); |
55 } | 72 } |
56 | 73 |
57 SocketStreamJob::~SocketStreamJob() {} | 74 SocketStreamJob::~SocketStreamJob() {} |
58 | 75 |
59 } // namespace net | 76 } // namespace net |
OLD | NEW |