Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(350)

Side by Side Diff: net/websockets/websocket_job.h

Issue 601077: Support HttpOnly cookie on Web Socket (Closed)
Patch Set: fix darin's comment Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/socket_stream/socket_stream_job_manager.cc ('k') | net/websockets/websocket_job.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 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 #ifndef NET_WEBSOCKETS_WEBSOCKET_JOB_H_
6 #define NET_WEBSOCKETS_WEBSOCKET_JOB_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/ref_counted.h"
12 #include "net/base/completion_callback.h"
13 #include "net/socket_stream/socket_stream_job.h"
14
15 class GURL;
16
17 namespace net {
18
19 // WebSocket protocol specific job on SocketStream.
20 // It captures WebSocket handshake message and handles cookie operations.
21 // Chome security policy doesn't allow renderer process (except dev tools)
22 // see HttpOnly cookies, so it injects cookie header in handshake request and
23 // strips set-cookie headers in handshake response.
24 // TODO(ukai): refactor to merge WebSocketThrottle functionality.
25 // TODO(ukai): refactor websocket.cc to use this.
26 class WebSocketJob : public SocketStreamJob, public SocketStream::Delegate {
27 public:
28 // This is state of WebSocket, not SocketStream.
29 enum State {
30 INITIALIZED = -1,
31 CONNECTING = 0,
32 OPEN = 1,
33 CLOSED = 2,
34 };
35 static void EnsureInit();
36
37 explicit WebSocketJob(SocketStream::Delegate* delegate);
38
39 virtual void Connect();
40 virtual bool SendData(const char* data, int len);
41 virtual void Close();
42 virtual void RestartWithAuth(
43 const std::wstring& username,
44 const std::wstring& password);
45 virtual void DetachDelegate();
46
47 // SocketStream::Delegate methods.
48 virtual void OnConnected(
49 SocketStream* socket, int max_pending_send_allowed);
50 virtual void OnSentData(
51 SocketStream* socket, int amount_sent);
52 virtual void OnReceivedData(
53 SocketStream* socket, const char* data, int len);
54 virtual void OnClose(SocketStream* socket);
55 virtual void OnAuthRequired(
56 SocketStream* socket, AuthChallengeInfo* auth_info);
57 virtual void OnError(
58 const SocketStream* socket, int error);
59
60 private:
61 friend class WebSocketJobTest;
62 virtual ~WebSocketJob();
63
64 bool SendHandshakeRequest(const char* data, int len);
65 void AddCookieHeaderAndSend();
66 void OnCanGetCookiesCompleted(int policy);
67
68 void OnSentHandshakeRequest(SocketStream* socket, int amount_sent);
69 void OnReceivedHandshakeResponse(
70 SocketStream* socket, const char* data, int len);
71 void SaveCookiesAndNotifyHeaderComplete();
72 void SaveNextCookie();
73 void OnCanSetCookieCompleted(int policy);
74
75 GURL GetURLForCookies() const;
76
77 SocketStream::Delegate* delegate_;
78 State state_;
79
80 std::string original_handshake_request_;
81 int original_handshake_request_header_length_;
82 std::string handshake_request_;
83 size_t handshake_request_sent_;
84
85 std::string handshake_response_;
86 int handshake_response_header_length_;
87 std::vector<std::string> response_cookies_;
88 size_t response_cookies_save_index_;
89
90 CompletionCallbackImpl<WebSocketJob> can_get_cookies_callback_;
91 CompletionCallbackImpl<WebSocketJob> can_set_cookie_callback_;
92
93 DISALLOW_COPY_AND_ASSIGN(WebSocketJob);
94 };
95
96 } // namespace
97
98 #endif // NET_WEBSOCKETS_WEBSOCKET_JOB_H_
OLDNEW
« no previous file with comments | « net/socket_stream/socket_stream_job_manager.cc ('k') | net/websockets/websocket_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698