CefUrlRequest.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 make a URL request. URL requests are not associated with a
  10. /// browser instance so no CefClient callbacks will be executed. URL requests
  11. /// can be created on any valid CEF thread in either the browser or render
  12. /// process. Once created the methods of the URL request object must be accessed
  13. /// on the same thread that created it.
  14. /// </summary>
  15. public sealed unsafe partial class CefUrlRequest
  16. {
  17. /// <summary>
  18. /// Create a new URL request that is not associated with a specific browser or
  19. /// frame. Use CefFrame::CreateURLRequest instead if you want the request to
  20. /// have this association, in which case it may be handled differently (see
  21. /// documentation on that method). A request created with this method may only
  22. /// originate from the browser process, and will behave as follows:
  23. /// - It may be intercepted by the client via CefResourceRequestHandler or
  24. /// CefSchemeHandlerFactory.
  25. /// - POST data may only contain only a single element of type PDE_TYPE_FILE
  26. /// or PDE_TYPE_BYTES.
  27. /// - If |request_context| is empty the global request context will be used.
  28. /// The |request| object will be marked as read-only after calling this method.
  29. /// </summary>
  30. public static CefUrlRequest Create(CefRequest request, CefUrlRequestClient client, CefRequestContext requestContext)
  31. {
  32. if (request == null) throw new ArgumentNullException("request");
  33. var n_request = request.ToNative();
  34. var n_client = client != null ? client.ToNative() : null;
  35. var n_requestContext = requestContext != null ? requestContext.ToNative() : null;
  36. return CefUrlRequest.FromNative(
  37. cef_urlrequest_t.create(n_request, n_client, n_requestContext)
  38. );
  39. }
  40. /// <summary>
  41. /// Returns the request object used to create this URL request. The returned
  42. /// object is read-only and should not be modified.
  43. /// </summary>
  44. public CefRequest GetRequest()
  45. {
  46. return CefRequest.FromNative(
  47. cef_urlrequest_t.get_request(_self)
  48. );
  49. }
  50. /// <summary>
  51. /// Returns the client.
  52. /// </summary>
  53. public CefUrlRequestClient GetClient()
  54. {
  55. return CefUrlRequestClient.FromNative(
  56. cef_urlrequest_t.get_client(_self)
  57. );
  58. }
  59. /// <summary>
  60. /// Returns the request status.
  61. /// </summary>
  62. public CefUrlRequestStatus RequestStatus
  63. {
  64. get { return cef_urlrequest_t.get_request_status(_self); }
  65. }
  66. /// <summary>
  67. /// Returns the request error if status is UR_CANCELED or UR_FAILED, or 0
  68. /// otherwise.
  69. /// </summary>
  70. public CefErrorCode RequestError
  71. {
  72. get { return cef_urlrequest_t.get_request_error(_self); }
  73. }
  74. /// <summary>
  75. /// Returns the response, or NULL if no response information is available.
  76. /// Response information will only be available after the upload has completed.
  77. /// The returned object is read-only and should not be modified.
  78. /// </summary>
  79. public CefResponse GetResponse()
  80. {
  81. return CefResponse.FromNativeOrNull(
  82. cef_urlrequest_t.get_response(_self)
  83. );
  84. }
  85. /// <summary>
  86. /// Returns true if the response body was served from the cache. This includes
  87. /// responses for which revalidation was required.
  88. /// </summary>
  89. public bool ResponseWasCached
  90. {
  91. get
  92. {
  93. return cef_urlrequest_t.response_was_cached(_self) != 0;
  94. }
  95. }
  96. /// <summary>
  97. /// Cancel the request.
  98. /// </summary>
  99. public void Cancel()
  100. {
  101. cef_urlrequest_t.cancel(_self);
  102. }
  103. }
  104. }