Esempio n. 1
0
 /**
  * Logs a message to the console with the given source information rather
  * than using the internal PPAPI plugin name. The name must be a string var.
  *
  * The regular log function will automatically prepend the name of your
  * plugin to the message as the "source" of the message. Some plugins may
  * wish to override this. For example, if your plugin is a Python
  * interpreter, you would want log messages to contain the source .py file
  * doing the log statement rather than have "python" show up in the console.
  */
 public static void LogWithSource(PPInstance instance,
                                  PPLogLevel level,
                                  PPVar source,
                                  PPVar value)
 {
     _LogWithSource(instance, level, source, value);
 }
Esempio n. 2
0
 /**
  * Sets a socket option on the TCP socket.
  * Please see the <code>PP_TCPSocket_Option</code> description for option
  * names, value types and allowed values.
  *
  * @param[in] tcp_socket A <code>PP_Resource</code> corresponding to a TCP
  * socket.
  * @param[in] name The option to set.
  * @param[in] value The option value to set.
  * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
  * completion.
  *
  * @return An int32_t containing an error code from <code>pp_errors.h</code>.
  */
 public static int SetOption(PPResource tcp_socket,
                             PPTCPSocketOption name,
                             PPVar value,
                             PPCompletionCallback callback)
 {
     return(_SetOption(tcp_socket, name, value, callback));
 }
Esempio n. 3
0
 /**
  * Retrieves the proxy that will be used for the given URL. The result will
  * be a string in PAC format. For more details about PAC format, please see
  * http://en.wikipedia.org/wiki/Proxy_auto-config
  *
  * @param[in] instance A <code>PP_Instance</code> identifying one instance
  * of a module.
  *
  * @param[in] url A string <code>PP_Var</code> containing a URL.
  *
  * @param[out] proxy_string A <code>PP_Var</code> that GetProxyForURL will
  * set upon successful completion. If the call fails, <code>proxy_string
  * </code> will be unchanged. Otherwise, it will be set to a string <code>
  * PP_Var</code> containing the appropriate PAC string for <code>url</code>.
  * If set, <code>proxy_string</code> will have a reference count of 1 which
  * the plugin must manage.
  *
  * @param[in] callback A <code>PP_CompletionCallback</code> to be called upon
  * completion.
  *
  * @return An int32_t containing an error code from <code>pp_errors.h</code>.
  */
 public static int GetProxyForURL(PPInstance instance,
                                  PPVar url,
                                  out PPVar proxy_string,
                                  PPCompletionCallback callback)
 {
     return(_GetProxyForURL(instance, url, out proxy_string, callback));
 }
Esempio n. 4
0
 /**
  * Invoked as a result of JavaScript invoking postMessageAndAwaitResponse()
  * on the plugin's DOM element.
  *
  * NOTE: JavaScript execution is blocked during the duration of this call.
  * Hence, the plugin should respond as quickly as possible. For this reason,
  * blocking completion callbacks are disallowed while handling a blocking
  * message.
  *
  * @param[in] instance A <code>PP_Instance</code> identifying one instance
  * of a module.
  * @param[in] user_data is the same pointer which was provided by a call to
  * RegisterMessageHandler().
  * @param[in] message is a copy of the parameter that JavaScript provided
  * to postMessageAndAwaitResponse().
  * @param[out] response will be copied to a JavaScript object which is
  * returned as the result of postMessageAndAwaitResponse() to the invoking
  *
  */
 public static void HandleBlockingMessage(PPInstance instance,
                                          IntPtr user_data,
                                          PPVar message,
                                          out PPVar response)
 {
     _HandleBlockingMessage(instance, user_data, message, out response);
 }
