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

Unified Diff: ppapi/cpp/dev/websocket_dev.h

Issue 8821010: WebSocket Pepper API: C++ bindings implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: straightforward C++ interface 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 side-by-side diff with in-line comments
Download patch
Index: ppapi/cpp/dev/websocket_dev.h
diff --git a/ppapi/cpp/dev/websocket_dev.h b/ppapi/cpp/dev/websocket_dev.h
index 8b25b8ee2ef5e31d67fd5f6821959fe37c534283..bc44b5b699fbc9d0161fd8bb15e2f4758d8d317a 100644
--- a/ppapi/cpp/dev/websocket_dev.h
+++ b/ppapi/cpp/dev/websocket_dev.h
@@ -6,12 +6,15 @@
#define PPAPI_CPP_DEV_WEBSOCKET_DEV_H_
#include "ppapi/c/dev/ppb_websocket_dev.h"
+#include "ppapi/cpp/resource.h"
/// @file
/// This file defines the WebSocket_Dev interface.
namespace pp {
+class CompletionCallback;
+class Instance;
class Var;
/// The <code>WebSocket_Dev</code> class
@@ -19,7 +22,7 @@ class Var;
class WebSocket_Dev : public Resource {
public:
/// Constructs a WebSocket_Dev object.
- WebSocket_Dev();
+ WebSocket_Dev(Instance* instance);
/// Destructs a WebSocket_Dev object.
virtual ~WebSocket_Dev();
@@ -27,40 +30,63 @@ class WebSocket_Dev : public Resource {
/// Connect() connects to the specified WebSocket server. Caller can call
/// this method at most once.
///
- /// @param[in] url A <code>PP_Var</code> representing a WebSocket server URL.
- /// The <code>PP_VarType</code> must be <code>PP_VARTYPE_STRING</code>.
- /// @param[in] protocols A pointer to an array of <code>PP_Var</code>
- /// specifying sub-protocols. Each <code>PP_Var</code> represents one
- /// sub-protocol and its <code>PP_VarType</code> must be
- /// <code>PP_VARTYPE_STRING</code>. This argument can be null only if
- /// <code>protocol_count</code> is 0.
+ /// @param[in] url A <code>Var</code> of string type representing a WebSocket
+ /// server URL.
+ /// @param[in] protocols An array of string type <code>Var</code> specifying
+ /// sub-protocols. Each <code>Var</code> represents one sub-protocol. This
+ /// argument can be null only if <code>protocol_count</code> is 0.
dmichael (off chromium) 2011/12/09 23:05:26 Is there a reason you removed this comment on the
Takashi Toyoshima 2011/12/13 14:08:23 Oh, sorry. I misunderstand on array like that foo[
/// @param[in] protocol_count The number of sub-protocols in
/// <code>protocols</code>.
+ /// @param[in] callback A <code>CompletionCallback</code> which is called
+ /// when the connection is established or an error occurs in establishing
+ /// connection.
dmichael (off chromium) 2011/12/09 23:05:26 "the" connection ?
Takashi Toyoshima 2011/12/13 14:08:23 s/the/a/. on this and idl definition.
///
- /// @return In case of immediate failure, returns an error code as follows.
- /// Returns <code>PP_ERROR_BADARGUMENT</code> corresponding to JavaScript
- /// SyntaxError and <code>PP_ERROR_NOACCESS</code> corresponding to
- /// JavaScript SecurityError. Otherwise, returns
- /// <code>PP_OK_COMPLETIONPENDING</code> and later invokes
- /// <code>OnOpen()</code> on success or <code>OnClose()</code> on failure.
- int32_t Connect(const Var& url, const Var protocols[],
- uint32_t protocol_count);
+ /// @return Returns <code>PP_OK_COMPLETIONPENDING</code> then callback is
dmichael (off chromium) 2011/12/09 23:05:26 Maybe this should be worded differently. It can re
Takashi Toyoshima 2011/12/13 14:08:23 Thank you. I fixed all description on C/C++ APIs w
+ /// invoked with one of following results.
+ /// <code>PP_ERROR_BADARGUMENT</code> corresponds to JavaScript SyntaxError,
dmichael (off chromium) 2011/12/09 23:05:26 I think it would be better to explain what the err
Takashi Toyoshima 2011/12/13 14:08:23 The error detection rule is complicated, but I try
+ /// <code>PP_ERROR_NOACCESS</code> corresponds to JavaScript SecurityError.
+ /// and returns <code>PP_ERROR_INPROGRESS</code> if the call is not the first
+ /// time.
+ int32_t Connect(const Var& url, const Var* const protocols,
dmichael (off chromium) 2011/12/09 23:05:26 Why did you change from const Var protocols[]? In
Takashi Toyoshima 2011/12/13 14:08:23 Done.
+ uint32_t protocol_count, const CompletionCallback& callback);
/// Close() closes the specified WebSocket connection by specifying
/// <code>code</code> and <code>reason</code>.
///
/// @param[in] code The WebSocket close code. Ignored if it is 0.
- /// @param[in] reason A <code>PP_Var</code> which represents the WebSocket
- /// close reason. Ignored if it is <code>PP_VARTYPE_UNDEFINED</code>.
- /// Otherwise, its <code>PP_VarType</code> must be
- /// <code>PP_VARTYPE_STRING</code>.
+ /// @param[in] reason A <code>Var</code> of string type which represents the
+ /// WebSocket close reason. Ignored if it is undefined type.
+ /// @param[in] callback A <code>CompletionCallback</code> which is called
+ /// when the connection is closed or an error occurs in closing connection.
dmichael (off chromium) 2011/12/09 23:05:26 closing 'the' connection?
Takashi Toyoshima 2011/12/13 14:08:23 Done.
///
- /// @return In case of immediate failure, returns an error code as follows.
- /// Returns <code>PP_ERROR_BADARGUMENT</code> corresponding to JavaScript
- /// SyntaxError and <code>PP_ERROR_NOACCESS</code> corresponding to
- /// JavaScript InvalidAccessError. Otherwise, returns
- /// <code>PP_OK_COMPLETIONPENDING</code> and invokes <code>OnClose</code>.
- int32_t Close(uint16_t code, const Var& reason);
+ /// @return Returns <code>PP_OK_COMPLETIONPENDING</code> then callback is
+ /// invoked with one of following results.
+ /// <code>PP_ERROR_BADARGUMENT</code> corresponds to JavaScript SyntaxError,
+ /// <code>PP_ERROR_NOACCESS</code> corresponds to JavaScript
+ /// InvalidAccessError. Returns <code>PP_ERROR_INPROGRESS</code> if the call
+ /// is not the first time.
+ int32_t Close(uint16_t code, const Var& reason,
+ const CompletionCallback& callback);
+
+ /// ReceiveMessage() receives a message from the WebSocket server.
+ /// This interface only returns bytes of a single message. That is, this
dmichael (off chromium) 2011/12/09 23:05:26 I would remove 'bytes of '
Takashi Toyoshima 2011/12/13 14:08:23 Done.
+ /// interface must be called at least N times to receive N messages, no
+ /// matter how small each message is.
+ ///
+ /// @param[out] message The received message is copied to provided
+ /// <code>message</code>.
dmichael (off chromium) 2011/12/09 23:05:26 Maybe it's worth noting that the Var passed for |m
Takashi Toyoshima 2011/12/13 14:08:23 Done.
+ /// @param[in] callback A <code>CompletionCallback</code> which is called
+ /// when the receiving message is completed. It is ignored when the function
dmichael (off chromium) 2011/12/09 23:05:26 It might be clearer to say something like: "It is
Takashi Toyoshima 2011/12/13 14:08:23 Thank you for good suggestion. Fixed.
+ /// return <code>PP_OK</code>.
+ ///
+ /// @return Returns <code>PP_OK_COMPLETIONPENDING</code> then callback is
+ /// invoked with <code>PP_OK</code> or <code>PP_ERROR_FAILED</code>.
+ /// If an error is detected or connection is closed, returns
+ /// <code>PP_ERROR_FAILED</code> after all buffered messages are received.
+ /// Until buffered message become empty, continues to returns
+ /// <code>PP_OK</code> as if connection is still established without errors.
+ int32_t ReceiveMessage(Var* message,
+ const CompletionCallback& callback);
/// Send() sends a message to the WebSocket server.
///
@@ -74,32 +100,50 @@ class WebSocket_Dev : public Resource {
/// JavaScript SyntaxError. Otherwise, return <code>PP_OK</code>.
/// <code>PP_OK</code> doesn't necessarily mean that the server received the
/// message.
- int32_t Send(const Var& data);
+ int32_t SendMessage(const Var& message);
/// GetBufferedAmount() returns the number of bytes of text and binary
/// messages that have been queued for the WebSocket connection to send but
/// have not been transmitted to the network yet.
///
- /// Note: This interface might not be able to return exact bytes in the first
- /// release. Current WebSocket implementation can not estimate exact protocol
- /// frame overheads.
- ///
/// @return Returns the number of bytes.
uint64_t GetBufferedAmount();
+ /// GetCloseCode() returns the connection close code for the WebSocket
+ /// connection.
+ ///
+ /// @return Returns 0 if called before the close code is set.
+ uint16_t GetCloseCode();
+
+ /// GetCloseReason() returns the connection close reason for the WebSocket
+ /// connection.
+ ///
+ /// @return Returns a <code>Var</code> of string type. If called before the
+ /// close reason is set, it contains empty string.
dmichael (off chromium) 2011/12/09 23:05:26 contains 'an' empty string?
Takashi Toyoshima 2011/12/13 14:08:23 Done.
+ Var GetCloseReason();
+
+ /// GetCloseWasClean() returns if the connection was closed cleanly for the
+ /// specified WebSocket connection.
+ ///
+ /// @return Returns <code>false</code> if called before the connection is
+ /// closed, or called on an invalid resource. Otherwise, returns
+ /// <code>true</code> if the connection was closed cleanly, or returns
+ /// <code>false</code> if the connection was closed by abnormal reasons.
dmichael (off chromium) 2011/12/09 23:05:26 by->for
Takashi Toyoshima 2011/12/13 14:08:23 Done.
+ bool GetCloseWasClean();
+
/// GetExtensions() returns the extensions selected by the server for the
/// specified WebSocket connection.
///
- /// @return Returns a <code>PP_VARTYPE_STRING</code> var. If called before
- /// the connection is established, its data is empty string.
+ /// @return Returns a <code>Var</code> of string type. If called before the
+ /// connection is established, its data is empty string.
/// Currently its data is always empty string.
dmichael (off chromium) 2011/12/09 23:05:26 'an' empty string?
Takashi Toyoshima 2011/12/13 14:08:23 Done.
Var GetExtensions();
/// GetProtocol() returns the sub-protocol chosen by the server for the
/// specified WebSocket connection.
///
- /// @return Returns a <code>PP_VARTYPE_STRING</code> var. If called before
- /// the connection is established, its data is empty string.
+ /// @return Returns a <code>Var</code> of string type. If called before the
+ /// connection is established, it containss empty string.
dmichael (off chromium) 2011/12/09 23:05:26 "containss"->"contains the"
Takashi Toyoshima 2011/12/13 14:08:23 Done.
Var GetProtocol();
/// GetReadyState() returns the ready state of the specified WebSocket
@@ -111,23 +155,9 @@ class WebSocket_Dev : public Resource {
/// GetURL() returns the URL associated with specified WebSocket connection.
///
- /// @return Returns a <code>PP_VARTYPE_STRING</code> var. If called before
- /// the connection is established, its data is empty string.
+ /// @return Returns a <code>Var</code> of string type. If called before the
+ /// connection is established, it contains empty string.
dmichael (off chromium) 2011/12/09 23:05:26 contains "the"?
Takashi Toyoshima 2011/12/13 14:08:23 Done.
Var GetURL();
-
- /// OnOpen() is invoked when the connection is established by Connect().
- virtual void OnOpen() = 0;
-
- /// OnMessage() is invoked when a message is received.
- virtual void OnMessage(Var message) = 0;
-
- /// OnError() is invoked if the user agent was required to fail the WebSocket
- /// connection or the WebSocket connection is closed with prejudice.
- /// OnClose() always follows OnError().
- virtual void OnError() = 0;
-
- /// OnClose() is invoked when the connection is closed by errors or Close().
- virtual void OnClose(bool wasClean, uint16_t code, const Var& reason) = 0;
};
} // namespace pp

Powered by Google App Engine
This is Rietveld 408576698