在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/數(shù)據(jù)分析&挖掘  C++  網(wǎng)絡安全  HTML/ Cef右鍵菜單顯示DevTools失敗

Cef右鍵菜單顯示DevTools失敗

我在cef 3.3239提供的CefSimple中想加一個 Show DevTools的右鍵菜單選項,但是調試發(fā)現(xiàn)一直沒進來OnBeforeContextMenu這個函數(shù)。代碼如下:

// 1. SimpleHandler添加CefContextMenuHandler繼承
class SimpleHandler : public ...
                      public public CefContextMenuHandler { /**/ }


// 2. 重寫CefContextMenuHandler和OnContextMenuCommand事件回調

// Cef源碼注釋:"Called before a context menu is displayed..."
void SimpleHandler::OnBeforeContextMenu(CefRefPtr<CefBrowser> browser, 
        CefRefPtr<CefFrame> frame,
        CefRefPtr<CefContextMenuParams> params,
        CefRefPtr<CefMenuModel> model) {
    CEF_REQUIRE_UI_THREAD();
    if ((params->GetTypeFlags() & (CM_TYPEFLAG_PAGE | CM_TYPEFLAG_FRAME)) != 0) {
        if (model->GetCount() > 0)
            model->AddSeparator();

        model->AddItem(DEV_TOOLS_ID, "&Show DevTools");    // 添加一個右鍵菜單項
    }
}

// Cef源碼注釋:Called to execute a command selected from the context menu
bool SimpleHandler::OnContextMenuCommand(CefRefPtr<CefBrowser> browser,
        CefRefPtr<CefFrame> frame,
        CefRefPtr<CefContextMenuParams> params,
        int command_id,
        EventFlags event_flags) {
    CEF_REQUIRE_UI_THREAD();
    switch (command_id)
    {
    case DEV_TOOLS_ID:
        ShowDevTools(browser);    // 顯示DevTools
        break;
    default:
        break;
    }
    
    return true;
}

void SimpleHandler::ShowDevTools(CefRefPtr<CefBrowser> browser)
{
    CefWindowInfo win_info;
    CefRefPtr<CefClient> client;
    CefBrowserSettings settings;

    browser->GetHost()->ShowDevTools(win_info, client, settings, CefPoint());
}

但是我運行程序之后,發(fā)現(xiàn)右鍵菜單沒有添加上我要的DevToos,斷點設置在OnBeforeContextMenuOnContextMenuCommand發(fā)現(xiàn)都沒進來。
請問是我實現(xiàn)的方式缺少調用某些操作了嗎?

回答
編輯回答
青瓷

找到原因了,還需要重寫GetContextMenuHandler接口。

virtual CefRefPtr<CefContextMenuHandler> SimpleHandler::GetContextMenuHandler() 
        OVERRIDE {
    return this;
}
2017年12月19日 07:31