Esempio n. 5
0
 /**
  * Close() closes the specified WebSocket connection by specifying
  * <code>code</code> and <code>reason</code>.
  *
  * @param[in] web_socket A <code>PP_Resource</code> corresponding to a
  * WebSocket.
  *
  * @param[in] code The WebSocket close code. This is ignored if it is
  * <code>PP_WEBSOCKETSTATUSCODE_NOT_SPECIFIED</code>.
  * <code>PP_WEBSOCKETSTATUSCODE_NORMAL_CLOSURE</code> must be used for the
  * usual case. To indicate some specific error cases, codes in the range
  * <code>PP_WEBSOCKETSTATUSCODE_USER_REGISTERED_MIN</code> to
  * <code>PP_WEBSOCKETSTATUSCODE_USER_REGISTERED_MAX</code>, and in the range
  * <code>PP_WEBSOCKETSTATUSCODE_USER_PRIVATE_MIN</code> to
  * <code>PP_WEBSOCKETSTATUSCODE_USER_PRIVATE_MAX</code> are available.
  *
  * @param[in] reason A <code>PP_Var</code> representing the WebSocket
  * close reason. This is ignored if it is <code>PP_VARTYPE_UNDEFINED</code>.
  * Otherwise, its <code>PP_VarType</code> must be
  * <code>PP_VARTYPE_STRING</code>.
  *
  * @param[in] callback A <code>PP_CompletionCallback</code> called
  * when the connection is closed or an error occurs in closing the
  * connection.
  *
  * @return An int32_t containing an error code from <code>pp_errors.h</code>.
  * Returns <code>PP_ERROR_BADARGUMENT</code> if <code>reason</code> contains
  * an invalid character as a UTF-8 string, or is longer than 123 bytes.
  * <code>PP_ERROR_BADARGUMENT</code> corresponds to a JavaScript SyntaxError
  * in the WebSocket API specification.
  * Returns <code>PP_ERROR_NOACCESS</code> if the code is not an integer
  * equal to 1000 or in the range 3000 to 4999. <code>PP_ERROR_NOACCESS</code>
  * corresponds to an InvalidAccessError in the WebSocket API specification.
  * Returns <code>PP_ERROR_INPROGRESS</code> if a previous call to Close() is
  * not finished.
  */
 public static int Close(PPResource web_socket,
                         ushort code,
                         PPVar reason,
                         PPCompletionCallback callback)
 {
     return(_Close(web_socket, code, reason, callback));
 }
Esempio n. 6
0
 /**
  * Connect() connects to the specified WebSocket server. You can call this
  * function once for a <code>web_socket</code>.
  *
  * @param[in] web_socket A <code>PP_Resource</code> corresponding to a
  * WebSocket.
  *
  * @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] protocol_count The number of sub-protocols in
  * <code>protocols</code>.
  *
  * @param[in] callback A <code>PP_CompletionCallback</code> called
  * when a connection is established or an error occurs in establishing
  * connection.
  *
  * @return An int32_t containing an error code from <code>pp_errors.h</code>.
  * Returns <code>PP_ERROR_BADARGUMENT</code> if the specified
  * <code>url</code>, or <code>protocols</code> contain an invalid string as
  * defined in the WebSocket API specification.
  * <code>PP_ERROR_BADARGUMENT</code> corresponds to a SyntaxError in the
  * WebSocket API specification.
  * Returns <code>PP_ERROR_NOACCESS</code> if the protocol specified in the
  * <code>url</code> is not a secure protocol, but the origin of the caller
  * has a secure scheme. Also returns <code>PP_ERROR_NOACCESS</code> if the
  * port specified in the <code>url</code> is a port that the user agent
  * is configured to block access to because it is a well-known port like
  * SMTP. <code>PP_ERROR_NOACCESS</code> corresponds to a SecurityError of the
  * specification.
  * Returns <code>PP_ERROR_INPROGRESS</code> if this is not the first call to
  * Connect().
  */
 public static int Connect(PPResource web_socket,
                           PPVar url,
                           PPVar[] protocols,
                           uint protocol_count,
                           PPCompletionCallback callback)
 {
     return(_Connect(web_socket, url, protocols, protocol_count, callback));
 }
Esempio n. 7
0
 public Var(Var other)
 {
     ppvar     = other.ppvar;
     isManaged = true;
     if (NeedsRefcounting(ppvar))
     {
         PPBVar.AddRef(ppvar);
     }
 }
