| OLD | NEW | 
|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/websockets/websocket_stream.h" | 5 #include "net/websockets/websocket_stream.h" | 
| 6 | 6 | 
| 7 #include <memory> | 7 #include <memory> | 
| 8 #include <utility> | 8 #include <utility> | 
| 9 | 9 | 
| 10 #include "base/logging.h" | 10 #include "base/logging.h" | 
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" | 
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" | 
| 13 #include "base/metrics/sparse_histogram.h" | 13 #include "base/metrics/sparse_histogram.h" | 
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" | 
| 15 #include "base/timer/timer.h" | 15 #include "base/timer/timer.h" | 
| 16 #include "net/base/load_flags.h" | 16 #include "net/base/load_flags.h" | 
| 17 #include "net/http/http_request_headers.h" | 17 #include "net/http/http_request_headers.h" | 
| 18 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" | 
| 19 #include "net/http/http_status_code.h" | 19 #include "net/http/http_status_code.h" | 
|  | 20 #include "net/traffic_annotation/network_traffic_annotation.h" | 
| 20 #include "net/url_request/redirect_info.h" | 21 #include "net/url_request/redirect_info.h" | 
| 21 #include "net/url_request/url_request.h" | 22 #include "net/url_request/url_request.h" | 
| 22 #include "net/url_request/url_request_context.h" | 23 #include "net/url_request/url_request_context.h" | 
| 23 #include "net/websockets/websocket_errors.h" | 24 #include "net/websockets/websocket_errors.h" | 
| 24 #include "net/websockets/websocket_event_interface.h" | 25 #include "net/websockets/websocket_event_interface.h" | 
| 25 #include "net/websockets/websocket_handshake_constants.h" | 26 #include "net/websockets/websocket_handshake_constants.h" | 
| 26 #include "net/websockets/websocket_handshake_stream_base.h" | 27 #include "net/websockets/websocket_handshake_stream_base.h" | 
| 27 #include "net/websockets/websocket_handshake_stream_create_helper.h" | 28 #include "net/websockets/websocket_handshake_stream_create_helper.h" | 
| 28 #include "url/gurl.h" | 29 #include "url/gurl.h" | 
| 29 #include "url/origin.h" | 30 #include "url/origin.h" | 
| 30 | 31 | 
|  | 32 namespace { | 
|  | 33 | 
|  | 34 constexpr net::NetworkTrafficAnnotationTag kTrafficAnnotation = | 
|  | 35     net::DefineNetworkTrafficAnnotation("websocket_stream", R"( | 
|  | 36         semantics { | 
|  | 37           sender: "WebSocket Handshake" | 
|  | 38           description: | 
|  | 39             "Renderer process initiated WebSocket handshake. The WebSocket " | 
|  | 40             "handshake is used to establish a connection between a web page " | 
|  | 41             "and a consenting server for bi-directional communication." | 
|  | 42           trigger: | 
|  | 43             "A handshake is performed every time a new connection is " | 
|  | 44             "established via the Javascript or PPAPI WebSocket API. Any web " | 
|  | 45             "page or extension can create a WebSocket connection." | 
|  | 46           data: "The path and sub-protocols requested when the WebSocket was " | 
|  | 47                 "created, plus the origin of the creating page." | 
|  | 48           destination: OTHER | 
|  | 49         } | 
|  | 50         policy { | 
|  | 51           cookies_allowed: true | 
|  | 52           cookies_store: "user or per-app cookie store" | 
|  | 53           setting: "These requests cannot be disabled." | 
|  | 54           policy_exception_justification: | 
|  | 55             "Not implemented. WebSocket is a core web platform API." | 
|  | 56         })"); | 
|  | 57 | 
|  | 58 }  // namespace | 
|  | 59 | 
| 31 namespace net { | 60 namespace net { | 
| 32 namespace { | 61 namespace { | 
| 33 | 62 | 
| 34 // The timeout duration of WebSocket handshake. | 63 // The timeout duration of WebSocket handshake. | 
| 35 // It is defined as the same value as the TCP connection timeout value in | 64 // It is defined as the same value as the TCP connection timeout value in | 
| 36 // net/socket/websocket_transport_client_socket_pool.cc to make it hard for | 65 // net/socket/websocket_transport_client_socket_pool.cc to make it hard for | 
| 37 // JavaScript programs to recognize the timeout cause. | 66 // JavaScript programs to recognize the timeout cause. | 
| 38 const int kHandshakeTimeoutIntervalInSeconds = 240; | 67 const int kHandshakeTimeoutIntervalInSeconds = 240; | 
| 39 | 68 | 
| 40 class WebSocketStreamRequestImpl; | 69 class WebSocketStreamRequestImpl; | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 83  public: | 112  public: | 
| 84   WebSocketStreamRequestImpl( | 113   WebSocketStreamRequestImpl( | 
| 85       const GURL& url, | 114       const GURL& url, | 
| 86       const URLRequestContext* context, | 115       const URLRequestContext* context, | 
| 87       const url::Origin& origin, | 116       const url::Origin& origin, | 
| 88       const GURL& first_party_for_cookies, | 117       const GURL& first_party_for_cookies, | 
| 89       const std::string& additional_headers, | 118       const std::string& additional_headers, | 
| 90       std::unique_ptr<WebSocketStream::ConnectDelegate> connect_delegate, | 119       std::unique_ptr<WebSocketStream::ConnectDelegate> connect_delegate, | 
| 91       std::unique_ptr<WebSocketHandshakeStreamCreateHelper> create_helper) | 120       std::unique_ptr<WebSocketHandshakeStreamCreateHelper> create_helper) | 
| 92       : delegate_(new Delegate(this)), | 121       : delegate_(new Delegate(this)), | 
| 93         url_request_( | 122         url_request_(context->CreateRequest(url, | 
| 94             context->CreateRequest(url, DEFAULT_PRIORITY, delegate_.get())), | 123                                             DEFAULT_PRIORITY, | 
|  | 124                                             delegate_.get(), | 
|  | 125                                             kTrafficAnnotation)), | 
| 95         connect_delegate_(std::move(connect_delegate)), | 126         connect_delegate_(std::move(connect_delegate)), | 
| 96         handshake_stream_(nullptr) { | 127         handshake_stream_(nullptr) { | 
| 97     create_helper->set_stream_request(this); | 128     create_helper->set_stream_request(this); | 
| 98     HttpRequestHeaders headers; | 129     HttpRequestHeaders headers; | 
| 99     headers.SetHeader(websockets::kUpgrade, websockets::kWebSocketLowercase); | 130     headers.SetHeader(websockets::kUpgrade, websockets::kWebSocketLowercase); | 
| 100     headers.SetHeader(HttpRequestHeaders::kConnection, websockets::kUpgrade); | 131     headers.SetHeader(HttpRequestHeaders::kConnection, websockets::kUpgrade); | 
| 101     headers.SetHeader(HttpRequestHeaders::kOrigin, origin.Serialize()); | 132     headers.SetHeader(HttpRequestHeaders::kOrigin, origin.Serialize()); | 
| 102     headers.SetHeader(websockets::kSecWebSocketVersion, | 133     headers.SetHeader(websockets::kSecWebSocketVersion, | 
| 103                       websockets::kSupportedVersion); | 134                       websockets::kSupportedVersion); | 
| 104 | 135 | 
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 401   DCHECK(connect_delegate); | 432   DCHECK(connect_delegate); | 
| 402   if (headers.get()) { | 433   if (headers.get()) { | 
| 403     connect_delegate->OnFinishOpeningHandshake( | 434     connect_delegate->OnFinishOpeningHandshake( | 
| 404         base::MakeUnique<WebSocketHandshakeResponseInfo>( | 435         base::MakeUnique<WebSocketHandshakeResponseInfo>( | 
| 405             url, headers->response_code(), headers->GetStatusText(), headers, | 436             url, headers->response_code(), headers->GetStatusText(), headers, | 
| 406             response_time)); | 437             response_time)); | 
| 407   } | 438   } | 
| 408 } | 439 } | 
| 409 | 440 | 
| 410 }  // namespace net | 441 }  // namespace net | 
| OLD | NEW | 
|---|