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 c639fc6b40591107c166eea01caa279570b1dfa3..807d3ff4795fb1fc00f758008a639a4446f5615d 100644 |
| --- a/webkit/plugins/ppapi/ppb_websocket_impl.cc |
| +++ b/webkit/plugins/ppapi/ppb_websocket_impl.cc |
| @@ -211,8 +211,11 @@ int32_t PPB_WebSocket_Impl::Close(uint16_t code, |
| if (!websocket_.get()) |
| return PP_ERROR_FAILED; |
| - // Validate |code|. Need to cast |CloseEventCodeNotSpecified| which is -1 to |
| - // uint16_t for the comparison to work. |
| + // Validate |code| and |reason|. Need to cast |CloseEventCodeNotSpecified| |
| + // which is -1 to uint16_t for the comparison to work. |reason| is valid only |
| + // when |code| is not PP_WEBSOCKETSTATUSCODE_NOT_SPECIFIED. |
| + scoped_refptr<StringVar> reason_string; |
| + WebString web_reason; |
| if (code != static_cast<uint16_t>(WebSocket::CloseEventCodeNotSpecified)) { |
| if (!(code == WebSocket::CloseEventCodeNormalClosure || |
| (WebSocket::CloseEventCodeMinimumUserDefined <= code && |
| @@ -221,18 +224,16 @@ int32_t PPB_WebSocket_Impl::Close(uint16_t code, |
| // section 7.4.2.. The WebSocket API (http://www.w3.org/TR/websockets/) |
| // defines this out of range error as InvalidAccessError in JavaScript. |
| return PP_ERROR_NOACCESS; |
| - } |
| - scoped_refptr<StringVar> reason_string; |
| - WebString web_reason; |
| - // |reason| must be ignored if it is PP_VARTYPE_UNDEFINED. |
| - if (reason.type != PP_VARTYPE_UNDEFINED) { |
| - // Validate |reason|. |
| - reason_string = StringVar::FromPPVar(reason); |
| - if (!reason_string || |
| - reason_string->value().size() > kMaxReasonSizeInBytes) |
| - return PP_ERROR_BADARGUMENT; |
| - web_reason = WebString::fromUTF8(reason_string->value()); |
| + // |reason| must be ignored if it is PP_VARTYPE_UNDEFINED. |
|
Takashi Toyoshima
2012/05/14 12:05:04
I moved reason handling code inside of 'code != no
|
| + if (reason.type != PP_VARTYPE_UNDEFINED) { |
| + // Validate |reason|. |
| + reason_string = StringVar::FromPPVar(reason); |
| + if (!reason_string || |
| + reason_string->value().size() > kMaxReasonSizeInBytes) |
| + return PP_ERROR_BADARGUMENT; |
| + web_reason = WebString::fromUTF8(reason_string->value()); |
| + } |
| } |
| // Check state. |