Return a new scheme handler instance to handle the request.
| 30 | |
| 31 | // Return a new scheme handler instance to handle the request. |
| 32 | CefRefPtr<CefResourceHandler> SchemeHandlerFactory::Create( |
| 33 | CefRefPtr<CefBrowser> browser, |
| 34 | CefRefPtr<CefFrame> frame, |
| 35 | const CefString& scheme_name, |
| 36 | CefRefPtr<CefRequest> request) |
| 37 | { |
| 38 | const auto DoErrorMessage = [&](std::string title, std::string body) { |
| 39 | if (hardFail_) { |
| 40 | MessageBoxA( |
| 41 | browser->GetHost()->GetWindowHandle(), |
| 42 | body.c_str(), title.c_str(), |
| 43 | MB_ICONERROR | MB_APPLMODAL |
| 44 | ); |
| 45 | } |
| 46 | }; |
| 47 | |
| 48 | if (mode_ == SchemeMode::Web) { |
| 49 | // anything goes if web mode |
| 50 | // but don't worry about loading app files (only use default schema managers) |
| 51 | pmlog_dbg(std::format("Processing request URL: {}", request->GetURL().ToString())); |
| 52 | return nullptr; |
| 53 | } |
| 54 | else if (mode_ == SchemeMode::Local) { |
| 55 | CefURLParts url_parts; |
| 56 | if (!CefParseURL(request->GetURL(), url_parts)) { |
| 57 | pmlog_error(std::format("Failed parsing URL: {}", request->GetURL().ToString())).no_trace(); |
| 58 | DoErrorMessage("URL Error", "Failed parsing URL, see log."); |
| 59 | } |
| 60 | else if (CefString(&url_parts.host) != localHost_ && CefString(&url_parts.port) != localPort_) { |
| 61 | if constexpr (IS_DEBUG) { |
| 62 | pmlog_warn(std::format("URL does not match dev endpoint: {}", request->GetURL().ToString())); |
| 63 | } |
| 64 | else { |
| 65 | pmlog_error(std::format("URL does not match dev endpoint: {}", request->GetURL().ToString())).no_trace(); |
| 66 | DoErrorMessage("URL Error", "URL does not match dev endpoint, see log."); |
| 67 | std::terminate(); |
| 68 | } |
| 69 | } |
| 70 | else { |
| 71 | pmlog_dbg(std::format("Processing request URL: {}", request->GetURL().ToString())); |
| 72 | } |
| 73 | return nullptr; |
| 74 | } |
| 75 | // otherwise mode is File (filesystem app assets) by default |
| 76 | if (scheme_name == "https") { |
| 77 | CefURLParts url_parts; |
| 78 | if (!CefParseURL(request->GetURL(), url_parts)) { |
| 79 | pmlog_error(std::format("Failed parsing URL: {}", request->GetURL().ToString())).no_trace(); |
| 80 | DoErrorMessage("URL Error", "Failed parsing URL, see log."); |
| 81 | return nullptr; |
| 82 | } |
| 83 | else if (const auto host = CefString(&url_parts.host); host != "app") { |
| 84 | pmlog_error(std::format("Non-app domain in File mode: {}", request->GetURL().ToString())).no_trace(); |
| 85 | DoErrorMessage("URL Error", "Non-app domain for File mode, see log."); |
| 86 | return nullptr; |
| 87 | } |
| 88 | else { |
| 89 | pmlog_dbg(std::format("Processing request URL: {}", request->GetURL().ToString())); |