CefPostData.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. namespace Xilium.CefGlue
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Runtime.InteropServices;
  7. using Xilium.CefGlue.Interop;
  8. /// <summary>
  9. /// Class used to represent post data for a web request. The methods of this
  10. /// class may be called on any thread.
  11. /// </summary>
  12. public sealed unsafe partial class CefPostData
  13. {
  14. /// <summary>
  15. /// Create a new CefPostData object.
  16. /// </summary>
  17. public static CefPostData Create()
  18. {
  19. return CefPostData.FromNative(
  20. cef_post_data_t.create()
  21. );
  22. }
  23. /// <summary>
  24. /// Returns true if this object is read-only.
  25. /// </summary>
  26. public bool IsReadOnly
  27. {
  28. get { return cef_post_data_t.is_read_only(_self) != 0; }
  29. }
  30. /// <summary>
  31. /// Returns true if the underlying POST data includes elements that are not
  32. /// represented by this CefPostData object (for example, multi-part file upload
  33. /// data). Modifying CefPostData objects with excluded elements may result in
  34. /// the request failing.
  35. /// </summary>
  36. public bool HasExcludedElements
  37. {
  38. get { return cef_post_data_t.has_excluded_elements(_self) != 0; }
  39. }
  40. /// <summary>
  41. /// Returns the number of existing post data elements.
  42. /// </summary>
  43. public int Count
  44. {
  45. get { return (int)cef_post_data_t.get_element_count(_self); }
  46. }
  47. /// <summary>
  48. /// Retrieve the post data elements.
  49. /// </summary>
  50. public CefPostDataElement[] GetElements()
  51. {
  52. // FIXME: CefPostDataElement.GetElements(): check CEF C API impl
  53. var count = Count;
  54. if (count == 0) return new CefPostDataElement[0];
  55. UIntPtr n_elementsCount = (UIntPtr)count;
  56. var n_elements = new cef_post_data_element_t*[count];
  57. fixed (cef_post_data_element_t** n_elements_ptr = n_elements)
  58. {
  59. cef_post_data_t.get_elements(_self, &n_elementsCount, n_elements_ptr);
  60. if ((int)n_elementsCount > count) throw new InvalidOperationException();
  61. }
  62. count = (int)n_elementsCount;
  63. var elements = new CefPostDataElement[count];
  64. for (var i = 0; i < count; i++)
  65. {
  66. elements[i] = CefPostDataElement.FromNative(n_elements[i]);
  67. }
  68. return elements;
  69. }
  70. /// <summary>
  71. /// Remove the specified post data element. Returns true if the removal
  72. /// succeeds.
  73. /// </summary>
  74. public bool Remove(CefPostDataElement element)
  75. {
  76. return cef_post_data_t.remove_element(_self, element.ToNative()) != 0;
  77. }
  78. /// <summary>
  79. /// Add the specified post data element. Returns true if the add succeeds.
  80. /// </summary>
  81. public bool Add(CefPostDataElement element)
  82. {
  83. return cef_post_data_t.add_element(_self, element.ToNative()) != 0;
  84. }
  85. /// <summary>
  86. /// Remove all existing post data elements.
  87. /// </summary>
  88. public void RemoveAll()
  89. {
  90. cef_post_data_t.remove_elements(_self);
  91. }
  92. }
  93. }