cef/patch/patches/print_preview_123.patch
Marshall Greenblatt 2ea7459a89 Use Chrome file dialogs on all platforms and runtimes (fixes issue #3314)
All file dialogs irrespective of source, platform and runtime will now be
routed through CefFileDialogManager and trigger CefDialogHandler callbacks
(see issue #3293).

Adds Chrome runtime support for CefBrowserHost::RunFileDialog and
CefDialogHandler callbacks.

Adds Alloy runtime support for internal GTK file and print dialogs on Linux
subject to the following limitations:

1. Internal GTK implementation:
   - Cannot be used with multi-threaded-message-loop because Chromium's
     internal GTK implementation is not thread-safe (does not use GDK threads).
   - Dialogs will not be modal to application windows when used with off-screen
     rendering due to lack of access to the client's top-level GtkWindow.
2. Cefclient CefDialogHandler implementation:
   - Cannot be used with Views because it requires a top-level GtkWindow.

Due to the above limitations no dialog implementation is currently provided for
Views + multi-threaded-message-loop on Linux. In cases where both
implementations are supported the cefclient version is now behind an optional
`--use-client-dialogs` command-line flag.

Expressly forbids multiple simultaneous file dialogs with the internal platform
implementation which uses modal dialogs. CefDialogHandler will still be notified
and can optionally handle each request without a modal dialog (see issue #3154).

Removes some RunFileDialog parameters that are not supported by the Chrome file
dialog implementation (selected_accept_filter parameter, cef_file_dialog_mode_t
overwrite/read-only flags).
2022-04-19 18:52:26 -04:00

173 lines
7.4 KiB
Diff

diff --git chrome/browser/download/download_prefs.cc chrome/browser/download/download_prefs.cc
index 04679ec67bf2e..864f08b030ccb 100644
--- chrome/browser/download/download_prefs.cc
+++ chrome/browser/download/download_prefs.cc
@@ -24,6 +24,7 @@
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
+#include "cef/libcef/features/runtime.h"
#include "chrome/browser/download/chrome_download_manager_delegate.h"
#include "chrome/browser/download/download_core_service_factory.h"
#include "chrome/browser/download/download_core_service_impl.h"
@@ -60,6 +61,10 @@
#include "chrome/browser/ui/pdf/adobe_reader_info_win.h"
#endif
+#if BUILDFLAG(ENABLE_CEF)
+#include "cef/libcef/browser/alloy/alloy_download_util.h"
+#endif
+
using content::BrowserContext;
using content::BrowserThread;
using content::DownloadManager;
@@ -342,6 +347,11 @@ DownloadPrefs* DownloadPrefs::FromDownloadManager(
// static
DownloadPrefs* DownloadPrefs::FromBrowserContext(
content::BrowserContext* context) {
+#if BUILDFLAG(ENABLE_CEF)
+ if (cef::IsAlloyRuntimeEnabled()) {
+ return alloy::GetDownloadPrefsFromBrowserContext(context);
+ }
+#endif
return FromDownloadManager(context->GetDownloadManager());
}
diff --git chrome/browser/printing/print_preview_dialog_controller.cc chrome/browser/printing/print_preview_dialog_controller.cc
index d656ccabc3899..a4b7ce6a7dcd8 100644
--- chrome/browser/printing/print_preview_dialog_controller.cc
+++ chrome/browser/printing/print_preview_dialog_controller.cc
@@ -15,6 +15,7 @@
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
+#include "cef/libcef/features/features.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/printing/print_view_manager.h"
#include "chrome/browser/task_manager/web_contents_tags.h"
diff --git chrome/browser/printing/print_view_manager_base.cc chrome/browser/printing/print_view_manager_base.cc
index 1f37c11047d47..eea8a9944ec3e 100644
--- chrome/browser/printing/print_view_manager_base.cc
+++ chrome/browser/printing/print_view_manager_base.cc
@@ -222,12 +222,12 @@ void UpdatePrintSettingsOnIO(
mojom::PrintManagerHost::UpdatePrintSettingsCallback callback,
scoped_refptr<PrintQueriesQueue> queue,
base::Value job_settings,
- base::WeakPtr<PrintViewManagerBase> manager) {
+ base::WeakPtr<PrintViewManagerBase> manager,
+ const content::GlobalRenderFrameHostId& global_id) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
std::unique_ptr<PrinterQuery> printer_query = queue->PopPrinterQuery(cookie);
if (!printer_query) {
- printer_query =
- queue->CreatePrinterQuery(content::GlobalRenderFrameHostId());
+ printer_query = queue->CreatePrinterQuery(global_id);
}
auto* printer_query_ptr = printer_query.get();
printer_query_ptr->SetSettings(
@@ -646,6 +646,7 @@ void PrintViewManagerBase::UpdatePrintSettings(
job_settings.SetIntKey(kSettingRasterizePdfDpi, value);
}
+ content::RenderFrameHost* render_frame_host = GetCurrentTargetFrame();
auto callback_wrapper =
base::BindOnce(&PrintViewManagerBase::UpdatePrintSettingsReply,
weak_ptr_factory_.GetWeakPtr(), std::move(callback));
@@ -653,7 +654,8 @@ void PrintViewManagerBase::UpdatePrintSettings(
FROM_HERE,
base::BindOnce(&UpdatePrintSettingsOnIO, cookie,
std::move(callback_wrapper), queue_,
- std::move(job_settings), weak_ptr_factory_.GetWeakPtr()));
+ std::move(job_settings), weak_ptr_factory_.GetWeakPtr(),
+ render_frame_host->GetGlobalId()));
}
#endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
diff --git chrome/browser/printing/print_view_manager_base.h chrome/browser/printing/print_view_manager_base.h
index 2661776307f77..b9edc98619c29 100644
--- chrome/browser/printing/print_view_manager_base.h
+++ chrome/browser/printing/print_view_manager_base.h
@@ -146,9 +146,6 @@ class PrintViewManagerBase : public PrintManager, public PrintJob::Observer {
// Manages the low-level talk to the printer.
scoped_refptr<PrintJob> print_job_;
- private:
- friend class TestPrintViewManager;
-
// content::WebContentsObserver implementation.
void RenderFrameHostStateChanged(
content::RenderFrameHost* render_frame_host,
diff --git chrome/browser/resources/print_preview/ui/destination_dialog.html chrome/browser/resources/print_preview/ui/destination_dialog.html
index 920f646f06484..76c0b5e5ee04b 100644
--- chrome/browser/resources/print_preview/ui/destination_dialog.html
+++ chrome/browser/resources/print_preview/ui/destination_dialog.html
@@ -25,10 +25,7 @@
</print-preview-destination-list>
</div>
<div slot="button-container">
- <cr-button on-click="onManageButtonClick_">
- $i18n{manage}
- <iron-icon icon="cr:open-in-new" id="manageIcon"></iron-icon>
- </cr-button>
+ <div></div>
<cr-button class="cancel-button" on-click="onCancelButtonClick_">
$i18n{cancel}
</cr-button>
diff --git chrome/browser/ui/webui/constrained_web_dialog_ui.cc chrome/browser/ui/webui/constrained_web_dialog_ui.cc
index f6098966f5b34..da78289b66155 100644
--- chrome/browser/ui/webui/constrained_web_dialog_ui.cc
+++ chrome/browser/ui/webui/constrained_web_dialog_ui.cc
@@ -13,6 +13,7 @@
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/values.h"
+#include "cef/libcef/features/runtime.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
@@ -57,7 +58,9 @@ class ConstrainedWebDialogDelegateUserData
ConstrainedWebDialogUI::ConstrainedWebDialogUI(content::WebUI* web_ui)
: WebUIController(web_ui) {
#if BUILDFLAG(ENABLE_EXTENSIONS)
+ if (!cef::IsAlloyRuntimeEnabled()) {
extensions::TabHelper::CreateForWebContents(web_ui->GetWebContents());
+ }
#endif
}
diff --git chrome/browser/ui/webui/print_preview/print_preview_ui.cc chrome/browser/ui/webui/print_preview/print_preview_ui.cc
index eba14d78d87ff..7901f000a44b5 100644
--- chrome/browser/ui/webui/print_preview/print_preview_ui.cc
+++ chrome/browser/ui/webui/print_preview/print_preview_ui.cc
@@ -22,6 +22,7 @@
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
+#include "cef/libcef/features/runtime.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/pdf/pdf_extension_util.h"
#include "chrome/browser/printing/background_printing_manager.h"
@@ -96,6 +97,13 @@ const char16_t kBasicPrintShortcut[] = u"\u0028\u21e7\u2318\u0050\u0029";
const char16_t kBasicPrintShortcut[] = u"(Ctrl+Shift+P)";
#endif
+const char16_t* GetBasicPrintShortcut() {
+ if (cef::IsAlloyRuntimeEnabled()) {
+ return u"";
+ }
+ return kBasicPrintShortcut;
+}
+
constexpr char kInvalidArgsForDidStartPreview[] =
"Invalid arguments for DidStartPreview";
constexpr char kInvalidPageNumberForDidPreviewPage[] =
@@ -339,7 +347,7 @@ void AddPrintPreviewStrings(content::WebUIDataSource* source) {
chrome::kCloudPrintCertificateErrorLearnMoreURL);
#if !BUILDFLAG(IS_CHROMEOS)
- const std::u16string shortcut_text(kBasicPrintShortcut);
+ const std::u16string shortcut_text(GetBasicPrintShortcut());
source->AddString("systemDialogOption",
l10n_util::GetStringFUTF16(
IDS_PRINT_PREVIEW_SYSTEM_DIALOG_OPTION, shortcut_text));