Discuz! Board

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 975|回复: 0
打印 上一主题 下一主题

libcef-框架架构中概念介绍-命令行参数-元素布局-应用程序结构(二)

[复制链接]

1228

主题

1997

帖子

7586

积分

认证用户组

Rank: 5Rank: 5

积分
7586
跳转到指定楼层
楼主
发表于 2023-2-3 18:33:47 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
文章目录
1.命令行参数
2.应用布局
2.1 windows
2.2 linux
2.3 MacOS
3.应用结构
3.1 入口函数
3.2 单个可执行文件
3.3 单独的子进程可执行文件
4.作者答疑
1.命令行参数
  CEF3 和 Chromium 中的许多功能可以使用命令行参数进行配置。这些参数采用“–some-argument[=optional-param]”的形式,并通过 CefExecuteProcess() 和 CefMainArgs 结构传递到 CEF(请参阅下面的“应用程序结构”部分)。

  要在将 CefSettings 结构传递到 CefInitialize() 之前,禁用来自命令行的参数处理,请将 CefSettings.command_line_args_disabled 设置为 true。

  要在主机应用程序中指定 CEF/Chromium 命令行参数,请实现 CefApp::OnBeforeCommandLineProcessing() 方法。要将特定于应用程序的(非 CEF/Chromium)命令行参数传递给子进程,请实现 CefBrowserProcessHandler::OnBeforeChildProcessLaunch() 方法。有关如何发现受支持的 CEF/Chromium 命令行开关的更多信息,请参阅shared/common/client_switches.cc 中的注释。

2.应用布局
2.1 windows
  在 Windows 上,默认布局将 libcef 库和相关资源放在应用程序可执行文件旁边。2623 分支的目录结构如下所示:

Application/
    cefclient.exe <= cefclient 应用程序可执行文件
    libcef.dll <= 主 CEF 库
    icudtl.dat <= unicode 支持数据
    libEGL.dll、libGLESv2.dll、... <= 加速合成支持库
    cef.pak、devtools_resources.pak , ... <= 非本地化资源和字符串
    natives_blob.bin, snapshot_blob.bin <= V8 初始快照
    语言环境/
        en-US.pak, ... <= 特定于语言环境的资源和字符串
1
2
3
4
5
6
7
8
9
  可以使用 CefSettings 结构自定义 CEF 库和资源文件的位置(有关详细信息,请参阅 README.txt 文件或“CefSettings”部分)。Windows 上的 cefclient 应用程序通过cefclient/resources/win/cefclient.rc 中的 BINARY 资源类型编译资源,但应用程序也可以轻松地从本地文件系统加载资源。

2.2 linux
  在 Linux 上,默认布局将 libcef 库和相关资源放在应用程序可执行文件旁边。但是请注意,libcef.so 在客户端发行版中的位置与它在您自己构建的二进制发行版中的位置之间存在差异。该位置取决于构建应用程序可执行文件时链接器 rpath 值的设置方式。例如,值“-Wl,-rpath,”。(“.”表示当前目录)将允许您将 libcef.so 放在应用程序可执行文件旁边。也可以使用 LD_LIBRARY_PATH 环境变量指定 libcef.so 的路径。2623 分支的目录结构如下所示:

Application/
    cefclient <= cefclient application executable
    chrome-sandbox <= sandbox support binary
    libcef.so <= main CEF library
    icudtl.dat <= unicode support data
    cef.pak, devtools_resources.pak, ... <= 非本地化资源和字符串
    natives_blob.bin、snapshot_blob.bin <= V8 初始快照
    语言环境/
        en-US.pak、... <= 特定于语言环境的资源和字符串
    文件/
        binding.html、... <= cefclient 应用程序资源
1
2
3
4
5
6
7
8
9
10
11
  CEF 库和资源文件的位置可以使用 CefSettings 结构进行自定义(有关详细信息,请参阅“CefSettings”部分的 README.txt 文件)

2.3 MacOS
  MacOS 上的应用程序(应用程序包)布局由 Chromium 实现强制要求,因此不是很灵活。2623 分支的目录结构如下所示:

cefclient.app/
    Contents/
        Frameworks/
            Chromium Embedded Framework.framework/
                Chromium Embedded Framework <= 主应用程序库
                Resources/
                    cef.pak, devtools_resources.pak, ... <= 非本地化资源和字符串
                    icudtl.dat <= unicode 支持数据
                    natives_blob.bin、snapshot_blob.bin <= V8 初始快照
                    en.lproj/、... <= 特定于语言环境的资源和字符串
            cefclient Helper.app/
                Contents/
                    Info.plist
                    MacOS/
                        cefclient Helper <= helper 可执行文件
                    Pkginfo
        Info.plist
        MacOS/
            cefclient <= cefclient 应用程序可执行文件
        Pkginfo
        Resources/
binding.html             , ... <= cefclient 应用程序资源

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  “Chromium Embedded Framework.framework”是一个包含所有 CEF 二进制文件和资源的无版本框架。可执行文件(cefclient、cefclient Helper 等)按此处所述动态加载 CEF 框架。“cefclient Helper”应用程序用于执行具有不同特性的单独进程(渲染器、插件等)。它需要有一个单独的应用程序包和 Info.plist 文件,以便除其他外,它不显示停靠栏图标。

