1. Check failed: !is_bound()
[1225/181834.383:FATAL:receiver.h(159)] Check failed: !is_bound(). Receiver for network.mojom.TrustedHeaderClient is already bound
解决方案: 增加命令行参数
--disable-request-handling-for-testing
2. CefRequestHandler GetResourceRequestHandler无法触发
解决方案: 取消命令行参数
--disable-request-handling-for-testing
3. 部分网页显示乱码
解决方案: 检查语言区域设置是否正确(本例设置为中文)
CefSettings settings;
CefString(&settings.locale).FromWString(L"zh-CN");
4. 无法打印
解决方案: 取消命令行参数
--disable-extensions
5. cef作为child窗口,打印中途取消崩溃
[0625/182734.509:WARNING:alloy_constrained_window_views_client.cc(63)] No likely focused browser
解决方案: 将父窗口的焦点传递给web
if (uMsg == WM_SETFOCUS)
{
if (browser)
browser->GetHost()->SetFocus(true);
}
7. OSR窗口疯狂点击崩溃
FATAL:event.cc(567)] Check failed : 3 >= click_count(3 vs. 4)
解决方案: SendMouseClickEvent判断点击次数是否大于3,如果大于3则默认为3
browser_host->SendMouseClickEvent(mouse_event, btnType, false,last_click_count_ >=4 ? 3: last_click_count_);
8. OSR输入中文崩溃(IME)
解决方案: 屏蔽所有WM_IME_
消息处理逻辑。
9. OSR输入焦点第一次无法获取
解决方案: 取消OSR窗口WS_EX_NOACTIVATE
属性
10.OSR背景透明或者锯齿
解决方案: 不使用opengl,改用原始方式UpdateLayeredWindow
实现(cef 109 demo基础改)
void DrawBuffer(HDC hDC, RECT rtDest,const void *buf)
{
COLORREF* pColors = nullptr;
HDC hMemDC = ::CreateCompatibleDC(hDC);
HBITMAP hBitMap = CreateRGBA32Bitmap(hDC, rtDest.right - rtDest.left, rtDest.bottom - rtDest.top, &pColors);
::SelectObject(hMemDC, hBitMap);
int w = rtDest.right - rtDest.left;
int h = rtDest.bottom - rtDest.top;
memcpy(pColors, buf, (rtDest.right - rtDest.left) * (rtDest.bottom - rtDest.top) * 4);
for (int ih = 0; ih < h/2; ++ih)
{
for (int iw = 0; iw < w; ++iw)
{
COLORREF temp = pColors[ih * w + iw];
pColors[ih * w + iw] = pColors[(h - 1 - ih) * w + iw];
pColors[(h - 1 - ih) * w + iw] = temp;
}
}
BLENDFUNCTION bf = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
AlphaBlend(hDC, rtDest.left, rtDest.top, rtDest.right - rtDest.left, rtDest.bottom - rtDest.top, hMemDC, 0, 0, rtDest.right - rtDest.left, rtDest.bottom - rtDest.top, bf);
DeleteObject(hBitMap);
DeleteDC(hMemDC);
}
void PaintContent(HDC hDc, RECT rcPaint,const void *buf)
{
//DrawAColor(hDc, rcPaint, 0xffff0000);
DrawBuffer(hDc, rcPaint, buf);
}
void OsrRenderHandlerWinGL::OnPaint(
CefRefPtr<CefBrowser> browser,
CefRenderHandler::PaintElementType type,
const CefRenderHandler::RectList& dirtyRects,
const void* buffer,
int width,
int height) {
CEF_REQUIRE_UI_THREAD();
RECT rtWindow;
GetWindowRect(hwnd(), &rtWindow);
if (buffer == nullptr || (rtWindow.right - rtWindow.left) != width || (rtWindow.bottom - rtWindow.top) != height)
{
return;
}
COLORREF* pOffscreenBits = NULL;
HDC hdc = GetDC(hwnd());
HDC hDcOffscreen = ::CreateCompatibleDC(hdc);
HBITMAP hbmpOffscreen = CreateRGBA32Bitmap(hdc, width, height, &pOffscreenBits);
HBITMAP hOldBitmap = (HBITMAP) ::SelectObject(hDcOffscreen, hbmpOffscreen);
RECT rtPaint = { 0,0,rtWindow.right - rtWindow.left, rtWindow.bottom - rtWindow.top };
PaintContent(hDcOffscreen, rtPaint,buffer);
BLENDFUNCTION bf = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
SIZE sizeWnd = { rtWindow.right - rtWindow.left, rtWindow.bottom - rtWindow.top };
POINT ptPos = { rtWindow.left, rtWindow.top };
//::ClientToScreen(hWnd, &ptPos);
POINT ptSrc = { 0,0 };
UpdateLayeredWindow(hwnd(), hdc, &ptPos, &sizeWnd, hDcOffscreen, &ptSrc, 0, &bf, ULW_ALPHA);
DeleteDC(hDcOffscreen);
DeleteObject(hbmpOffscreen);
ReleaseDC(hwnd(),hdc);
if (type == PET_VIEW && !renderer_.popup_rect().IsEmpty()) {
painting_popup_ = true;
browser->GetHost()->Invalidate(PET_POPUP);
painting_popup_ = false;
}
}