Exemplo n.º 1
0
        /// <summary>
        /// Frees memory allocated for the <see cref="cef_string_userfree_t"/>&apos;s value.
        /// </summary>
        /// <param name="str">The pointer to the CEF string.</param>
        public static void Free(cef_string_userfree_t str)
        {
            if (str.Base.Base == null)
            {
                return;
            }

            CefNativeApi.cef_string_userfree_utf16_free(str.Base);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Allocates a managed <see cref="string"/>, copies <see cref="cef_string_userfree_t"/>&apos;s
        /// value into it and frees memory allocated for the <see cref="cef_string_userfree_t"/>&apos;s
        /// value.
        /// </summary>
        /// <param name="str">The pointer to the CEF string.</param>
        /// <returns>A managed string that holds a copy of the CEF string.</returns>
        public static string ReadAndFree(cef_string_userfree_t str)
        {
            cef_string_utf16_t *s = str.Base.Base;

            if (s == null)
            {
                return(null);
            }
            string rv = Marshal.PtrToStringUni((IntPtr)s->str, (int)s->length);

            CefNativeApi.cef_string_userfree_utf16_free(str.Base);
            return(rv);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a <see cref="cef_string_userfree_t"/> from the specified <see cref="string"/>.
        /// </summary>
        /// <param name="s">The source string.</param>
        /// <returns>A new <see cref="cef_string_userfree_t"/> that this method creates.</returns>
        public static cef_string_userfree_t Create(string s)
        {
            cef_string_userfree_t str = default;

            str.Base = CefNativeApi.cef_string_userfree_utf16_alloc();
            if (s != null)
            {
                str.Base.Base->str    = (char *)Marshal.StringToHGlobalUni(s);
                str.Base.Base->length = (UIntPtr)s.Length;
                str.Base.Base->dtor   = DestructorAddress;
            }
            return(str);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Copies the V8 string into <see cref="CefValue"/> object.
        /// </summary>
        /// <param name="value">The destination <see cref="CefValue"/> object.</param>
        /// <returns>Returns true if the value was set successfully.</returns>
        public bool CopyV8StringToCefValue(CefValue value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }
            if (!IsString)
            {
                throw new InvalidOperationException();
            }

            cef_string_userfree_t userfreeStr = NativeInstance->GetStringValue();

            try
            {
                return(value.NativeInstance->SetString((cef_string_t *)userfreeStr.Base.Base) != 0);
            }
            finally
            {
                CefString.Free(userfreeStr);
                GC.KeepAlive(this);
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Frees memory allocated for the <see cref="cef_string_userfree_t"/>&apos;s value.
 /// </summary>
 /// <param name="str">The pointer to the CEF string.</param>
 public static void Free(cef_string_userfree_t str)
 {
     CefNativeApi.cef_string_userfree_utf16_free(str.Base);
 }