Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Linux builds and upgrade CEF #148

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions common/webview_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <iostream>
#include <chrono>
#include <unordered_map>
#include <cstdint>

#include "include/base/cef_callback.h"
#include "include/cef_app.h"
Expand All @@ -18,6 +19,18 @@
#include "include/wrapper/cef_closure_task.h"
#include "include/wrapper/cef_helpers.h"

#include <sstream>

namespace stringpatch
{
template < typename T > std::string to_string( const T& n )
{
std::ostringstream stm ;
stm << n ;
return stm.str() ;
}
}

#include "webview_js_handler.h"

namespace {
Expand Down Expand Up @@ -67,7 +80,7 @@ bool WebviewHandler::OnProcessMessageReceived(
}

onJavaScriptChannelMessage(
fun_name,param,std::to_string(js_callback_id), browser->GetIdentifier(), std::to_string(frame->GetIdentifier()));
fun_name,param,stringpatch::to_string(js_callback_id), browser->GetIdentifier(), stringpatch::to_string(frame->GetIdentifier()));
}
else if(message_name == kEvaluateCallbackMessage){
CefString callbackId = message->GetArgumentList()->GetString(0);
Expand Down Expand Up @@ -543,8 +556,12 @@ void WebviewHandler::sendJavaScriptChannelCallBack(const bool error, const std::
args->SetString(2, result);
auto bit = browser_map_.find(browserId);
if(bit != browser_map_.end()){
int64_t frameIdInt = atoll(frameId.c_str());

CefRefPtr<CefFrame> frame = bit->second.browser->GetMainFrame();
if (frame->GetIdentifier() == atoll(frameId.c_str()))

// GetIdentifier().ToString() does not work on MacOS
if (std::stoll(stringpatch::to_string(frame->GetIdentifier())) == frameIdInt)
{
frame->SendProcessMessage(PID_RENDERER, message);
}
Expand Down
4 changes: 3 additions & 1 deletion common/webview_js_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include <functional>
#include <memory>
#include <cstdint>


static const char kJSCallCppFunctionMessage[] = "JSCallCppFunction"; //js call c++ message
static const char kExecuteJsCallbackMessage[] = "ExecuteJsCallback"; //c++ call js message
Expand All @@ -29,7 +31,7 @@ class CefJSBridge
void RemoveCallbackFuncWithFrame(CefRefPtr<CefFrame> frame);
bool ExecuteJSCallbackFunc(int js_callback_id, bool has_error, const CefString& json_result);
private:
uint32 js_callback_id_ = 0;
uint32_t js_callback_id_ = 0;
RenderCallbackMap render_callback_;
StartRequestCallbackMap startRequest_callback_;
};
Expand Down
6 changes: 5 additions & 1 deletion common/webview_value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <memory>
#include <string.h>
#include <inttypes.h>
#include <cstdlib>

#if defined(_MSC_VER)
#pragma warning(disable: 4996)
Expand All @@ -12,6 +13,9 @@ typedef SSIZE_T ssize_t;
#define return_val_if_fail(p, ret) if(!(p)) return (ret)
#define return_if_fail(p) if(!(p)) return

using std::malloc;
using std::free;

struct webview_value{
WValueType type;
int ref_count;
Expand Down Expand Up @@ -914,4 +918,4 @@ char* webview_value_to_string(WValue* value) {
default:
return strdup("<unknown type>");
}
}
}
2 changes: 2 additions & 0 deletions linux/webview_cef_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ FLUTTER_PLUGIN_EXPORT gboolean processKeyEventForCEF(GtkWidget *widget, GdkEvent
if(system("xclip -o -sel clipboard | xclip -i -sel clipboard &>/dev/null") == 0){
res = system("xclip -o -sel clipboard | xclip -i &>/dev/null");
}
// Suppress unused variable warning
(void)res;
}
else {
// FIXME: fix for non BMP chars
Expand Down
12 changes: 7 additions & 5 deletions third/download.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
message(WARNING "current system is Linux")
if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "aarch64")
set(cef_prebuilt_path "https://github.com/hlwhl/webview_cef/releases/download/prebuilt_cef_bin_linux/cef_binary_114.2.9+g1a97a28+chromium-114.0.5735.91_linuxarm64.zip")
set(cef_prebuilt_version "cef_binary_114.2.9+g1a97a28+chromium-114.0.5735.91_linuxarm64")
else()
set(cef_prebuilt_path "https://github.com/hlwhl/webview_cef/releases/download/prebuilt_cef_bin_linux/cef_binary_114.2.9+g1a97a28+chromium-114.0.5735.91_linux64.zip")
set(cef_prebuilt_path "https://cef-builds.spotifycdn.com/cef_binary_128.4.12%2Bg1d7a1f9%2Bchromium-128.0.6613.138_linux64.tar.bz2")
set(cef_prebuilt_version "cef_binary_128.4.12%2Bg1d7a1f9%2Bchromium-128.0.6613.138_linux64")
endif()
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
message(WARNING "current system is Windows")
set(cef_prebuilt_path "https://github.com/hlwhl/webview_cef/releases/download/prebuilt_cef_bin_linux/webview_cef_bin_0.0.2_101.0.18+chromium-101.0.4951.67_windows64.zip")
set(cef_prebuilt_version "webview_cef_bin_0.0.2_101.0.18+chromium-101.0.4951.67_windows64")
# elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
# message(STATUS "current system is MacOS")
# set(cef_prebuilt_path "")
Expand Down Expand Up @@ -35,7 +38,7 @@ function(extract_file filename extract_dir)
get_filename_component(contents ${contents} ABSOLUTE)

file(INSTALL "${contents}/" DESTINATION ${extract_dir})

file(REMOVE_RECURSE ${temp_dir})
endfunction()

Expand All @@ -55,10 +58,8 @@ function(prepare_prebuilt_files filepath)
message(WARNING "No ${filepath}/version.txt found")
set(need_download TRUE)
else()
download_file(${cef_prebuilt_version_path} ${filepath}/new_version.txt)
file(READ ${filepath}/version.txt local_version)
file(READ ${filepath}/new_version.txt new_version)
if(local_version STREQUAL new_version)
if(local_version STREQUAL cef_prebuilt_version)
message(WARNING "No need to update ${filepath}")
else()
set(need_download TRUE)
Expand All @@ -73,6 +74,7 @@ function(prepare_prebuilt_files filepath)
download_file(${cef_prebuilt_path} ${CMAKE_CURRENT_SOURCE_DIR}/prebuilt.zip)
file(MAKE_DIRECTORY ${filepath})
extract_file(${CMAKE_CURRENT_SOURCE_DIR}/prebuilt.zip ${filepath})
file(WRITE "${filepath}/version.txt" "${cef_prebuilt_version}")
file(REMOVE_RECURSE ${CMAKE_CURRENT_SOURCE_DIR}/prebuilt.zip)
endif()
endfunction(prepare_prebuilt_files)