├── example ├── linux │ ├── .gitignore │ ├── main.cc │ ├── flutter │ │ ├── generated_plugin_registrant.h │ │ ├── generated_plugin_registrant.cc │ │ ├── generated_plugins.cmake │ │ └── CMakeLists.txt │ ├── my_application.h │ ├── my_application.cc │ └── CMakeLists.txt ├── lib │ ├── third_party │ │ ├── README.md │ │ └── webview_flutter │ │ │ ├── LICENSE │ │ │ ├── README.webview │ │ │ └── example │ │ │ ├── lib │ │ │ └── main.dart │ │ │ ├── assets │ │ │ └── www │ │ │ │ ├── index.html │ │ │ │ └── styles │ │ │ │ └── style.css │ │ │ └── integration_test │ │ │ └── flutter_linux_webview_test.dart │ ├── main.dart │ ├── simple_example.dart │ └── multiple_webviews_example.dart ├── myassets │ ├── my_sample_audio.ogg │ └── my_sample_video.webm ├── integration_test │ └── flutter_linux_webview_test.dart ├── .metadata ├── .gitignore ├── analysis_options.yaml ├── README.md └── pubspec.yaml ├── .clang-format ├── linux ├── third_party │ ├── README.md │ └── cef │ │ ├── README.webview │ │ └── src │ │ ├── LICENSE.txt │ │ └── tests │ │ ├── cefsimple │ │ └── CMakeLists_subprocess_project.txt │ │ └── cefclient │ │ └── browser │ │ ├── flutter_webview_osr_renderer.cc │ │ └── flutter_webview_osr_renderer.h ├── cmake │ └── link_to_cef_library.cmake ├── subprocess │ ├── src │ │ ├── CMakeLists.txt │ │ ├── flutter_webview_subprocess.cc │ │ ├── flutter_webview_render_app.h │ │ ├── flutter_webview_process_messages.cc │ │ ├── flutter_webview_process_messages.h │ │ └── flutter_webview_render_app.cc │ └── cef_distrib_patch │ │ └── build_flutter_webview_subprocess.patch ├── flutter_webview_types.cc ├── flutter_webview_app.cc ├── flutter_webview_app.h ├── include │ └── flutter_linux_webview │ │ ├── flutter_linux_webview_plugin.h │ │ ├── fl_custom_texture_gl.h │ │ └── flutter_webview_types.h ├── fl_custom_texture_gl.cc ├── flutter_webview_texture_manager.h ├── flutter_webview_texture_manager.cc ├── flutter_webview_handler.h └── README.md ├── lib ├── src │ ├── third_party │ │ ├── README.md │ │ ├── cef │ │ │ ├── README.webview │ │ │ └── src │ │ │ │ ├── LICENSE.txt │ │ │ │ ├── include │ │ │ │ └── internal │ │ │ │ │ └── cef_types.dart │ │ │ │ └── tests │ │ │ │ └── cefclient │ │ │ │ └── browser │ │ │ │ └── windows_key_code.dart │ │ ├── flutter_engine │ │ │ ├── LICENSE │ │ │ ├── README.webview │ │ │ └── shell │ │ │ │ └── platform │ │ │ │ └── linux │ │ │ │ └── native_key_code.dart │ │ └── webview_flutter_android │ │ │ ├── LICENSE │ │ │ ├── README.webview │ │ │ └── lib │ │ │ ├── src │ │ │ └── instance_manager.dart │ │ │ └── webview_linux_cookie_manager.dart │ ├── logging.dart │ ├── webview_linux.dart │ └── linux_webview_plugin.dart └── flutter_linux_webview.dart ├── third_party_base ├── webview_flutter │ ├── example │ │ └── assets │ │ │ └── www │ │ │ ├── styles │ │ │ └── style.css │ │ │ └── index.html │ ├── README.webview │ └── LICENSE ├── webview_flutter_android │ ├── README.webview │ ├── LICENSE │ └── lib │ │ ├── src │ │ └── instance_manager.dart │ │ └── webview_linux_cookie_manager.dart ├── flutter_engine │ ├── README.webview │ └── LICENSE ├── cef │ ├── README.webview │ └── src │ │ ├── LICENSE.txt │ │ ├── tests │ │ ├── cefclient │ │ │ └── browser │ │ │ │ ├── flutter_webview_osr_renderer.h │ │ │ │ └── flutter_webview_osr_renderer.cc │ │ └── cefsimple │ │ │ └── CMakeLists_subprocess_project.txt │ │ └── include │ │ └── internal │ │ └── cef_types.dart └── README.md ├── doc_assets ├── main_webview.gif └── multiple_webviews.gif ├── analysis_options.yaml ├── .metadata ├── .vscode ├── launch.json ├── c_cpp_properties.json └── settings.json ├── .gitignore ├── .pubignore ├── CHANGELOG.md ├── LICENSE ├── pubspec.yaml ├── ThirdPartyNotices.txt ├── create_symlinks_to_third_party.sh └── validation_report.md /example/linux/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral 2 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | BasedOnStyle: Chromium 2 | Standard: Cpp11 3 | -------------------------------------------------------------------------------- /linux/third_party/README.md: -------------------------------------------------------------------------------- 1 | ../../third_party_base/README.md -------------------------------------------------------------------------------- /example/lib/third_party/README.md: -------------------------------------------------------------------------------- 1 | ../../../third_party_base/README.md -------------------------------------------------------------------------------- /lib/src/third_party/README.md: -------------------------------------------------------------------------------- 1 | ../../../third_party_base/README.md -------------------------------------------------------------------------------- /linux/third_party/cef/README.webview: -------------------------------------------------------------------------------- 1 | ../../../third_party_base/cef/README.webview -------------------------------------------------------------------------------- /lib/src/third_party/cef/README.webview: -------------------------------------------------------------------------------- 1 | ../../../../third_party_base/cef/README.webview -------------------------------------------------------------------------------- /linux/third_party/cef/src/LICENSE.txt: -------------------------------------------------------------------------------- 1 | ../../../../third_party_base/cef/src/LICENSE.txt -------------------------------------------------------------------------------- /lib/src/third_party/cef/src/LICENSE.txt: -------------------------------------------------------------------------------- 1 | ../../../../../third_party_base/cef/src/LICENSE.txt -------------------------------------------------------------------------------- /lib/src/third_party/flutter_engine/LICENSE: -------------------------------------------------------------------------------- 1 | ../../../../third_party_base/flutter_engine/LICENSE -------------------------------------------------------------------------------- /example/lib/third_party/webview_flutter/LICENSE: -------------------------------------------------------------------------------- 1 | ../../../../third_party_base/webview_flutter/LICENSE -------------------------------------------------------------------------------- /linux/cmake/link_to_cef_library.cmake: -------------------------------------------------------------------------------- 1 | target_link_libraries(${BINARY_NAME} PRIVATE cef_library) 2 | -------------------------------------------------------------------------------- /lib/src/third_party/flutter_engine/README.webview: -------------------------------------------------------------------------------- 1 | ../../../../third_party_base/flutter_engine/README.webview -------------------------------------------------------------------------------- /third_party_base/webview_flutter/example/assets/www/styles/style.css: -------------------------------------------------------------------------------- 1 | h1 { 2 | color: blue; 3 | } 4 | -------------------------------------------------------------------------------- /example/lib/third_party/webview_flutter/README.webview: -------------------------------------------------------------------------------- 1 | ../../../../third_party_base/webview_flutter/README.webview -------------------------------------------------------------------------------- /lib/src/third_party/webview_flutter_android/LICENSE: -------------------------------------------------------------------------------- 1 | ../../../../third_party_base/webview_flutter_android/LICENSE -------------------------------------------------------------------------------- /doc_assets/main_webview.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/access-company/flutter_linux_webview/HEAD/doc_assets/main_webview.gif -------------------------------------------------------------------------------- /lib/src/third_party/webview_flutter_android/README.webview: -------------------------------------------------------------------------------- 1 | ../../../../third_party_base/webview_flutter_android/README.webview -------------------------------------------------------------------------------- /linux/subprocess/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(../../third_party/cef/src/tests/cefsimple/CMakeLists_subprocess_project.txt) 2 | -------------------------------------------------------------------------------- /example/lib/third_party/webview_flutter/example/lib/main.dart: -------------------------------------------------------------------------------- 1 | ../../../../../../third_party_base/webview_flutter/example/lib/main.dart -------------------------------------------------------------------------------- /doc_assets/multiple_webviews.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/access-company/flutter_linux_webview/HEAD/doc_assets/multiple_webviews.gif -------------------------------------------------------------------------------- /lib/src/third_party/cef/src/include/internal/cef_types.dart: -------------------------------------------------------------------------------- 1 | ../../../../../../../third_party_base/cef/src/include/internal/cef_types.dart -------------------------------------------------------------------------------- /example/myassets/my_sample_audio.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/access-company/flutter_linux_webview/HEAD/example/myassets/my_sample_audio.ogg -------------------------------------------------------------------------------- /example/myassets/my_sample_video.webm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/access-company/flutter_linux_webview/HEAD/example/myassets/my_sample_video.webm -------------------------------------------------------------------------------- /example/lib/main.dart: -------------------------------------------------------------------------------- 1 | import 'third_party/webview_flutter/example/lib/main.dart' as real_main; 2 | 3 | void main() { 4 | real_main.main(); 5 | } 6 | -------------------------------------------------------------------------------- /example/lib/third_party/webview_flutter/example/assets/www/index.html: -------------------------------------------------------------------------------- 1 | ../../../../../../../third_party_base/webview_flutter/example/assets/www/index.html -------------------------------------------------------------------------------- /lib/src/third_party/webview_flutter_android/lib/src/instance_manager.dart: -------------------------------------------------------------------------------- 1 | ../../../../../../third_party_base/webview_flutter_android/lib/src/instance_manager.dart -------------------------------------------------------------------------------- /example/lib/third_party/webview_flutter/example/assets/www/styles/style.css: -------------------------------------------------------------------------------- 1 | ../../../../../../../../third_party_base/webview_flutter/example/assets/www/styles/style.css -------------------------------------------------------------------------------- /lib/src/third_party/cef/src/tests/cefclient/browser/windows_key_code.dart: -------------------------------------------------------------------------------- 1 | ../../../../../../../../third_party_base/cef/src/tests/cefclient/browser/windows_key_code.dart -------------------------------------------------------------------------------- /linux/third_party/cef/src/tests/cefsimple/CMakeLists_subprocess_project.txt: -------------------------------------------------------------------------------- 1 | ../../../../../../third_party_base/cef/src/tests/cefsimple/CMakeLists_subprocess_project.txt -------------------------------------------------------------------------------- /lib/src/third_party/flutter_engine/shell/platform/linux/native_key_code.dart: -------------------------------------------------------------------------------- 1 | ../../../../../../../third_party_base/flutter_engine/shell/platform/linux/native_key_code.dart -------------------------------------------------------------------------------- /lib/src/third_party/webview_flutter_android/lib/webview_linux_cookie_manager.dart: -------------------------------------------------------------------------------- 1 | ../../../../../third_party_base/webview_flutter_android/lib/webview_linux_cookie_manager.dart -------------------------------------------------------------------------------- /linux/third_party/cef/src/tests/cefclient/browser/flutter_webview_osr_renderer.cc: -------------------------------------------------------------------------------- 1 | ../../../../../../../third_party_base/cef/src/tests/cefclient/browser/flutter_webview_osr_renderer.cc -------------------------------------------------------------------------------- /linux/third_party/cef/src/tests/cefclient/browser/flutter_webview_osr_renderer.h: -------------------------------------------------------------------------------- 1 | ../../../../../../../third_party_base/cef/src/tests/cefclient/browser/flutter_webview_osr_renderer.h -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | include: package:flutter_lints/flutter.yaml 2 | 3 | # Additional information about this file can be found at 4 | # https://dart.dev/guides/language/analysis-options 5 | -------------------------------------------------------------------------------- /example/lib/third_party/webview_flutter/example/integration_test/flutter_linux_webview_test.dart: -------------------------------------------------------------------------------- 1 | ../../../../../../third_party_base/webview_flutter/example/integration_test/flutter_linux_webview_test.dart -------------------------------------------------------------------------------- /example/linux/main.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | int main(int argc, char** argv) { 4 | g_autoptr(MyApplication) app = my_application_new(); 5 | return g_application_run(G_APPLICATION(app), argc, argv); 6 | } 7 | -------------------------------------------------------------------------------- /example/integration_test/flutter_linux_webview_test.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_linux_webview_example/third_party/webview_flutter/example/integration_test/flutter_linux_webview_test.dart' 2 | as real_integration_test; 3 | 4 | Future main() async { 5 | await real_integration_test.main(); 6 | } 7 | -------------------------------------------------------------------------------- /.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: 049ea73c4d40d1870840d27034d4814c3b7cc6ca 8 | channel: master 9 | 10 | project_type: plugin 11 | -------------------------------------------------------------------------------- /example/.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: 049ea73c4d40d1870840d27034d4814c3b7cc6ca 8 | channel: master 9 | 10 | project_type: app 11 | -------------------------------------------------------------------------------- /third_party_base/webview_flutter_android/README.webview: -------------------------------------------------------------------------------- 1 | Name: webview_flutter_android 2 | URL: https://github.com/flutter/plugins/tree/webview_flutter-v3.0.4/packages/webview_flutter/webview_flutter_android 3 | Version: 2.8.8 4 | License: BSD-3-Clause 5 | License File: LICENSE 6 | 7 | Description: 8 | * Use CookieManager for the Linux implementation 9 | * Use InstanceManager as it is 10 | -------------------------------------------------------------------------------- /example/linux/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void fl_register_plugins(FlPluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /third_party_base/webview_flutter/README.webview: -------------------------------------------------------------------------------- 1 | Name: webview_flutter 2 | URL: https://github.com/flutter/plugins/tree/webview_flutter-v3.0.4/packages/webview_flutter/webview_flutter 3 | Version: 3.0.4 4 | License: BSD-3-Clause 5 | License File: LICENSE 6 | 7 | Description: 8 | The example app, assets, and integration_test are copied. These are for testing 9 | purposes and to demonstrate compatibility with mobile webview_flutter. 10 | -------------------------------------------------------------------------------- /third_party_base/flutter_engine/README.webview: -------------------------------------------------------------------------------- 1 | Name: Flutter Engine 2 | URL: https://github.com/flutter/engine/tree/6ba2af10bb05c88a2731482cedf2cfd11cf5af0b 3 | Revision: 6ba2af10bb05c88a2731482cedf2cfd11cf5af0b 4 | Version: 3.0.4 5 | License: BSD-3-Clause 6 | License File: LICENSE 7 | 8 | Description: 9 | The variable xkb_to_physical_key_map in key_mapping.cc was copied and translated 10 | to Dart in order to pass the key input from Dart to the CEF side. 11 | -------------------------------------------------------------------------------- /example/linux/my_application.h: -------------------------------------------------------------------------------- 1 | #ifndef FLUTTER_MY_APPLICATION_H_ 2 | #define FLUTTER_MY_APPLICATION_H_ 3 | 4 | #include 5 | 6 | G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION, 7 | GtkApplication) 8 | 9 | /** 10 | * my_application_new: 11 | * 12 | * Creates a new Flutter-based application. 13 | * 14 | * Returns: a new #MyApplication. 15 | */ 16 | MyApplication* my_application_new(); 17 | 18 | #endif // FLUTTER_MY_APPLICATION_H_ 19 | -------------------------------------------------------------------------------- /third_party_base/cef/README.webview: -------------------------------------------------------------------------------- 1 | Name: Chromium Embedded Framework (CEF) 2 | URL: https://bitbucket.org/chromiumembedded/cef/src/4664/ 3 | Version: 96.0.18 4 | Revision: fe551e4054895193c50598e64085e46a1eda77b0 5 | License: BSD-3-Clause 6 | License File: src/LICENSE.txt 7 | 8 | Description: 9 | We use the following components: 10 | - Type definitions for transferring key input from the Dart side to the CEF side. 11 | - Off-screen rendering logic. 12 | - The tests/cefsimple/CMakeLists.txt.in file for building the subprocess executable. 13 | -------------------------------------------------------------------------------- /example/linux/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | #include 10 | 11 | void fl_register_plugins(FlPluginRegistry* registry) { 12 | g_autoptr(FlPluginRegistrar) flutter_linux_webview_registrar = 13 | fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterLinuxWebviewPlugin"); 14 | flutter_linux_webview_plugin_register_with_registrar(flutter_linux_webview_registrar); 15 | } 16 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "Run the integration test app", 9 | "type": "dart", 10 | "request": "launch", 11 | "program": "example/integration_test/flutter_linux_webview_test.dart" 12 | }, 13 | { 14 | "name": "Flutter", 15 | "type": "dart", 16 | "request": "launch", 17 | "program": "example/lib/simple_example.dart" 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # clangd integration 24 | **/.cache/clangd/ 25 | 26 | 27 | # Flutter/Dart/Pub related 28 | # Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. 29 | /pubspec.lock 30 | **/doc/api/ 31 | .dart_tool/ 32 | .packages 33 | build/ 34 | linux/lib 35 | 36 | GPUCache 37 | linux/cef_binary* 38 | -------------------------------------------------------------------------------- /linux/subprocess/cef_distrib_patch/build_flutter_webview_subprocess.patch: -------------------------------------------------------------------------------- 1 | --- CMakeLists.txt 2 | +++ CMakeLists.txt 3 | @@ -133,7 +133,7 @@ 4 | # 5 | 6 | # For VS2019 and Xcode 12+ support. 7 | -cmake_minimum_required(VERSION 3.19) 8 | +cmake_minimum_required(VERSION 3.10) 9 | 10 | # Only generate Debug and Release configuration types. 11 | set(CMAKE_CONFIGURATION_TYPES Debug Release) 12 | @@ -219,6 +219,8 @@ 13 | # directory. 14 | add_subdirectory(${CEF_LIBCEF_DLL_WRAPPER_PATH} libcef_dll_wrapper) 15 | 16 | +add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../subprocess/src" "${WEBVIEW_SUBPROCESS_PROJECT_NAME}") 17 | + 18 | # Include application targets. 19 | # Comes from the /CMakeLists.txt file in the current directory. 20 | # TODO: Change these lines to match your project target when you copy this file. 21 | -------------------------------------------------------------------------------- /example/linux/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | flutter_linux_webview 7 | ) 8 | 9 | list(APPEND FLUTTER_FFI_PLUGIN_LIST 10 | ) 11 | 12 | set(PLUGIN_BUNDLED_LIBRARIES) 13 | 14 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 15 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin}) 16 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 18 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 19 | endforeach(plugin) 20 | 21 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST}) 22 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin}) 23 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries}) 24 | endforeach(ffi_plugin) 25 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | **/doc/api/ 25 | **/ios/Flutter/.last_build_id 26 | .dart_tool/ 27 | .flutter-plugins 28 | .flutter-plugins-dependencies 29 | .packages 30 | .pub-cache/ 31 | .pub/ 32 | /build/ 33 | 34 | # Web related 35 | lib/generated_plugin_registrant.dart 36 | 37 | # Symbolication related 38 | app.*.symbols 39 | 40 | # Obfuscation related 41 | app.*.map.json 42 | 43 | # Android Studio will place build artifacts here 44 | /android/app/debug 45 | /android/app/profile 46 | /android/app/release 47 | 48 | GPUCache/ 49 | -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Linux", 5 | "includePath": [ 6 | "${workspaceFolder}/**", 7 | "/usr/include/gtk-3.0", 8 | "/${workspaceFolder}/example/linux/flutter/ephemeral", 9 | "/usr/include/glib-2.0", 10 | "/usr/lib/x86_64-linux-gnu/glib-2.0/include", 11 | "/usr/include/pango-1.0", 12 | "/usr/include/cairo", 13 | "/usr/include/gdk-pixbuf-2.0", 14 | "/usr/include/atk-1.0", 15 | "${workspaceFolder}/linux/include", 16 | "/usr/include/c++/9", 17 | ], 18 | "defines": [], 19 | "compilerPath": "/usr/bin/clang", 20 | "cStandard": "c11", 21 | "cppStandard": "c++14", 22 | "intelliSenseMode": "linux-clang-x64" 23 | } 24 | ], 25 | "version": 4 26 | } 27 | -------------------------------------------------------------------------------- /.pubignore: -------------------------------------------------------------------------------- 1 | ### 2 | ### This file (.pubignore) should always be synced with .gitignore because 3 | ### `pub pulish` will ignore .gitignore if this file exists. 4 | ### 5 | 6 | ### Copy of .gitignore 7 | 8 | # Miscellaneous 9 | *.class 10 | *.log 11 | *.pyc 12 | *.swp 13 | .DS_Store 14 | .atom/ 15 | .buildlog/ 16 | .history 17 | .svn/ 18 | 19 | # IntelliJ related 20 | *.iml 21 | *.ipr 22 | *.iws 23 | .idea/ 24 | 25 | # The .vscode folder contains launch configuration and tasks you configure in 26 | # VS Code which you may wish to be included in version control, so this line 27 | # is commented out by default. 28 | #.vscode/ 29 | 30 | # clangd integration 31 | **/.cache/clangd/ 32 | 33 | 34 | # Flutter/Dart/Pub related 35 | # Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. 36 | /pubspec.lock 37 | **/doc/api/ 38 | .dart_tool/ 39 | .packages 40 | build/ 41 | linux/lib 42 | 43 | GPUCache 44 | linux/cef_binary* 45 | 46 | # 47 | # Additional ignore list for Pub 48 | # 49 | third_party_base/ 50 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.1.3 2 | 3 | * Centralized third-party source code in `//third_party_base/` and separated it from our code. 4 | * However, our Dart code and C++ code do not directly reference `//third_party_base/`, but instead access it through symbolic links from each `third_party/` directory. This is due to limitations in Dart. Additionally, when uploading packages to Pub, `//third_party_base/` is not uploaded, and instead symbolic links within each `third_party/` directory are materialized into regular files. For more details, refer to [third_party_base/README.md](./third_party_base/README.md) and [create_symlinks_to_third_party](./create_symlinks_to_third_party.sh). 5 | * ThirdPartyNotices.txt is now auto-generated by [create_symlinks_to_third_party](./create_symlinks_to_third_party.sh). 6 | * Changed the internal process of building the subprocess-executable. Previously, symbolic links were created to `//linux/subprocess/src/*` in the CEF binary distribution, but this has been discontinued. Please refer to `//linux/README.md` and `//linux/CMakeLists.txt` for details on the new build process. 7 | * Fixed build errors with clang 15. 8 | * Improvements to the documentation. 9 | 10 | ## 0.1.2 11 | 12 | * Minor improvements to the documentation. 13 | 14 | ## 0.1.1 15 | 16 | * Fix the broken GIF image links in README.md. 17 | * (Increase the patch version to reflect the fixed README in pub.dev.) 18 | 19 | ## 0.1.0 20 | 21 | * Initial release. Works with webview\_flutter v3.0.4. 22 | -------------------------------------------------------------------------------- /example/analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # This file configures the analyzer, which statically analyzes Dart code to 2 | # check for errors, warnings, and lints. 3 | # 4 | # The issues identified by the analyzer are surfaced in the UI of Dart-enabled 5 | # IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be 6 | # invoked from the command line by running `flutter analyze`. 7 | 8 | # The following line activates a set of recommended lints for Flutter apps, 9 | # packages, and plugins designed to encourage good coding practices. 10 | include: package:flutter_lints/flutter.yaml 11 | 12 | linter: 13 | # The lint rules applied to this project can be customized in the 14 | # section below to disable rules from the `package:flutter_lints/flutter.yaml` 15 | # included above or to enable additional rules. A list of all available lints 16 | # and their documentation is published at 17 | # https://dart-lang.github.io/linter/lints/index.html. 18 | # 19 | # Instead of disabling a lint rule for the entire project in the 20 | # section below, it can also be suppressed for a single line of code 21 | # or a specific dart file by using the `// ignore: name_of_lint` and 22 | # `// ignore_for_file: name_of_lint` syntax on the line or in the file 23 | # producing the lint. 24 | rules: 25 | # avoid_print: false # Uncomment to disable the `avoid_print` rule 26 | # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule 27 | 28 | # Additional information about this file can be found at 29 | # https://dart.dev/guides/language/analysis-options 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2023 ACCESS CO., LTD. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of ACCESS CO., LTD. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /third_party_base/flutter_engine/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2013 The Flutter Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without modification, 4 | are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above 9 | copyright notice, this list of conditions and the following 10 | disclaimer in the documentation and/or other materials provided 11 | with the distribution. 12 | * Neither the name of Google Inc. nor the names of its 13 | contributors may be used to endorse or promote products derived 14 | from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /third_party_base/webview_flutter/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2013 The Flutter Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without modification, 4 | are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above 9 | copyright notice, this list of conditions and the following 10 | disclaimer in the documentation and/or other materials provided 11 | with the distribution. 12 | * Neither the name of Google Inc. nor the names of its 13 | contributors may be used to endorse or promote products derived 14 | from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /third_party_base/webview_flutter_android/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2013 The Flutter Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without modification, 4 | are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above 9 | copyright notice, this list of conditions and the following 10 | disclaimer in the documentation and/or other materials provided 11 | with the distribution. 12 | * Neither the name of Google Inc. nor the names of its 13 | contributors may be used to endorse or promote products derived 14 | from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | -------------------------------------------------------------------------------- /third_party_base/README.md: -------------------------------------------------------------------------------- 1 | (This file may be `flutter_linux_webview/third_party_base/README.md` itself, 2 | or a copy or symlink of it.) 3 | 4 | # About `third_party/` directories in the repository 5 | 6 | `flutter_linux_webview` incorporates third-party software materials. 7 | 8 | Third-party source code is organized under several directories named `third_party/` in the repository. 9 | 10 | If this package is a Git repository, each third-party file exists as a symlink to a file in the `//third_party_base/` directory. 11 | However, if this package is downloaded from Pub, these symlinks are converted to regular files, and the `//third_party_base/` directory does not exist. 12 | 13 | 14 | ## `//third_party_base/` 15 | 16 | To centralize third-party source code and prevent scattering throughout the repository, we store them under `//third_party_base/` for plugin development. 17 | 18 | When we need to use these third-party source files, we create symlinks at the respective locations. We do not directly reference `//third_party_base/` in our source code. 19 | 20 | This approach is necessary due to the following restrictions: 21 | 22 | * Dart source code cannot access directories outside of lib/ due to Dart limitations. 23 | * Pub restricts the upload of packages with symlinks to directories (symlinks to files are allowed, but they are converted to regular files upon upload). 24 | 25 | For consistency, we apply the same approach to native source code as well as Dart code. (However, files in `//linux/` can directly access `//third_party_base/` with CMake configuration). 26 | 27 | The creation of symlinks is performed by the `//create_symlinks_to_third_party.sh` script. 28 | -------------------------------------------------------------------------------- /third_party_base/cef/src/LICENSE.txt: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2008-2020 Marshall A. Greenblatt. Portions Copyright (c) 2 | // 2006-2009 Google Inc. All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the name Chromium Embedded 15 | // Framework nor the names of its contributors may be used to endorse 16 | // or promote products derived from this software without specific prior 17 | // written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # flutter_linux_webview_example 2 | 3 | ## About the example apps 4 | 5 | There are several example apps as shown below. 6 | 7 | Note: If you are using Flutter prior to version 3.10, the example apps will fail to compile and require some editing. See each example app. 8 | 9 | - lib/simple_example.dart 10 | - The simplest example app that displays a single WebView. It is the same as the example in the [README.md of the plugin](../README.md). 11 | - lib/main.dart 12 | - This came from webview_flutter v3.0.4 example. 13 | - lib/multiple_webviews_example.dart 14 | - The simple demo of dynamically adding and removing webviews. This app is not well maintained. 15 | 16 | --- 17 | 18 | - integration_test/flutter_linux_webview_test.dart 19 | - This came from webview_flutter v3.0.4 example/integration_test. 20 | 21 | ## How to run 22 | 23 | ### Build and run 24 | 25 | ```shell 26 | # Debug build and run 27 | $ flutter run -t lib/simple_example.dart 28 | # or 29 | # Release build and run 30 | $ flutter run --release -t lib/simple_example.dart 31 | ``` 32 | 33 | You can add `-v` option for verbose outputs. 34 | 35 | ### Only Building 36 | 37 | For debug build: 38 | 39 | ```shell 40 | # Debug build 41 | $ flutter build linux --debug -t lib/simple_example.dart 42 | # To run: 43 | $ build/linux/x64/debug/bundle/flutter_linux_webview_example 44 | ``` 45 | 46 | For release build: 47 | 48 | ```shell 49 | # Release build 50 | $ flutter build linux -t lib/webview_sample.dart 51 | # To run: 52 | $ build/linux/x64/release/bundle/flutter_linux_webview_example 53 | ``` 54 | 55 | ## Clean build artifacts and Flutter cache 56 | 57 | ```shell 58 | $ flutter clean 59 | ``` 60 | 61 | ## Run the test 62 | 63 | ```shell 64 | $ flutter test integration_test/flutter_linux_webview_test.dart 65 | ``` 66 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "*.rc": "shellscript", 4 | "any": "cpp", 5 | "array": "cpp", 6 | "atomic": "cpp", 7 | "*.tcc": "cpp", 8 | "cctype": "cpp", 9 | "chrono": "cpp", 10 | "clocale": "cpp", 11 | "cmath": "cpp", 12 | "cstdarg": "cpp", 13 | "cstddef": "cpp", 14 | "cstdint": "cpp", 15 | "cstdio": "cpp", 16 | "cstdlib": "cpp", 17 | "cstring": "cpp", 18 | "ctime": "cpp", 19 | "cwchar": "cpp", 20 | "cwctype": "cpp", 21 | "deque": "cpp", 22 | "list": "cpp", 23 | "unordered_map": "cpp", 24 | "vector": "cpp", 25 | "exception": "cpp", 26 | "algorithm": "cpp", 27 | "functional": "cpp", 28 | "iterator": "cpp", 29 | "map": "cpp", 30 | "memory": "cpp", 31 | "memory_resource": "cpp", 32 | "optional": "cpp", 33 | "ratio": "cpp", 34 | "set": "cpp", 35 | "string": "cpp", 36 | "string_view": "cpp", 37 | "system_error": "cpp", 38 | "tuple": "cpp", 39 | "type_traits": "cpp", 40 | "utility": "cpp", 41 | "fstream": "cpp", 42 | "initializer_list": "cpp", 43 | "iomanip": "cpp", 44 | "iosfwd": "cpp", 45 | "iostream": "cpp", 46 | "istream": "cpp", 47 | "limits": "cpp", 48 | "new": "cpp", 49 | "ostream": "cpp", 50 | "sstream": "cpp", 51 | "stdexcept": "cpp", 52 | "streambuf": "cpp", 53 | "thread": "cpp", 54 | "cinttypes": "cpp", 55 | "typeinfo": "cpp", 56 | "variant": "cpp", 57 | "numeric": "cpp", 58 | "random": "cpp", 59 | "bit": "cpp" 60 | }, 61 | "files.insertFinalNewline": true, 62 | "files.trimFinalNewlines": true 63 | } 64 | -------------------------------------------------------------------------------- /lib/flutter_linux_webview.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 ACCESS CO., LTD. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of ACCESS CO., LTD. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | library flutter_linux_webview; 30 | 31 | export 'src/third_party/webview_flutter_android/lib/webview_linux_cookie_manager.dart'; 32 | export 'src/linux_webview_plugin.dart'; 33 | export 'src/webview_linux.dart'; 34 | export 'src/webview_linux_widget.dart'; 35 | -------------------------------------------------------------------------------- /lib/src/logging.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 ACCESS CO., LTD. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of ACCESS CO., LTD. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | import 'package:logging/logging.dart'; 30 | 31 | final Logger log = Logger('flutter_linux_webview'); 32 | 33 | void setupLogger() { 34 | log.onRecord.listen((record) { 35 | print('${record.level.name}: ${record.time}: ${record.message}'); 36 | }); 37 | } 38 | -------------------------------------------------------------------------------- /linux/flutter_webview_types.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 ACCESS CO., LTD. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of ACCESS CO., LTD. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #include "flutter_linux_webview/flutter_webview_types.h" 30 | 31 | #include 32 | 33 | WebviewError::WebviewError(const std::string& code, const std::string& message) 34 | : code(code), message(message) {} 35 | 36 | WebviewError::WebviewError() {} 37 | -------------------------------------------------------------------------------- /linux/flutter_webview_app.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 ACCESS CO., LTD. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of ACCESS CO., LTD. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #include "flutter_webview_app.h" 30 | 31 | #include 32 | 33 | #include "include/wrapper/cef_helpers.h" 34 | 35 | FlutterWebviewApp::FlutterWebviewApp( 36 | std::function on_context_initialized) 37 | : on_context_initialized_(on_context_initialized) {} 38 | 39 | void FlutterWebviewApp::OnContextInitialized() { 40 | CEF_REQUIRE_UI_THREAD(); 41 | on_context_initialized_(); 42 | } 43 | -------------------------------------------------------------------------------- /linux/subprocess/src/flutter_webview_subprocess.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 ACCESS CO., LTD. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of ACCESS CO., LTD. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #include "include/cef_app.h" 30 | 31 | #include "flutter_webview_render_app.h" 32 | 33 | // Entry point function for sub-processes (i.e. render, plugin, GPU, etc) 34 | int main(int argc, char* argv[]) { 35 | CefMainArgs main_args(argc, argv); 36 | 37 | CefRefPtr app(new FlutterWebviewRenderApp()); 38 | 39 | int exit_code = CefExecuteProcess(main_args, app, nullptr); 40 | if (exit_code >= 0) { 41 | return exit_code; 42 | } 43 | 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /third_party_base/webview_flutter/example/assets/www/index.html: -------------------------------------------------------------------------------- 1 | 2 | 29 | 30 | 31 | 32 | Load file or HTML string example 33 | 34 | 35 | 36 | 37 |

