/// <summary> /// Initializes a new instance of the <see cref="CefStringMap"/> class. /// </summary> public CefStringMap() { _instance = CefNativeApi.cef_string_map_alloc(); #if DEBUG _finalizable = true; #endif }
/// <summary> /// Create a new server that binds to |ip| and |port|. A new thread will /// be created for each CreateServer call (the "dedicated server thread"). /// See CefServerHandler::OnServerCreated documentation for a description of /// server lifespan. /// </summary> /// <param name="ipString"> /// A valid IPv4 or IPv6 address (e.g. 127.0.0.1 or ::1). /// </param> /// <param name="port"> /// A port number outside of the reserved range (e.g. between 1025 and 65535 on most platforms). /// </param> /// <param name="backlog"> /// The maximum number of pending connections. /// </param> /// <param name="handler"> /// It is therefore recommended to use a different CefServerHandler instance for /// each CreateServer call to avoid thread safety issues in the CefServerHandler /// implementation. The CefServerHandler::OnServerCreated function will be called /// on the dedicated server thread to report success or failure. /// </param> public static void Create(IPAddress ip, int port, int backlog, CefServerHandler handler) { if (ip == null) { throw new ArgumentNullException(nameof(ip)); } if (ip.AddressFamily != AddressFamily.InterNetwork && ip.AddressFamily != AddressFamily.InterNetworkV6) { throw new ArgumentOutOfRangeException(nameof(ip)); } if (port <= 0 || port > ushort.MaxValue) { throw new ArgumentOutOfRangeException(nameof(port)); } if (handler == null) { throw new ArgumentNullException(nameof(handler)); } string ipString = ip.ToString(); fixed(char *s0 = ipString) { var cstr0 = new cef_string_t { Str = s0, Length = ipString.Length }; CefNativeApi.cef_server_create(&cstr0, unchecked ((ushort)port), backlog, handler.GetNativeInstance()); } }
/// <summary> /// Gets the value associated with the specified key. /// </summary> /// <param name="key">The key of the value to get.</param> /// <exception cref="ArgumentNullException">key is null.</exception> /// <exception cref="KeyNotFoundException"> /// The property is retrieved and key does not exist in the collection. /// </exception> public string this[string key] { get { if (key is null) { throw new ArgumentNullException(nameof(key)); fixed(char *k = key) { cef_string_t s0 = new cef_string_t { Str = k, Length = key.Length }; cef_string_t s1 = new cef_string_t(); int rv = CefNativeApi.cef_string_map_find(Instance, &s0, &s1); string value = CefString.ReadAndFree(&s1); if (rv == 0) { throw new KeyNotFoundException(); } return(value); } } set { throw new NotSupportedException(); } }
/// <summary> /// Copies the entries in the specified <see cref="NameValueCollection"/> to the <see cref="CefStringMultimap"/>. /// </summary> /// <param name="collection">The <see cref="NameValueCollection"/> to copy to the <see cref="CefStringMultimap"/>.</param> public void Add(NameValueCollection collection) { if (collection is null) { throw new ArgumentNullException(nameof(collection)); } for (int i = 0; i < collection.Count; i++) { string key = collection.GetKey(i); string value = collection[i]; fixed(char *s0 = key) fixed(char *s1 = value) { var cstr0 = new cef_string_t { Str = s0, Length = key is null ? 0 : key.Length }; var cstr1 = new cef_string_t { Str = s1, Length = value is null ? 0 : value.Length }; CefNativeApi.cef_string_multimap_append(Instance, &cstr0, &cstr1); } } }
/// <summary> /// Gets the values associated with the specified key from the <see cref="CefStringMultimap"/>. /// </summary> /// <returns> /// A <see cref="String"/> array that contains the values associated with /// the specified key from the <see cref="CefStringMultimap"/>, if found; otherwise, null. /// </returns> public string[] GetValues(string key) { fixed(char *s0 = key) { var cstr0 = new cef_string_t { Str = s0, Length = key is null ? 0 : key.Length }; uint count = (uint)CefNativeApi.cef_string_multimap_find_count(Instance, &cstr0); if (count == 0) { return(null); } var cstr1 = new cef_string_t(); var values = new string[count]; for (uint i = 0; i < count; i++) { if (CefNativeApi.cef_string_multimap_enumerate(Instance, &cstr0, new UIntPtr(i), &cstr1) == 0) { if (i == 0) { return(null); } Array.Resize(ref values, Math.Max((int)i, 0)); return(values); } values[i] = CefString.ReadAndFree(&cstr1); } return(values); } }
/// <summary> /// Create a new <see cref="CefPostData"/> object with the application/x-www-form-urlencoded data. /// </summary> /// <param name="content">The post data.</param> public CefPostData(IEnumerable <KeyValuePair <string, string> > content) : this(CefNativeApi.cef_post_data_create()) { if (content != null) { AddUrlEncoded(content); } }
protected virtual void Dispose(bool disposing) { if (!IsNative) { CefNativeApi.cef_string_list_free(_instance); } _instance.Base = null; }
/// <summary> /// Create a new <see cref="CefPostData"/> object with the application/x-www-form-urlencoded data. /// </summary> /// <param name="content">The post data.</param> public CefPostData(NameValueCollection content) : this(CefNativeApi.cef_post_data_create()) { if (content != null) { AddUrlEncoded(content); } }
private static cef_binary_value_t *CreateFromBuffer(byte[] buffer) { if (buffer == null) throw new ArgumentNullException(nameof(buffer)); fixed(void *data = buffer) { return(CefNativeApi.cef_binary_value_create(data, unchecked ((UIntPtr)buffer.Length))); } }
/// <summary> /// Frees memory allocated for the <see cref="cef_string_userfree_t"/>'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); }
/// <summary> /// Create a new CefImage. It will initially be NULL. Use the Add*() functions /// to add representations at different scale factors. /// </summary> public CefImage() : this(CefNativeApi.cef_image_create()) { #if USESAFECACHE lock (WeakRefs) { WeakRefs.Add(this.WeakRef); } #endif }
/// <summary> /// Returns the number of values with the specified key. /// </summary> /// <param name="key">The specified key.</param> /// <returns>The number of values with the specified key.</returns> public int CountWith(string key) { fixed(char *s0 = key) { var cstr0 = new cef_string_t { Str = s0, Length = key is null ? 0 : key.Length }; return((int)CefNativeApi.cef_string_multimap_find_count(Instance, &cstr0)); } }
public void Add(string item) { fixed(char *s0 = item) { var cstr0 = new cef_string_t { Str = s0, Length = (item != null ? item.Length : 0) }; CefNativeApi.cef_string_list_append(GetNativeInstance(), &cstr0); } }
private void Dispose(bool disposing) { if (_instance.Base == null) { return; } CefNativeApi.cef_string_multimap_clear(_instance); CefNativeApi.cef_string_multimap_free(_instance); _instance = default; }
private static cef_v8value_t *CreateStringInternal(string value) { fixed(char *s = value) { var cstr = new cef_string_t { Str = s, Length = (value != null ? value.Length : 0) }; return(CefNativeApi.cef_v8value_create_string(&cstr)); } }
/// <summary> /// Create a new <see cref="CefV8Value"/> object of type ArrayBuffer which wraps the /// provided <paramref name="buffer"/> of size <paramref name="length"/> bytes.<para/> /// This function should only be called from within the scope of a /// <see cref="CefRenderProcessHandler"/>, <see cref="CefV8Handler"/> or /// <see cref="CefV8Accessor"/> callback, or in combination with calling /// <see cref="CefV8Context.Enter"/> and <see cref="CefV8Context.Exit"/> /// on a stored <see cref="CefV8Context"/> reference. /// </summary> /// <param name="buffer"> /// The ArrayBuffer is externalized, meaning that it does not own <paramref name="buffer"/>. /// </param> /// <param name="callback"> /// The caller is responsible for freeing <paramref name="buffer"/> when requested via /// a call to <see cref="CefV8ArrayBufferReleaseCallback.ReleaseBuffer"/>. /// </param> /// <param name="length">The size of buffer in bytes.</param> /// <returns>Returns a new <see cref="CefV8Value"/> object of type ArrayBuffer.</returns> public static CefV8Value CreateArrayBuffer(void *buffer, int length, CefV8ArrayBufferReleaseCallback callback) { if (buffer == null) { throw new ArgumentNullException(nameof(buffer)); } if (length < 0) { throw new ArgumentOutOfRangeException(nameof(length)); } return(new CefV8Value(CefNativeApi.cef_v8value_create_array_buffer(buffer, unchecked ((UIntPtr)length), callback.GetNativeInstance()))); }
/// <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); }
/// <summary> /// Allocates a managed <see cref="string"/>, copies <see cref="cef_string_userfree_t"/>'s /// value into it and frees memory allocated for the <see cref="cef_string_userfree_t"/>'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); }
private static cef_process_message_t *Create(string name) { fixed(char *s = name) { cef_string_t cstr = new cef_string_t(); cstr.Base.str = s; if (name != null) { cstr.Base.length = unchecked ((UIntPtr)name.Length); } return(CefNativeApi.cef_process_message_create(&cstr)); } }
private static cef_thread_t *CreateInternal(string name, CefThreadPriority priority, CefMessageLoopType messageLoopType, bool stoppable, CefComInitMode comInitMode) { if (name == null) throw new ArgumentNullException(nameof(name)); fixed(char *s0 = name) { var cstr0 = new cef_string_t { Str = s0, Length = name.Length }; return(CefNativeApi.cef_thread_create(&cstr0, priority, messageLoopType, stoppable ? 1 : 0, comInitMode)); } }
public static cef_xml_reader_t *Create(CefStreamReader reader, CefXmlEncodingType encodingType, string uri) { if (reader == null) throw new ArgumentNullException(nameof(reader)); fixed(char *s0 = uri) { var cstr0 = new cef_string_t { Str = s0, Length = (uri != null ? uri.Length : 0) }; return(CefNativeApi.cef_xml_reader_create(reader.GetNativeInstance(), encodingType, &cstr0)); } }
/// <summary> /// Returns the value of the entry at the specified index of the <see cref="CefStringMultimap"/>. /// </summary> /// <param name="index">The zero-based index of the entry to locate in the <see cref="CefStringMultimap"/>.</param> /// <returns> /// A <see cref="String"/> that contains the value of the entry at the specified index of the collection. /// </returns> public string Get(int index) { if (index < 0) { throw new IndexOutOfRangeException(); } var cstr = new cef_string_t(); if (CefNativeApi.cef_string_multimap_value(Instance, new UIntPtr((uint)index), &cstr) == 0) { throw new IndexOutOfRangeException(); } return(CefString.ReadAndFree(&cstr)); }
/// <summary> /// Create a new <see cref="CefV8Value"/> object of type function.<para/> /// This function should only be called from within the scope of a /// <see cref="CefRenderProcessHandler"/>, <see cref="CefV8Handler"/> or /// <see cref="CefV8Accessor"/> callback, or in combination with calling /// <see cref="CefV8Context.Enter"/> and <see cref="CefV8Context.Exit"/> /// on a stored <see cref="CefV8Context"/> reference. /// </summary> /// <returns>Returns a new <see cref="CefV8Value"/> object of type function.</returns> public static CefV8Value CreateFunction(string name, CefV8Handler handler) { if (handler == null) { throw new ArgumentNullException(nameof(handler)); fixed(char *s = name) { var aName = new cef_string_t { Str = s, Length = (name != null ? name.Length : 0) }; return(new CefV8Value(CefNativeApi.cef_v8value_create_function(&aName, handler.GetNativeInstance()))); } }
public void CopyTo(string[] array, int arrayIndex) { cef_string_list_t instance = GetNativeInstance(); var cstr0 = new cef_string_t(); for (int i = 0; i < array.Length; i++) { if (CefNativeApi.cef_string_list_value(instance, unchecked ((UIntPtr)i), &cstr0) == 0) { throw new InvalidOperationException(); } array[i + arrayIndex] = CefString.ReadAndFree(&cstr0); } }
/// <summary> /// Gets the value of the entry at the specified index. /// </summary> /// <param name="index">The zero-based index of the element to get.</param> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="index"/> is less than 0; /// or, <paramref name="index"/> is equal to or greater than <see cref="Count"/>. /// </exception> public string this[int index] { get { if (index < 0) { throw new ArgumentOutOfRangeException(nameof(index)); } cef_string_t s0 = new cef_string_t(); int rv = CefNativeApi.cef_string_map_value(Instance, new UIntPtr((uint)index), &s0); string value = CefString.ReadAndFree(&s0); if (rv == 0) throw new ArgumentOutOfRangeException(nameof(index)); } return(value);
public string this[int index] { get { var cstr0 = new cef_string_t(); if (CefNativeApi.cef_string_list_value(GetNativeInstance(), unchecked ((UIntPtr)index), &cstr0) != 0) { return(CefString.ReadAndFree(&cstr0)); } throw new ArgumentOutOfRangeException(nameof(index)); } set { throw new NotSupportedException(); } }
/// <summary> /// Adds an entry with the specified name and value to the <see cref="CefStringMultimap"/>. /// </summary> /// <param name="name">The <see cref="String"/> key of the entry to add. The <paramref name="key"/> can be null.</param> /// <param name="value">The <see cref="String"/> value of the entry to add. The <paramref name="value"/> can be null.</param> public void Add(string name, string value) { fixed(char *s0 = name) fixed(char *s1 = value) { var cstr0 = new cef_string_t { Str = s0, Length = name is null ? 0 : name.Length }; var cstr1 = new cef_string_t { Str = s1, Length = value is null ? 0 : value.Length }; if (CefNativeApi.cef_string_multimap_append(Instance, &cstr0, &cstr1) != 1) { throw new ArgumentOutOfRangeException(); } } }
public string[] ToArray() { cef_string_list_t instance = GetNativeInstance(); var cstr0 = new cef_string_t(); var array = new string[this.Count]; for (int i = 0; i < array.Length; i++) { if (CefNativeApi.cef_string_list_value(instance, unchecked ((UIntPtr)i), &cstr0) == 0) { throw new InvalidOperationException(); } array[i] = CefString.ReadAndFree(&cstr0); } return(array); }
/// <summary> /// Gets a value indicating whether the <see cref="CefStringMultimap"/> contains keys that are not null. /// </summary> /// <returns>true if the <see cref="CefStringMultimap"/> contains keys that are not null; otherwise, false.</returns> public bool HasKeys() { uint count = (uint)this.Count; for (uint i = 0; i < count; i++) { var cstr = new cef_string_t(); if (CefNativeApi.cef_string_multimap_key(Instance, new UIntPtr(i), &cstr) == 0) { return(false); } if (CefString.ReadAndFree(&cstr) != null) { return(true); } } return(false); }
/// <summary> /// Adds the elements of the specified collection to the end of the <see cref="CefStringMultimap"/>. /// </summary> /// <param name="collection"> /// The collection whose elements should be added to the end of the <see cref="CefStringMultimap"/>. /// The collection itself cannot be null, but it can contain key/value pairs that the key or the value are null. /// </param> public void Add(IEnumerable <KeyValuePair <string, string> > collection) { if (collection is null) { throw new ArgumentNullException(nameof(collection)); } foreach (KeyValuePair <string, string> kvp in collection) { fixed(char *s0 = kvp.Key) fixed(char *s1 = kvp.Value) { var cstr0 = new cef_string_t { Str = s0, Length = s0 == null ? 0 : kvp.Key.Length }; var cstr1 = new cef_string_t { Str = s1, Length = s1 == null ? 0 : kvp.Value.Length }; CefNativeApi.cef_string_multimap_append(Instance, &cstr0, &cstr1); } } }