diff --git chrome/browser/download/download_prefs.cc chrome/browser/download/download_prefs.cc index 5f5f6cc2d1024..ab5e0d1517c01 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; @@ -349,6 +354,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 434d4781e2342..2bdd03803c6f8 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/extensions/chrome_extension_web_contents_observer.h" #include "chrome/browser/printing/print_view_manager.h" @@ -404,8 +405,11 @@ WebContents* PrintPreviewDialogController::CreatePrintPreviewDialog( content::HostZoomMap::Get(preview_dialog->GetSiteInstance()) ->SetZoomLevelForHostAndScheme(print_url.scheme(), print_url.host(), 0); PrintViewManager::CreateForWebContents(preview_dialog); + +#if !BUILDFLAG(ENABLE_CEF) extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( preview_dialog); +#endif // Add an entry to the map. preview_dialog_map_[preview_dialog] = initiator; diff --git chrome/browser/printing/print_view_manager_base.cc chrome/browser/printing/print_view_manager_base.cc index 2011d52338081..362d741d50a33 100644 --- chrome/browser/printing/print_view_manager_base.cc +++ chrome/browser/printing/print_view_manager_base.cc @@ -21,6 +21,7 @@ #include "base/timer/timer.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/chrome_notification_types.h" #include "chrome/browser/printing/print_job.h" @@ -58,6 +59,10 @@ #include "printing/printing_features.h" #endif +#if BUILDFLAG(ENABLE_CEF) +#include "cef/libcef/browser/printing/print_view_manager.h" +#endif + #if BUILDFLAG(ENABLE_PRINT_PREVIEW) #include "chrome/browser/printing/print_error_dialog.h" #include "chrome/browser/printing/print_view_manager.h" @@ -217,8 +222,13 @@ PrintViewManager* GetPrintViewManager(int render_process_id, DCHECK_CURRENTLY_ON(content::BrowserThread::UI); content::WebContents* web_contents = GetWebContentsForRenderFrame(render_process_id, render_frame_id); - return web_contents ? PrintViewManager::FromWebContents(web_contents) - : nullptr; + if (!web_contents) + return nullptr; +#if BUILDFLAG(ENABLE_CEF) + if (cef::IsAlloyRuntimeEnabled()) + return CefPrintViewManager::FromWebContents(web_contents); +#endif + return PrintViewManager::FromWebContents(web_contents); } void NotifySystemDialogCancelled(int render_process_id, int routing_id) { @@ -274,8 +284,7 @@ void UpdatePrintSettingsOnIO( DCHECK_CURRENTLY_ON(content::BrowserThread::IO); std::unique_ptr printer_query = queue->PopPrinterQuery(cookie); if (!printer_query) { - printer_query = queue->CreatePrinterQuery( - content::ChildProcessHost::kInvalidUniqueID, MSG_ROUTING_NONE); + printer_query = queue->CreatePrinterQuery(process_id, routing_id); } auto* printer_query_ptr = printer_query.get(); printer_query_ptr->SetSettings( diff --git chrome/browser/printing/print_view_manager_base.h chrome/browser/printing/print_view_manager_base.h index c4bcf96d0ac01..c549e3bf2ca36 100644 --- chrome/browser/printing/print_view_manager_base.h +++ chrome/browser/printing/print_view_manager_base.h @@ -149,9 +149,6 @@ class PrintViewManagerBase : public content::NotificationObserver, // Manages the low-level talk to the printer. scoped_refptr print_job_; - private: - friend class TestPrintViewManager; - // content::NotificationObserver implementation. void Observe(int type, const content::NotificationSource& source, 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 @@
- - $i18n{manage} - - +
$i18n{cancel} diff --git chrome/browser/ui/webui/constrained_web_dialog_ui.cc chrome/browser/ui/webui/constrained_web_dialog_ui.cc index 1b6b4e93b45d2..b51f277453529 100644 --- chrome/browser/ui/webui/constrained_web_dialog_ui.cc +++ chrome/browser/ui/webui/constrained_web_dialog_ui.cc @@ -26,6 +26,8 @@ #include "chrome/browser/extensions/tab_helper.h" #endif +#include "cef/libcef/features/features.h" + using content::RenderFrameHost; using content::WebContents; using content::WebUIMessageHandler; @@ -57,8 +59,10 @@ class ConstrainedWebDialogDelegateUserData ConstrainedWebDialogUI::ConstrainedWebDialogUI(content::WebUI* web_ui) : WebUIController(web_ui) { #if BUILDFLAG(ENABLE_EXTENSIONS) +#if !BUILDFLAG(ENABLE_CEF) extensions::TabHelper::CreateForWebContents(web_ui->GetWebContents()); #endif +#endif } ConstrainedWebDialogUI::~ConstrainedWebDialogUI() = default; diff --git chrome/browser/ui/webui/print_preview/pdf_printer_handler.cc chrome/browser/ui/webui/print_preview/pdf_printer_handler.cc index 8933bc14bdefe..796b8827692c3 100644 --- chrome/browser/ui/webui/print_preview/pdf_printer_handler.cc +++ chrome/browser/ui/webui/print_preview/pdf_printer_handler.cc @@ -21,6 +21,7 @@ #include "base/values.h" #include "build/build_config.h" #include "build/chromeos_buildflags.h" +#include "cef/libcef/features/runtime.h" #include "chrome/browser/app_mode/app_mode_utils.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/download/download_prefs.h" @@ -62,6 +63,10 @@ #include "chromeos/lacros/lacros_service.h" #endif +#if BUILDFLAG(ENABLE_CEF) +#include "cef/libcef/browser/alloy/alloy_dialog_util.h" +#endif + namespace printing { namespace { @@ -411,16 +416,18 @@ void PdfPrinterHandler::SelectFile(const base::FilePath& default_filename, service->GetRemote() ->GetMountPointPath( base::BindOnce(&PdfPrinterHandler::OnSaveLocationReady, - weak_ptr_factory_.GetWeakPtr(), + weak_ptr_factory_.GetWeakPtr(), initiator, std::move(default_filename), prompt_user)); return; } #endif - OnSaveLocationReady(default_filename, prompt_user, GetSaveLocation()); + OnSaveLocationReady(initiator, default_filename, prompt_user, + GetSaveLocation()); } void PdfPrinterHandler::OnSaveLocationReady( + content::WebContents* initiator, const base::FilePath& default_filename, bool prompt_user, const base::FilePath& path) { @@ -438,10 +445,27 @@ void PdfPrinterHandler::OnSaveLocationReady( // If the directory is empty there is no reason to create it or use the // default location. if (path.empty()) { +#if BUILDFLAG(ENABLE_CEF) + if (cef::IsAlloyRuntimeEnabled()) { + ShowCefSaveAsDialog(initiator, default_filename, path); + return; + } +#endif OnDirectorySelected(default_filename, path); return; } + auto callback = base::BindOnce(&PdfPrinterHandler::OnDirectorySelected, + weak_ptr_factory_.GetWeakPtr(), + default_filename); +#if BUILDFLAG(ENABLE_CEF) + if (cef::IsAlloyRuntimeEnabled()) { + callback = base::BindOnce(&PdfPrinterHandler::ShowCefSaveAsDialog, + weak_ptr_factory_.GetWeakPtr(), initiator, + default_filename); + } +#endif + // Get default download directory. This will be used as a fallback if the // save directory does not exist. DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext(profile_); @@ -449,8 +473,7 @@ void PdfPrinterHandler::OnSaveLocationReady( base::ThreadPool::PostTaskAndReplyWithResult( FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT}, base::BindOnce(&SelectSaveDirectory, path, default_path), - base::BindOnce(&PdfPrinterHandler::OnDirectorySelected, - weak_ptr_factory_.GetWeakPtr(), default_filename)); + std::move(callback)); } void PdfPrinterHandler::PostPrintToPdfTask() { @@ -496,6 +519,36 @@ void PdfPrinterHandler::OnDirectorySelected(const base::FilePath& filename, platform_util::GetTopLevel(preview_web_contents_->GetNativeView()), NULL); } +#if BUILDFLAG(ENABLE_CEF) + +void PdfPrinterHandler::ShowCefSaveAsDialog(content::WebContents* initiator, + const base::FilePath& filename, + const base::FilePath& directory) { + base::FilePath path = directory.Append(filename); + + blink::mojom::FileChooserParams params; + params.mode = blink::mojom::FileChooserParams::Mode::kSave; + params.default_file_name = path; + params.accept_types.push_back( + alloy::FilePathTypeToString16(path.Extension())); + + alloy::RunFileChooser(initiator, params, + base::BindOnce(&PdfPrinterHandler::SaveAsDialogDismissed, + weak_ptr_factory_.GetWeakPtr())); +} + +void PdfPrinterHandler::SaveAsDialogDismissed( + int selected_accept_filter, + const std::vector& file_paths) { + if (file_paths.size() == 1) { + FileSelected(file_paths[0], 0, nullptr); + } else { + FileSelectionCanceled(nullptr); + } +} + +#endif // BUILDFLAG(ENABLE_CEF) + base::FilePath PdfPrinterHandler::GetSaveLocation() const { #if BUILDFLAG(IS_CHROMEOS_ASH) drive::DriveIntegrationService* drive_service = diff --git chrome/browser/ui/webui/print_preview/pdf_printer_handler.h chrome/browser/ui/webui/print_preview/pdf_printer_handler.h index b3a6eaa270877..aa4e84fea1387 100644 --- chrome/browser/ui/webui/print_preview/pdf_printer_handler.h +++ chrome/browser/ui/webui/print_preview/pdf_printer_handler.h @@ -11,6 +11,7 @@ #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" #include "build/chromeos_buildflags.h" +#include "cef/libcef/features/features.h" #include "chrome/browser/ui/webui/print_preview/printer_handler.h" #include "ui/shell_dialogs/select_file_dialog.h" @@ -94,10 +95,20 @@ class PdfPrinterHandler : public PrinterHandler, void OnDirectorySelected(const base::FilePath& filename, const base::FilePath& directory); - void OnSaveLocationReady(const base::FilePath& default_filename, + void OnSaveLocationReady(content::WebContents* initiator, + const base::FilePath& default_filename, bool prompt_user, const base::FilePath& path); +#if BUILDFLAG(ENABLE_CEF) + void ShowCefSaveAsDialog(content::WebContents* initiator, + const base::FilePath& filename, + const base::FilePath& directory); + + void SaveAsDialogDismissed(int selected_accept_filter, + const std::vector& file_paths); +#endif + // Return save location as the Drive mount or fetch from Download Preferences. base::FilePath GetSaveLocation() const; diff --git chrome/browser/ui/webui/print_preview/print_preview_ui.cc chrome/browser/ui/webui/print_preview/print_preview_ui.cc index 7695cf2a3a2e2..887e047b83b72 100644 --- chrome/browser/ui/webui/print_preview/print_preview_ui.cc +++ chrome/browser/ui/webui/print_preview/print_preview_ui.cc @@ -29,6 +29,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" @@ -102,6 +103,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[] = @@ -391,7 +399,7 @@ void AddPrintPreviewStrings(content::WebUIDataSource* source) { chrome::kCloudPrintCertificateErrorLearnMoreURL); #if !defined(OS_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));