Local demo page

38 |

39 | This is an example page used to demonstrate how to load a local file or HTML 40 | string using the Flutter 41 | webview plugin. 42 |

43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /linux/flutter_webview_app.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 ACCESS CO., LTD. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of ACCESS CO., LTD. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef LINUX_FLUTTER_WEBVIEW_APP_H_ 30 | #define LINUX_FLUTTER_WEBVIEW_APP_H_ 31 | 32 | #include 33 | 34 | #include "include/cef_app.h" 35 | 36 | // application-level callbacks for the browser process (plugin process). 37 | class FlutterWebviewApp : public CefApp, public CefBrowserProcessHandler { 38 | public: 39 | explicit FlutterWebviewApp(std::function on_context_initialized); 40 | 41 | // CefApp methods: 42 | CefRefPtr GetBrowserProcessHandler() override { 43 | return this; 44 | } 45 | 46 | // CefBrowserProcessHandler methods: 47 | void OnContextInitialized() override; 48 | 49 | private: 50 | std::function on_context_initialized_; 51 | 52 | IMPLEMENT_REFCOUNTING(FlutterWebviewApp); 53 | }; 54 | 55 | #endif // LINUX_FLUTTER_WEBVIEW_APP_H_ 56 | -------------------------------------------------------------------------------- /linux/include/flutter_linux_webview/flutter_linux_webview_plugin.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 ACCESS CO., LTD. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of ACCESS CO., LTD. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef LINUX_INCLUDE_FLUTTER_LINUX_WEBVIEW_FLUTTER_LINUX_WEBVIEW_PLUGIN_H_ 30 | #define LINUX_INCLUDE_FLUTTER_LINUX_WEBVIEW_FLUTTER_LINUX_WEBVIEW_PLUGIN_H_ 31 | 32 | #include 33 | 34 | G_BEGIN_DECLS 35 | 36 | #ifdef FLUTTER_PLUGIN_IMPL 37 | #define FLUTTER_PLUGIN_EXPORT __attribute__((visibility("default"))) 38 | #else 39 | #define FLUTTER_PLUGIN_EXPORT 40 | #endif 41 | 42 | typedef struct _FlutterLinuxWebviewPlugin FlutterLinuxWebviewPlugin; 43 | typedef struct { 44 | GObjectClass parent_class; 45 | } FlutterLinuxWebviewPluginClass; 46 | 47 | FLUTTER_PLUGIN_EXPORT GType flutter_linux_webview_plugin_get_type(); 48 | 49 | FLUTTER_PLUGIN_EXPORT void flutter_linux_webview_plugin_register_with_registrar( 50 | FlPluginRegistrar* registrar); 51 | 52 | G_END_DECLS 53 | 54 | #endif // LINUX_INCLUDE_FLUTTER_LINUX_WEBVIEW_FLUTTER_LINUX_WEBVIEW_PLUGIN_H_ 55 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: flutter_linux_webview 2 | description: "A Linux Desktop implementation for the webview_flutter (v3.0.4) plugin, powered by CEF (Chromium Embedded Framework)" 3 | version: 0.1.3 4 | repository: https://github.com/access-company/flutter_linux_webview 5 | 6 | environment: 7 | sdk: ">=2.17.0 <4.0.0" 8 | flutter: ">=3.0.0" 9 | 10 | dependencies: 11 | flutter: 12 | sdk: flutter 13 | logging: ^1.1.0 14 | path: ^1.8.1 15 | webview_flutter_platform_interface: ^1.8.0 16 | 17 | dev_dependencies: 18 | flutter_test: 19 | sdk: flutter 20 | flutter_lints: ^1.0.0 21 | 22 | # note: Symbols defined in the webview_flutter package, such as the [WebView] 23 | # and [WebViewController] and other classes, are not resolved 24 | # (i.e., hyperlinked) when generating documentation for this plugin. To make 25 | # them resolved, you need to temporarily add a dependency on the 26 | # webview_flutter package here and import it in the files that have the 27 | # references to be resolved. 28 | # 29 | # (Unfortunately, temporary reference resolution only during document 30 | # generation does not seem to be possible.) 31 | # 32 | # webview_flutter: ^3.0.4 33 | 34 | # For information on the generic Dart part of this file, see the 35 | # following page: https://dart.dev/tools/pub/pubspec 36 | 37 | # The following section is specific to Flutter. 38 | flutter: 39 | # This section identifies this Flutter project as a plugin project. 40 | # The 'pluginClass' and Android 'package' identifiers should not ordinarily 41 | # be modified. They are used by the tooling to maintain consistency when 42 | # adding or updating assets for this project. 43 | plugin: 44 | implements: webview_flutter 45 | platforms: 46 | linux: 47 | # This tells the SDK that this class is a plugin entry point for C++. 48 | # Auto-generated build/linux/flutter/generated_plugin_registrant.cc will 49 | # call `flutter_linux_webview_plugin_register_with_registrar()`. 50 | pluginClass: FlutterLinuxWebviewPlugin 51 | 52 | # TODO(Ino): Support auto registration of our platform implementation 53 | # when upgrading to v4. This can be done with `dartPluginClass` field 54 | # below. `dartPluginClass` filed tells the SDK that this class is a 55 | # plugin entry point for Dart. The auto-generated 56 | # .dart_tool/flutter_build/dart_plugin_registrant.dart 57 | # will call `MyWebViewPlatform.registerWith()` so we can register our 58 | # platform implementation at that time with 59 | # webview_flutter_platform_interface. 60 | ### dartPluginClass: MyWebViewPlatform 61 | -------------------------------------------------------------------------------- /linux/include/flutter_linux_webview/fl_custom_texture_gl.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 ACCESS CO., LTD. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of ACCESS CO., LTD. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef LINUX_INCLUDE_FLUTTER_LINUX_WEBVIEW_FL_CUSTOM_TEXTURE_GL_H_ 30 | #define LINUX_INCLUDE_FLUTTER_LINUX_WEBVIEW_FL_CUSTOM_TEXTURE_GL_H_ 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | 38 | G_DECLARE_FINAL_TYPE(FlCustomTextureGL, 39 | fl_custom_texture_gl, 40 | FL, 41 | CUSTOM_TEXTURE_GL, 42 | FlTextureGL) 43 | 44 | struct _FlCustomTextureGL { 45 | FlTextureGL parent_instance; 46 | 47 | uint32_t target; 48 | GLuint native_texture_id; 49 | uint32_t width; 50 | uint32_t height; 51 | }; 52 | 53 | FlCustomTextureGL* fl_custom_texture_gl_new(uint32_t target, 54 | uint32_t name, 55 | uint32_t width, 56 | uint32_t height); 57 | 58 | #endif // LINUX_INCLUDE_FLUTTER_LINUX_WEBVIEW_FL_CUSTOM_TEXTURE_GL_H_ 59 | -------------------------------------------------------------------------------- /lib/src/webview_linux.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 ACCESS CO., LTD. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of ACCESS CO., LTD. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | import 'dart:async'; 30 | 31 | import 'package:flutter/foundation.dart'; 32 | import 'package:flutter/gestures.dart'; 33 | import 'package:flutter/widgets.dart'; 34 | import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; 35 | 36 | import 'webview_linux_widget.dart'; 37 | 38 | class LinuxWebView implements WebViewPlatform { 39 | @override 40 | Widget build({ 41 | required BuildContext context, 42 | required CreationParams creationParams, 43 | required WebViewPlatformCallbacksHandler webViewPlatformCallbacksHandler, 44 | required JavascriptChannelRegistry javascriptChannelRegistry, 45 | WebViewPlatformCreatedCallback? onWebViewPlatformCreated, 46 | Set>? gestureRecognizers, 47 | }) { 48 | return WebViewLinuxWidget( 49 | onWebViewPlatformCreated: onWebViewPlatformCreated, 50 | callbacksHandler: webViewPlatformCallbacksHandler, 51 | javascriptChannelRegistry: javascriptChannelRegistry, 52 | creationParams: creationParams, 53 | ); 54 | } 55 | 56 | @override 57 | Future clearCookies() => MethodChannelWebViewPlatform.clearCookies(); 58 | } 59 | -------------------------------------------------------------------------------- /linux/subprocess/src/flutter_webview_render_app.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 ACCESS CO., LTD. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of ACCESS CO., LTD. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef LINUX_SUBPROCESS_SRC_FLUTTER_WEBVIEW_RENDER_APP_H_ 30 | #define LINUX_SUBPROCESS_SRC_FLUTTER_WEBVIEW_RENDER_APP_H_ 31 | 32 | #include "include/cef_app.h" 33 | 34 | // Client app implementation for the renderer process. 35 | class FlutterWebviewRenderApp : public CefApp, public CefRenderProcessHandler { 36 | public: 37 | FlutterWebviewRenderApp(); 38 | 39 | CefRefPtr GetRenderProcessHandler() override { 40 | return this; 41 | } 42 | 43 | // CefRenderProcessHandler methods: 44 | void OnContextCreated(CefRefPtr browser, 45 | CefRefPtr frame, 46 | CefRefPtr context) override; 47 | bool OnProcessMessageReceived(CefRefPtr browser, 48 | CefRefPtr frame, 49 | CefProcessId source_process, 50 | CefRefPtr message) override; 51 | 52 | IMPLEMENT_REFCOUNTING(FlutterWebviewRenderApp); 53 | DISALLOW_COPY_AND_ASSIGN(FlutterWebviewRenderApp); 54 | }; 55 | 56 | #endif // LINUX_SUBPROCESS_SRC_FLUTTER_WEBVIEW_RENDER_APP_H_ 57 | -------------------------------------------------------------------------------- /example/linux/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file controls Flutter-level build steps. It should not be edited. 2 | cmake_minimum_required(VERSION 3.10) 3 | 4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 5 | 6 | # Configuration provided via flutter tool. 7 | include(${EPHEMERAL_DIR}/generated_config.cmake) 8 | 9 | # TODO: Move the rest of this into files in ephemeral. See 10 | # https://github.com/flutter/flutter/issues/57146. 11 | 12 | # Serves the same purpose as list(TRANSFORM ... PREPEND ...), 13 | # which isn't available in 3.10. 14 | function(list_prepend LIST_NAME PREFIX) 15 | set(NEW_LIST "") 16 | foreach(element ${${LIST_NAME}}) 17 | list(APPEND NEW_LIST "${PREFIX}${element}") 18 | endforeach(element) 19 | set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) 20 | endfunction() 21 | 22 | # === Flutter Library === 23 | # System-level dependencies. 24 | find_package(PkgConfig REQUIRED) 25 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) 26 | pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) 27 | pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) 28 | 29 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") 30 | 31 | # Published to parent scope for install step. 32 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 33 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 34 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 35 | set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) 36 | 37 | list(APPEND FLUTTER_LIBRARY_HEADERS 38 | "fl_basic_message_channel.h" 39 | "fl_binary_codec.h" 40 | "fl_binary_messenger.h" 41 | "fl_dart_project.h" 42 | "fl_engine.h" 43 | "fl_json_message_codec.h" 44 | "fl_json_method_codec.h" 45 | "fl_message_codec.h" 46 | "fl_method_call.h" 47 | "fl_method_channel.h" 48 | "fl_method_codec.h" 49 | "fl_method_response.h" 50 | "fl_plugin_registrar.h" 51 | "fl_plugin_registry.h" 52 | "fl_standard_message_codec.h" 53 | "fl_standard_method_codec.h" 54 | "fl_string_codec.h" 55 | "fl_value.h" 56 | "fl_view.h" 57 | "flutter_linux.h" 58 | ) 59 | list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") 60 | add_library(flutter INTERFACE) 61 | target_include_directories(flutter INTERFACE 62 | "${EPHEMERAL_DIR}" 63 | ) 64 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") 65 | target_link_libraries(flutter INTERFACE 66 | PkgConfig::GTK 67 | PkgConfig::GLIB 68 | PkgConfig::GIO 69 | ) 70 | add_dependencies(flutter flutter_assemble) 71 | 72 | # === Flutter tool backend === 73 | # _phony_ is a non-existent file to force this command to run every time, 74 | # since currently there's no way to get a full input/output list from the 75 | # flutter tool. 76 | add_custom_command( 77 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 78 | ${CMAKE_CURRENT_BINARY_DIR}/_phony_ 79 | COMMAND ${CMAKE_COMMAND} -E env 80 | ${FLUTTER_TOOL_ENVIRONMENT} 81 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" 82 | ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} 83 | VERBATIM 84 | ) 85 | add_custom_target(flutter_assemble DEPENDS 86 | "${FLUTTER_LIBRARY}" 87 | ${FLUTTER_LIBRARY_HEADERS} 88 | ) 89 | -------------------------------------------------------------------------------- /linux/fl_custom_texture_gl.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 ACCESS CO., LTD. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of ACCESS CO., LTD. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #include "flutter_linux_webview/fl_custom_texture_gl.h" 30 | 31 | // FlCustomTextureGL: A class derived from the abstract class FlTextureGL 32 | 33 | G_DEFINE_TYPE(FlCustomTextureGL, fl_custom_texture_gl, fl_texture_gl_get_type()) 34 | 35 | static void fl_custom_texture_gl_dispose(GObject* object) { 36 | G_OBJECT_CLASS(fl_custom_texture_gl_parent_class)->dispose(object); 37 | } 38 | 39 | static gboolean fl_custom_texture_gl_populate(FlTextureGL* texture, 40 | uint32_t* target, 41 | uint32_t* name, 42 | uint32_t* width, 43 | uint32_t* height, 44 | GError** error) { 45 | FlCustomTextureGL* self = FL_CUSTOM_TEXTURE_GL(texture); 46 | 47 | *target = self->target; 48 | *name = self->native_texture_id; 49 | *width = self->width; 50 | *height = self->height; 51 | 52 | return TRUE; 53 | } 54 | 55 | FlCustomTextureGL* fl_custom_texture_gl_new(uint32_t target, 56 | GLuint native_texture_id, 57 | uint32_t width, 58 | uint32_t height) { 59 | auto r = FL_CUSTOM_TEXTURE_GL( 60 | g_object_new(fl_custom_texture_gl_get_type(), nullptr)); 61 | r->target = target; 62 | r->native_texture_id = native_texture_id; 63 | r->width = width; 64 | r->height = height; 65 | return r; 66 | } 67 | 68 | static void fl_custom_texture_gl_class_init(FlCustomTextureGLClass* klass) { 69 | G_OBJECT_CLASS(klass)->dispose = fl_custom_texture_gl_dispose; 70 | FL_TEXTURE_GL_CLASS(klass)->populate = fl_custom_texture_gl_populate; 71 | } 72 | 73 | static void fl_custom_texture_gl_init(FlCustomTextureGL* self) {} 74 | -------------------------------------------------------------------------------- /third_party_base/webview_flutter_android/lib/src/instance_manager.dart: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Flutter Authors. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without modification, 4 | // are permitted provided that the following conditions are met: 5 | // 6 | // * Redistributions of source code must retain the above copyright 7 | // notice, this list of conditions and the following disclaimer. 8 | // * Redistributions in binary form must reproduce the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer in the documentation and/or other materials provided 11 | // with the distribution. 12 | // * Neither the name of Google Inc. nor the names of its 13 | // contributors may be used to endorse or promote products derived 14 | // from this software without specific prior written permission. 15 | // 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 20 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | // This file was copied from https://github.com/flutter/plugins/blob/webview_flutter-v3.0.4/packages/webview_flutter/webview_flutter_android/lib/src/instance_manager.dart 28 | 29 | /// Maintains instances stored to communicate with java objects. 30 | class InstanceManager { 31 | final Map _instanceIdsToInstances = {}; 32 | final Map _instancesToInstanceIds = {}; 33 | 34 | int _nextInstanceId = 0; 35 | 36 | /// Global instance of [InstanceManager]. 37 | static final InstanceManager instance = InstanceManager(); 38 | 39 | /// Attempt to add a new instance. 40 | /// 41 | /// Returns new if [instance] has already been added. Otherwise, it is added 42 | /// with a new instance id. 43 | int? tryAddInstance(Object instance) { 44 | if (_instancesToInstanceIds.containsKey(instance)) { 45 | return null; 46 | } 47 | 48 | final int instanceId = _nextInstanceId++; 49 | _instancesToInstanceIds[instance] = instanceId; 50 | _instanceIdsToInstances[instanceId] = instance; 51 | return instanceId; 52 | } 53 | 54 | /// Remove the instance from the manager. 55 | /// 56 | /// Returns null if the instance is removed. Otherwise, return the instanceId 57 | /// of the removed instance. 58 | int? removeInstance(Object instance) { 59 | final int? instanceId = _instancesToInstanceIds[instance]; 60 | if (instanceId != null) { 61 | _instancesToInstanceIds.remove(instance); 62 | _instanceIdsToInstances.remove(instanceId); 63 | } 64 | return instanceId; 65 | } 66 | 67 | /// Retrieve the Object paired with instanceId. 68 | Object? getInstance(int instanceId) { 69 | return _instanceIdsToInstances[instanceId]; 70 | } 71 | 72 | /// Retrieve the instanceId paired with instance. 73 | int? getInstanceId(Object instance) { 74 | return _instancesToInstanceIds[instance]; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /example/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: flutter_linux_webview_example 2 | description: Demonstrates how to use the flutter_linux_webview plugin. 3 | 4 | # The following line prevents the package from being accidentally published to 5 | # pub.dev using `flutter pub publish`. This is preferred for private packages. 6 | publish_to: 'none' # Remove this line if you wish to publish to pub.dev 7 | 8 | environment: 9 | sdk: ">=2.15.1 <4.0.0" 10 | 11 | # Dependencies specify other packages that your package needs in order to work. 12 | # To automatically upgrade your package dependencies to the latest versions 13 | # consider running `flutter pub upgrade --major-versions`. Alternatively, 14 | # dependencies can be manually updated by changing the version numbers below to 15 | # the latest version available on pub.dev. To see which dependencies have newer 16 | # versions available, run `flutter pub outdated`. 17 | dependencies: 18 | flutter: 19 | sdk: flutter 20 | 21 | flutter_linux_webview: 22 | # When depending on this package from a real application you should use: 23 | # flutter_linux_webview: ^x.y.z 24 | # See https://dart.dev/tools/pub/dependencies#version-constraints 25 | # The example app is bundled with the plugin so we use a path dependency on 26 | # the parent directory to use the current plugin's version. 27 | path: ../ 28 | 29 | webview_flutter: ^3.0.4 30 | path_provider: ^2.0.9 31 | 32 | dev_dependencies: 33 | flutter_test: 34 | sdk: flutter 35 | 36 | # The "flutter_lints" package below contains a set of recommended lints to 37 | # encourage good coding practices. The lint set provided by the package is 38 | # activated in the `analysis_options.yaml` file located at the root of your 39 | # package. See that file for information about deactivating specific lint 40 | # rules and activating additional ones. 41 | flutter_lints: ^1.0.0 42 | 43 | integration_test: 44 | sdk: flutter 45 | 46 | # For information on the generic Dart part of this file, see the 47 | # following page: https://dart.dev/tools/pub/pubspec 48 | 49 | # The following section is specific to Flutter. 50 | flutter: 51 | 52 | # The following line ensures that the Material Icons font is 53 | # included with your application, so that you can use the icons in 54 | # the material Icons class. 55 | uses-material-design: true 56 | 57 | # To add assets to your application, add an assets section, like this: 58 | # assets: 59 | # - images/a_dot_burr.jpeg 60 | # - images/a_dot_ham.jpeg 61 | assets: 62 | - lib/third_party/webview_flutter/example/assets/www/index.html 63 | - lib/third_party/webview_flutter/example/assets/www/styles/style.css 64 | - myassets/my_sample_audio.ogg 65 | - myassets/my_sample_video.webm 66 | 67 | # An image asset can refer to one or more resolution-specific "variants", see 68 | # https://flutter.dev/assets-and-images/#resolution-aware. 69 | 70 | # For details regarding adding assets from package dependencies, see 71 | # https://flutter.dev/assets-and-images/#from-packages 72 | 73 | # To add custom fonts to your application, add a fonts section here, 74 | # in this "flutter" section. Each entry in this list should have a 75 | # "family" key with the font family name, and a "fonts" key with a 76 | # list giving the asset and other descriptors for the font. For 77 | # example: 78 | # fonts: 79 | # - family: Schyler 80 | # fonts: 81 | # - asset: fonts/Schyler-Regular.ttf 82 | # - asset: fonts/Schyler-Italic.ttf 83 | # style: italic 84 | # - family: Trajan Pro 85 | # fonts: 86 | # - asset: fonts/TrajanPro.ttf 87 | # - asset: fonts/TrajanPro_Bold.ttf 88 | # weight: 700 89 | # 90 | # For details regarding fonts from package dependencies, 91 | # see https://flutter.dev/custom-fonts/#from-packages 92 | -------------------------------------------------------------------------------- /linux/subprocess/src/flutter_webview_process_messages.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 ACCESS CO., LTD. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of ACCESS CO., LTD. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #include "flutter_webview_process_messages.h" 30 | 31 | #include 32 | 33 | namespace flutter_webview_process_messages { 34 | 35 | CefRefPtr Create_FrameMsg_RequestRunJavascript( 36 | int js_run_id, 37 | std::string javascript) { 38 | CefRefPtr msg = 39 | CefProcessMessage::Create(kFrameMsg_RequestRunJavascript); 40 | CefRefPtr args = msg->GetArgumentList(); 41 | args->SetInt(0, js_run_id); 42 | args->SetString(1, javascript); 43 | return msg; 44 | } 45 | 46 | void Read_FrameMsg_RequestRunJavascript(CefRefPtr message, 47 | int* out_js_run_id, 48 | std::string* out_javascript) { 49 | message->GetArgumentList(); 50 | CefRefPtr args = message->GetArgumentList(); 51 | *out_js_run_id = args->GetInt(0); 52 | *out_javascript = args->GetString(1); 53 | } 54 | 55 | CefRefPtr Create_FrameHostMsg_RunJavascriptResponse( 56 | int js_run_id, 57 | bool was_executed, 58 | bool is_exception, 59 | std::string js_result, 60 | bool is_undefined) { 61 | CefRefPtr msg = 62 | CefProcessMessage::Create(kFrameHostMsg_RunJavascriptResponse); 63 | CefRefPtr args = msg->GetArgumentList(); 64 | args->SetInt(0, js_run_id); 65 | args->SetBool(1, was_executed); 66 | args->SetBool(2, is_exception); 67 | args->SetString(3, js_result); 68 | args->SetBool(4, is_undefined); 69 | return msg; 70 | } 71 | 72 | void Read_FrameHostMsg_RunJavascriptResponse( 73 | CefRefPtr message, 74 | int* out_js_run_id, 75 | bool* out_was_executed, 76 | bool* out_is_exception, 77 | std::string* out_result, 78 | bool* out_is_undefined) { 79 | message->GetArgumentList(); 80 | CefRefPtr args = message->GetArgumentList(); 81 | *out_js_run_id = args->GetInt(0); 82 | *out_was_executed = args->GetBool(1); 83 | *out_is_exception = args->GetBool(2); 84 | *out_result = args->GetString(3); 85 | *out_is_undefined = args->GetBool(4); 86 | } 87 | 88 | } // namespace flutter_webview_process_messages 89 | -------------------------------------------------------------------------------- /example/linux/my_application.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | #include 4 | #ifdef GDK_WINDOWING_X11 5 | #include 6 | #endif 7 | 8 | #include "flutter/generated_plugin_registrant.h" 9 | 10 | struct _MyApplication { 11 | GtkApplication parent_instance; 12 | char** dart_entrypoint_arguments; 13 | }; 14 | 15 | G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) 16 | 17 | // Implements GApplication::activate. 18 | static void my_application_activate(GApplication* application) { 19 | MyApplication* self = MY_APPLICATION(application); 20 | GtkWindow* window = 21 | GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); 22 | 23 | // Use a header bar when running in GNOME as this is the common style used 24 | // by applications and is the setup most users will be using (e.g. Ubuntu 25 | // desktop). 26 | // If running on X and not using GNOME then just use a traditional title bar 27 | // in case the window manager does more exotic layout, e.g. tiling. 28 | // If running on Wayland assume the header bar will work (may need changing 29 | // if future cases occur). 30 | gboolean use_header_bar = TRUE; 31 | #ifdef GDK_WINDOWING_X11 32 | GdkScreen* screen = gtk_window_get_screen(window); 33 | if (GDK_IS_X11_SCREEN(screen)) { 34 | const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen); 35 | if (g_strcmp0(wm_name, "GNOME Shell") != 0) { 36 | use_header_bar = FALSE; 37 | } 38 | } 39 | #endif 40 | if (use_header_bar) { 41 | GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); 42 | gtk_widget_show(GTK_WIDGET(header_bar)); 43 | gtk_header_bar_set_title(header_bar, "flutter_linux_webview_example"); 44 | gtk_header_bar_set_show_close_button(header_bar, TRUE); 45 | gtk_window_set_titlebar(window, GTK_WIDGET(header_bar)); 46 | } else { 47 | gtk_window_set_title(window, "flutter_linux_webview_example"); 48 | } 49 | 50 | gtk_window_set_default_size(window, 1280, 720); 51 | gtk_widget_show(GTK_WIDGET(window)); 52 | 53 | g_autoptr(FlDartProject) project = fl_dart_project_new(); 54 | fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments); 55 | 56 | FlView* view = fl_view_new(project); 57 | gtk_widget_show(GTK_WIDGET(view)); 58 | gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view)); 59 | 60 | fl_register_plugins(FL_PLUGIN_REGISTRY(view)); 61 | 62 | gtk_widget_grab_focus(GTK_WIDGET(view)); 63 | } 64 | 65 | // Implements GApplication::local_command_line. 66 | static gboolean my_application_local_command_line(GApplication* application, gchar*** arguments, int* exit_status) { 67 | MyApplication* self = MY_APPLICATION(application); 68 | // Strip out the first argument as it is the binary name. 69 | self->dart_entrypoint_arguments = g_strdupv(*arguments + 1); 70 | 71 | g_autoptr(GError) error = nullptr; 72 | if (!g_application_register(application, nullptr, &error)) { 73 | g_warning("Failed to register: %s", error->message); 74 | *exit_status = 1; 75 | return TRUE; 76 | } 77 | 78 | g_application_activate(application); 79 | *exit_status = 0; 80 | 81 | return TRUE; 82 | } 83 | 84 | // Implements GObject::dispose. 85 | static void my_application_dispose(GObject* object) { 86 | MyApplication* self = MY_APPLICATION(object); 87 | g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev); 88 | G_OBJECT_CLASS(my_application_parent_class)->dispose(object); 89 | } 90 | 91 | static void my_application_class_init(MyApplicationClass* klass) { 92 | G_APPLICATION_CLASS(klass)->activate = my_application_activate; 93 | G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line; 94 | G_OBJECT_CLASS(klass)->dispose = my_application_dispose; 95 | } 96 | 97 | static void my_application_init(MyApplication* self) {} 98 | 99 | MyApplication* my_application_new() { 100 | return MY_APPLICATION(g_object_new(my_application_get_type(), 101 | "application-id", APPLICATION_ID, 102 | "flags", G_APPLICATION_NON_UNIQUE, 103 | nullptr)); 104 | } 105 | -------------------------------------------------------------------------------- /linux/subprocess/src/flutter_webview_process_messages.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 ACCESS CO., LTD. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of ACCESS CO., LTD. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef LINUX_SUBPROCESS_SRC_FLUTTER_WEBVIEW_PROCESS_MESSAGES_H_ 30 | #define LINUX_SUBPROCESS_SRC_FLUTTER_WEBVIEW_PROCESS_MESSAGES_H_ 31 | 32 | #include 33 | 34 | #include "include/cef_process_message.h" 35 | 36 | namespace flutter_webview_process_messages { 37 | 38 | const char kFrameMsg_RequestRunJavascript[] = "FrameMsg_RequestRunJavascript"; 39 | const char kFrameHostMsg_RunJavascriptResponse[] = 40 | "FrameHostMsg_RunJavascriptResponse"; 41 | 42 | // ----------------------------------------------------------------------------- 43 | // Messages sent from the brwoser to the renderer. 44 | 45 | // Request to execute the javascript in the renderer. The result of the 46 | // execution is returned with FrameHostMsg_RunJavascriptResponse. 47 | // 48 | // FrameMsg_RequestRunJavascript message format: 49 | // 0. js_run_id: int 50 | // The javascript execution ID, given by Dart side. 51 | // 1. javascript: string 52 | // The javascript string to be executed on the renderer process. 53 | CefRefPtr Create_FrameMsg_RequestRunJavascript( 54 | int js_run_id, 55 | std::string javascript); 56 | void Read_FrameMsg_RequestRunJavascript(CefRefPtr message, 57 | int* out_js_run_id, 58 | std::string* out_javascript); 59 | 60 | // ----------------------------------------------------------------------------- 61 | // Messages sent from the renderer to the browser. 62 | 63 | // Response to FrameMsg_RequestRunJavascript. 64 | // 65 | // FrameHostMsg_RunJavascriptResponse message format: 66 | // 0. js_run_id: int 67 | // The javascript execution ID. 68 | // 1. was_executed: bool 69 | // Whether the javascript was executed or not. 70 | // 2. is_exception: bool 71 | // Whether the result is an exception or not. 72 | // 3. js_result: string 73 | // The result of the javascript execution. 74 | // 4. is_undefined: bool 75 | // Whether the result is an undefined value. 76 | CefRefPtr Create_FrameHostMsg_RunJavascriptResponse( 77 | int js_run_id, 78 | bool was_executed, 79 | bool is_exception, 80 | std::string js_result, 81 | bool is_undefined); 82 | void Read_FrameHostMsg_RunJavascriptResponse( 83 | CefRefPtr message, 84 | int* out_js_run_id, 85 | bool* out_was_executed, 86 | bool* out_is_exception, 87 | std::string* out_result, 88 | bool* out_is_undefined); 89 | 90 | } // namespace flutter_webview_process_messages 91 | 92 | #endif // LINUX_SUBPROCESS_SRC_FLUTTER_WEBVIEW_PROCESS_MESSAGES_H_ 93 | -------------------------------------------------------------------------------- /linux/flutter_webview_texture_manager.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 ACCESS CO., LTD. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of ACCESS CO., LTD. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef LINUX_FLUTTER_WEBVIEW_TEXTURE_MANAGER_H_ 30 | #define LINUX_FLUTTER_WEBVIEW_TEXTURE_MANAGER_H_ 31 | 32 | #include 33 | #include 34 | 35 | #include 36 | #include 37 | 38 | #include "flutter_linux_webview/fl_custom_texture_gl.h" 39 | #include "flutter_linux_webview/flutter_webview_types.h" 40 | 41 | // A utility class regarding fl_texture_gl. Accessed only on the platform plugin 42 | // thread. 43 | class FlutterWebviewTextureManager { 44 | public: 45 | FlutterWebviewTextureManager(); 46 | 47 | /// 48 | /// For a given |webview_id|, creates a native texture, creates a 49 | /// FlCustomTextureGL from it, registers it with the engine, and stores it. 50 | /// 51 | /// @return (transfer none): Returns the newly created FlCustomTextureGL* on 52 | /// success, nullptr otherwise. 53 | /// 54 | FlCustomTextureGL* CreateAndRegisterTexture( 55 | WebviewId webview_id, 56 | GdkGLContext* context, 57 | FlTextureRegistrar* texture_registrar, 58 | int width, 59 | int height); 60 | 61 | /// 62 | /// Get a stored texture for a given |webview_id| 63 | /// 64 | /// @return (transfer none): Returns a FlCustomTextureGL*. Returns nullptr if 65 | /// a texture is not found. 66 | /// 67 | FlCustomTextureGL* GetTexture(WebviewId webview_id); 68 | 69 | /// 70 | /// Returns the ID of the given texture. This is the ID to pass to the Dart 71 | /// side. 72 | /// 73 | /// @return Returns the ID of |fl_texture|. 74 | /// 75 | int64_t GetTextureId(FlTexture* fl_texture); 76 | 77 | /// 78 | /// Unregister and delete a texture for a given |webview_id|. 79 | /// 80 | /// @return Returns if the native texture was successfully deleted. 81 | /// 82 | bool UnregisterAndDestroyTexture(WebviewId webview_id, 83 | FlTextureRegistrar* texture_registrar); 84 | 85 | /// Unregisters and deletes all registered textures. 86 | /// If |skip_unregister_texture| is true, it skips calling 87 | /// fl_texture_unregister_texture(). 88 | void UnregisterAndDestroyAllTextures(FlTextureRegistrar* texture_registrar, 89 | bool skip_unregister_texture); 90 | 91 | private: 92 | bool UnregisterAndDestroyTextureInternal( 93 | WebviewId webview_id, 94 | FlTextureRegistrar* texture_registrar, 95 | bool skip_unregister_texture); 96 | 97 | std::unordered_map texture_store_; 98 | }; 99 | 100 | #endif // LINUX_FLUTTER_WEBVIEW_TEXTURE_MANAGER_H_ 101 | -------------------------------------------------------------------------------- /third_party_base/webview_flutter_android/lib/webview_linux_cookie_manager.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 ACCESS CO., LTD. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of ACCESS CO., LTD. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | // This file is based on https://github.com/flutter/plugins/blob/webview_flutter-v3.0.4/packages/webview_flutter/webview_flutter_android/lib/webview_android_cookie_manager.dart 30 | 31 | // Copyright 2013 The Flutter Authors. All rights reserved. 32 | // 33 | // Redistribution and use in source and binary forms, with or without modification, 34 | // are permitted provided that the following conditions are met: 35 | // 36 | // * Redistributions of source code must retain the above copyright 37 | // notice, this list of conditions and the following disclaimer. 38 | // * Redistributions in binary form must reproduce the above 39 | // copyright notice, this list of conditions and the following 40 | // disclaimer in the documentation and/or other materials provided 41 | // with the distribution. 42 | // * Neither the name of Google Inc. nor the names of its 43 | // contributors may be used to endorse or promote products derived 44 | // from this software without specific prior written permission. 45 | // 46 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 47 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 48 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 49 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 50 | // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 51 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 52 | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 53 | // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 54 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 55 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 56 | 57 | import 'package:flutter_linux_webview/src/linux_webview_plugin.dart'; 58 | import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; 59 | 60 | /// Handles all cookie operations for the current platform. 61 | class WebViewLinuxCookieManager extends WebViewCookieManagerPlatform { 62 | @override 63 | Future clearCookies() async { 64 | bool? result = await (await LinuxWebViewPlugin.channel) 65 | .invokeMethod('clearCookies'); 66 | return result!; 67 | } 68 | 69 | @override 70 | Future setCookie(WebViewCookie cookie) async { 71 | if (!_isValidPath(cookie.path)) { 72 | throw ArgumentError( 73 | 'The path property for the provided cookie was not given a legal value.'); 74 | } 75 | await (await LinuxWebViewPlugin.channel) 76 | .invokeMethod('setCookie', { 77 | 'domain': cookie.domain, 78 | 'path': cookie.path, 79 | 'name': cookie.name, 80 | 'value': cookie.value, 81 | }); 82 | } 83 | 84 | static bool _isValidPath(String path) { 85 | // Permitted ranges based on RFC6265bis: https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.1 86 | for (final int char in path.codeUnits) { 87 | if ((char < 0x20 || char > 0x3A) && (char < 0x3C || char > 0x7E)) { 88 | return false; 89 | } 90 | } 91 | return true; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /third_party_base/cef/src/tests/cefclient/browser/flutter_webview_osr_renderer.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 ACCESS CO., LTD. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of ACCESS CO., LTD. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | // This file is based on 30 | // https://bitbucket.org/chromiumembedded/cef/src/4664/tests/cefclient/browser/osr_renderer.h 31 | // for off-screen rendering. 32 | 33 | // Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights 34 | // reserved. 35 | // 36 | // Redistribution and use in source and binary forms, with or without 37 | // modification, are permitted provided that the following conditions are 38 | // met: 39 | // 40 | // * Redistributions of source code must retain the above copyright 41 | // notice, this list of conditions and the following disclaimer. 42 | // * Redistributions in binary form must reproduce the above 43 | // copyright notice, this list of conditions and the following disclaimer 44 | // in the documentation and/or other materials provided with the 45 | // distribution. 46 | // * Neither the name of Google Inc. nor the name Chromium Embedded 47 | // Framework nor the names of its contributors may be used to endorse 48 | // or promote products derived from this software without specific prior 49 | // written permission. 50 | // 51 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 52 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 53 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 54 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 55 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 56 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 57 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 58 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 59 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 60 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 61 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 62 | 63 | #ifndef LINUX_FLUTTER_WEBVIEW_OSR_RENDERER_H_ 64 | #define LINUX_FLUTTER_WEBVIEW_OSR_RENDERER_H_ 65 | 66 | #include 67 | 68 | #include 69 | #include 70 | 71 | #include "flutter_linux_webview/flutter_webview_types.h" 72 | #include "include/cef_browser.h" 73 | #include "include/cef_render_handler.h" 74 | 75 | class FlutterWebviewOsrRenderer { 76 | public: 77 | explicit FlutterWebviewOsrRenderer(GLuint native_texture_id); 78 | 79 | // Forwarded from CefRenderHandler callbacks. 80 | void OnPopupShow(CefRefPtr browser, bool show); 81 | // |rect| must be in pixel coordinates. 82 | void OnPopupSize(CefRefPtr browser, const CefRect& rect); 83 | void OnPaint(CefRefPtr browser, 84 | CefRenderHandler::PaintElementType type, 85 | const CefRenderHandler::RectList& dirtyRects, 86 | const void* buffer, 87 | int width, 88 | int height); 89 | 90 | int GetViewWidth() const { return view_width_; } 91 | int GetViewHeight() const { return view_height_; } 92 | 93 | CefRect popup_rect() const { return popup_rect_; } 94 | 95 | void ClearPopupRects(); 96 | 97 | private: 98 | CefRect GetPopupRectInWebView(const CefRect& original_rect); 99 | 100 | GLuint native_texture_id_; 101 | int view_width_; 102 | int view_height_; 103 | CefRect popup_rect_; 104 | CefRect original_popup_rect_; 105 | 106 | DISALLOW_COPY_AND_ASSIGN(FlutterWebviewOsrRenderer); 107 | }; 108 | 109 | #endif // LINUX_FLUTTER_WEBVIEW_OSR_RENDERER_H_ 110 | -------------------------------------------------------------------------------- /linux/subprocess/src/flutter_webview_render_app.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 ACCESS CO., LTD. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of ACCESS CO., LTD. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #include "flutter_webview_render_app.h" 30 | 31 | #include 32 | 33 | #include "flutter_webview_process_messages.h" 34 | #include "include/base/cef_logging.h" 35 | #include "include/cef_browser.h" 36 | #include "include/wrapper/cef_helpers.h" 37 | 38 | namespace { 39 | 40 | CefRefPtr JSONStringify(CefRefPtr context, 41 | CefRefPtr in_value) { 42 | auto global = context->GetGlobal(); 43 | auto json = global->GetValue("JSON"); 44 | if (!json) { 45 | return nullptr; 46 | } 47 | auto stringify = json->GetValue("stringify"); 48 | if (!stringify) { 49 | return nullptr; 50 | } 51 | CefV8ValueList args; 52 | args.push_back(in_value); 53 | return stringify->ExecuteFunction(json, args); 54 | } 55 | 56 | } // namespace 57 | 58 | FlutterWebviewRenderApp::FlutterWebviewRenderApp() {} 59 | 60 | void FlutterWebviewRenderApp::OnContextCreated( 61 | CefRefPtr browser, 62 | CefRefPtr frame, 63 | CefRefPtr context) { 64 | VLOG(1) << "CefRenderProcessHandler::OnContextCreated called"; 65 | } 66 | 67 | bool FlutterWebviewRenderApp::OnProcessMessageReceived( 68 | CefRefPtr browser, 69 | CefRefPtr frame, 70 | CefProcessId source_process, 71 | CefRefPtr message) { 72 | const std::string& message_name = message->GetName(); 73 | 74 | if (message_name == 75 | flutter_webview_process_messages::kFrameMsg_RequestRunJavascript) { 76 | int js_run_id; 77 | std::string javascript; 78 | flutter_webview_process_messages::Read_FrameMsg_RequestRunJavascript( 79 | message, &js_run_id, &javascript); 80 | 81 | VLOG(1) << "The renderer process received the JS to execute: js_run_id=" 82 | << js_run_id << ", javascript=" << javascript; 83 | 84 | bool was_executed = false; 85 | bool is_exception = false; 86 | std::string result = ""; 87 | bool is_undefined = false; 88 | 89 | // run v8 90 | CefRefPtr context = frame->GetV8Context(); 91 | if (context.get() && context->Enter()) { 92 | CefRefPtr exception; 93 | CefRefPtr retval; 94 | 95 | was_executed = true; 96 | 97 | if (!context->Eval(javascript, frame->GetURL(), 1, retval, exception)) { 98 | // exception 99 | is_exception = true; 100 | result = exception->GetMessage(); 101 | } else { 102 | CefRefPtr v8result = JSONStringify(context, retval); 103 | if (!v8result) { 104 | is_exception = true; 105 | result = "JSON.stringify() failed"; 106 | } else { 107 | if (v8result->IsUndefined()) { 108 | VLOG(1) << "V8result: (undefined)"; 109 | is_exception = false; 110 | result = "undefined"; 111 | is_undefined = true; 112 | } else if (v8result->IsString()) { 113 | VLOG(1) << "V8result: " << v8result->GetStringValue(); 114 | is_exception = false; 115 | result = v8result->GetStringValue(); 116 | is_undefined = false; 117 | } 118 | } 119 | } 120 | context->Exit(); 121 | } 122 | 123 | CefRefPtr response = flutter_webview_process_messages:: 124 | Create_FrameHostMsg_RunJavascriptResponse( 125 | js_run_id, was_executed, is_exception, result, is_undefined); 126 | frame->SendProcessMessage(PID_BROWSER, response); 127 | return true; 128 | } 129 | 130 | return false; 131 | } 132 | -------------------------------------------------------------------------------- /third_party_base/cef/src/include/internal/cef_types.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 ACCESS CO., LTD. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of ACCESS CO., LTD. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | // This file is based on https://bitbucket.org/chromiumembedded/cef/src/4664/include/internal/cef_types.h 30 | // and translates some of the CEF types defined in it into Dart. 31 | 32 | // Copyright (c) 2014 Marshall A. Greenblatt. All rights reserved. 33 | // 34 | // Redistribution and use in source and binary forms, with or without 35 | // modification, are permitted provided that the following conditions are 36 | // met: 37 | // 38 | // * Redistributions of source code must retain the above copyright 39 | // notice, this list of conditions and the following disclaimer. 40 | // * Redistributions in binary form must reproduce the above 41 | // copyright notice, this list of conditions and the following disclaimer 42 | // in the documentation and/or other materials provided with the 43 | // distribution. 44 | // * Neither the name of Google Inc. nor the name Chromium Embedded 45 | // Framework nor the names of its contributors may be used to endorse 46 | // or promote products derived from this software without specific prior 47 | // written permission. 48 | // 49 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 50 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 51 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 52 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 53 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 54 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 55 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 56 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 57 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 58 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 59 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 | 61 | // Translation of cef_mouse_button_type_t 62 | /// 63 | /// Mouse button types. 64 | /// 65 | enum CefMouseButtonType { 66 | MBT_LEFT(0), 67 | MBT_MIDDLE(1), 68 | MBT_RIGHT(2); 69 | 70 | final int value; 71 | const CefMouseButtonType(this.value); 72 | } 73 | 74 | // Translation of cef_event_flags_t 75 | /// 76 | /// Supported event bit flags. 77 | /// 78 | enum CefEventFlags { 79 | EVENTFLAG_NONE(0), 80 | EVENTFLAG_CAPS_LOCK_ON(1 << 0), 81 | EVENTFLAG_SHIFT_DOWN(1 << 1), 82 | EVENTFLAG_CONTROL_DOWN(1 << 2), 83 | EVENTFLAG_ALT_DOWN(1 << 3), 84 | EVENTFLAG_LEFT_MOUSE_BUTTON(1 << 4), 85 | EVENTFLAG_MIDDLE_MOUSE_BUTTON(1 << 5), 86 | EVENTFLAG_RIGHT_MOUSE_BUTTON(1 << 6), 87 | // Mac OS-X command key. 88 | EVENTFLAG_COMMAND_DOWN(1 << 7), 89 | EVENTFLAG_NUM_LOCK_ON(1 << 8), 90 | EVENTFLAG_IS_KEY_PAD(1 << 9), 91 | EVENTFLAG_IS_LEFT(1 << 10), 92 | EVENTFLAG_IS_RIGHT(1 << 11), 93 | EVENTFLAG_ALTER_DOWN(1 << 12), 94 | EVENTFLAG_IS_REPEAT(1 << 13); 95 | 96 | final int value; 97 | const CefEventFlags(this.value); 98 | } 99 | 100 | // Translation of cef_key_event_type_t 101 | /// 102 | /// Key event types. 103 | /// 104 | enum CefKeyEventType { 105 | /// 106 | /// Notification that a key transitioned from "up" to "down". 107 | /// 108 | KEYEVENT_RAWKEYDOWN(0), 109 | 110 | /// 111 | /// Notification that a key was pressed. This does not necessarily correspond 112 | /// to a character depending on the key and language. Use KEYEVENT_CHAR for 113 | /// character input. 114 | /// 115 | KEYEVENT_KEYDOWN(1), 116 | 117 | /// 118 | /// Notification that a key was released. 119 | /// 120 | KEYEVENT_KEYUP(2), 121 | 122 | /// 123 | /// Notification that a character was typed. Use this for text input. Key 124 | /// down events may generate 0, 1, or more than one character event depending 125 | /// on the key, locale, and operating system. 126 | /// 127 | KEYEVENT_CHAR(3); 128 | 129 | final int value; 130 | const CefKeyEventType(this.value); 131 | } 132 | -------------------------------------------------------------------------------- /example/lib/simple_example.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 ACCESS CO., LTD. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of ACCESS CO., LTD. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | import 'dart:async'; 30 | // Required to use AppExitResponse for Fluter 3.10 or later 31 | import 'dart:ui'; 32 | import 'package:flutter/material.dart'; 33 | import 'package:webview_flutter/webview_flutter.dart'; 34 | import 'package:flutter_linux_webview/flutter_linux_webview.dart'; 35 | 36 | void main() { 37 | // ensureInitialized() is required if the plugin is initialized before runApp() 38 | WidgetsFlutterBinding.ensureInitialized(); 39 | 40 | // Run `LinuxWebViewPlugin.initialize()` first before creating a WebView. 41 | LinuxWebViewPlugin.initialize(options: { 42 | 'user-agent': 'UA String', 43 | 'remote-debugging-port': '8888', 44 | 'autoplay-policy': 'no-user-gesture-required', 45 | }); 46 | 47 | // Configure [WebView] to use the [LinuxWebView]. 48 | WebView.platform = LinuxWebView(); 49 | 50 | runApp(const MaterialApp(home: _WebViewExample())); 51 | } 52 | 53 | class _WebViewExample extends StatefulWidget { 54 | const _WebViewExample({Key? key}) : super(key: key); 55 | 56 | @override 57 | _WebViewExampleState createState() => _WebViewExampleState(); 58 | } 59 | 60 | class _WebViewExampleState extends State<_WebViewExample> 61 | with WidgetsBindingObserver { 62 | final Completer _controller = 63 | Completer(); 64 | 65 | /// Prior to Flutter 3.10, comment out the following code since 66 | /// [WidgetsBindingObserver.didRequestAppExit] does not exist. 67 | // ===== begin: For Flutter 3.10 or later ===== 68 | @override 69 | void initState() { 70 | super.initState(); 71 | WidgetsBinding.instance.addObserver(this); 72 | } 73 | 74 | @override 75 | void dispose() { 76 | WidgetsBinding.instance.removeObserver(this); 77 | super.dispose(); 78 | } 79 | 80 | @override 81 | Future didRequestAppExit() async { 82 | await LinuxWebViewPlugin.terminate(); 83 | return AppExitResponse.exit; 84 | } 85 | // ===== end: For Flutter 3.10 or later ===== 86 | 87 | @override 88 | Widget build(BuildContext context) { 89 | return Scaffold( 90 | appBar: AppBar( 91 | title: const Text('flutter_linux_webview example'), 92 | ), 93 | body: WebView( 94 | initialUrl: 'https://flutter.dev', 95 | initialCookies: const [ 96 | WebViewCookie(name: 'mycookie', value: 'foo', domain: 'flutter.dev') 97 | ], 98 | onWebViewCreated: (WebViewController webViewController) { 99 | _controller.complete(webViewController); 100 | }, 101 | javascriptMode: JavascriptMode.unrestricted, 102 | ), 103 | floatingActionButton: favoriteButton(), 104 | ); 105 | } 106 | 107 | Widget favoriteButton() { 108 | return FutureBuilder( 109 | future: _controller.future, 110 | builder: (BuildContext context, 111 | AsyncSnapshot controller) { 112 | if (controller.hasData) { 113 | return FloatingActionButton( 114 | onPressed: () async { 115 | final String useragent = (await controller.data! 116 | .runJavascriptReturningResult('navigator.userAgent')); 117 | final String title = (await controller.data!.getTitle())!; 118 | final String url = (await controller.data!.currentUrl())!; 119 | final String cookies = await (controller.data! 120 | .runJavascriptReturningResult('document.cookie')); 121 | ScaffoldMessenger.of(context).showSnackBar( 122 | SnackBar( 123 | content: Text( 124 | 'userAgent: $useragent, title: $title, url: $url, cookie: $cookies'), 125 | ), 126 | ); 127 | }, 128 | child: const Icon(Icons.favorite), 129 | ); 130 | } 131 | return Container(); 132 | }); 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /example/linux/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Project-level configuration. 2 | cmake_minimum_required(VERSION 3.10) 3 | project(runner LANGUAGES CXX) 4 | 5 | # The name of the executable created for the application. Change this to change 6 | # the on-disk name of your application. 7 | set(BINARY_NAME "flutter_linux_webview_example") 8 | # The unique GTK application identifier for this application. See: 9 | # https://wiki.gnome.org/HowDoI/ChooseApplicationID 10 | set(APPLICATION_ID "com.accesscompany.flutter_linux_webview.flutter_linux_webview") 11 | 12 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent 13 | # versions of CMake. 14 | cmake_policy(SET CMP0063 NEW) 15 | 16 | # Load bundled libraries from the lib/ directory relative to the binary. 17 | set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") 18 | 19 | # Root filesystem for cross-building. 20 | if(FLUTTER_TARGET_PLATFORM_SYSROOT) 21 | set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) 22 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) 23 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 24 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 25 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 26 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 27 | endif() 28 | 29 | # Define build configuration options. 30 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 31 | set(CMAKE_BUILD_TYPE "Debug" CACHE 32 | STRING "Flutter build mode" FORCE) 33 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS 34 | "Debug" "Profile" "Release") 35 | endif() 36 | 37 | # Compilation settings that should be applied to most targets. 38 | # 39 | # Be cautious about adding new options here, as plugins use this function by 40 | # default. In most cases, you should add new options to specific targets instead 41 | # of modifying this function. 42 | function(APPLY_STANDARD_SETTINGS TARGET) 43 | target_compile_features(${TARGET} PUBLIC cxx_std_14) 44 | target_compile_options(${TARGET} PRIVATE -Wall -Werror) 45 | target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") 46 | target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") 47 | endfunction() 48 | 49 | # Flutter library and tool build rules. 50 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") 51 | add_subdirectory(${FLUTTER_MANAGED_DIR}) 52 | 53 | # System-level dependencies. 54 | find_package(PkgConfig REQUIRED) 55 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) 56 | 57 | add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") 58 | 59 | # Define the application target. To change its name, change BINARY_NAME above, 60 | # not the value here, or `flutter run` will no longer work. 61 | # 62 | # Any new source files that you add to the application should be added here. 63 | add_executable(${BINARY_NAME} 64 | "main.cc" 65 | "my_application.cc" 66 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 67 | ) 68 | 69 | # Apply the standard set of build settings. This can be removed for applications 70 | # that need different build settings. 71 | apply_standard_settings(${BINARY_NAME}) 72 | 73 | # Add dependency libraries. Add any application-specific dependencies here. 74 | target_link_libraries(${BINARY_NAME} PRIVATE flutter) 75 | target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) 76 | 77 | # Run the Flutter tool portions of the build. This must not be removed. 78 | add_dependencies(${BINARY_NAME} flutter_assemble) 79 | 80 | # Only the install-generated bundle's copy of the executable will launch 81 | # correctly, since the resources must in the right relative locations. To avoid 82 | # people trying to run the unbundled copy, put it in a subdirectory instead of 83 | # the default top-level location. 84 | set_target_properties(${BINARY_NAME} 85 | PROPERTIES 86 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" 87 | ) 88 | 89 | # Required to run the flutter_linux_webview plugin. See the plugin docs. 90 | include( 91 | flutter/ephemeral/.plugin_symlinks/flutter_linux_webview/linux/cmake/link_to_cef_library.cmake) 92 | 93 | # Generated plugin build rules, which manage building the plugins and adding 94 | # them to the application. 95 | include(flutter/generated_plugins.cmake) 96 | 97 | 98 | # === Installation === 99 | # By default, "installing" just makes a relocatable bundle in the build 100 | # directory. 101 | set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") 102 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) 103 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) 104 | endif() 105 | 106 | # Start with a clean build bundle directory every time. 107 | install(CODE " 108 | file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") 109 | " COMPONENT Runtime) 110 | 111 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") 112 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") 113 | 114 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" 115 | COMPONENT Runtime) 116 | 117 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" 118 | COMPONENT Runtime) 119 | 120 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 121 | COMPONENT Runtime) 122 | 123 | foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) 124 | install(FILES "${bundled_library}" 125 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 126 | COMPONENT Runtime) 127 | endforeach(bundled_library) 128 | 129 | # Fully re-copy the assets directory on each build to avoid having stale files 130 | # from a previous install. 131 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets") 132 | install(CODE " 133 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") 134 | " COMPONENT Runtime) 135 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" 136 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) 137 | 138 | # Install the AOT library on non-Debug builds only. 139 | if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") 140 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" 141 | COMPONENT Runtime) 142 | endif() 143 | -------------------------------------------------------------------------------- /example/lib/multiple_webviews_example.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 ACCESS CO., LTD. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of ACCESS CO., LTD. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | import 'package:flutter/material.dart'; 30 | import 'dart:async'; 31 | import 'dart:io' show Platform; 32 | // Required to use AppExitResponse for Fluter 3.10 or later 33 | import 'dart:ui'; 34 | 35 | import 'package:flutter_linux_webview/flutter_linux_webview.dart'; 36 | import 'package:webview_flutter/webview_flutter.dart'; 37 | 38 | Future main() async { 39 | WebView.platform = LinuxWebView(); 40 | WidgetsFlutterBinding.ensureInitialized(); 41 | await LinuxWebViewPlugin.initialize(); 42 | runApp(const MyApp()); 43 | } 44 | 45 | class MyApp extends StatefulWidget { 46 | const MyApp({Key? key}) : super(key: key); 47 | 48 | @override 49 | State createState() => _MyAppState(); 50 | } 51 | 52 | class _MyAppState extends State with WidgetsBindingObserver { 53 | int _webviewWidth = 700; 54 | int _webviewHeight = 300; 55 | 56 | final webviewsModel = []; 57 | final savedControllers = []; 58 | 59 | @override 60 | void initState() { 61 | super.initState(); 62 | Map envVars = Platform.environment; 63 | List? size = envVars['WEBVIEW_SIZE']?.split("x"); 64 | if (size != null && size.length == 2) { 65 | _webviewWidth = int.parse(size[0]); 66 | _webviewHeight = int.parse(size[1]); 67 | } 68 | WidgetsBinding.instance.addObserver(this); 69 | initPlatformState(); 70 | } 71 | 72 | /// Prior to Flutter 3.10, comment it out since 73 | /// [WidgetsBindingObserver.didRequestAppExit] does not exist. 74 | @override 75 | Future didRequestAppExit() async { 76 | await LinuxWebViewPlugin.terminate(); 77 | return AppExitResponse.exit; 78 | } 79 | 80 | // Platform messages are asynchronous, so we initialize in an async method. 81 | Future initPlatformState() async { 82 | // If the widget was removed from the tree while the asynchronous platform 83 | // message was in flight, we want to discard the reply rather than calling 84 | // setState to update our non-existent appearance. 85 | if (!mounted) return; 86 | 87 | setState(() {}); 88 | } 89 | 90 | @override 91 | Widget build(BuildContext context) { 92 | Widget wrapWebviewWithCard(WebView webview) { 93 | return Card( 94 | child: Column( 95 | mainAxisSize: MainAxisSize.min, 96 | children: [ 97 | ListTile( 98 | title: Text('WEBVIEW_SIZE: ${_webviewWidth}x${_webviewHeight}'), 99 | ), 100 | SizedBox( 101 | width: _webviewWidth.toDouble(), 102 | height: _webviewHeight.toDouble(), 103 | child: webview) 104 | ], 105 | ), 106 | ); 107 | } 108 | 109 | return MaterialApp( 110 | home: Scaffold( 111 | backgroundColor: Color.fromARGB(255, 220, 220, 220), 112 | appBar: AppBar( 113 | title: const Text('Plugin example app'), 114 | ), 115 | body: Center( 116 | child: Container( 117 | width: _webviewWidth + 200, 118 | child: ListView( 119 | children: [ 120 | ButtonBar(children: [ 121 | TextButton( 122 | child: const Text('Add a new WebView'), 123 | onPressed: () { 124 | setState(() { 125 | webviewsModel.add(WebView( 126 | initialUrl: 'https://www.google.com', 127 | onWebViewCreated: (WebViewController controller) { 128 | savedControllers.add(controller); 129 | })); 130 | }); 131 | }, 132 | ), 133 | TextButton( 134 | child: const Text('Remove a WebView'), 135 | onPressed: () { 136 | setState(() { 137 | webviewsModel.removeAt(0); 138 | }); 139 | }, 140 | ), 141 | ]), 142 | for (int i = 0; i < webviewsModel.length; i++) 143 | wrapWebviewWithCard(webviewsModel[i]) 144 | ], 145 | ), 146 | ), 147 | )), 148 | ); 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /third_party_base/cef/src/tests/cefsimple/CMakeLists_subprocess_project.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2023 ACCESS CO., LTD. All rights reserved. 2 | # 3 | # Redistribution and use in source and binary forms, with or without 4 | # modification, are permitted provided that the following conditions are 5 | # met: 6 | # 7 | # * Redistributions of source code must retain the above copyright 8 | # notice, this list of conditions and the following disclaimer. 9 | # * Redistributions in binary form must reproduce the above 10 | # copyright notice, this list of conditions and the following disclaimer 11 | # in the documentation and/or other materials provided with the 12 | # distribution. 13 | # * Neither the name of ACCESS CO., LTD. nor the names of its 14 | # contributors may be used to endorse or promote products derived from 15 | # this software without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | # This file is based on https://bitbucket.org/chromiumembedded/cef/src/4664/tests/cefsimple/CMakeLists.txt.in 30 | 31 | # Copyright (c) 2014 The Chromium Embedded Framework Authors. All rights 32 | # reserved. 33 | # 34 | # Redistribution and use in source and binary forms, with or without 35 | # modification, are permitted provided that the following conditions are 36 | # met: 37 | # 38 | # * Redistributions of source code must retain the above copyright 39 | # notice, this list of conditions and the following disclaimer. 40 | # * Redistributions in binary form must reproduce the above 41 | # copyright notice, this list of conditions and the following disclaimer 42 | # in the documentation and/or other materials provided with the 43 | # distribution. 44 | # * Neither the name of Google Inc. nor the name Chromium Embedded 45 | # Framework nor the names of its contributors may be used to endorse 46 | # or promote products derived from this software without specific prior 47 | # written permission. 48 | # 49 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 50 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 51 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 52 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 53 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 54 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 55 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 56 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 57 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 58 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 59 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 | 61 | # 62 | # Source files. 63 | # 64 | 65 | # cefsimple sources. 66 | set(CEFSIMPLE_SRCS 67 | flutter_webview_render_app.cc 68 | flutter_webview_render_app.h 69 | flutter_webview_process_messages.cc 70 | flutter_webview_process_messages.h 71 | ) 72 | set(CEFSIMPLE_SRCS_LINUX 73 | flutter_webview_subprocess.cc 74 | ) 75 | APPEND_PLATFORM_SOURCES(CEFSIMPLE_SRCS) 76 | source_group(cefsimple FILES ${CEFSIMPLE_SRCS}) 77 | 78 | set(CEFSIMPLE_SRCS 79 | ${CEFSIMPLE_SRCS} 80 | ) 81 | 82 | 83 | # 84 | # Shared configuration. 85 | # 86 | 87 | # Target executable names. 88 | set(CEF_TARGET "${WEBVIEW_SUBPROCESS_PROJECT_NAME}") 89 | # Logical target used to link the libcef library. 90 | ADD_LOGICAL_TARGET("libcef_lib" "${CEF_LIB_DEBUG}" "${CEF_LIB_RELEASE}") 91 | 92 | # Determine the target output directory. 93 | SET_CEF_TARGET_OUT_DIR() 94 | 95 | 96 | # 97 | # Linux configuration. 98 | # 99 | 100 | if(OS_LINUX) 101 | # Executable target. 102 | add_executable(${CEF_TARGET} ${CEFSIMPLE_SRCS}) 103 | SET_EXECUTABLE_TARGET_PROPERTIES(${CEF_TARGET}) 104 | add_dependencies(${CEF_TARGET} libcef_dll_wrapper) 105 | 106 | if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") 107 | if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15) 108 | target_compile_options(libcef_dll_wrapper PUBLIC "-Wno-deprecated-builtins") 109 | endif() 110 | endif() 111 | if("${WEBVIEW_DEBUG}") 112 | target_link_libraries(${CEF_TARGET} libcef_lib libcef_dll_wrapper ${CEF_STANDARD_LIBS}) 113 | else() 114 | target_link_libraries(${CEF_TARGET} ${CEF_LIB_RELEASE} libcef_dll_wrapper ${CEF_STANDARD_LIBS}) 115 | endif() 116 | 117 | # Set rpath so that libraries can be placed next to the executable. 118 | set_target_properties(${CEF_TARGET} PROPERTIES INSTALL_RPATH "$ORIGIN") 119 | set_target_properties(${CEF_TARGET} PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE) 120 | set_target_properties(${CEF_TARGET} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CEF_TARGET_OUT_DIR}) 121 | 122 | # # Copy binary and resource files to the target output directory. 123 | # COPY_FILES("${CEF_TARGET}" "${CEF_BINARY_FILES}" "${CEF_BINARY_DIR}" "${CEF_TARGET_OUT_DIR}") 124 | # COPY_FILES("${CEF_TARGET}" "${CEF_RESOURCE_FILES}" "${CEF_RESOURCE_DIR}" "${CEF_TARGET_OUT_DIR}") 125 | # if (EXISTS "${CEF_BINARY_DIR}/libminigbm.so") 126 | # COPY_FILES("${CEF_TARGET}" "libminigbm.so" "${CEF_BINARY_DIR}" "${CEF_TARGET_OUT_DIR}") 127 | # endif() 128 | 129 | # Set SUID permissions on the chrome-sandbox target. 130 | SET_LINUX_SUID_PERMISSIONS("${CEF_TARGET}" "${CEF_TARGET_OUT_DIR}/chrome-sandbox") 131 | endif() 132 | -------------------------------------------------------------------------------- /lib/src/linux_webview_plugin.dart: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 ACCESS CO., LTD. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of ACCESS CO., LTD. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | import 'dart:async'; 30 | import 'dart:io'; 31 | import 'logging.dart'; 32 | import 'package:flutter/services.dart'; 33 | 34 | import 'package:path/path.dart' as path; 35 | 36 | import 'webview_linux_widget.dart'; 37 | 38 | enum _PluginState { 39 | uninitialized, 40 | initializing, 41 | initialized, 42 | } 43 | 44 | class LinuxWebViewPlugin { 45 | /// The private MethodChannel. To be exported with [channel]. 46 | /// Users should not create and use their own 47 | /// MethodChannel('flutter_linux_webview') object. 48 | static const MethodChannel _channel = MethodChannel('flutter_linux_webview'); 49 | 50 | /// The plugin state used for exporting the MethodChannel. 51 | static _PluginState _pluginState = _PluginState.uninitialized; 52 | 53 | /// The completer for the exported method channels that wait for [initialize]. 54 | static final Completer _pluginInitDone = Completer(); 55 | 56 | /// An internal property that users should not use. The exported MethodChannel 57 | /// that is resolved when the plugin is initialized. 58 | static Future get channel async { 59 | switch (_pluginState) { 60 | case _PluginState.uninitialized: 61 | throw StateError('LinuxWebViewPlugin has not been initialized.' 62 | ' Call LinuxWebViewPlugin.initialize() first to' 63 | ' initialize the plugin if you have not already done so.'); 64 | case _PluginState.initializing: 65 | log.info( 66 | 'LinuxWebViewPlugin.channel is pending completion of plugin initialization...'); 67 | await _pluginInitDone.future; 68 | return _channel; 69 | case _PluginState.initialized: 70 | return _channel; 71 | } 72 | } 73 | 74 | /// Initializes the plugin. This method must be called before the first 75 | /// WebView creation. 76 | /// 77 | /// [options] are additional options used to initialize the underlying browser 78 | /// (CEF; Chromium Embedded Framework). The CEF command line arguments can be 79 | /// specified. Specify arguments in the following format: 80 | /// 81 | /// ```dart 82 | /// { 83 | /// 'user-agent': 'UA String', 84 | /// 'remote-debugging-port': '8888', 85 | /// 'autoplay-policy': 'no-user-gesture-required', 86 | /// } 87 | /// ``` 88 | /// 89 | /// Note that `--` and `=` are not needed, although the usual CEF command line 90 | /// arguments are of the form `--switch=value`. 91 | /// 92 | /// The following fundamental options are specified by default: 93 | /// - `browser-subprocess-path`: `` 94 | /// - `disable-javascript-close-windows` 95 | /// - `ozone-platform`: `wayland` (if XDG_SESSION_TYPE is wayland) 96 | /// 97 | /// If [options] overlap with the default options, the specified [options] 98 | /// override the default options. 99 | /// 100 | /// You do not necessarily need to wait for this method to complete. [channel] 101 | /// is resolved when this initialization is completed. 102 | static Future initialize({Map? options}) async { 103 | _channel.setMethodCallHandler(WebViewLinuxPlatformController.onMethodCall); 104 | setupLogger(); 105 | _pluginState = _PluginState.initializing; 106 | 107 | final Map defaultSwitches = { 108 | if (Platform.environment['XDG_SESSION_TYPE'] == 'wayland') 109 | 'ozone-platform': 'wayland' 110 | }; 111 | 112 | final Map essentialSwitches = { 113 | 'browser-subprocess-path': 114 | '${path.dirname(Platform.resolvedExecutable)}/lib/flutter_webview_subprocess', 115 | // Necessary to prevent browsers from closing with window.close(): 116 | 'disable-javascript-close-windows': null, 117 | }; 118 | 119 | final Map switches = {} 120 | ..addAll(defaultSwitches) 121 | ..addAll(essentialSwitches) 122 | ..addAll(options ?? {}); 123 | 124 | final List commandLineArgs = [ 125 | // The Map in Dart iterates in key insertion order. 126 | for (MapEntry entry in switches.entries) 127 | entry.value != null ? '--${entry.key}=${entry.value}' : '--${entry.key}' 128 | ]; 129 | 130 | log.fine('Initialize the plugin with args: $commandLineArgs'); 131 | 132 | await _channel.invokeMethod('startCef', { 133 | 'commandLineArgs': commandLineArgs, 134 | }); 135 | _pluginState = _PluginState.initialized; 136 | _pluginInitDone.complete(); 137 | log.fine('LinuxWebViewPlugin initialization done.'); 138 | } 139 | 140 | /// Terminates the plugin. **In Flutter 3.10 or later, this method must be 141 | /// called before the application exits. Prior to Flutter 3.10, this method 142 | /// does not need to be called.** because the plugin automatically exits. 143 | /// 144 | /// Since [WidgetsBindingObserver.didRequestAppExit] was added in Flutter 145 | /// 3.10, that could be used as a timing for plugin termination. 146 | static Future terminate() async { 147 | await _channel.invokeMethod('shutdownCef'); 148 | _pluginState = _PluginState.uninitialized; 149 | log.fine('LinuxWebviewPlugin has been terminated.'); 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /linux/flutter_webview_texture_manager.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 ACCESS CO., LTD. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of ACCESS CO., LTD. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #include "flutter_webview_texture_manager.h" 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | #include "flutter_linux_webview/fl_custom_texture_gl.h" 39 | #include "flutter_linux_webview/flutter_linux_webview_plugin.h" 40 | 41 | FlutterWebviewTextureManager::FlutterWebviewTextureManager() {} 42 | 43 | FlCustomTextureGL* FlutterWebviewTextureManager::CreateAndRegisterTexture( 44 | WebviewId webview_id, 45 | GdkGLContext* context, 46 | FlTextureRegistrar* texture_registrar, 47 | int width, 48 | int height) { 49 | auto it_inserted = texture_store_.emplace(webview_id, nullptr); 50 | if (!it_inserted.second) { 51 | std::cerr << "Error: a texture for webview_id=" << webview_id 52 | << " is already stored." << std::endl; 53 | return nullptr; 54 | } 55 | 56 | gdk_gl_context_make_current(context); 57 | 58 | // Create a native texture 59 | GLuint native_texture_id; 60 | glGenTextures(1, &native_texture_id); 61 | 62 | // Create a custom fl texture 63 | g_autoptr(FlCustomTextureGL) flCustomTextureGL = 64 | fl_custom_texture_gl_new(GL_TEXTURE_2D, native_texture_id, width, height); 65 | 66 | // Store the created texture 67 | it_inserted.first->second = 68 | FL_CUSTOM_TEXTURE_GL(g_object_ref(flCustomTextureGL)); 69 | 70 | if (!fl_texture_registrar_register_texture(texture_registrar, 71 | FL_TEXTURE(flCustomTextureGL))) { 72 | std::cerr << "Error: fl_texture_registrar_register_texture() failed." 73 | << std::endl; 74 | glDeleteTextures(1, &native_texture_id); 75 | g_object_unref(it_inserted.first->second); 76 | texture_store_.erase(it_inserted.first); 77 | return nullptr; 78 | } 79 | 80 | return flCustomTextureGL; 81 | } 82 | 83 | FlCustomTextureGL* FlutterWebviewTextureManager::GetTexture( 84 | WebviewId webview_id) { 85 | auto it = texture_store_.find(webview_id); 86 | if (it == texture_store_.end()) { 87 | // texture not found for webview_id 88 | return nullptr; 89 | } 90 | return it->second; 91 | } 92 | 93 | int64_t FlutterWebviewTextureManager::GetTextureId(FlTexture* fl_texture) { 94 | static_assert(sizeof(int64_t) >= sizeof(intptr_t), 95 | "Must be sizeof(int64_t) >= sizeof(intptr_t)"); 96 | 97 | // As of Flutter Engine 3.0.4, since the Flutter Linux Embedder does not 98 | // provide an API to create a texture ID to pass to the Dart side, we have to 99 | // create it manually. Since the texture ID accepted by the Flutter Linux 100 | // Embedder is the memory address of the texture, we generate the ID that way. 101 | // See https://github.com/flutter/engine/pull/24916#discussion_r707007673 and 102 | // https://github.com/flutter/engine/blob/6ba2af10bb05c88a2731482cedf2cfd11cf5af0b/shell/platform/linux/fl_texture.cc#L20 103 | // (engine v3.0.4) 104 | // 105 | // TODO(Ino): In the near future, after Flutter 3.10.0, the texture ID to be 106 | // passed to the Dart side will be changed to the return value of the 107 | // fl_texture_get_id() instead of the texture's memory address. At that time, 108 | // this GetTextureId() will no longer be necessary and fl_texture_get_id() 109 | // should be used instead, see https://github.com/flutter/engine/pull/40899. 110 | // See also https://github.com/flutter/engine/pull/40290 and 111 | // https://github.com/flutter/flutter/issues/124009. 112 | return reinterpret_cast(fl_texture); 113 | } 114 | 115 | bool FlutterWebviewTextureManager::UnregisterAndDestroyTexture( 116 | WebviewId webview_id, 117 | FlTextureRegistrar* texture_registrar) { 118 | return UnregisterAndDestroyTextureInternal(webview_id, texture_registrar, 119 | false); 120 | } 121 | 122 | bool FlutterWebviewTextureManager::UnregisterAndDestroyTextureInternal( 123 | WebviewId webview_id, 124 | FlTextureRegistrar* texture_registrar, 125 | bool skip_unregister_texture) { 126 | auto it = texture_store_.find(webview_id); 127 | if (it == texture_store_.end()) { 128 | // Texture not found 129 | std::cerr << "Error: The FlCustomTextureGL texture for webview_id=" 130 | << webview_id << " is not found." << std::endl; 131 | return false; 132 | } 133 | 134 | FlCustomTextureGL* texture = it->second; 135 | 136 | if (!skip_unregister_texture) { 137 | if (!fl_texture_registrar_unregister_texture(texture_registrar, 138 | FL_TEXTURE(texture))) { 139 | std::cerr << "Warning: fl_texture_registrar_unregister_texture() failed" 140 | << std::endl; 141 | } 142 | } 143 | 144 | GLuint native_texture_id[1] = {texture->native_texture_id}; 145 | glDeleteTextures(1, native_texture_id); 146 | g_object_unref(texture); 147 | texture_store_.erase(it); 148 | 149 | return true; 150 | } 151 | 152 | void FlutterWebviewTextureManager::UnregisterAndDestroyAllTextures( 153 | FlTextureRegistrar* texture_registrar, 154 | bool skip_unregister_texture) { 155 | std::vector keys; 156 | for (auto it = texture_store_.begin(); it != texture_store_.end(); it++) { 157 | keys.push_back(it->first); 158 | } 159 | for (WebviewId key : keys) { 160 | UnregisterAndDestroyTextureInternal(key, texture_registrar, 161 | skip_unregister_texture); 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /linux/include/flutter_linux_webview/flutter_webview_types.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 ACCESS CO., LTD. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of ACCESS CO., LTD. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef LINUX_INCLUDE_FLUTTER_LINUX_WEBVIEW_FLUTTER_WEBVIEW_TYPES_H_ 30 | #define LINUX_INCLUDE_FLUTTER_LINUX_WEBVIEW_FLUTTER_WEBVIEW_TYPES_H_ 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | using WebviewId = int64_t; 39 | 40 | struct WebviewError { 41 | public: 42 | static constexpr char kInvalidWebviewId[] = "Invalid Webview ID"; 43 | static constexpr char kInvalidWebviewIdErrorMessage[] = 44 | "The browser specified by the webview id is not found."; 45 | static constexpr char kRuntimeError[] = "Runtime Error"; 46 | static constexpr char kBadArgumentsError[] = "Bad Arguments"; 47 | 48 | WebviewError(const std::string& code, const std::string& message); 49 | WebviewError(); 50 | 51 | std::string code; 52 | std::string message; 53 | }; 54 | 55 | template 56 | class Nullable { 57 | public: 58 | Nullable(const Nullable& other) = default; 59 | Nullable(Nullable&& other) = default; 60 | Nullable& operator=(const Nullable& other) { 61 | has_value_ = other.has_value_; 62 | value_ = other.value_; 63 | return *this; 64 | } 65 | Nullable& operator=(Nullable&& other) { 66 | has_value_ = other.has_value_; 67 | value_ = std::move(other.value_); 68 | return *this; 69 | } 70 | ~Nullable() = default; 71 | 72 | explicit Nullable(const T& value) : has_value_(true), value_(value) {} 73 | explicit Nullable(T&& value) : has_value_(true), value_(std::move(value)) {} 74 | Nullable() : has_value_(false), value_() {} 75 | 76 | T& value() { return value_; } 77 | const T& value() const { return value_; } 78 | bool is_null() const { return !has_value_; } 79 | 80 | private: 81 | bool has_value_; 82 | T value_; 83 | }; 84 | 85 | struct WebviewCreationParams { 86 | using PageStartedCallback = 87 | std::function; 88 | using PageFinishedCallback = 89 | std::function; 90 | using PageLoadingCallback = 91 | std::function; 92 | 93 | using WebResourceErrorCallback = 94 | std::function; 98 | 99 | using JavascriptResultCallback = std::function; 105 | 106 | WebviewCreationParams( 107 | uint32_t native_texture_id, 108 | int width, 109 | int height, 110 | std::function on_paint_begin, 111 | std::function on_paint_end, 112 | std::string url, 113 | std::vector background_color, 114 | PageStartedCallback on_page_started, 115 | PageFinishedCallback on_page_finished, 116 | PageLoadingCallback on_progress, 117 | WebResourceErrorCallback on_web_resource_error, 118 | JavascriptResultCallback on_javascript_result) 119 | : native_texture_id(native_texture_id), 120 | width(width), 121 | height(height), 122 | on_paint_begin(on_paint_begin), 123 | on_paint_end(on_paint_end), 124 | url(url), 125 | background_color(background_color), 126 | on_page_started(on_page_started), 127 | on_page_finished(on_page_finished), 128 | on_progress(on_progress), 129 | on_web_resource_error(on_web_resource_error), 130 | on_javascript_result(on_javascript_result) {} 131 | 132 | // ID of the OpenGL texture to which the browser rendering will be drawn. 133 | uint32_t native_texture_id; 134 | 135 | // initial width of the browser 136 | int width; 137 | 138 | // initial height of the browser 139 | int height; 140 | 141 | // Callback called at the beginning of CefRenderHandler::OnPaint, called on 142 | // the CEF UI thread. 143 | // Bind the context and surface here before GL drawing in OnPaint. 144 | std::function on_paint_begin; 145 | 146 | // Callback called at the end of CefRenderHandler::OnPaint, called on the CEF 147 | // UI thread. 148 | std::function on_paint_end; 149 | 150 | // Representation of the WebView.initialUrl property. If empty, about:blank is 151 | // loaded. 152 | std::string url; 153 | 154 | // Representation of the WebView.backgroundColor property. Represented by a 155 | // vector in the format {A, R, G, B} 156 | std::vector background_color; 157 | 158 | // Representation of the WebView.onPageStarted callback, called on the CEF UI 159 | // thread. Called after a navigation has been committed and before the browser 160 | // begins loading contents in the main frame. 161 | PageStartedCallback on_page_started; 162 | 163 | // Representation of the WebView.onPageFinished callback, called on the CEF UI 164 | // thread. Called when the browser is done loading the main frame. 165 | PageFinishedCallback on_page_finished; 166 | 167 | // Representation of the WebView.onProgress callback, called on the CEF UI 168 | // thread. Called when the overall page loading progress has changed. The 169 | // progress ranges from 0 to 100. 170 | PageLoadingCallback on_progress; 171 | 172 | // Representation of the WebView.onWebResourceError callback, called on the 173 | // CEF UI thread. Called when a navigation fails or is canceled. 174 | WebResourceErrorCallback on_web_resource_error; 175 | 176 | // Callback called when the result of runJavascript is returned, called on the 177 | // CEF UI thread. 178 | JavascriptResultCallback on_javascript_result; 179 | }; 180 | 181 | #endif // LINUX_INCLUDE_FLUTTER_LINUX_WEBVIEW_FLUTTER_WEBVIEW_TYPES_H_ 182 | -------------------------------------------------------------------------------- /linux/flutter_webview_handler.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 ACCESS CO., LTD. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of ACCESS CO., LTD. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef LINUX_FLUTTER_WEBVIEW_HANDLER_H_ 30 | #define LINUX_FLUTTER_WEBVIEW_HANDLER_H_ 31 | 32 | #include 33 | 34 | #include 35 | #include 36 | 37 | #include "flutter_linux_webview/flutter_webview_types.h" 38 | #include "third_party/cef/src/tests/cefclient/browser/flutter_webview_osr_renderer.h" 39 | #include "include/cef_client.h" 40 | 41 | class FlutterWebviewHandler : public CefClient, 42 | public CefDisplayHandler, 43 | public CefLifeSpanHandler, 44 | public CefLoadHandler, 45 | public CefRenderHandler { 46 | public: 47 | FlutterWebviewHandler( 48 | WebviewId webview_id, 49 | const WebviewCreationParams& params, 50 | const std::function browser)>& 52 | on_after_created, 53 | const std::function& on_browser_ready, 54 | const std::function browser)>& 56 | on_before_close); 57 | 58 | // CefClient methods: 59 | virtual CefRefPtr GetDisplayHandler() override { 60 | return this; 61 | } 62 | virtual CefRefPtr GetLifeSpanHandler() override { 63 | return this; 64 | } 65 | virtual CefRefPtr GetLoadHandler() override { return this; } 66 | virtual CefRefPtr GetRenderHandler() override { 67 | return this; 68 | } 69 | virtual bool OnProcessMessageReceived( 70 | CefRefPtr browser, 71 | CefRefPtr frame, 72 | CefProcessId source_process, 73 | CefRefPtr message) override; 74 | 75 | // CefDisplayHandler methods: 76 | virtual void OnLoadingProgressChange(CefRefPtr browser, 77 | double progress) override; 78 | 79 | // CefLifeSpanHandler methods: 80 | virtual bool OnBeforePopup(CefRefPtr browser, 81 | CefRefPtr frame, 82 | const CefString& target_url, 83 | const CefString& target_frame_name, 84 | WindowOpenDisposition target_disposition, 85 | bool user_gesture, 86 | const CefPopupFeatures& popupFeatures, 87 | CefWindowInfo& windowInfo, 88 | CefRefPtr& client, 89 | CefBrowserSettings& settings, 90 | CefRefPtr& extra_info, 91 | bool* no_javascript_access) override; 92 | virtual void OnAfterCreated(CefRefPtr browser) override; 93 | virtual bool DoClose(CefRefPtr browser) override; 94 | virtual void OnBeforeClose(CefRefPtr browser) override; 95 | 96 | // CefLoadHandler methods: 97 | virtual void OnLoadStart(CefRefPtr browser, 98 | CefRefPtr frame, 99 | TransitionType transition_type) override; 100 | virtual void OnLoadEnd(CefRefPtr browser, 101 | CefRefPtr frame, 102 | int httpStatusCode) override; 103 | virtual void OnLoadError(CefRefPtr browser, 104 | CefRefPtr frame, 105 | ErrorCode errorCode, 106 | const CefString& errorText, 107 | const CefString& failedUrl) override; 108 | 109 | // CefRenderHandler methods: 110 | virtual void GetViewRect(CefRefPtr browser, 111 | CefRect& rect) override; 112 | virtual void OnPaint(CefRefPtr browser, 113 | PaintElementType type, 114 | const RectList& dirtyRects, 115 | const void* buffer, 116 | int width, 117 | int height) override; 118 | virtual void OnPopupShow(CefRefPtr browser, bool show) override; 119 | virtual void OnPopupSize(CefRefPtr browser, 120 | const CefRect& rect) override; 121 | 122 | // Close this browser asynchronously. |close_browser_cb| is called just 123 | // before a browser is destroyed. 124 | void CloseBrowser(const std::function& close_browser_cb); 125 | 126 | // Set the OSR resolution 127 | void SetWebviewSize(int width, int height); 128 | 129 | private: 130 | enum class BrowserState { 131 | kBeforeCreated, 132 | kCreated, 133 | // Currently, "ready" means when main_frame->GetURL() returns a meaningful 134 | // value. 135 | kReady, 136 | kClosing, 137 | kClosed 138 | }; 139 | 140 | std::function on_paint_begin_; 141 | std::function on_paint_end_; 142 | 143 | // callbacks for methods of the WebViewPlatformCallbacksHandler class 144 | WebviewCreationParams::PageStartedCallback on_page_started_; 145 | WebviewCreationParams::PageFinishedCallback on_page_finished_; 146 | WebviewCreationParams::PageLoadingCallback on_progress_; 147 | WebviewCreationParams::WebResourceErrorCallback on_web_resource_error_; 148 | 149 | WebviewCreationParams::JavascriptResultCallback on_javascript_result_; 150 | std::function browser)> 151 | on_after_created_; 152 | std::function on_browser_ready_; 153 | std::function browser)> 154 | on_before_close_; 155 | std::function close_browser_cb_; 156 | 157 | WebviewId webview_id_; 158 | BrowserState browser_state_; 159 | CefRefPtr browser_; 160 | FlutterWebviewOsrRenderer renderer_; 161 | int webview_width_; 162 | int webview_height_; 163 | 164 | // Include the default reference counting implementation. 165 | IMPLEMENT_REFCOUNTING(FlutterWebviewHandler); 166 | }; 167 | 168 | #endif // LINUX_FLUTTER_WEBVIEW_HANDLER_H_ 169 | -------------------------------------------------------------------------------- /ThirdPartyNotices.txt: -------------------------------------------------------------------------------- 1 | Third-Party Software Notices 2 | 3 | flutter_linux_webview incorporates materials from third-party software as listed 4 | below. 5 | 6 | -------------------------------------------------------------------------------- 7 | 8 | Chromium Embedded Framework (CEF) 9 | https://bitbucket.org/chromiumembedded/cef/src/4664/ 10 | 11 | // Copyright (c) 2008-2020 Marshall A. Greenblatt. Portions Copyright (c) 12 | // 2006-2009 Google Inc. All rights reserved. 13 | // 14 | // Redistribution and use in source and binary forms, with or without 15 | // modification, are permitted provided that the following conditions are 16 | // met: 17 | // 18 | // * Redistributions of source code must retain the above copyright 19 | // notice, this list of conditions and the following disclaimer. 20 | // * Redistributions in binary form must reproduce the above 21 | // copyright notice, this list of conditions and the following disclaimer 22 | // in the documentation and/or other materials provided with the 23 | // distribution. 24 | // * Neither the name of Google Inc. nor the name Chromium Embedded 25 | // Framework nor the names of its contributors may be used to endorse 26 | // or promote products derived from this software without specific prior 27 | // written permission. 28 | // 29 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 30 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 31 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 32 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 33 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 34 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 35 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 36 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 37 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 38 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 39 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 40 | -------------------------------------------------------------------------------- 41 | 42 | -------------------------------------------------------------------------------- 43 | 44 | Flutter Engine 45 | https://github.com/flutter/engine/tree/6ba2af10bb05c88a2731482cedf2cfd11cf5af0b 46 | 47 | Copyright 2013 The Flutter Authors. All rights reserved. 48 | 49 | Redistribution and use in source and binary forms, with or without modification, 50 | are permitted provided that the following conditions are met: 51 | 52 | * Redistributions of source code must retain the above copyright 53 | notice, this list of conditions and the following disclaimer. 54 | * Redistributions in binary form must reproduce the above 55 | copyright notice, this list of conditions and the following 56 | disclaimer in the documentation and/or other materials provided 57 | with the distribution. 58 | * Neither the name of Google Inc. nor the names of its 59 | contributors may be used to endorse or promote products derived 60 | from this software without specific prior written permission. 61 | 62 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 63 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 64 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 65 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 66 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 67 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 68 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 69 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 70 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 71 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 72 | -------------------------------------------------------------------------------- 73 | 74 | -------------------------------------------------------------------------------- 75 | 76 | webview_flutter_android 77 | https://github.com/flutter/plugins/tree/webview_flutter-v3.0.4/packages/webview_flutter/webview_flutter_android 78 | 79 | Copyright 2013 The Flutter Authors. All rights reserved. 80 | 81 | Redistribution and use in source and binary forms, with or without modification, 82 | are permitted provided that the following conditions are met: 83 | 84 | * Redistributions of source code must retain the above copyright 85 | notice, this list of conditions and the following disclaimer. 86 | * Redistributions in binary form must reproduce the above 87 | copyright notice, this list of conditions and the following 88 | disclaimer in the documentation and/or other materials provided 89 | with the distribution. 90 | * Neither the name of Google Inc. nor the names of its 91 | contributors may be used to endorse or promote products derived 92 | from this software without specific prior written permission. 93 | 94 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 95 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 96 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 97 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 98 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 99 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 100 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 101 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 102 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 103 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 104 | -------------------------------------------------------------------------------- 105 | 106 | -------------------------------------------------------------------------------- 107 | 108 | webview_flutter 109 | https://github.com/flutter/plugins/tree/webview_flutter-v3.0.4/packages/webview_flutter/webview_flutter 110 | 111 | Copyright 2013 The Flutter Authors. All rights reserved. 112 | 113 | Redistribution and use in source and binary forms, with or without modification, 114 | are permitted provided that the following conditions are met: 115 | 116 | * Redistributions of source code must retain the above copyright 117 | notice, this list of conditions and the following disclaimer. 118 | * Redistributions in binary form must reproduce the above 119 | copyright notice, this list of conditions and the following 120 | disclaimer in the documentation and/or other materials provided 121 | with the distribution. 122 | * Neither the name of Google Inc. nor the names of its 123 | contributors may be used to endorse or promote products derived 124 | from this software without specific prior written permission. 125 | 126 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 127 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 128 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 129 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 130 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 131 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 132 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 133 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 134 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 135 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 136 | -------------------------------------------------------------------------------- 137 | 138 | -------------------------------------------------------------------------------- /create_symlinks_to_third_party.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | # flutter_linux_webview/ 6 | PROJECT_ROOT_DIR="$(realpath "$(dirname "$0")")" 7 | 8 | cd "$(dirname "$0")" || exit 9 | 10 | # $1: src_root_dir (example: "third_party_base/cef") 11 | # $2: files_to_link (one line per file) 12 | # $3: dst_root_dir (example: "linux/third_party/cef") 13 | # 14 | # For each $files_to_link under $src_root_dir, creates symlinks to them under 15 | # $dst_root_dir. 16 | # 17 | # Example: 18 | # $1: "third_party_base/some_oss" 19 | # $2: "file1 20 | # dir1/file2 21 | # dir2/file5" 22 | # $3: "linux/third_party/some_oss" 23 | # 24 | # flutter_linux_webview/ 25 | # └── third_party_base/ 26 | # ├── some_oss/ # $src_root_dir 27 | # │ ├── file1 28 | # │ ├── dir1/ 29 | # │ │ ├── file2 # specified in $files_to_link 30 | # │ │ └── file3 31 | # │ └── dir2/ 32 | # │ ├── file4 33 | # │ └── file5 # specified in $files_to_link 34 | # ├── linux/ 35 | # │ └── third_party/ # must exist 36 | # │ ================ (begin) symlinks and directories are created as follows =============== 37 | # │ └── some_oss/ # $dst_root_dir 38 | # │ ├── file1 (-> ../../../third_party_base/some_oss/file1) 39 | # │ ├── dir1/ 40 | # │ │ └── file2 (-> ../../../../third_party_base/some_oss/dir1/file2) 41 | # │ └── dir2/ 42 | # │ └── file5 (-> ../../../../third_party_base/some_oss/dir2/file5) 43 | # │ ================ (end) ================ 44 | # └── ... 45 | function copy_directory_structure_and_create_symlinks_for_files() { 46 | local src_root_dir; src_root_dir="$PROJECT_ROOT_DIR"/"$1" 47 | local files_to_link; files_to_link="$2" 48 | local dst_root_dir; dst_root_dir="$PROJECT_ROOT_DIR"/"$3" 49 | 50 | if [ ! -d "$src_root_dir" ]; then 51 | echo "Error: Source directory '$src_root_dir' does not exist." 52 | exit 1 53 | fi 54 | 55 | if [ -e "$dst_root_dir" ]; then 56 | echo "Warning: '$dst_root_dir' already exists." 57 | echo "Do you want to delete this directory and its contents? (y/n)" 58 | read -r answer 59 | if [ "$answer" != "y" ]; then 60 | echo "Abort." 61 | exit 1 62 | fi 63 | rm -rf "$dst_root_dir" 64 | fi 65 | 66 | mkdir -p "$dst_root_dir" || { 67 | echo "Error: Failed to create directory '$dst_root_dir'." 68 | exit 1 69 | } 70 | 71 | for file_rel in $files_to_link; do 72 | _create_symlink_with_mkdir "$src_root_dir" "$file_rel" "$dst_root_dir" || { 73 | exit 1 74 | } 75 | done 76 | } 77 | 78 | function _create_symlink_with_mkdir() { 79 | local src_root_dir; src_root_dir="$1" 80 | local rel_filepath; rel_filepath="$2" 81 | local dst_root_dir; dst_root_dir="$3" 82 | 83 | local abs_src_file_path; abs_src_file_path="$(realpath "$src_root_dir/$rel_filepath")" 84 | local abs_dst_file_path; abs_dst_file_path="$(realpath --canonicalize-missing "$dst_root_dir/$rel_filepath")" 85 | local dst_file_dirname; dst_file_dirname="$(dirname "$abs_dst_file_path")" 86 | local rel_path_for_symlink; rel_path_for_symlink=$(realpath "$abs_src_file_path" --canonicalize-missing --relative-to="$dst_file_dirname") 87 | 88 | mkdir -p "$(dirname "$abs_dst_file_path")" || { 89 | echo "Error: Failed to create directory '$dst_file_dirname'." 90 | exit 1 91 | } 92 | ln -sv "$rel_path_for_symlink" "$abs_dst_file_path" || { 93 | echo "Error: Failed to create symbolic link." 94 | echo "File: '$abs_src_file_path' could not be symbolically linked to '$abs_dst_file_path'." 95 | exit 1 96 | } 97 | } 98 | 99 | 100 | # $1: target_dir (example: "lib/src/third_party") 101 | # 102 | # Creates a directory named $target_dir as a third-party top directory. 103 | function create_third_party_dir() { 104 | local target_dir; target_dir="$PROJECT_ROOT_DIR"/"$1" 105 | 106 | if [ -e "$target_dir" ]; then 107 | echo "Warning: '$target_dir' already exists." 108 | echo "Do you want to delete this directory and its contents? (y/n)" 109 | read -r answer 110 | if [ "$answer" != "y" ]; then 111 | echo "Abort." 112 | exit 1 113 | fi 114 | rm -rf "$target_dir" 115 | fi 116 | 117 | mkdir -p "$target_dir" 118 | _create_symlink_with_mkdir "third_party_base" "README.md" "$target_dir" 119 | } 120 | 121 | # 122 | # Generates ThirdPartyNotices.txt from a list of README.webview 123 | # 124 | # $1: the list of README.webview file paths 125 | function generate_third_party_notices_txt_from_README_webviews() { 126 | local list_of_readme_webview; list_of_readme_webview=$1 127 | 128 | for readme_path in $list_of_readme_webview; do 129 | grep "^Name: " "$readme_path" || { echo "${readme_path} must have 'Name: '"; exit 1; } 130 | grep "^URL: " "$readme_path" || { echo "${readme_path} must have 'URL: '"; exit 1; } 131 | grep "^License File: " "$readme_path" || { echo "${readme_path} must have 'License File: '"; exit 1; } 132 | done 133 | 134 | local tmp_file 135 | tmp_file=`mktemp tmp_third_party_notices_XXXXXX` 136 | 137 | cat <> "$tmp_file" 138 | Third-Party Software Notices 139 | 140 | flutter_linux_webview incorporates materials from third-party software as listed 141 | below. 142 | 143 | EOS 144 | 145 | for readme_path in $list_of_readme_webview; do 146 | local oss_name; oss_name=$(grep "^Name: " "$readme_path" | sed -e 's/^Name: \(.*\)$/\1/') 147 | local oss_url; oss_url=$(grep "^URL: " "$readme_path" | sed -e 's/^URL: \(.*\)$/\1/') 148 | local oss_license_relpath; oss_license_relpath=$(grep "^License File: " "$readme_path" | sed -e 's/^License File: \(.*\)$/\1/') 149 | local oss_license_abspath; oss_license_abspath="$(dirname "$( realpath "$readme_path" )")/${oss_license_relpath}" 150 | 151 | cat <> "$tmp_file" 152 | -------------------------------------------------------------------------------- 153 | 154 | ${oss_name} 155 | ${oss_url} 156 | 157 | $(cat "$oss_license_abspath") 158 | -------------------------------------------------------------------------------- 159 | 160 | EOS 161 | done 162 | 163 | mv "$tmp_file" "./ThirdPartyNotices.txt" 164 | } 165 | 166 | ### 167 | ### Dart side third-party 168 | ### 169 | 170 | create_third_party_dir "lib/src/third_party" 171 | 172 | # cef 173 | 174 | param_src_root_dir="third_party_base/cef" 175 | param_dst_root_dir="lib/src/third_party/cef" 176 | param_files_to_link="README.webview 177 | src/LICENSE.txt 178 | src/include/internal/cef_types.dart 179 | src/tests/cefclient/browser/windows_key_code.dart 180 | " 181 | copy_directory_structure_and_create_symlinks_for_files "$param_src_root_dir" "$param_files_to_link" "$param_dst_root_dir" 182 | 183 | 184 | # flutter_engine 185 | 186 | param_src_root_dir="third_party_base/flutter_engine" 187 | param_dst_root_dir="lib/src/third_party/flutter_engine" 188 | param_files_to_link="README.webview 189 | LICENSE 190 | shell/platform/linux/native_key_code.dart 191 | " 192 | copy_directory_structure_and_create_symlinks_for_files "$param_src_root_dir" "$param_files_to_link" "$param_dst_root_dir" 193 | 194 | 195 | # webview_flutter_android 196 | 197 | param_src_root_dir="third_party_base/webview_flutter_android" 198 | param_dst_root_dir="lib/src/third_party/webview_flutter_android" 199 | param_files_to_link="README.webview 200 | LICENSE 201 | lib/src/instance_manager.dart 202 | lib/webview_linux_cookie_manager.dart 203 | " 204 | copy_directory_structure_and_create_symlinks_for_files "$param_src_root_dir" "$param_files_to_link" "$param_dst_root_dir" 205 | 206 | 207 | ### 208 | ### Platform (C++) side third-party 209 | ### 210 | 211 | create_third_party_dir "linux/third_party" 212 | 213 | # cef 214 | 215 | param_src_root_dir="third_party_base/cef" 216 | param_dst_root_dir="linux/third_party/cef" 217 | param_files_to_link="README.webview 218 | src/LICENSE.txt 219 | src/tests/cefclient/browser/flutter_webview_osr_renderer.cc 220 | src/tests/cefclient/browser/flutter_webview_osr_renderer.h 221 | src/tests/cefsimple/CMakeLists_subprocess_project.txt 222 | " 223 | copy_directory_structure_and_create_symlinks_for_files "$param_src_root_dir" "$param_files_to_link" "$param_dst_root_dir" 224 | 225 | 226 | # webview_flutter 227 | # * for the example app and the integration_test 228 | 229 | create_third_party_dir "example/lib/third_party" 230 | 231 | param_src_root_dir="third_party_base/webview_flutter" 232 | param_dst_root_dir="example/lib/third_party/webview_flutter" 233 | param_files_to_link="README.webview 234 | LICENSE 235 | example/assets/www/index.html 236 | example/assets/www/styles/style.css 237 | example/integration_test/flutter_linux_webview_test.dart 238 | example/lib/main.dart 239 | " 240 | copy_directory_structure_and_create_symlinks_for_files "$param_src_root_dir" "$param_files_to_link" "$param_dst_root_dir" 241 | 242 | generate_third_party_notices_txt_from_README_webviews "third_party_base/cef/README.webview 243 | third_party_base/flutter_engine/README.webview 244 | third_party_base/webview_flutter_android/README.webview 245 | third_party_base/webview_flutter/README.webview 246 | " 247 | -------------------------------------------------------------------------------- /third_party_base/cef/src/tests/cefclient/browser/flutter_webview_osr_renderer.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2023 ACCESS CO., LTD. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of ACCESS CO., LTD. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | // This file is based on 30 | // https://bitbucket.org/chromiumembedded/cef/src/4664/tests/cefclient/browser/osr_renderer.cc 31 | // for off-screen rendering. 32 | 33 | // Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights 34 | // reserved. 35 | // 36 | // Redistribution and use in source and binary forms, with or without 37 | // modification, are permitted provided that the following conditions are 38 | // met: 39 | // 40 | // * Redistributions of source code must retain the above copyright 41 | // notice, this list of conditions and the following disclaimer. 42 | // * Redistributions in binary form must reproduce the above 43 | // copyright notice, this list of conditions and the following disclaimer 44 | // in the documentation and/or other materials provided with the 45 | // distribution. 46 | // * Neither the name of Google Inc. nor the name Chromium Embedded 47 | // Framework nor the names of its contributors may be used to endorse 48 | // or promote products derived from this software without specific prior 49 | // written permission. 50 | // 51 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 52 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 53 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 54 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 55 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 56 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 57 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 58 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 59 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 60 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 61 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 62 | 63 | #include "flutter_webview_osr_renderer.h" 64 | 65 | #include 66 | 67 | #include 68 | #include 69 | #include 70 | 71 | #include "flutter_linux_webview/flutter_webview_types.h" 72 | #include "include/base/cef_callback.h" 73 | #include "include/base/cef_logging.h" 74 | #include "include/cef_app.h" 75 | #include "include/cef_parser.h" 76 | #include "include/views/cef_browser_view.h" 77 | #include "include/views/cef_window.h" 78 | #include "include/wrapper/cef_closure_task.h" 79 | #include "include/wrapper/cef_helpers.h" 80 | 81 | // DCHECK on gl errors. 82 | #if DCHECK_IS_ON() 83 | #define VERIFY_NO_ERROR \ 84 | { \ 85 | int _gl_error = glGetError(); \ 86 | DCHECK(_gl_error == GL_NO_ERROR) << "glGetError returned " << _gl_error; \ 87 | } 88 | #else 89 | #define VERIFY_NO_ERROR 90 | #endif 91 | 92 | FlutterWebviewOsrRenderer::FlutterWebviewOsrRenderer(GLuint native_texture_id) 93 | : native_texture_id_(native_texture_id) {} 94 | 95 | void FlutterWebviewOsrRenderer::OnPopupShow(CefRefPtr browser, 96 | bool show) { 97 | if (!show) { 98 | // Clear the popup rectangle. 99 | ClearPopupRects(); 100 | } 101 | } 102 | 103 | void FlutterWebviewOsrRenderer::OnPopupSize(CefRefPtr browser, 104 | const CefRect& rect) { 105 | if (rect.width <= 0 || rect.height <= 0) 106 | return; 107 | original_popup_rect_ = rect; 108 | popup_rect_ = GetPopupRectInWebView(original_popup_rect_); 109 | } 110 | 111 | CefRect FlutterWebviewOsrRenderer::GetPopupRectInWebView( 112 | const CefRect& original_rect) { 113 | CefRect rc(original_rect); 114 | // if x or y are negative, move them to 0. 115 | if (rc.x < 0) 116 | rc.x = 0; 117 | if (rc.y < 0) 118 | rc.y = 0; 119 | // if popup goes outside the view, try to reposition origin 120 | if (rc.x + rc.width > view_width_) 121 | rc.x = view_width_ - rc.width; 122 | if (rc.y + rc.height > view_height_) 123 | rc.y = view_height_ - rc.height; 124 | // if x or y became negative, move them to 0 again. 125 | if (rc.x < 0) 126 | rc.x = 0; 127 | if (rc.y < 0) 128 | rc.y = 0; 129 | return rc; 130 | } 131 | 132 | void FlutterWebviewOsrRenderer::ClearPopupRects() { 133 | popup_rect_.Set(0, 0, 0, 0); 134 | original_popup_rect_.Set(0, 0, 0, 0); 135 | } 136 | 137 | void FlutterWebviewOsrRenderer::OnPaint( 138 | CefRefPtr browser, 139 | CefRenderHandler::PaintElementType type, 140 | const CefRenderHandler::RectList& dirtyRects, 141 | const void* buffer, 142 | int width, 143 | int height) { 144 | DCHECK_NE(native_texture_id_, 0U); 145 | glBindTexture(GL_TEXTURE_2D, native_texture_id_); 146 | VERIFY_NO_ERROR; 147 | 148 | if (type == PET_VIEW) { 149 | int old_width = view_width_; 150 | int old_height = view_height_; 151 | 152 | view_width_ = width; 153 | view_height_ = height; 154 | 155 | glPixelStorei(GL_UNPACK_ROW_LENGTH, view_width_); 156 | VERIFY_NO_ERROR; 157 | 158 | if (old_width != view_width_ || old_height != view_height_ || 159 | (dirtyRects.size() == 1 && 160 | dirtyRects[0] == CefRect(0, 0, view_width_, view_height_))) { 161 | // Update/resize the whole texture. 162 | glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); 163 | VERIFY_NO_ERROR; 164 | glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); 165 | VERIFY_NO_ERROR; 166 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, view_width_, view_height_, 0, 167 | GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, buffer); 168 | VERIFY_NO_ERROR; 169 | } else { 170 | // Update just the dirty rectangles. 171 | CefRenderHandler::RectList::const_iterator i = dirtyRects.begin(); 172 | for (; i != dirtyRects.end(); ++i) { 173 | const CefRect& rect = *i; 174 | DCHECK(rect.x + rect.width <= view_width_); 175 | DCHECK(rect.y + rect.height <= view_height_); 176 | glPixelStorei(GL_UNPACK_SKIP_PIXELS, rect.x); 177 | VERIFY_NO_ERROR; 178 | glPixelStorei(GL_UNPACK_SKIP_ROWS, rect.y); 179 | VERIFY_NO_ERROR; 180 | glTexSubImage2D(GL_TEXTURE_2D, 0, rect.x, rect.y, rect.width, 181 | rect.height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 182 | buffer); 183 | VERIFY_NO_ERROR; 184 | } 185 | } 186 | } else if (type == PET_POPUP && popup_rect_.width > 0 && 187 | popup_rect_.height > 0) { 188 | int skip_pixels = 0, x = popup_rect_.x; 189 | int skip_rows = 0, y = popup_rect_.y; 190 | int w = width; 191 | int h = height; 192 | 193 | // Adjust the popup to fit inside the view. 194 | if (x < 0) { 195 | skip_pixels = -x; 196 | x = 0; 197 | } 198 | if (y < 0) { 199 | skip_rows = -y; 200 | y = 0; 201 | } 202 | if (x + w > view_width_) 203 | w -= x + w - view_width_; 204 | if (y + h > view_height_) 205 | h -= y + h - view_height_; 206 | 207 | // Update the popup rectangle. 208 | glPixelStorei(GL_UNPACK_ROW_LENGTH, width); 209 | VERIFY_NO_ERROR; 210 | glPixelStorei(GL_UNPACK_SKIP_PIXELS, skip_pixels); 211 | VERIFY_NO_ERROR; 212 | glPixelStorei(GL_UNPACK_SKIP_ROWS, skip_rows); 213 | VERIFY_NO_ERROR; 214 | glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_BGRA, 215 | GL_UNSIGNED_INT_8_8_8_8_REV, buffer); 216 | VERIFY_NO_ERROR; 217 | } 218 | } 219 | -------------------------------------------------------------------------------- /validation_report.md: -------------------------------------------------------------------------------- 1 | # flutter_linux_webview Validation Report 2 | 3 | * flutter_linux_webview version: 0.1.0 4 | * Validated on 2023-12-13 5 | 6 | ## Validation Apps 7 | 8 | - example/lib/multiple_webviews_example.dart 9 | - A simple demo app that allows us to "Add a new WebView" or "Remove a WebView" to/from the ListView by pressing the buttons. 10 | - The validation procedure: 11 | - Repeat the process of "Adding about 10 times then Removing about 10 times" about 10 times. 12 | - example/integration_test/flutter_linux_webview_test.dart 13 | - The integration test brought from webview_flutter v3.0.4. 14 | - During the test, more than 10 WebViews repeatedly start and disappear in a few seconds. 15 | 16 | ## Flutter versions used for the validation 17 | 18 | Using Flutter Linux stable channel. 19 | 20 | - Flutter 3.10.0 [release date: 2023-05-11] 21 | - Flutter 3.13.9 [release date: 2023-10-26] 22 | - Flutter 3.16.3 [release date: 2023-12-07] (stable as of 2023-12-13) 23 | 24 | ## Target Platforms 25 | 26 | - (1) [laptop] Macbook Air 2014 x86_64 / Ubuntu 22.04 Desktop 27 | - (2) [laptop] NEC LE150/N (2013) x86_64 / Debian 11 (bullseye) 28 | - (3) [Desktop PC] Ryzen9 5900X + GeForce GTX 1650 x86_64 / Ubuntu 18.04 Chrome Remote Desktop 29 | - (4) [Desktop PC] Ryzen9 5900X + Radeon RX 7800 XT x86_64 / Ubuntu 22.04 Desktop 30 | - (5) Raspberry Pi 4 Model B arm64 / Raspberry Pi OS bullseye 64bit 31 | - (6) Raspberry Pi 4 Model B arm64 / Ubuntu 22.04 Desktop 32 | 33 | ## Results 34 | 35 | ### (1) [laptop] Macbook Air 2014 x86_64 / Ubuntu 22.04 Desktop 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 |
Flutter 3.10.0 [2023-05-11] Flutter 3.13.9 [2023-10-26] Flutter 3.16.3 [2023-12-07]
X11 lib/multiple_webviews_example.dart It works. No errors. It works. No errors. It works. No errors.
X11 integration_test/flutter_linux_webview_test.dart Test completes to the end. Test completes to the end. Test hangs on the first item.
Wayland lib/multiple_webviews_example.dart It works. No errors. It works. No errors. It works. No errors.
Wayland integration_test/flutter_linux_webview_test.dart Test completes to the end. Test sometimes crashes in the middle? Test hangs on the first item.
74 | 75 | 76 | 77 | ### (2) [laptop] NEC LE150/N (2013) x86_64 / Debian 11 (bullseye) 78 | 79 | Almost same results as above (1) Macbook Air Ubuntu 22.04 Desktop. 80 | 81 | 82 | ### (3) [Desktop PC] Ryzen9 5900X + GeForce GTX 1650 x86_64 / Ubuntu 18.04 Chrome Remote Desktop 83 | 84 | Same results for X11 as above (1) Macbook Air Ubuntu 22.04 Desktop. (Not trying with Wayland.) 85 | 86 | ### (4) [Desktop PC] Ryzen9 5900X + Radeon RX 7800 XT x86_64 / Ubuntu 22.04 Desktop 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 |
Flutter 3.10.0 Flutter 3.13.9 Flutter 3.16.3
X11 lib/multiple_webviews_example.dart It works, but crashes about once every few dozen times when "Add a new webview" is pressed. (the crash message below) It works, but crashes about once every few dozen times when "Add a new webview" is pressed. (the crash message below) It works, but crashes about once every few dozen times when "Add a new webview" is pressed. (the crash message below)
X11 integration_test/flutter_linux_webview_test.dart Test crashes in the middle. Test crashes in the middle. Test hangs on the first item.
Wayland lib/multiple_webviews_example.dart It works. No errors. It works. No errors. It works. No errors.
Wayland integration_test/flutter_linux_webview_test.dart Test crashes in the middle. Test crashes in the middle. Test hangs on the first item.
126 | 127 | #### Crash message: `X Window System BadAccess (attempt to access private resource denied)` 128 | 129 | ``` 130 | (flutter_linux_webview_example:7404): Gdk-ERROR **: 19:05:33.186: The program 'flutter_linux_webview_example' received an X Window System error. 131 | This probably reflects a bug in the program. 132 | The error was 'BadAccess (attempt to access private resource denied)'. 133 | (Details: serial 16332 error_code 10 request_code 152 (GLX) minor_code 26) 134 | (Note to programmers: normally, X errors are reported asynchronously; 135 | that is, you will receive the error a while after causing it. 136 | To debug your program, run it with the GDK_SYNCHRONIZE environment 137 | variable to change this behavior. You can then get a meaningful 138 | backtrace from your debugger if you break on the gdk_x_error() function.) 139 | ``` 140 | 141 | ### (5) Raspberry Pi 4 Model B arm64 / Raspberry Pi OS bullseye 64bit 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 |
Flutter 3.10.0 Flutter 3.13.9 Flutter 3.16.3
X11 lib/multiple_webviews_example.dart It works. No errors. Pressing "Add a new WebView" causes the app to hang (force termination required). But sometimes it does not hang at all. (*) Pressing "Add a new WebView" causes the app to hang (force termination required). But sometimes it does not hang at all.
X11 integration_test/flutter_linux_webview_test.dart Test completes to the end. Test completes to the end. Test hangs on the first item.
167 | 168 | 169 | (*) In Flutter 3.13.9, on rare occasions, I have seen crashes with the following errors instead of hangs. 170 | 171 | ``` 172 | [xcb] Unknown sequence number while processing queue 173 | [xcb] Most likely this is a multi-threaded client and XInitThreads has not been called 174 | [xcb] Aborting, sorry about that. 175 | flutter_linux_webview_example: ../../src/xcb_io.c:269: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed. 176 | [0100/000000.502783:ERROR:zygote_linux.cc(607)] Zygote could not fork: process_type renderer numfds 4 child_pid -1 177 | [0100/000000.503420:ERROR:zygote_linux.cc(639)] write: Broken pipe (32) 178 | ``` 179 | 180 | ### (6) Raspberry Pi 4 Model B arm64 / Ubuntu 22.04 Desktop 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 |
Flutter 3.10.0 Flutter 3.13.9 Flutter 3.16.3
X11 lib/multiple_webviews_example.dart It works. No errors. It works. No errors. It works. No errors.
X11 integration_test/flutter_linux_webview_test.dart Test completes to the end. Test completes to the end. Test hangs on the first item.
Wayland lib/multiple_webviews_example.dart No hang, but only black texture is displayed. (*) No hang, but only black texture is displayed. (*) No hang, but only black texture is displayed. (*)
Wayland integration_test/flutter_linux_webview_test.dart Test crashes in the middle. Test crashes in the middle. Test hangs on the first item.
220 | 221 | (*) On RPi4 Ubuntu 22.04 Wayland, any Flutter app will not work without `GDK_GL=gles`. 222 | (ref. [Flutter app can't create a GL context on RPi 4/Ubuntu Core 20 - Issue #49 - MirServer/ubuntu-frame - GitHub](https://github.com/MirServer/ubuntu-frame/issues/49)) 223 | However, with `GDK_GL=gles`, off-screen rendering does not work. The texture is not rendered and we get a black WebView. 224 | `$ GDK_GL=gles cefclient --off-screen-rendering-enabled` also results in a white screen. 225 | -------------------------------------------------------------------------------- /linux/README.md: -------------------------------------------------------------------------------- 1 | # flutter_linux_webview v0.1.0 plugin Overview 2 | 3 | This package provides the Linux Desktop implementation of `webview_flutter` (v3.0.4). 4 | 5 | [webview_flutter v3.0.4](https://pub.dev/packages/webview_flutter/versions/3.0.4) is a [federated package](https://docs.flutter.dev/packages-and-plugins/developing-packages#federated-plugins), consisting of an app-facing package, platform interface package, and platform packages. 6 | 7 | This plugin package provides the platform part for Linux. 8 | 9 | | Package Type | Package Name | Components (not exhaustive) | 10 | | -------------------------- | ---------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | 11 | | app-facing package | [webview_flutter](https://pub.dev/packages/webview_flutter/versions/3.0.4) | WebView, WebViewController | 12 | | (↓ depends on) | | (↓ uses) | 13 | | platform interface package | [webview_flutter_platform_interface](https://pub.dev/packages/webview_flutter_platform_interface/versions/1.8.1) | WebViewPlatform, WebViewPlatformController, WebViewCookieManagerPlatform, ... | 14 | | (↑ depends on) | | (↑ implements, extends, uses) | 15 | | platform package | [flutter_linux_android](https://pub.dev/packages/webview_flutter_android/versions/2.8.8) | AndroidWebView, WebViewAndroidPlatformController, WebViewAndroidCookieManager, native implementation | 16 | | platform package | **flutter_linux_webview (this package)** | **LinuxWebView, WebViewLinuxPlatformController, WebViewLinuxCookieManager, native implementation (C++/CEF)** | 17 | 18 | ## How a WebView user uses the platform implementation 19 | 20 | When users create a [WebView](https://pub.dev/documentation/webview_flutter/3.0.4/webview_flutter/WebView-class.html) widget in their app, they can obtain a [WebViewController](https://pub.dev/documentation/webview_flutter/3.0.4/webview_flutter/WebViewController-class.html) through the `WebView.onWebViewCreated` callback, which they can use to manipulate the WebView. 21 | 22 | The `WebViewController` delegates platform-specific operations to [its private member](https://github.com/flutter/plugins/blob/webview_flutter-v3.0.4/packages/webview_flutter/webview_flutter/lib/src/webview.dart#L505) of the [WebViewPlatformController](https://github.com/flutter/plugins/blob/webview_flutter-v3.0.4/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_interface/webview_platform_controller.dart#L18) type. 23 | 24 | On Linux, this member is an instance of `WebViewLinuxPlatformController`, which extends `WebViewPlatformController`. 25 | 26 | Therefore, the `WebViewController` delegates operations to the `WebViewLinuxPlatformController`, which is provided in this package. `WebViewLinuxPlatformController` also invokes the native implementation. 27 | 28 | It can be represented using the following diagram: 29 | 30 | ``` 31 | A WebView User ---uses---> WebViewController ---delegates---> WebViewLinuxPlatformController ---invokes---> native implementation (C++/CEF) 32 | ``` 33 | 34 | See `/example` or `../README.md` for examples of using a WebView widget and WebViewController. 35 | 36 | ### FYI: How the platform implementation is set in WebViewController 37 | 38 | 1. The user sets `LinuxWebView()` to the `WebView.platform` property. 39 | * where `LinuxWebView` implements `WebViewPlatform`. 40 | 1. The user creates a `WebView` widget in the app. 41 | * (Before this point, the user must call `LinuxWebViewPlugin.initialize()` (located in `lib/src/linux_webview_plugin.dart`) in advance to start CEF.) 42 | 1. In `_WebViewState.build()`, `WebView.platform.build()`, that is, `LinuxWebView.build()` is called. 43 | * Here [_WebViewState._onWebViewPlatformCreated()](https://github.com/flutter/plugins/blob/webview_flutter-v3.0.4/packages/webview_flutter/webview_flutter/lib/src/webview.dart#L342) is passed to `LinuxWebView.build()` as a callback. 44 | 1. `LinuxWebView.build()` returns `WebViewLinuxWidget`. 45 | 1. `WebViewLinuxWidget.initState()` is called by the Flutter Framework. 46 | 1. In `WebViewLinuxWidget.initState()`, `WebViewLinuxPlatformController` (extends `WebViewPlatformController`) is asynchronously initialized. 47 | 1. After initializing `WebViewLinuxPlatformController`, The `WebViewLinuxWidget` returns it to the given `onWebViewPlatformCreated` callback, that is, `_WebViewState._onWebViewPlatformCreated()`. 48 | 1. `_WebViewState._onWebViewPlatformCreated()` takes the `WebViewLinuxPlatformController`, creates a `WebViewController` with it, and passes the `WebViewController` to the `WebView.onWebViewCreated` callback. 49 | 1. The user obtains the `WebViewController` through the `WebView.onWebViewCreated` callback. 50 | * This `WebViewController` delegates operations to `WebViewLinuxPlatformController`. 51 | 52 | ## The Native Plugin Implementation (C++/CEF) 53 | 54 | The native implementation of the plugin uses CEF (Chromium Embedded Framework) as the underlying browser (see `../README.md` for the version of CEF) and consists of three main parts: 55 | 56 | * `FlutterLinuxWebviewPlugin` 57 | * The base part of the plugin. It handles the initialization and termination of the plugin, and is the connection point between the Dart-side method calls and `FlutterWebviewController`. 58 | * `FlutterWebviewController` 59 | * It provides the API to control a WebView, wrapping the CEF API. 60 | * `FlutterWebviewHandler` 61 | * It defines the behavior of a WebView. 62 | 63 | ### Initialization, method calls, termination, and the threads 64 | 65 | * The native plugin runs on the platform thread, which is the same thread on which the Flutter Engine runs. 66 | * When the Flutter application starts, `flutter_linux_webview_plugin_register_with_registrar()` located in `flutter_linux_webview_plugin.cc` is called to initialize this plugin. 67 | * Once the plugin is initialized, method calls from the Dart side come to `method_call_cb()` and are handled by `flutter_linux_webview_plugin_handle_method_call()`. 68 | * A user explicitly calls `LinuxWebViewPlugin.initialize()` (located in `lib/src/linux_webview_plugin.dart`) to start CEF before creating the first WebView. 69 | * `LinuxWebViewPlugin.initialize()` invokes `FlutterWebviewController::StartCef()` on the native side. 70 | * `FlutterWebviewController::StartCef()` creates and starts a new thread, the CEF UI thread, whose entry point is `FlutterWebviewController::CefMainThread()`. 71 | * `FlutterWebviewController::CefMainThread()` calls `CefInitialize()` and `CefRunMessageLoop()`, which starts CEF. (The thread is blocked by the message loop.) 72 | * `FlutterWebviewController` methods except `StartCef()` and `ShutdownCef()` must be executed in the CEF UI thread. 73 | * (**Prior to Flutter 3.10**) When the plugin object is destroyed, that is, when the application exits, `flutter_linux_webview_plugin_class_finalize()` is called, which calls `FlutterWebviewController::ShutdownCef()`. 74 | * (**Flutter 3.10 or later (as of 3.13)**) The user explicitly calls `LinuxWebViewPlugin.terminate()` when the application exits. It invokes `FlutterWebviewController::ShutdownCef()` on the native side. 75 | * In Flutter 3.10, [WidgetsBindingObserver.didRequestAppExit](https://api.flutter.dev/flutter/widgets/WidgetsBindingObserver/didRequestAppExit.html) API has been added. However, as a side effect of that change, it no longer calls the `flutter_linux_webview_plugin_class_finalize()/_dispose()`. So we need to have users explicitly call `LinuxWebViewPlugin.terminate()`. 76 | * ref. https://github.com/flutter/flutter/pull/121378 + https://github.com/flutter/engine/pull/40033#discussion_r1200216166 77 | * `FlutterWebviewController::ShutdownCef()` requests all running browsers to exit and waits for all browsers and the CEF UI thread to exit. 78 | 79 | ### Separate executables layout 80 | 81 | CEF runs using a browser process and sub-processes. This plugin executes the browser using the separate sub-process executable layout (ref. https://bitbucket.org/chromiumembedded/cef/wiki/GeneralUsage#markdown-header-separate-sub-process-executable). 82 | 83 | The sub-process executable is built with the name `flutter_webview_subprocess`, bundled with the Flutter app, and launched as needed. 84 | 85 | The source files for the sub-process executable are located in `linux/subprocess/`. 86 | 87 | ``` 88 | ├── linux/ 89 | │ ├── CMakeLists.txt 90 | │ ├── 91 | │ ├── subprocess/ 92 | │ │ ├── src/ 93 | │ │ │ ├── CMakeLists.txt 94 | │ │ │ ├── 95 | │ │ └── cef_distrib_patch/ 96 | │ │ └── build_flutter_webview_subprocess.patch 97 | │ └── / # to be downloaded and extracted 98 | │ ├── CMakeLists.txt # to be modified with `build_flutter_webview_subprocess.patch` 99 | │ └── ... # CEF headers, binaries, resources... 100 | ``` 101 | 102 | 103 | ## The build process for the plugin 104 | 105 | The build process is described in `linux/CMakeLists.txt` and is outlined below. 106 | 107 | First of all, this directory (`linux/`) is added using `add_subdirectory()` during the build configuration of the Flutter Linux app project. 108 | 109 | 1. Verifies that the string `include(flutter/ephemeral/.plugin_symlinks/flutter_linux_webview/linux/cmake/link_to_cef_library.cmake)` is included in the `CMakeLists.txt` of the app project. If it is not included, adds the string to the end of that file and shows a message to prompt the user to rebuild the app. 110 | - `linux/cmake/link_to_cef_library.cmake` contains a `target_link_libraries()` command for linking to `libcef.so`. 111 | - This setting is necessary because the plugin will hang in the `CefInitialize()` function if the Flutter app executable is not linked to `libcef.so`. 112 | 2. Downloads and extracts the CEF binary distribution (cef_binary_96.0.18+gfe551e4+chromium-96.0.4664.110_linux64_minimal) in the `linux/` directory. 113 | 3. Modifies the CEF binary distribution to prepare for building the sub-process executable. 114 | - Applies `linux/subprocess/cef_distrib_patch/build_flutter_webview_subprocess.patch` to `linux//CMakeLists.txt` to enable building for the `linux/subprocess/src/`. 115 | 4. The plugin (`libflutter_linux_webview.so` and `flutter_webview_subprocess`) is built under the `/plugins/flutter_linux_webview/` directory. 116 | 5. CEF binary files, CEF resource files, and the sub-process executable are bundled in `/bundle/lib`. 117 | --------------------------------------------------------------------------------