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

Unified Diff: ppapi/utility/websocket/websocket_api.h

Issue 8956008: WebSocket Pepper API: C++ utility class implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add unit tests Created 8 years, 11 months 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/utility/websocket/websocket_api.h
diff --git a/ppapi/utility/websocket/websocket_api.h b/ppapi/utility/websocket/websocket_api.h
new file mode 100644
index 0000000000000000000000000000000000000000..6de2d45ca5f14457903631353a88560e7f0025c6
--- /dev/null
+++ b/ppapi/utility/websocket/websocket_api.h
@@ -0,0 +1,152 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef PPAPI_UTILITY_WEBSOCKET_WEBSOCKET_API_H_
+#define PPAPI_UTILITY_WEBSOCKET_WEBSOCKET_API_H_
+
+#include "ppapi/c/dev/ppb_websocket_dev.h"
+
+/// @file
+/// This file defines the WebSocketAPI interface.
+
+namespace pp {
+
+class CompletionCallback;
+class Instance;
+class Var;
+
+/// The <code>WebSocketAPI_Dev</code> class
+class WebSocketAPI {
+ public:
+ /// Constructs a WebSocketAPI_Dev object.
+ WebSocketAPI(Instance* instance);
dmichael (off chromium) 2012/02/01 23:05:18 explicit
Takashi Toyoshima 2012/02/03 07:58:27 Oops, sorry I missed again.
+
+ /// Destructs a WebSocketAPI_Dev object.
+ virtual ~WebSocketAPI();
+
+ /// Connect() connects to the specified WebSocket server. Caller can call
+ /// this method at most once.
+ ///
+ /// @param[in] url A <code>Var</code> of string type representing a WebSocket
+ /// server URL.
+ /// @param[in] protocols A pointer to an array of string type
+ /// <code>Var</code> specifying sub-protocols. Each <code>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] protocol_count The number of sub-protocols in
+ /// <code>protocols</code>.
+ ///
+ /// @return An int32_t containing an error code from
+ /// <code>pp_errors.h</code>.
+ /// See also <code>pp::WebSocket_Dev::Connect</code>.
+ int32_t Connect(const Var& url, const Var protocols[],
+ uint32_t protocol_count);
+
+ /// 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>Var</code> of string type which represents the
+ /// WebSocket close reason. Ignored if it is undefined type.
+ ///
+ /// @return An int32_t containing an error code from
+ /// <code>pp_errors.h</code>.
+ /// See also <code>pp::WebSocket_Dev::Close</code>.
+ int32_t Close(uint16_t code, const Var& reason);
+
+ /// Send() sends a message to the WebSocket server.
+ ///
+ /// @param[in] data A message to send. The message is copied to internal
+ /// buffer. So caller can free <code>data</code> safely after returning
+ /// from the function.
+ ///
+ /// @return An int32_t containing an error code from
+ /// <code>pp_errors.h</code>.
+ /// See also <code>pp::WebSocket_Dev::SendMessage</code>.
+ int32_t Send(const Var& data);
+
+ /// 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.
+ ///
+ /// @return Returns the number of bytes.
+ uint64_t GetBufferedAmount();
+
+ /// GetExtensions() returns the extensions selected by the server for the
+ /// specified WebSocket connection.
+ ///
+ /// @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 an empty string.
+ Var GetExtensions();
+
+ /// GetProtocol() returns the sub-protocol chosen by the server for the
+ /// specified WebSocket connection.
+ ///
+ /// @return Returns a <code>Var</code> of string type. If called before the
+ /// connection is established, it contains the empty string.
+ Var GetProtocol();
+
+ /// GetReadyState() returns the ready state of the specified WebSocket
+ /// connection.
+ ///
+ /// @return Returns <code>PP_WEBSOCKETREADYSTATE_INVALID_DEV</code> if called
+ /// before connect() is called.
+ PP_WebSocketReadyState_Dev GetReadyState();
+
+ /// GetURL() returns the URL associated with specified WebSocket connection.
+ ///
+ /// @return Returns a <code>Var</code> of string type. If called before the
+ /// connection is established, it contains the empty string.
+ Var GetURL();
+
+ /// SetBinaryType() specifies the binary object type for receiving binary
+ /// frames representation. Receiving text frames are always mapped to
+ /// <code>Var</code> of string type regardless of this attribute.
+ /// This function should be called before Connect() to ensure receiving all
+ /// incoming binary frames as the specified binary object type.
+ /// Default type is <code>Var</code> of Blob type.
+ ///
+ /// Currently, Blob bindings is not supported in Pepper, so receiving binary
+ /// type is always ArrayBuffer. To ensure backward compatibility, you must
+ /// call this function with
+ /// <code>PP_WEBSOCKETBINARYTYPE_ARRAYBUFFER_DEV</code> to use binary frames.
+ ///
+ /// @param[in] binary_type Binary object type for receiving binary frames
+ /// representation.
+ ///
+ /// @return Returns <code>false</code> if the specified type is not
+ /// supported. Otherwise, return <code>true</code>.
+ bool SetBinaryType(PP_WebSocketBinaryType_Dev binary_type);
+
+ /// GetBinaryType() returns the currently specified binary object type for
+ /// receiving binary frames.
+ ///
+ /// @return Returns <code>PP_WebSocketBinaryType_Dev</code> represents the
+ /// current binary object type.
+ PP_WebSocketBinaryType_Dev GetBinaryType();
+
+ /// OnOpen() is invoked when the connection is established by Connect().
+ virtual void OnOpen() = 0;
dmichael (off chromium) 2012/02/01 23:05:18 In PPAPI, we use "Did" or "HandleBlah" instead of
Takashi Toyoshima 2012/02/03 07:58:27 OK. I also reorder these methods. Maybe DidOpen, D
+
+ /// OnMessage() is invoked when a message is received.
+ virtual void OnMessage(const 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;
+
+ private:
+ class Implement;
+ Implement* impl_;
+};
+
+} // namespace pp
+
+#endif // PPAPI_UTILITY_WEBSOCKET_WEBSOCKET_API_H_

Powered by Google App Engine
This is Rietveld 408576698