Skip to content

Commit

Permalink
draft(test): find libchromium-efl-impl.so
Browse files Browse the repository at this point in the history
We need to find the exact location of libchromium-efl-impl.so.
  • Loading branch information
JSUYA committed Jan 17, 2024
1 parent ab0e905 commit 141ec61
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 14 deletions.
10 changes: 5 additions & 5 deletions packages/webview_flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ Page resource error:
''');
},
onNavigationRequest: (NavigationRequest request) {
if (request.url.startsWith('https://www.youtube.com/')) {
debugPrint('blocking navigation to ${request.url}');
return NavigationDecision.prevent;
}
// if (request.url.startsWith('https://www.youtube.com/')) {
// debugPrint('blocking navigation to ${request.url}');
// return NavigationDecision.prevent;
// }
debugPrint('allowing navigation to ${request.url}');
return NavigationDecision.navigate;
},
Expand All @@ -162,7 +162,7 @@ Page resource error:
);
},
)
..loadRequest(Uri.parse('https://flutter.dev'));
..loadRequest(Uri.parse('https://google.com'));
}

@override
Expand Down
47 changes: 46 additions & 1 deletion packages/webview_flutter/tizen/src/ewk_internal_api_binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

#include "ewk_internal_api_binding.h"

#include <EWebKit.h>
#include <dlfcn.h>

#include <string>

EwkInternalApiBinding::EwkInternalApiBinding() {
handle_ = dlopen("libchromium-ewk.so", RTLD_LAZY);
}
Expand All @@ -14,6 +17,40 @@ EwkInternalApiBinding::~EwkInternalApiBinding() {
if (handle_) {
dlclose(handle_);
}

if (handle_impl_) {
dlclose(handle_impl_);
}
}

void EwkInternalApiBinding::EwkImpleDlopen() {
std::string path[6] = {
"/usr/apps/org.tizen.chromium-efl",
"/opt/usr/globalapps/org.tizen.chromium-efl",
"/opt/usr/globalapps/org.tizen.chromium-efl-upgrade",
"/usr/share/chromium-efl/update",
"/usr/share/chromium-efl/",
"/usr/share/chromium-efl/upgrade",
};

for (int i = 0; i < 6; i++) {
std::string p = path[i] + "/lib/libchromium-impl.so";
handle_impl_ = dlopen(p.c_str(), RTLD_LAZY);
if (!handle_impl_) {
log += "\n load fail " + p + "\n";
} else {
log += "\n load success " + p + "\n";
break;
}
}
}

void* EwkInternalApiBinding::EwkImplDlsym(const char* function_name) {
if (!handle_impl_) return nullptr;

void* function_addr = dlsym(handle_impl_, function_name);

return function_addr;
}

bool EwkInternalApiBinding::Initialize() {
Expand All @@ -37,6 +74,8 @@ bool EwkInternalApiBinding::Initialize() {
dlsym(handle_, "ewk_view_key_events_enabled_set"));
view.SupportVideoHoleSet = reinterpret_cast<EwkViewSupportVideoHoleSetFnPtr>(
dlsym(handle_, "ewk_view_set_support_video_hole"));
view.AddWithContext = reinterpret_cast<EwkViewAddWithContextFnPtr>(
dlsym(handle_, "ewk_view_add_with_context"));

// ewk_main
main.SetArguments = reinterpret_cast<EwkSetArgumentsFnPtr>(
Expand All @@ -50,6 +89,12 @@ bool EwkInternalApiBinding::Initialize() {
reinterpret_cast<EwkSettingsImePanelEnabledSetFnPtr>(
dlsym(handle_, "ewk_settings_ime_panel_enabled_set"));

settings.ContextDefaultGet = reinterpret_cast<EwkContextDefaultGetFnPtr>(
dlsym(handle_, "ewk_context_default_get"));

settings.ContextNew =
reinterpret_cast<EwkContextNewFnPtr>(dlsym(handle_, "ewk_context_new"));

// ewk_console_message
console_message.LevelGet = reinterpret_cast<EwkConsoleMessageLevelGetFnPtr>(
dlsym(handle_, "ewk_console_message_level_get"));
Expand All @@ -63,7 +108,7 @@ bool EwkInternalApiBinding::Initialize() {
return view.SetBackgroundColor && view.FeedTouchEvent && view.SendKeyEvent &&
view.OffscreenRenderingEnabledSet && view.ImeWindowSet &&
view.KeyEventsEnabledSet && view.SupportVideoHoleSet &&
main.SetArguments && main.SetVersionPolicy &&
view.AddWithContext && main.SetArguments && main.SetVersionPolicy &&
settings.ImePanelEnabledSet && console_message.LevelGet &&
console_message.TextGet && console_message.LineGet &&
console_message.SourceGet;
Expand Down
17 changes: 16 additions & 1 deletion packages/webview_flutter/tizen/src/ewk_internal_api_binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include <Evas.h>

#include <string>

typedef enum {
EWK_TOUCH_START,
EWK_TOUCH_MOVE,
Expand Down Expand Up @@ -41,6 +43,8 @@ typedef Eina_Bool (*EwkViewSupportVideoHoleSetFnPtr)(Evas_Object* obj,
Eina_Bool enabled,
Eina_Bool boo);

typedef Evas_Object* (*EwkViewAddWithContextFnPtr)(Evas* e, void* context);

typedef struct {
EwkViewBgColorSetFnPtr SetBackgroundColor = nullptr;
EwkViewFeedTouchEventFnPtr FeedTouchEvent = nullptr;
Expand All @@ -50,10 +54,11 @@ typedef struct {
EwkViewImeWindowSetFnPtr ImeWindowSet = nullptr;
EwkViewKeyEventsEnabledSetFnPtr KeyEventsEnabledSet = nullptr;
EwkViewSupportVideoHoleSetFnPtr SupportVideoHoleSet = nullptr;
EwkViewAddWithContextFnPtr AddWithContext = nullptr;
} EwkViewProcTable;

typedef void (*EwkSetArgumentsFnPtr)(int argc, char** argv);
typedef void (*EwkSetVersionPolicyFnPtr)(int preference);
typedef int (*EwkSetVersionPolicyFnPtr)(int preference);

typedef struct {
EwkSetArgumentsFnPtr SetArguments = nullptr;
Expand All @@ -63,9 +68,13 @@ typedef struct {
typedef struct Ewk_Settings Ewk_Settings;
typedef void (*EwkSettingsImePanelEnabledSetFnPtr)(Ewk_Settings* settings,
Eina_Bool enabled);
typedef void* (*EwkContextDefaultGetFnPtr)();
typedef void* (*EwkContextNewFnPtr)();

typedef struct {
EwkSettingsImePanelEnabledSetFnPtr ImePanelEnabledSet = nullptr;
EwkContextDefaultGetFnPtr ContextDefaultGet = nullptr;
EwkContextNewFnPtr ContextNew = nullptr;
} EwkSettingsProcTable;

typedef struct _Ewk_Console_Message Ewk_Console_Message;
Expand Down Expand Up @@ -109,15 +118,21 @@ class EwkInternalApiBinding {

bool Initialize();

void EwkImpleDlopen();
void* EwkImplDlsym(const char* function_name);

EwkViewProcTable view;
EwkMainProcTable main;
EwkSettingsProcTable settings;
EwkConsoleMessageProcTable console_message;

std::string log = "";

private:
EwkInternalApiBinding();

void* handle_ = nullptr;
void* handle_impl_ = nullptr;
};

#endif // FLUTTER_PLUGIN_EWK_INTERNAL_API_BINDING_H_
63 changes: 56 additions & 7 deletions packages/webview_flutter/tizen/src/webview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "webview.h"

#include <Ecore_Evas.h>
#include <Elementary.h>
#include <app_common.h>
#include <flutter/standard_method_codec.h>
#include <flutter_texture_registrar.h>
Expand Down Expand Up @@ -104,6 +105,8 @@ WebView::WebView(flutter::PluginRegistrar* registrar, int view_id,
return;
}

log += EwkInternalApiBinding::GetInstance().log;

tbm_pool_ = std::make_unique<SingleBufferPool>(width, height);

texture_variant_ =
Expand Down Expand Up @@ -288,22 +291,67 @@ void WebView::SetDirection(int direction) {
}

void WebView::InitWebView() {
EwkInternalApiBinding::GetInstance().main.SetVersionPolicy(1);
bool impl = false;

if (EwkInternalApiBinding::GetInstance().main.SetVersionPolicy(1) ==
0) { // 1 or 0.
EwkInternalApiBinding::GetInstance().EwkImpleDlopen();
log += "ewk_set_version_policy fail\n";
typedef int (*ewk_set_version_policy_ptr_t)(int);
ewk_set_version_policy_ptr_t _ewk_set_version_policy =
reinterpret_cast<ewk_set_version_policy_ptr_t>(
EwkInternalApiBinding::GetInstance().EwkImplDlsym(
"ewk_set_version_policy"));
if (_ewk_set_version_policy) {
impl = true;
log += "\n _ewk_set_version_policy impl function load result : " +
std::to_string(_ewk_set_version_policy(1)) + +"\n";
} else {
log += "\n _ewk_set_version_policy impl function load fail\n";
}
} else {
EwkInternalApiBinding::GetInstance().EwkImpleDlopen();
log += "ewk_set_version_policy success\n";
}

char* chromium_argv[] = {
const_cast<char*>("--disable-pinch"),
const_cast<char*>("--js-flags=--expose-gc"),
const_cast<char*>("--impl-library-upgrade"),
const_cast<char*>("--single-process"),
const_cast<char*>("--no-zygote"),
};
int chromium_argc = sizeof(chromium_argv) / sizeof(chromium_argv[0]);
EwkInternalApiBinding::GetInstance().main.SetArguments(chromium_argc,
chromium_argv);

ewk_init();
if (impl) {
typedef int (*ewk_init_ptr_t)(void);
ewk_init_ptr_t _ewk_init = reinterpret_cast<ewk_init_ptr_t>(
EwkInternalApiBinding::GetInstance().EwkImplDlsym("ewk_init"));
if (!_ewk_init) {
log += "\n ewk_init function load fail\n";
return;
}
log += "ewk_init count " + std::to_string(_ewk_init()) + "\n";
} else {
log += "ewk_init count " + std::to_string(ewk_init()) + "\n";
}

Ecore_Evas* evas = ecore_evas_new("wayland_egl", 0, 0, 1, 1, 0);
Ewk_Context* default_context = static_cast<Ewk_Context*>(
EwkInternalApiBinding::GetInstance().settings.ContextDefaultGet());
if (!default_context) {
log += "ewk default context is null\n";
} else {
log += "ewk default context is exist\n";
}

webview_instance_ = ewk_view_add(ecore_evas_get(evas));
if (!webview_instance_) {
log += "webview_instance_ is null\n";
}

ecore_evas_focus_set(evas, true);
ewk_view_focus_set(webview_instance_, true);
EwkInternalApiBinding::GetInstance().view.OffscreenRenderingEnabledSet(
Expand Down Expand Up @@ -354,11 +402,12 @@ void WebView::InitWebView() {

void WebView::HandleWebViewMethodCall(const FlMethodCall& method_call,
std::unique_ptr<FlMethodResult> result) {
if (!webview_instance_) {
result->Error("Invalid operation",
"The webview instance has not been initialized.");
return;
}
// if (!webview_instance_) {
result->Error("Invalid operation",
"test log + \n" + log + "\nBind log\n" +
EwkInternalApiBinding::GetInstance().log);
// return;
// }

const std::string& method_name = method_call.method_name();
const flutter::EncodableValue* arguments = method_call.arguments();
Expand Down
2 changes: 2 additions & 0 deletions packages/webview_flutter/tizen/src/webview.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class WebView : public PlatformView {
std::unique_ptr<flutter::TextureVariant> texture_variant_;
std::mutex mutex_;
std::unique_ptr<BufferPool> tbm_pool_;

std::string log;
};

#endif // FLUTTER_PLUGIN_WEBVIEW_H_

0 comments on commit 141ec61

Please sign in to comment.