| 15 | |
| 16 | |
| 17 | void ContextMenuHandler::OnBeforeContextMenu( |
| 18 | CefRefPtr<CefBrowser> browser, |
| 19 | CefRefPtr<CefFrame> frame, |
| 20 | CefRefPtr<CefContextMenuParams> params, |
| 21 | CefRefPtr<CefMenuModel> model) |
| 22 | { |
| 23 | bool enabled = ApplicationSettings_GetBoolFromDict( |
| 24 | "context_menu", "enabled"); |
| 25 | bool navigation = ApplicationSettings_GetBoolFromDict( |
| 26 | "context_menu", "navigation"); |
| 27 | bool print = ApplicationSettings_GetBoolFromDict( |
| 28 | "context_menu", "print"); |
| 29 | bool view_source = ApplicationSettings_GetBoolFromDict( |
| 30 | "context_menu", "view_source"); |
| 31 | bool external_browser = ApplicationSettings_GetBoolFromDict( |
| 32 | "context_menu", "external_browser"); |
| 33 | bool devtools = ApplicationSettings_GetBoolFromDict( |
| 34 | "context_menu", "devtools"); |
| 35 | |
| 36 | if (!enabled) { |
| 37 | model->Clear(); |
| 38 | return; |
| 39 | } |
| 40 | if (!navigation && model->IsVisible(MENU_ID_BACK) |
| 41 | && model->IsVisible(MENU_ID_FORWARD)) { |
| 42 | model->Remove(MENU_ID_BACK); |
| 43 | model->Remove(MENU_ID_FORWARD); |
| 44 | // Remove separator |
| 45 | if (model->GetTypeAt(0) == MENUITEMTYPE_SEPARATOR) { |
| 46 | model->RemoveAt(0); |
| 47 | } |
| 48 | } |
| 49 | if (!print) { |
| 50 | model->Remove(MENU_ID_PRINT); |
| 51 | } |
| 52 | if (!view_source) { |
| 53 | model->Remove(MENU_ID_VIEW_SOURCE); |
| 54 | } |
| 55 | if (!params->IsEditable() && params->GetSelectionText().empty() |
| 56 | && (params->GetPageUrl().length() |
| 57 | || params->GetFrameUrl().length())) { |
| 58 | if (external_browser) { |
| 59 | model->AddItem(_MENU_ID_OPEN_PAGE_IN_EXTERNAL_BROWSER, |
| 60 | "Open in external browser"); |
| 61 | if (params->GetFrameUrl().length() |
| 62 | && params->GetPageUrl() != params->GetFrameUrl()) { |
| 63 | model->AddItem(_MENU_ID_OPEN_FRAME_IN_EXTERNAL_BROWSER, |
| 64 | "Open frame in external browser"); |
| 65 | } |
| 66 | } |
| 67 | if (navigation) { |
| 68 | model->InsertItemAt(2, _MENU_ID_RELOAD_PAGE, "Reload"); |
| 69 | } |
| 70 | if (devtools) { |
| 71 | model->AddSeparator(); |
| 72 | model->AddItem(_MENU_ID_DEVTOOLS, "Developer Tools"); |
| 73 | } |
| 74 | } |