The Webview Univeral Flutter package for Appeto SDK.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

93 lignes
2.1 KiB

  1. //
  2. // Created by yangbin on 2021/11/12.
  3. //
  4. #ifndef WEBVIEW_WINDOW_WINDOWS_WEB_VIEW_H_
  5. #define WEBVIEW_WINDOW_WINDOWS_WEB_VIEW_H_
  6. #include <windows.h>
  7. #include <string>
  8. #include <flutter/method_channel.h>
  9. #include <flutter/encodable_value.h>
  10. #include "wil/resource.h"
  11. #include "wil/com.h"
  12. #include "WebView2.h"
  13. namespace webview_window {
  14. class WebView {
  15. public:
  16. WebView(std::shared_ptr<flutter::MethodChannel<flutter::EncodableValue>> method_channel,
  17. int64_t web_view_id,
  18. std::wstring userDataFolder,
  19. std::function<void(HRESULT)> on_web_view_created_callback
  20. );
  21. virtual ~WebView();
  22. [[nodiscard]] const wil::unique_hwnd &NativeWindow() const { return view_window_; }
  23. void UpdateBounds();
  24. void Navigate(const std::wstring &url);
  25. void AddScriptToExecuteOnDocumentCreated(const std::wstring &javaScript);
  26. void SetApplicationNameForUserAgent(const std::wstring &application_name);
  27. void GoBack();
  28. void GoForward();
  29. void Reload();
  30. void Stop();
  31. void openDevToolsWindow();
  32. void ExecuteJavaScript(const std::wstring &javaScript,
  33. std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> completer);
  34. void PostWebMessageAsString(const std::wstring &webmessage,
  35. std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> completer);
  36. void PostWebMessageAsJson(const std::wstring &webmessage,
  37. std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> completer);
  38. private:
  39. wil::unique_hwnd view_window_;
  40. // Pointer to WebViewController
  41. wil::com_ptr<ICoreWebView2Controller> webview_controller_;
  42. // Pointer to WebView
  43. wil::com_ptr<ICoreWebView2> webview_;
  44. std::wstring default_user_agent_;
  45. std::shared_ptr<flutter::MethodChannel<flutter::EncodableValue>> method_channel_;
  46. int64_t web_view_id_;
  47. std::function<void(HRESULT)> on_web_view_created_callback_;
  48. std::wstring user_data_folder_;
  49. void OnWebviewControllerCreated();
  50. [[nodiscard]] bool CanGoBack() const;
  51. [[nodiscard]] bool CanGoForward() const;
  52. };
  53. }
  54. #endif //WEBVIEW_WINDOW_WINDOWS_WEB_VIEW_H_