1 // Copyright 2013 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/websockets/websocket_handshake_stream_create_helper.h"
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h"
10 #include "net/socket/client_socket_handle.h"
11 #include "net/spdy/spdy_session.h"
12 #include "net/websockets/websocket_basic_handshake_stream.h"
16 WebSocketHandshakeStreamCreateHelper::WebSocketHandshakeStreamCreateHelper(
17 WebSocketStream::ConnectDelegate
* connect_delegate
,
18 const std::vector
<std::string
>& requested_subprotocols
)
19 : requested_subprotocols_(requested_subprotocols
),
21 connect_delegate_(connect_delegate
),
22 failure_message_(NULL
) {
23 DCHECK(connect_delegate_
);
26 WebSocketHandshakeStreamCreateHelper::~WebSocketHandshakeStreamCreateHelper() {}
28 WebSocketHandshakeStreamBase
*
29 WebSocketHandshakeStreamCreateHelper::CreateBasicStream(
30 scoped_ptr
<ClientSocketHandle
> connection
,
32 DCHECK(failure_message_
) << "set_failure_message() must be called";
33 // The list of supported extensions and parameters is hard-coded.
34 // TODO(ricea): If more extensions are added, consider a more flexible
36 std::vector
<std::string
> extensions(
37 1, "permessage-deflate; client_max_window_bits");
38 WebSocketBasicHandshakeStream
* stream
=
39 new WebSocketBasicHandshakeStream(connection
.Pass(),
42 requested_subprotocols_
,
45 OnStreamCreated(stream
);
50 // TODO(ricea): Create a WebSocketSpdyHandshakeStream. crbug.com/323852
51 WebSocketHandshakeStreamBase
*
52 WebSocketHandshakeStreamCreateHelper::CreateSpdyStream(
53 const base::WeakPtr
<SpdySession
>& session
,
54 bool use_relative_url
) {
55 NOTREACHED() << "Not implemented";
59 scoped_ptr
<WebSocketStream
> WebSocketHandshakeStreamCreateHelper::Upgrade() {
61 WebSocketHandshakeStreamBase
* stream
= stream_
;
63 return stream
->Upgrade();
66 void WebSocketHandshakeStreamCreateHelper::OnStreamCreated(
67 WebSocketBasicHandshakeStream
* stream
) {