基于cef3浏览器开发精力

匿名 (未验证) 提交于 2019-12-03 00:22:01

cef3下载地址
说明:
1. Standard Distribution 里面包含了一些动态和静态库及源码
3. Sample Application 一个典型的示例程序
2. Release 里面仅有一个libcef.pdb

下载好后,需要自行编译一个libcef_dll_wrapper.lib库文件,编译方法:
1. 下载一个cmake程序
2. 安装好,配置环境变量,保证cmake命令能够响应(或使用gui)
3.解压下载好的源码(例如解压到:D:\Longruan\third\trunk\cef_3.3396.1775)文件夹
4.进入文件夹下(D:\Longruan\third\trunk\cef_3.3396.1775)目录
5.输入命令如下

 cmake -G "Visual Studio 10"

等待执行完毕
6. 打开cef.sln工程,编译libcef_dll_wrapper工程,即可。

  1. cef3开发的浏览器,关闭时程序崩溃
CefShutdown(); // 执行这句话,程序崩溃

相信使用最新的cef库的同学会遇到这个问题。cef的示例程序里有完整的示例,基本能够满足要求。但是cef的示例使用了单例,在自己的程序里,如果把cef嵌入到自己的对话框中,cef是作为一个child存在的,需要把单例去掉(使用类成员可解决这个问题)。

单例模式去掉,使用时用类的成员函数来定义。

  1. openstack novnc 界面显示10006,连接不成功,但是使用chrome/firfox等都可以
    我下了好几个版本的cef3,使用3.3396.1775这个版本是可以显示novnc界面。至于为何有的版本不可用,未知。
    可以将网址输入到cefclient.exe来测试,看看能否使用。

  2. novnc界面显示,但是不响应鼠标
    novnc不响应鼠标,有的chrome浏览器也不响应。why?why?why?不肯能吧。问了相关人员,说清理缓存。。。怎么肯能呢~我一直用隐身模式好吧。解决方法如下:

chrome浏览器解决方法

在chrome浏览器里输入如下地址:

chrome://flags/#touch-events

下面的黄色字体设置disabled

重启后,即可使用
参考地址
chrome命令行参数表

cef3解决方法
联想chrome是怎么解决的,猜想cef3是可以通过传递command-line来解决这个问题.可以参考chrome命令行参数。设置touch-events。

解决代码,增加一个webapp,来加载command-line

#ifndef WEB_APP_HPP #define WEB_APP_HPP  #include "include/cef_app.h"  // Implement application-level callbacks for the browser process. class CWebApp : public CefApp, public CefBrowserProcessHandler { public:     CWebApp(){}      // CefApp methods:     virtual CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler()         OVERRIDE {             return this;     }      // CefBrowserProcessHandler methods:     virtual void OnContextInitialized() OVERRIDE{         CEF_REQUIRE_UI_THREAD();         CefRefPtr<CefCommandLine> command_line =             CefCommandLine::GetGlobalCommandLine();      }     virtual void OnBeforeCommandLineProcessing(         const CefString& process_type,         CefRefPtr<CefCommandLine> command_line) OVERRIDE{             CEF_REQUIRE_UI_THREAD();              command_line->AppendSwitch("process-per-site");              // 解决novnc鼠标不响应问题,禁用touch-events              command_line->AppendSwitchWithValue("touch-events","disabled");     } private:     // Include the default reference counting implementation.     IMPLEMENT_REFCOUNTING(CWebApp); };  #endif  // 

在创建web时,方法如下:

...  void CWebClient::CreateBrowser(HWND hParentWnd, const RECT& rect) {     CEF_REQUIRE_UI_THREAD();     CefEnableHighDPISupport();     CefSettings cSettings;       CefSettingsTraits::init( &cSettings);       cSettings.multi_threaded_message_loop = true;       CefRefPtr<CWebApp> spApp(new CWebApp);       //CefInitialize( cSettings, spApp);      CefMainArgs main_args(::GetModuleHandle(NULL));     int exit_code = CefExecuteProcess(main_args, spApp.get(),NULL);     if (exit_code>0)     {         return;     }     CefInitialize(main_args, cSettings, spApp.get(), NULL);     CefWindowInfo info;      info.SetAsChild( hParentWnd, rect);     CefBrowserSettings browserSettings;       if( m_strHomePage.empty())          m_strHomePage = L"http://www.baidu.com/";     CefBrowserHost::CreateBrowser(info,this, m_strHomePage,         browserSettings, NULL); } ...

这里是创建一个子对话框。command_line需要在app里处理

可能需要做个UI界面或自己定制右键菜单,使用下列代码

 bool CWebClient::OnContextMenuCommand(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefContextMenuParams> params, int command_id, EventFlags event_flags) {         CEF_REQUIRE_UI_THREAD();         return false; }  void CWebClient::OnBeforeContextMenu(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefContextMenuParams> params, CefRefPtr<CefMenuModel> model) {     if ((params->GetTypeFlags() & (CM_TYPEFLAG_PAGE | CM_TYPEFLAG_FRAME)) != 0) {         if (model->GetCount() > 0)         {             model->Clear();         }     } } 

这两个函数都需要重写.我看网上很多没有把 OnContextMenuCommand 重写,不知道他们是怎么成功的。

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!