QCefView项目源码的构建部分这里就不赘述了,有问题的朋友可以回到《QCefView(1)—— CMAKE项目、库文件生成和项目测试》查看相关介绍。本次优化主要包括以下几个部分:
(1)设置部分,关闭代理服务器,关闭同源策略,使用系统flash等。
(2)增加F5按键刷新页面和F12调用控制台调试工具。更多按键快捷操作可以参考代码增加部分。
上代码:
1、打开:QCefView\CefViewBrowserApp\QCefViewBrowserApp.cpp
修改如下函数:
void
QCefViewBrowserApp::OnBeforeCommandLineProcessing(const CefString& process_type, CefRefPtr<CefCommandLine> command_line)
{
command_line->AppendSwitch("disable-spell-checking");
//command_line->AppendSwitch("disable-extensions");
command_line->AppendSwitch("disable-pdf-extension");
command_line->AppendSwitch("enable-direct-write");
command_line->AppendSwitch("allow-file-access-from-files");
command_line->AppendSwitch("no-proxy-server"); // 关闭代理
command_line->AppendSwitch("in-process-gpu");
command_line->AppendSwitch("disable-direct-composition");
command_line->AppendSwitchWithValue("disable-features", "NetworkService");
command_line->AppendSwitchWithValue("renderer-process-limit", "1");
command_line->AppendSwitch("--disable-web-security"); //关闭同源策略
command_line->AppendSwitch("--enable-system-flash"); //使用系统flash
}
2、打开QCefView\CefViewBrowserApp\QCefViewBrowserHandler.cpp
// 增加下函数,调用控制台 ==》头文件QCefViewBrowserHandler类中添加函数声明
void QCefViewBrowserHandler::ShowDevTools(CefRefPtr<CefBrowser> browser, const CefPoint& inspect_element_at)
{
CefWindowInfo windowInfo;
CefBrowserSettings settings;
browser->GetHost()->ShowDevTools(windowInfo, this, settings, CefPoint());
}
bool QCefViewBrowserHandler::OnPreKeyEvent(CefRefPtr<CefBrowser> browser,
const CefKeyEvent& event,
CefEventHandle os_event,
bool* is_keyboard_shortcut)
{
// 屏蔽以下两行代码
// CEF_REQUIRE_UI_THREAD();
// return false;
// 增加按键事件,处理F5刷新和F12调用调试工具
bool bRet(false);
if (event.type == KEYEVENT_RAWKEYDOWN) {
if (event.windows_key_code == VK_F5) { // 刷新
browser->Reload();
bRet = true;
} else if (event.windows_key_code == VK_F12) { // 调试控制台
ShowDevTools(browser, CefPoint());
}
}
return bRet;
}
效果如下:
需要修改后的源码的,可以留言或私我。暂时没时间整理和发布共享。
看到还有朋友们在留言需要源码的,整理下附上:
文件组织结构:
├─dep
├─out
│ ├─QCefView
│ │ ├─bin
│ │ │ ├─Debug
│ │ │ │ ├─resources
│ │ │ │ │ └─locales
│ │ │ │ └─swiftshader
│ │ │ └─Release
│ │ │ ├─resources
│ │ │ │ └─locales
│ │ │ ├─swiftshader
│ │ │ └─update-dpi-1
│ │ ├─include
│ │ └─lib
│ │ ├─Debug
│ │ └─Release
│ └─QCefViewTest
│ ├─Debug
│ │ ├─GPUCache
│ │ ├─resources
│ │ │ └─locales
│ │ └─swiftshader
│ └─Release
│ ├─cache
│ │ ├─blob_storage
│ │ │ └─9eaea8ec-714e-4082-b8c3-83a179b43db5
│ │ ├─Cache
│ │ ├─Code Cache
│ │ │ └─js
│ │ │ └─index-dir
│ │ └─GPUCache
│ ├─GPUCache
│ ├─platforms
│ ├─resources
│ │ └─locales
│ ├─software
│ │ ├─plugins
│ │ │ ├─audio
│ │ │ ├─bearer
│ │ │ ├─canbus
│ │ │ ├─designer
│ │ │ ├─gamepads
│ │ │ ├─generic
│ │ │ ├─geometryloaders
│ │ │ ├─geoservices
│ │ │ ├─iconengines
│ │ │ ├─imageformats
│ │ │ ├─mediaservice
│ │ │ ├─platforms
│ │ │ ├─platformthemes
│ │ │ ├─playlistformats
│ │ │ ├─position
│ │ │ ├─printsupport
│ │ │ ├─qmltooling
│ │ │ ├─renderplugins
│ │ │ ├─scenegraph
│ │ │ ├─sceneparsers
│ │ │ ├─sensorgestures
│ │ │ ├─sensors
│ │ │ ├─sqldrivers
│ │ │ ├─styles
│ │ │ ├─texttospeech
│ │ │ └─webview
│ │ └─theme
│ │ └─TitleImage
│ └─swiftshader
├─src
│ ├─QCefProto
│ ├─QCefView
│ │ ├─CefViewBrowserApp
│ │ │ ├─BrowserDelegates
│ │ │ └─SchemeHandlers
│ │ └─Include
│ └─QCefWing
│ └─CefViewRenderApp
│ └─RenderDelegates
└─test
├─build-QCefViewTest-Desktop_Qt_5_13_0_MSVC2017_32bit-Minimum-Size-Release
│ ├─CMakeFiles
│ │ ├─3.10.0
│ │ │ ├─CompilerIdC
│ │ │ │ └─tmp
│ │ │ └─CompilerIdCXX
│ │ │ └─tmp
│ │ ├─CMakeTmp
│ │ ├─QCefViewTest.dir
│ │ │ └─QCefViewTest_autogen
│ │ ├─QCefViewTest_autogen.dir
│ │ └─ShowIncludes
│ └─QCefViewTest_autogen
│ ├─EWIEGA46WW
│ └─include
└─QCefViewTest
├─images
└─out
└─QCefViewTest
链接:https://pan.baidu.com/s/1Wvtih0Uyevjmws1ef35ehg
提取码:lpnt