From 3cea70aa41b7a520e9f5e424cb57af77fd0ba7b8 Mon Sep 17 00:00:00 2001 From: Takashi Hashida Date: Tue, 3 Dec 2024 18:34:48 +0900 Subject: [PATCH] Fix IsEnablePDFExtension to work The `disable-pdf-extension` command line parameter is no longer supported on CEF 126.2.7+. CEF does the same behavior with specifying the preference `plugins.always_open_pdf_externally` on CEF 126+. Note that we can't use the preference `plugins.always_open_pdf_externally` on older version, at least CEF119, because it does not exist. --- client_app.cpp | 6 ++++++ client_handler.cpp | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/client_app.cpp b/client_app.cpp index 8bda407..5089f6f 100644 --- a/client_app.cpp +++ b/client_app.cpp @@ -69,9 +69,15 @@ void ClientApp::OnBeforeCommandLineProcessing(const CefString& process_type, Cef // command_line->AppendSwitch(_T("disable-extensions")); //command_line->AppendSwitchWithValue(_T("proxy-server"),_T("127.0.0.1:8080")); +#if CHROME_VERSION_MAJOR < 126 //pdf + //CEF126.2.7以降、disable-pdf-extensionオプションが非サポートになった。 + //そのため、CEF126以降では、ClientHandler::OnAfterCreatedでPreferenceを指定することで同等の処理を行う。 + //https://github.com/cefsharp/CefSharp/issues/4880 if (!theApp.m_AppSettings.IsEnablePDFExtension()) command_line->AppendSwitch(_T("disable-pdf-extension")); +#endif + ////flash //2020-12-31 EOL diff --git a/client_handler.cpp b/client_handler.cpp index 3121d36..f49c18f 100644 --- a/client_handler.cpp +++ b/client_handler.cpp @@ -91,6 +91,20 @@ void ClientHandler::OnAfterCreated(CefRefPtr browser) REQUIRE_UI_THREAD(); PROC_TIME(OnAfterCreated) +#if CHROME_VERSION_MAJOR >= 126 + //CEF126.2.7以降、disable-pdf-extensionオプションが非サポートになった。 + //そのため、CEF126以降では、ClientHandler::OnAfterCreatedでPreferenceを指定することで同等の処理を行う。 + //https://github.com/cefsharp/CefSharp/issues/4880 + if (!theApp.m_AppSettings.IsEnablePDFExtension()) + { + CefRefPtr requestContext = browser->GetHost()->GetRequestContext(); + CefString error; + CefRefPtr value = CefValue::Create(); + value->SetBool(true); + requestContext->SetPreference("plugins.always_open_pdf_externally", value, error); + } +#endif + // get browser ID INT nBrowserId = browser->GetIdentifier();