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

Side by Side Diff: webkit/plugins/ppapi/ppb_websocket_impl.cc

Issue 8764022: WebSocket Pepper API: use net::IsPortAllowedByDefault() to validate port (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 9 years 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 | Annotate | Revision Log
« no previous file with comments | « ppapi/tests/test_websocket.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "webkit/plugins/ppapi/ppb_websocket_impl.h" 5 #include "webkit/plugins/ppapi/ppb_websocket_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 20 matching lines...) Expand all
31 using ppapi::StringVar; 31 using ppapi::StringVar;
32 using ppapi::thunk::PPB_WebSocket_API; 32 using ppapi::thunk::PPB_WebSocket_API;
33 using ppapi::VarTracker; 33 using ppapi::VarTracker;
34 using WebKit::WebData; 34 using WebKit::WebData;
35 using WebKit::WebDocument; 35 using WebKit::WebDocument;
36 using WebKit::WebString; 36 using WebKit::WebString;
37 using WebKit::WebSocket; 37 using WebKit::WebSocket;
38 using WebKit::WebSocketClient; 38 using WebKit::WebSocketClient;
39 using WebKit::WebURL; 39 using WebKit::WebURL;
40 40
41 namespace {
42
43 const uint32_t kMaxReasonSizeInBytes = 123; 41 const uint32_t kMaxReasonSizeInBytes = 123;
44 const size_t kHybiBaseFramingOverhead = 2; 42 const size_t kHybiBaseFramingOverhead = 2;
45 const size_t kHybiMaskingKeyLength = 4; 43 const size_t kHybiMaskingKeyLength = 4;
46 const size_t kMinimumPayloadSizeWithTwoByteExtendedPayloadLength = 126; 44 const size_t kMinimumPayloadSizeWithTwoByteExtendedPayloadLength = 126;
47 const size_t kMinimumPayloadSizeWithEightByteExtendedPayloadLength = 0x10000; 45 const size_t kMinimumPayloadSizeWithEightByteExtendedPayloadLength = 0x10000;
48 46
47 namespace {
48
49 uint64_t SaturateAdd(uint64_t a, uint64_t b) { 49 uint64_t SaturateAdd(uint64_t a, uint64_t b) {
50 if (kuint64max - a < b) 50 if (kuint64max - a < b)
51 return kuint64max; 51 return kuint64max;
52 return a + b; 52 return a + b;
53 } 53 }
54 54
55 uint64_t GetFrameSize(uint64_t payload_size) { 55 uint64_t GetFrameSize(uint64_t payload_size) {
56 if (!payload_size) 56 if (!payload_size)
57 return 0; 57 return 0;
58 58
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 return PP_ERROR_BADARGUMENT; 132 return PP_ERROR_BADARGUMENT;
133 GURL gurl(url_string->value()); 133 GURL gurl(url_string->value());
134 url_ = new StringVar( 134 url_ = new StringVar(
135 PpapiGlobals::Get()->GetModuleForInstance(pp_instance()), gurl.spec()); 135 PpapiGlobals::Get()->GetModuleForInstance(pp_instance()), gurl.spec());
136 if (!gurl.is_valid()) 136 if (!gurl.is_valid())
137 return PP_ERROR_BADARGUMENT; 137 return PP_ERROR_BADARGUMENT;
138 if (!gurl.SchemeIs("ws") && !gurl.SchemeIs("wss")) 138 if (!gurl.SchemeIs("ws") && !gurl.SchemeIs("wss"))
139 return PP_ERROR_BADARGUMENT; 139 return PP_ERROR_BADARGUMENT;
140 if (gurl.has_ref()) 140 if (gurl.has_ref())
141 return PP_ERROR_BADARGUMENT; 141 return PP_ERROR_BADARGUMENT;
142 // TODO(toyoshim): Must check if the port is allowed by default. 142 if (!net::IsPortAllowedByDefault(gurl.IntPort()))
143 // We could not just use net::IsPortAllowedByDefault() because it doesn't 143 return PP_ERROR_BADARGUMENT;
144 // be exported over the shared library.
145 WebURL web_url(gurl); 144 WebURL web_url(gurl);
146 145
147 // Validate protocols and convert it to WebString. 146 // Validate protocols and convert it to WebString.
148 // TODO(toyoshim): Detect duplicated protocols as error. 147 // TODO(toyoshim): Detect duplicated protocols as error.
149 std::string protocol_string; 148 std::string protocol_string;
150 for (uint32_t i = 0; i < protocol_count; i++) { 149 for (uint32_t i = 0; i < protocol_count; i++) {
151 // TODO(toyoshim): Similar function exist in WebKit::WebSocket. 150 // TODO(toyoshim): Similar function exist in WebKit::WebSocket.
152 // We must rearrange them into WebKit::WebChannel and share its protocol 151 // We must rearrange them into WebKit::WebChannel and share its protocol
153 // related implementation via WebKit API. 152 // related implementation via WebKit API.
154 scoped_refptr<StringVar> string_var; 153 scoped_refptr<StringVar> string_var;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 close_callback_ = callback; 228 close_callback_ = callback;
230 229
231 if (state_ == PP_WEBSOCKETREADYSTATE_CONNECTING_DEV) { 230 if (state_ == PP_WEBSOCKETREADYSTATE_CONNECTING_DEV) {
232 state_ = PP_WEBSOCKETREADYSTATE_CLOSING_DEV; 231 state_ = PP_WEBSOCKETREADYSTATE_CLOSING_DEV;
233 PP_RunAndClearCompletionCallback(&connect_callback_, PP_ERROR_ABORTED); 232 PP_RunAndClearCompletionCallback(&connect_callback_, PP_ERROR_ABORTED);
234 websocket_->fail( 233 websocket_->fail(
235 "WebSocket was closed before the connection was established."); 234 "WebSocket was closed before the connection was established.");
236 return PP_OK_COMPLETIONPENDING; 235 return PP_OK_COMPLETIONPENDING;
237 } 236 }
238 237
239 // TODO(toyoshim): Handle bufferedAmount here.
240
241 state_ = PP_WEBSOCKETREADYSTATE_CLOSING_DEV; 238 state_ = PP_WEBSOCKETREADYSTATE_CLOSING_DEV;
242 WebString web_reason = WebString::fromUTF8(reason_string->value()); 239 WebString web_reason = WebString::fromUTF8(reason_string->value());
243 websocket_->close(code, web_reason); 240 websocket_->close(code, web_reason);
244 241
245 return PP_OK_COMPLETIONPENDING; 242 return PP_OK_COMPLETIONPENDING;
246 } 243 }
247 244
248 int32_t PPB_WebSocket_Impl::ReceiveMessage(PP_Var* message, 245 int32_t PPB_WebSocket_Impl::ReceiveMessage(PP_Var* message,
249 PP_CompletionCallback callback) { 246 PP_CompletionCallback callback) {
250 // Check state. 247 // Check state.
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 426
430 *receive_callback_var_ = received_messages_.front(); 427 *receive_callback_var_ = received_messages_.front();
431 received_messages_.pop(); 428 received_messages_.pop();
432 receive_callback_var_ = NULL; 429 receive_callback_var_ = NULL;
433 wait_for_receive_ = false; 430 wait_for_receive_ = false;
434 return PP_OK; 431 return PP_OK;
435 } 432 }
436 433
437 } // namespace ppapi 434 } // namespace ppapi
438 } // namespace webkit 435 } // namespace webkit
OLDNEW
« no previous file with comments | « ppapi/tests/test_websocket.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698