Chromium Code Reviews| Index: webkit/plugins/ppapi/ppb_websocket_impl.cc |
| diff --git a/webkit/plugins/ppapi/ppb_websocket_impl.cc b/webkit/plugins/ppapi/ppb_websocket_impl.cc |
| index 9d4fc20048dad6f8ecea1095b6e914a4b01da146..b5ab02329c2dc3398bf55c66ecd1229c6fee2a40 100644 |
| --- a/webkit/plugins/ppapi/ppb_websocket_impl.cc |
| +++ b/webkit/plugins/ppapi/ppb_websocket_impl.cc |
| @@ -8,6 +8,7 @@ |
| #include "base/basictypes.h" |
| #include "base/logging.h" |
| +#include "base/values.h" |
| #include "googleurl/src/gurl.h" |
| #include "net/base/net_util.h" |
| #include "ppapi/c/pp_completion_callback.h" |
| @@ -146,16 +147,25 @@ int32_t PPB_WebSocket_Impl::Connect(PP_Var url, |
| WebURL web_url(gurl); |
| // Validate protocols and convert it to WebString. |
| - // TODO(toyoshim): Detect duplicated protocols as error. |
| std::string protocol_string; |
| + base::DictionaryValue protocol_set; |
|
dmichael (off chromium)
2011/12/07 20:21:13
Why not just use std::set? This seems like overkil
Takashi Toyoshima
2011/12/08 05:12:46
Oh, that's right.
I misunderstood about std::set<s
|
| for (uint32_t i = 0; i < protocol_count; i++) { |
| // TODO(toyoshim): Similar function exist in WebKit::WebSocket. |
| // We must rearrange them into WebKit::WebChannel and share its protocol |
| // related implementation via WebKit API. |
| scoped_refptr<StringVar> string_var; |
| string_var = StringVar::FromPPVar(protocols[i]); |
| + |
| + // Check duplicated protocol entries. |
| + if (protocol_set.HasKey(string_var->value())) |
| + return PP_ERROR_BADARGUMENT; |
| + protocol_set.SetBoolean(string_var->value(), true); |
| + |
| + // Check invalid and empty entries. |
| if (!string_var || !string_var->value().length()) |
| return PP_ERROR_BADARGUMENT; |
| + |
| + // Check containing characters. |
| for (std::string::const_iterator it = string_var->value().begin(); |
| it != string_var->value().end(); |
| ++it) { |
| @@ -174,6 +184,7 @@ int32_t PPB_WebSocket_Impl::Connect(PP_Var url, |
| character == '{' || character == '}') |
| return PP_ERROR_BADARGUMENT; |
| } |
| + // Join protocols with the comma separator. |
| if (i != 0) |
| protocol_string.append(","); |
| protocol_string.append(string_var->value()); |