3.应用结构
  每个 CEF3 应用程序都具有相同的通用结构。

提供初始化 CEF 并运行子进程可执行逻辑或 CEF 消息循环的入口点函数。
提供CefApp的实现来处理特定于进程的回调。
提供CefClient的实现来处理特定于浏览器实例的回调。
调用 CefBrowserHost::CreateBrowser() 以创建浏览器实例并使用CefLifeSpanHandler管理浏览器生命周期。
3.1 入口函数
  如“进程”部分所述,CEF3 应用程序将运行多个进程。进程可以全部使用相同的可执行文件,也可以为子进程指定单独的可执行文件。进程的执行从入口点函数开始。针对 Windows、Linux 和 Mac OS-X 的完整平台特定示例分别在cefclient/cefclient_win.cc、cefclient/cefclient_gtk.cc和cefclient/cefclient_mac.mm 中可用。

  启动子进程时,CEF 将使用命令行指定配置信息,该信息必须通过 CefMainArgs 结构传递到 CefExecuteProcess 函数中。CefMainArgs 的定义是特定于平台的。在 Linux 和 MacOS 上,它接受传递到main() 函数的 argc 和 argv 值。

CefMainArgs main_args(argc, argv);
1
  在 Windows 上,它接受传递到wWinMain() 函数的实例句柄 (HINSTANCE) 。实例句柄也可通过 GetModuleHandle(NULL) 检索。

CefMainArgs main_args(hInstance);
1
3.2 单个可执行文件
  当作为单个可执行文件运行时,需要入口点函数来区分不同的进程类型。Windows 和 Linux 支持单一可执行结构,但 MacOS 不支持。

// Program entry-point function.
int main(int argc, char *argv[])
{
    // Structure for passing command-line arguments.
    // The definition of this structure is platform-specific.
    CefMainArgs main_args(argc, argv);

    // Optional implementation of the CefApp interface.
    CefRefPtr<MyApp> app(new MyApp);

    // Execute the sub-process logic, if any. This will either return immediately for the browser
    // process or block until the sub-process should exit.
    int exit_code = CefExecuteProcess(main_args, app.get());
    if (exit_code >= 0)
    {
        // The sub-process terminated, exit now.
        return exit_code;
    }

    // Populate this structure to customize CEF behavior.
    CefSettings settings;

    // Initialize CEF in the main process.
    CefInitialize(main_args, settings, app.get());

    // Run the CEF message loop. This will block until CefQuitMessageLoop() is called.
    CefRunMessageLoop();

    // Shut down CEF.
    CefShutdown();

    return 0;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
3.3 单独的子进程可执行文件
  使用单独的子流程可执行文件时,您需要两个单独的可执行项目和两个单独的入口点函数。主要应用入口函数:

// Program entry-point function.
int main(int argc, char *argv[])
{
    // Load the CEF framework library at runtime instead of linking directly
    // as required by the macOS sandbox implementation.
    CefScopedLibraryLoader library_loader;
    if (!library_loader.LoadInMain())
        return 1;

    // Structure for passing command-line arguments.
    // The definition of this structure is platform-specific.
    CefMainArgs main_args(argc, argv);

    // Optional implementation of the CefApp interface.
    CefRefPtr<MyApp> app(new MyApp);

    // Populate this structure to customize CEF behavior.
    CefSettings settings;

    // Specify the path for the sub-process executable.
    CefString(&settings.browser_subprocess_path).FromASCII(“ / path / to / subprocess”);

    // Initialize CEF in the main process.
    CefInitialize(main_args, settings, app.get());

    // Run the CEF message loop. This will block until CefQuitMessageLoop() is called.
    CefRunMessageLoop();

    // Shut down CEF.
    CefShutdown();

    return 0;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
  子流程应用入口函数:

// Program entry-point function.
int main(int argc, char *argv[])
{
    // Initialize the macOS sandbox for this helper process.
    CefScopedSandboxContext sandbox_context;
    if (!sandbox_context.Initialize(argc, argv))
        return 1;

    // Load the CEF framework library at runtime instead of linking directly
    // as required by the macOS sandbox implementation.
    CefScopedLibraryLoader library_loader;
    if (!library_loader.LoadInHelper())
        return 1;

    // Structure for passing command-line arguments.
    // The definition of this structure is platform-specific.
    CefMainArgs main_args(argc, argv);

    // Optional implementation of the CefApp interface.
    CefRefPtr<MyApp> app(new MyApp);

    // Execute the sub-process logic. This will block until the sub-process should exit.
    return CefExecuteProcess(main_args, app.get());
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
4.作者答疑
————————————————
版权声明:本文为CSDN博主「插件开发」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/m0_67316550/article/details/123565337

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|firemail ( 粤ICP备15085507号-1 )

GMT+8, 2024-5-9 09:44 , Processed in 0.056679 second(s), 19 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表