Esempio n. 8
0
 public Var(PPVar var)
 {
     ppvar     = var;
     isManaged = true;
     if (NeedsRefcounting(ppvar))
     {
         PPBVar.AddRef(ppvar);
     }
 }
Esempio n. 9
0
 public Var(object var)
 {
     if (var is int)
     {
         ppvar.type         = PPVarType.Int32;
         ppvar.value.as_int = (int)var;
         isManaged          = true;
     }
     if (var is uint)
     {
         ppvar.type         = PPVarType.Int32;
         ppvar.value.as_int = Convert.ToInt32(var);
         isManaged          = true;
     }
     else if (var is string)
     {
         ppvar     = VarFromUtf8Helper((string)var);
         isManaged = true;
     }
     else if (var is bool)
     {
         ppvar.type          = PPVarType.Bool;
         ppvar.value.as_bool = (bool)var ? PPBool.True : PPBool.False;
         isManaged           = true;
     }
     else if (var is double)
     {
         ppvar.type            = PPVarType.Double;
         ppvar.value.as_double = (double)var;
         isManaged             = true;
     }
     // Note: You may see precision differences
     else if (var is float)
     {
         ppvar.type            = PPVarType.Double;
         ppvar.value.as_double = Convert.ToDouble((float)var);
         isManaged             = true;
     }
     else if (var is Var)
     {
         ppvar     = ((Var)var).ppvar;
         isManaged = true;
         if (NeedsRefcounting(ppvar))
         {
             PPBVar.AddRef(ppvar);
         }
     }
     else
     {
         ppvar.type = PPVarType.Undefined;
         isManaged  = true;
     }
 }
Esempio n. 10
0
        private async Task <PPError> ConnectAsyncCore(Uri uri, string[] protocols, MessageLoop connectLoop = null)
        {
            var tcs = new TaskCompletionSource <PPError>();
            EventHandler <PPError> handler = (s, e) => { tcs.TrySetResult(e); };

            try
            {
                Connection += handler;

                if (MessageLoop == null && connectLoop == null)
                {
                    Connect(uri, protocols);
                }
                else
                {
                    PPVar[] varProtocols = null;

                    if (protocols != null)
                    {
                        varProtocols = new PPVar[protocols.Length];

                        for (int p = 0; p < protocols.Length; p++)
                        {
                            varProtocols[p] = new Var(protocols[p]);
                        }
                    }
                    Action <PPError> action = new Action <PPError>((e) =>
                    {
                        var result = (PPError)PPBWebSocket.Connect(this, new Var(uri.AbsoluteUri),
                                                                   varProtocols, varProtocols == null ? 0 : (uint)varProtocols.Length,
                                                                   new BlockUntilComplete()
                                                                   );
                        tcs.TrySetResult(result);
                    }
                                                                   );
                    InvokeHelper(action, connectLoop);
                }
                return(await tcs.Task);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
                tcs.SetException(exc);
                return(PPError.Aborted);
            }
            finally
            {
                Connection -= handler;
            }
        }
