diff options
author | toyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-31 09:25:45 +0000 |
---|---|---|
committer | toyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-31 09:25:45 +0000 |
commit | b6b90fed5146f71f39757249b00bfa3b9f40ac02 (patch) | |
tree | a4bb50304e9603399cb88def533deb9bed06658f /webkit/plugins | |
parent | 9d890b7e2e2eb291863f984e2ed3e50141d20cc8 (diff) | |
download | chromium_src-b6b90fed5146f71f39757249b00bfa3b9f40ac02.zip chromium_src-b6b90fed5146f71f39757249b00bfa3b9f40ac02.tar.gz chromium_src-b6b90fed5146f71f39757249b00bfa3b9f40ac02.tar.bz2 |
WebSocket Pepper API: allow to close connection without code and reason
- define PP_WEBSOCKETSTATUSCODE_NOT_SPECIFIED to close without status code
- omit reason for WebKit API explicitly when code is not specified
BUG=none
TEST=browser_tests --gtest_filter'PPAPI*WebSocket_*Close'
Review URL: https://chromiumcodereview.appspot.com/10332138
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139764 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/plugins')
-rw-r--r-- | webkit/plugins/ppapi/ppb_websocket_impl.cc | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/webkit/plugins/ppapi/ppb_websocket_impl.cc b/webkit/plugins/ppapi/ppb_websocket_impl.cc index c639fc6..8cdada8 100644 --- a/webkit/plugins/ppapi/ppb_websocket_impl.cc +++ b/webkit/plugins/ppapi/ppb_websocket_impl.cc @@ -211,28 +211,35 @@ 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. - if (code != static_cast<uint16_t>(WebSocket::CloseEventCodeNotSpecified)) { - if (!(code == WebSocket::CloseEventCodeNormalClosure || - (WebSocket::CloseEventCodeMinimumUserDefined <= code && - code <= WebSocket::CloseEventCodeMaximumUserDefined))) - // RFC 6455 limits applications to use reserved connection close code in - // 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; - } - + // Validate |code| and |reason|. 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()); + WebSocket::CloseEventCode event_code = + static_cast<WebSocket::CloseEventCode>(code); + if (code == PP_WEBSOCKETSTATUSCODE_NOT_SPECIFIED) { + // PP_WEBSOCKETSTATUSCODE_NOT_SPECIFIED and CloseEventCodeNotSpecified are + // assigned to different values. A conversion is needed if + // PP_WEBSOCKETSTATUSCODE_NOT_SPECIFIED is specified. + event_code = WebSocket::CloseEventCodeNotSpecified; + } else { + if (!(code == PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE || + (PP_WEBSOCKETSTATUSCODE_USER_REGISTERED_MIN <= code && + code <= PP_WEBSOCKETSTATUSCODE_USER_PRIVATE_MAX))) + // RFC 6455 limits applications to use reserved connection close code in + // 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; + + // |reason| must be ignored if it is PP_VARTYPE_UNDEFINED or |code| is + // PP_WEBSOCKETSTATUSCODE_NOT_SPECIFIED. + 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. @@ -271,7 +278,7 @@ int32_t PPB_WebSocket_Impl::Close(uint16_t code, // Close connection. state_ = PP_WEBSOCKETREADYSTATE_CLOSING; - websocket_->close(code, web_reason); + websocket_->close(event_code, web_reason); return PP_OK_COMPLETIONPENDING; } |