CefSchemeHandlerFactory.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 that creates CefResourceHandler instances for handling scheme requests.
  10. /// The methods of this class will always be called on the IO thread.
  11. /// </summary>
  12. public abstract unsafe partial class CefSchemeHandlerFactory
  13. {
  14. private cef_resource_handler_t* create(cef_scheme_handler_factory_t* self, cef_browser_t* browser, cef_frame_t* frame, cef_string_t* scheme_name, cef_request_t* request)
  15. {
  16. CheckSelf(self);
  17. var m_browser = CefBrowser.FromNativeOrNull(browser);
  18. var m_frame = CefFrame.FromNativeOrNull(frame);
  19. var m_schemeName = cef_string_t.ToString(scheme_name);
  20. var m_request = CefRequest.FromNative(request); // TODO dispose?
  21. var handler = Create(m_browser, m_frame, m_schemeName, m_request);
  22. // TODO: [ApiUsage] method can return null, only when schemeName is built-in scheme, in other cases it is incorrect.
  23. return handler != null ? handler.ToNative() : null;
  24. }
  25. /// <summary>
  26. /// Return a new resource handler instance to handle the request or an empty
  27. /// reference to allow default handling of the request. |browser| and |frame|
  28. /// will be the browser window and frame respectively that originated the
  29. /// request or NULL if the request did not originate from a browser window
  30. /// (for example, if the request came from CefURLRequest). The |request| object
  31. /// passed to this method cannot be modified.
  32. /// </summary>
  33. protected abstract CefResourceHandler Create(CefBrowser browser, CefFrame frame, string schemeName, CefRequest request);
  34. }
  35. }