Esempio n. 11
0
        private static async Task <ProxyInfo> GetProxyForURLAsyncCore(Instance instance, string url, MessageLoop messageLoop = null)
        {
            var tcs = new TaskCompletionSource <ProxyInfo>();
            EventHandler <ProxyInfo> handler = (s, e) => { tcs.TrySetResult(e); };

            try
            {
                HandleProxyForUrl += handler;

                if (messageLoop == null)
                {
                    GetProxyForURL(instance, url);
                }
                else
                {
                    Action <PPError> action = new Action <PPError>((e) =>
                    {
                        var output  = new PPVar();
                        var presult = (PPError)PPBNetworkProxy.GetProxyForURL(instance, new Var(url),
                                                                              out output, new BlockUntilComplete());

                        tcs.TrySetResult(new ProxyInfo(presult, ((Var)output).AsString()));
                    }
                                                                   );
                    messageLoop.PostWork(action);
                }
                return(await tcs.Task);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
                tcs.SetException(exc);
                return(new ProxyInfo(PPError.Aborted, string.Empty));
            }
            finally
            {
                HandleProxyForUrl -= handler;
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Connects to the specified WebSocket server
        /// </summary>
        /// <param name="url">The URI of the WebSocket server to connect to.</param>
        /// <param name="protocols"></param>
        public void Connect(Uri url, string[] protocols = null)
        {
            if (PPBWebSocket.IsWebSocket(this) != PPBool.True)
            {
                throw new PlatformNotSupportedException("Websocket not supported");
            }

            if (url == null)
            {
                throw new ArgumentNullException(nameof(url));
            }
            if (!url.IsAbsoluteUri)
            {
                throw new ArgumentException("Not Absolute URI", nameof(url));
            }
            if (url.Scheme.ToLower() != UriSchemeWs && url.Scheme.ToLower() != UriSchemeWss)
            {
                throw new ArgumentException("Scheme invalid", nameof(url));
            }

            PPVar[] varProtocols = null;

            if (protocols != null)
            {
                varProtocols = new PPVar[protocols.Length];

                for (int p = 0; p < protocols.Length; p++)
                {
                    varProtocols[p] = new Var(protocols[p]);
                }
            }

            var connectResult = (PPError)PPBWebSocket.Connect(this, new Var(url.AbsoluteUri),
                                                              varProtocols, varProtocols == null ? 0 : (uint)varProtocols.Length,
                                                              new CompletionCallback(OnConnect)
                                                              );
        }
Esempio n. 13
0
 /**
  * VarToUtf8() converts a string-type var to a char* encoded in UTF-8. This
  * string is NOT NULL-terminated. The length will be placed in
  * <code>*len</code>. If the string is valid but empty the return value will
  * be non-NULL, but <code>*len</code> will still be 0.
  *
  * If the var is not a string, this function will return NULL and
  * <code>*len</code> will be 0.
  *
  * The returned buffer will be valid as long as the underlying var is alive.
  * If the instance frees its reference, the string will be freed and the
  * pointer will be to arbitrary memory.
  *
  * @param[in] var A PP_Var struct containing a string-type var.
  * @param[in,out] len A pointer to the length of the string-type var.
  *
  * @return A char* encoded in UTF-8.
  */
 public static string VarToUtf8(PPVar var, out uint len)
 {
     return(Marshal.PtrToStringAnsi(_VarToUtf8(var, out len)));
 }
Esempio n. 14
0
 extern static IntPtr _VarToUtf8(PPVar var, out uint len);
Esempio n. 15
0
 // Technically you can call AddRef and Release on any Var, but it may involve
 // cross-process calls depending on the plugin. This is an optimization so we
 // only do refcounting on the necessary objects.
 bool NeedsRefcounting(PPVar var)
 {
     return(var.type > PPVarType.Double);
 }
Esempio n. 16
0
 extern static void _HandleBlockingMessage(PPInstance instance,
                                           IntPtr user_data,
                                           PPVar message,
                                           out PPVar response);
Esempio n. 17
0
 /**
  * Invoked as a result of JavaScript invoking postMessage() on the plugin's
  * DOM element.
  *
  * @param[in] instance A <code>PP_Instance</code> identifying one instance
  * of a module.
  * @param[in] user_data is the same pointer which was provided by a call to
  * RegisterMessageHandler().
  * @param[in] message A copy of the parameter that JavaScript provided to
  * postMessage().
  */
 public static void HandleMessage(PPInstance instance,
                                  IntPtr user_data,
                                  PPVar message)
 {
     _HandleMessage(instance, user_data, message);
 }
Esempio n. 18
0
 extern static void _HandleMessage(PPInstance instance,
                                   IntPtr user_data,
                                   PPVar message);
Esempio n. 19
0
 /**
  * Gets all the keys in a dictionary. Please note that for each key that you
  * set into the dictionary, a string var with the same contents is returned;
  * but it may not be the same string var (i.e., <code>value.as_id</code> may
  * be different).
  *
  * @param[in] dict A dictionary var.
  *
  * @return An array var which contains all the keys of <code>dict</code>. Its
  * reference count is incremented on behalf of the caller. The elements are
  * string vars. Returns a null var if failed.
  */
 public static PPVar GetKeys(PPVar dict)
 {
     return(_GetKeys(dict));
 }
Esempio n. 20
0
 /**
  * Deletes the specified key and its associated value, if the key exists. The
  * reference to the element will be released.
  *
  * @param[in] dict A dictionary var.
  * @param[in] key A string var.
  */
 public static void Delete(PPVar dict, PPVar key)
 {
     _Delete(dict, key);
 }
Esempio n. 21
0
 extern static void _Delete(PPVar dict, PPVar key);
Esempio n. 22
0
 /**
  * Checks whether a key exists.
  *
  * @param[in] dict A dictionary var.
  * @param[in] key A string var.
  *
  * @return A <code>PP_Bool</code> indicating whether the key exists.
  */
 public static PPBool HasKey(PPVar dict, PPVar key)
 {
     return(_HasKey(dict, key));
 }
Esempio n. 23
0
 extern static int _SetOption(PPResource tcp_socket,
                              PPTCPSocketOption name,
                              PPVar value,
                              PPCompletionCallback callback);
Esempio n. 24
0
 /**
  * Gets the value associated with the specified key.
  *
  * @param[in] dict A dictionary var.
  * @param[in] key A string var.
  *
  * @return The value that is associated with <code>key</code>. The reference
  * count of the element returned is incremented on behalf of the caller. If
  * <code>key</code> is not a string var, or it doesn't exist in
  * <code>dict</code>, an undefined var is returned.
  */
 public static PPVar Get(PPVar dict, PPVar key)
 {
     return(_Get(dict, key));
 }
Esempio n. 25
0
 extern static PPVar _Get(PPVar dict, PPVar key);
Esempio n. 26
0
 /**
  * HandleMessage() is a function that the browser calls when PostMessage()
  * is invoked on the DOM element for the module instance in JavaScript. Note
  * that PostMessage() in the JavaScript interface is asynchronous, meaning
  * JavaScript execution will not be blocked while HandleMessage() is
  * processing the message.
  *
  * @param[in] instance A <code>PP_Instance</code> identifying one instance
  * of a module.
  * @param[in] message A <code>PP_Var</code> which has been converted from a
  * JavaScript value. JavaScript array/object types are supported from Chrome
  * M29 onward. All JavaScript values are copied when passing them to the
  * plugin.
  *
  * When converting JavaScript arrays, any object properties whose name
  * is not an array index are ignored. When passing arrays and objects, the
  * entire reference graph will be converted and transferred. If the reference
  * graph has cycles, the message will not be sent and an error will be logged
  * to the console.
  *
  * The following JavaScript code invokes <code>HandleMessage</code>, passing
  * the module instance on which it was invoked, with <code>message</code>
  * being a string <code>PP_Var</code> containing "Hello world!"
  *
  * <strong>Example:</strong>
  *
  * @code
  *
  * <body>
  *   <object id="plugin"
  *           type="application/x-ppapi-postMessage-example"/>
  *   <script type="text/javascript">
  *     document.getElementById('plugin').postMessage("Hello world!");
  *   </script>
  * </body>
  *
  * @endcode
  *
  */
 public static void HandleMessage(PPInstance instance, PPVar message)
 {
     _HandleMessage(instance, message);
 }
Esempio n. 27
0
 extern static PPBool _HasKey(PPVar dict, PPVar key);
Esempio n. 28
0
 extern static PPVar _GetKeys(PPVar dict);
Esempio n. 29
0
 extern static PPBool _Set(PPVar dict, PPVar key, PPVar value);
Esempio n. 30
0
 /**
  * Sets the value associated with the specified key.
  *
  * @param[in] dict A dictionary var.
  * @param[in] key A string var. If this key hasn't existed in
  * <code>dict</code>, it is added and associated with <code>value</code>;
  * otherwise, the previous value is replaced with <code>value</code>.
  * @param[in] value The value to set. The dictionary holds a reference to it
  * on success.
  *
  * @return A <code>PP_Bool</code> indicating whether the operation succeeds.
  */
 public static PPBool Set(PPVar dict, PPVar key, PPVar value)
 {
     return(_Set(dict, key, value));
 }