Web applications support with
the Chromium Embedded
Framework on AGL
Roger Zanoni
AGL AMM, 13.07.2023
Web applications support with the Chromium Embedded Framework on AGL
Roger Zanoni, Igalia
Agenda
● About
● Goals
● WAM Architecure recap
● Why CEF?
● What is CEF
● Demonstration
● Q&A
About Igalia
● Open Source Consultancy with HQ in Galicia, Spain
● 100+ engineers around the world
● Web rendering and browsers experience in Chromium, WebKit, WPE and Firefox,
Compilers, JavaScript engines (V8, JSC), Graphics, Multimedia, Kernel, Accessibility
● 2nd main contributor to Chrome, right after Google
● 2nd main contributor to WebKit, right after Apple
Web applications support with the Chromium Embedded Framework on AGL
Roger Zanoni, Igalia
Goals
● SPEC 3872 - Support WAM running on top of CEF
● 2023 Roadmap
Web applications support with the Chromium Embedded Framework on AGL
Roger Zanoni, Igalia
WAM
● WAM: an embedded web runtime history for LG webOS and
Automotive Grade Linux - FOSDEM 2023, José Dapena
● Web Applications Support on AGL - Previous AMM, March 2023
● Not framework specific. Any front-end framework allowed.
● Out-of-the-box compatibility with standard web APIs
● Built on top of chromium (webosose)
● Manages webapp life-cycle
● CPU usage optimization, status monitoring, memory management
Web applications support with the Chromium Embedded Framework on AGL
Roger Zanoni, Igalia
How does it work?
How does it work (CEF)?
● WebRuntime
int WebRuntimeCEF::Run(int argc, char** argv) {
…
CefRefPtr<CefApp> app;
if (!command_line->HasSwitch(kProcessType))
app = new WamCefBrowserHandler();
else {
auto process_type = command_line->GetSwitchValue(kProcessType);
if (process_type == kRendererProcess || process_type == kZygoteProcess)
app = new WamCefRenderHandler();
else
app = new WamCefUtilityHandler();
}
auto exit_code = CefExecuteProcess(main_args, app.get(), nullptr);
…
return 0;
}
How does it work (CEF)?
● WebApp/WebPage
class WebAppCEF : public WebAppBase, public CefWindowDelegate {
public:
WebAppCEF(std::shared_ptr<ApplicationDescription> app_desc);
...
void SuspendAppRendering() override {}
void ResumeAppRendering() override {}
bool IsFocused() const override { return false; }
void Resize(int width, int height) override;
...
class WebPageCEF : public WebPageBase,
public CefBrowserViewDelegate {
public:
WebPageCEF(std::shared_ptr<ApplicationDescription> app_desc, const std::string&
url);
...
wam::Url Url() const override { return wam::Url(""); }
std::string FailedUrl() const override { return ""; }
void LoadUrl(const std::string& url) override;
int Progress() const override { return 0; }
bool HasBeenShown() const override;
...
Web applications support with the Chromium Embedded Framework on AGL
Roger Zanoni, Igalia
WAM - CEF status
● Demo
● CEF as a WAM backend
● Used WAM implementation parts
○ Wayland window
○ Wayland extensions/agl shell
Web applications support with the Chromium Embedded Framework on AGL
Roger Zanoni, Igalia
What is CEF
● Framework for facilitating embedded browser use-cases
○ Hides chromium complexity and offers an API
○ Generates a library and resources
○ Embedding in existing applications, running it's own browser
processes and managing windows, off-screen rendering
● Keeps up-to-date with the current milestone releases (with around 1
week delay)
Top-level architecture description can be found on CEF wiki
List of applications using CEF
CEF on bitbucket
Web applications support with the Chromium Embedded Framework on AGL
Roger Zanoni, Igalia
Similar Projects
● WPE (webkit)
● webview (webkit)
● webOS OSE WAM (chromium)
● Qt WebEngine (chromium)
● Crosswalk (chromium - discontinued)
● XULRunner (mozilla platform - discontinued)
Web applications support with the Chromium Embedded Framework on AGL
Roger Zanoni, Igalia
Why CEF?
● WAM upgrade model
● Toolkit independence
● Release cycle
● Security
○ ChromeOS LTS
● Current PoC built on top of the AGL WAM fork
Web applications support with the Chromium Embedded Framework on AGL
Roger Zanoni, Igalia
Project structure
● cef has a collection of scripts to automate fetching and patching
● adds itself as a path on chromium root, adding new targets
● generates libcef, a sandbox executable and uses chromium
resource files (locales, artifacts)
● libcef exposes a C API and provides a C++ Wrapper library
○ c -> cpp / cpp -> c automatic translation
How CEF works
● Provides two different runtimes
○ Alloy runtime
■ Based on "content" layer
○ Chrome runtime
■ Based on "chrome" layer
● Can use Views framework or the native platform framework to
manage windows
● For each runtime, CEF implements a different process and
browser bootstrapping logic
Javascript Bindings
● Wiki
void WamCefRenderHandler::OnContextCreated(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Context> context) {
CefRefPtr<CefV8Value> app_service = CefV8Value::CreateObject(nullptr, nullptr);
CefRefPtr<CefV8Value> start = CefV8Value::CreateFunction("start", this);
app_service->SetValue("start", start, V8_PROPERTY_ATTRIBUTE_NONE);
CefRefPtr<CefV8Value> get_applications = CefV8Value::CreateFunction("getApplications", this);
app_service->SetValue("getApplications", get_applications, V8_PROPERTY_ATTRIBUTE_NONE);
CefRefPtr<CefV8Value> global = context->GetGlobal(); // window object
CefRefPtr<CefV8Value> navigator = global->GetValue("navigator");
navigator->SetValue("appService", app_service, V8_PROPERTY_ATTRIBUTE_NONE);
}
Javascript Bindings
bool WamCefRenderHandler::Execute(const CefString& name,
CefRefPtr<CefV8Value> object,
const CefV8ValueList& arguments,
CefRefPtr<CefV8Value>& retval,
CefString& exception) {
if (name == "start") {
if (arguments.size() != 1 || !arguments[0]->IsString()) {
return false;
}
std::string app_id = arguments[0]->GetStringValue();
Start(app_id);
return true;
} else if (name == "getApplications") {
if (arguments.size() != 2 ||
!arguments[0]->IsBool() ||
!arguments[1]->IsFunction()) {
return false;
}
GetApplications(arguments[0]->GetBoolValue(), arguments[1]);
return true;
}
return false;
}
Web applications support with the Chromium Embedded Framework on AGL
Roger Zanoni, Igalia
CEF IPC
● Wiki
void WamCefRenderHandler::Start(const std::string &app_id) {
LOG(INFO) << "Sending start call to browser process with app_id " << app_id;
CefRefPtr<CefProcessMessage> message = CefProcessMessage::Create("start");
CefRefPtr<CefListValue> args = message->GetArgumentList();
args->SetString(0, app_id);
auto context = CefV8Context::GetCurrentContext();
context->GetFrame()->SendProcessMessage(PID_BROWSER, message);
}
CEF IPC
bool WamCefClient::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message) {
std::string message_name = message->GetName();
CefRefPtr<CefListValue> args = message->GetArgumentList();
if (message_name == "start") {
…
std::string app_id = args->GetString(0);
applauncher_.Start(app_id);
return true;
} else if (message_name == "get_applications") {
…
bool only_graphical = args->GetBool(0);
applauncher_.GetApplications(browser, only_graphical);
return true;
}
return false;
}
Web applications support with the Chromium Embedded Framework on AGL
Roger Zanoni, Igalia
Future work
● Bugfixing
● Improve application life-cycle management
● Finish adapting webapp demos
● Webapp bundling
● Deprecate WaylandWindow interface to agl_shell
○ OSR?
● Browser app
Web Applications Support with the Chromium Embedded Framework on AGL

Web Applications Support with the Chromium Embedded Framework on AGL

