cef 问题集锦

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;
  }
}
  • 8
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值