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
3 // found in the LICENSE file.
4
5 #include "net/socket_stream/socket_stream_job.h"
6
7 #include "base/memory/singleton.h"
8 #include "net/base/transport_security_state.h"
9 #include "net/socket_stream/socket_stream_job_manager.h"
10 #include "net/url_request/url_request_context.h"
11
12 namespace net {
13
14 // static
RegisterProtocolFactory(const std::string & scheme,ProtocolFactory * factory)15 SocketStreamJob::ProtocolFactory* SocketStreamJob::RegisterProtocolFactory(
16 const std::string& scheme, ProtocolFactory* factory) {
17 return SocketStreamJobManager::GetInstance()->RegisterProtocolFactory(
18 scheme, factory);
19 }
20
21 // static
CreateSocketStreamJob(const GURL & url,SocketStream::Delegate * delegate,const URLRequestContext & context)22 SocketStreamJob* SocketStreamJob::CreateSocketStreamJob(
23 const GURL& url,
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);
40 }
41
SocketStreamJob()42 SocketStreamJob::SocketStreamJob() {}
43
GetUserData(const void * key) const44 SocketStream::UserData* SocketStreamJob::GetUserData(const void* key) const {
45 return socket_->GetUserData(key);
46 }
47
SetUserData(const void * key,SocketStream::UserData * data)48 void SocketStreamJob::SetUserData(const void* key,
49 SocketStream::UserData* data) {
50 socket_->SetUserData(key, data);
51 }
52
Connect()53 void SocketStreamJob::Connect() {
54 socket_->Connect();
55 }
56
SendData(const char * data,int len)57 bool SocketStreamJob::SendData(const char* data, int len) {
58 return socket_->SendData(data, len);
59 }
60
Close()61 void SocketStreamJob::Close() {
62 socket_->Close();
63 }
64
RestartWithAuth(const string16 & username,const string16 & password)65 void SocketStreamJob::RestartWithAuth(const string16& username,
66 const string16& password) {
67 socket_->RestartWithAuth(username, password);
68 }
69
DetachDelegate()70 void SocketStreamJob::DetachDelegate() {
71 socket_->DetachDelegate();
72 }
73
~SocketStreamJob()74 SocketStreamJob::~SocketStreamJob() {}
75
76 } // namespace net
77