  • 1.
    Web applications supportwith the Chromium Embedded Framework on AGL Roger Zanoni AGL AMM, 13.07.2023
  • 2.
    Web applications supportwith the Chromium Embedded Framework on AGL Roger Zanoni, Igalia Agenda ● About ● Goals ● WAM Architecure recap ● Why CEF? ● What is CEF ● Demonstration ● Q&A
  • 3.
    About Igalia ● OpenSource Consultancy with HQ in Galicia, Spain ● 100+ engineers around the world ● Web rendering and browsers experience in Chromium, WebKit, WPE and Firefox, Compilers, JavaScript engines (V8, JSC), Graphics, Multimedia, Kernel, Accessibility ● 2nd main contributor to Chrome, right after Google ● 2nd main contributor to WebKit, right after Apple
  • 4.
    Web applications supportwith the Chromium Embedded Framework on AGL Roger Zanoni, Igalia Goals ● SPEC 3872 - Support WAM running on top of CEF ● 2023 Roadmap
  • 5.
    Web applications supportwith the Chromium Embedded Framework on AGL Roger Zanoni, Igalia WAM ● WAM: an embedded web runtime history for LG webOS and Automotive Grade Linux - FOSDEM 2023, José Dapena ● Web Applications Support on AGL - Previous AMM, March 2023 ● Not framework specific. Any front-end framework allowed. ● Out-of-the-box compatibility with standard web APIs ● Built on top of chromium (webosose) ● Manages webapp life-cycle ● CPU usage optimization, status monitoring, memory management
  • 6.
    Web applications supportwith the Chromium Embedded Framework on AGL Roger Zanoni, Igalia How does it work?
  • 7.
    How does itwork (CEF)? ● WebRuntime int WebRuntimeCEF::Run(int argc, char** argv) { … CefRefPtr<CefApp> app; if (!command_line->HasSwitch(kProcessType)) app = new WamCefBrowserHandler(); else { auto process_type = command_line->GetSwitchValue(kProcessType); if (process_type == kRendererProcess || process_type == kZygoteProcess) app = new WamCefRenderHandler(); else app = new WamCefUtilityHandler(); } auto exit_code = CefExecuteProcess(main_args, app.get(), nullptr); … return 0; }
  • 8.
    How does itwork (CEF)? ● WebApp/WebPage class WebAppCEF : public WebAppBase, public CefWindowDelegate { public: WebAppCEF(std::shared_ptr<ApplicationDescription> app_desc); ... void SuspendAppRendering() override {} void ResumeAppRendering() override {} bool IsFocused() const override { return false; } void Resize(int width, int height) override; ... class WebPageCEF : public WebPageBase, public CefBrowserViewDelegate { public: WebPageCEF(std::shared_ptr<ApplicationDescription> app_desc, const std::string& url); ... wam::Url Url() const override { return wam::Url(""); } std::string FailedUrl() const override { return ""; } void LoadUrl(const std::string& url) override; int Progress() const override { return 0; } bool HasBeenShown() const override; ...
  • 9.
    Web applications supportwith the Chromium Embedded Framework on AGL Roger Zanoni, Igalia WAM - CEF status ● Demo ● CEF as a WAM backend ● Used WAM implementation parts ○ Wayland window ○ Wayland extensions/agl shell
  • 10.
    Web applications supportwith the Chromium Embedded Framework on AGL Roger Zanoni, Igalia What is CEF ● Framework for facilitating embedded browser use-cases ○ Hides chromium complexity and offers an API ○ Generates a library and resources ○ Embedding in existing applications, running it's own browser processes and managing windows, off-screen rendering ● Keeps up-to-date with the current milestone releases (with around 1 week delay) Top-level architecture description can be found on CEF wiki List of applications using CEF CEF on bitbucket
  • 11.
    Web applications supportwith the Chromium Embedded Framework on AGL Roger Zanoni, Igalia Similar Projects ● WPE (webkit) ● webview (webkit) ● webOS OSE WAM (chromium) ● Qt WebEngine (chromium) ● Crosswalk (chromium - discontinued) ● XULRunner (mozilla platform - discontinued)
  • 12.
    Web applications supportwith the Chromium Embedded Framework on AGL Roger Zanoni, Igalia Why CEF? ● WAM upgrade model ● Toolkit independence ● Release cycle ● Security ○ ChromeOS LTS ● Current PoC built on top of the AGL WAM fork
  • 13.
    Web applications supportwith the Chromium Embedded Framework on AGL Roger Zanoni, Igalia Project structure ● cef has a collection of scripts to automate fetching and patching ● adds itself as a path on chromium root, adding new targets ● generates libcef, a sandbox executable and uses chromium resource files (locales, artifacts) ● libcef exposes a C API and provides a C++ Wrapper library ○ c -> cpp / cpp -> c automatic translation
  • 14.
    How CEF works ●Provides two different runtimes ○ Alloy runtime ■ Based on "content" layer ○ Chrome runtime ■ Based on "chrome" layer ● Can use Views framework or the native platform framework to manage windows ● For each runtime, CEF implements a different process and browser bootstrapping logic
  • 15.
    Javascript Bindings ● Wiki voidWamCefRenderHandler::OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) { CefRefPtr<CefV8Value> app_service = CefV8Value::CreateObject(nullptr, nullptr); CefRefPtr<CefV8Value> start = CefV8Value::CreateFunction("start", this); app_service->SetValue("start", start, V8_PROPERTY_ATTRIBUTE_NONE); CefRefPtr<CefV8Value> get_applications = CefV8Value::CreateFunction("getApplications", this); app_service->SetValue("getApplications", get_applications, V8_PROPERTY_ATTRIBUTE_NONE); CefRefPtr<CefV8Value> global = context->GetGlobal(); // window object CefRefPtr<CefV8Value> navigator = global->GetValue("navigator"); navigator->SetValue("appService", app_service, V8_PROPERTY_ATTRIBUTE_NONE); }
  • 16.
    Javascript Bindings bool WamCefRenderHandler::Execute(constCefString& name, CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval, CefString& exception) { if (name == "start") { if (arguments.size() != 1 || !arguments[0]->IsString()) { return false; } std::string app_id = arguments[0]->GetStringValue(); Start(app_id); return true; } else if (name == "getApplications") { if (arguments.size() != 2 || !arguments[0]->IsBool() || !arguments[1]->IsFunction()) { return false; } GetApplications(arguments[0]->GetBoolValue(), arguments[1]); return true; } return false; }
  • 17.
    Web applications supportwith the Chromium Embedded Framework on AGL Roger Zanoni, Igalia CEF IPC ● Wiki void WamCefRenderHandler::Start(const std::string &app_id) { LOG(INFO) << "Sending start call to browser process with app_id " << app_id; CefRefPtr<CefProcessMessage> message = CefProcessMessage::Create("start"); CefRefPtr<CefListValue> args = message->GetArgumentList(); args->SetString(0, app_id); auto context = CefV8Context::GetCurrentContext(); context->GetFrame()->SendProcessMessage(PID_BROWSER, message); }
  • 18.
    CEF IPC bool WamCefClient::OnProcessMessageReceived(CefRefPtr<CefBrowser>browser, CefRefPtr<CefFrame> frame, CefProcessId source_process, CefRefPtr<CefProcessMessage> message) { std::string message_name = message->GetName(); CefRefPtr<CefListValue> args = message->GetArgumentList(); if (message_name == "start") { … std::string app_id = args->GetString(0); applauncher_.Start(app_id); return true; } else if (message_name == "get_applications") { … bool only_graphical = args->GetBool(0); applauncher_.GetApplications(browser, only_graphical); return true; } return false; }
  • 19.
    Web applications supportwith the Chromium Embedded Framework on AGL Roger Zanoni, Igalia Future work ● Bugfixing ● Improve application life-cycle management ● Finish adapting webapp demos ● Webapp bundling ● Deprecate WaylandWindow interface to agl_shell ○ OSR? ● Browser app