cef/patch/patches/print_preview_123.patch

372 lines
15 KiB
Diff

diff --git chrome/browser/download/download_prefs.cc chrome/browser/download/download_prefs.cc
index 4e04a86c2d06..6d82d55acd15 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"
@@ -58,6 +59,10 @@
#include "chrome/browser/ui/pdf/adobe_reader_info_win.h"
#endif
+#if BUILDFLAG(ENABLE_CEF)
+#include "cef/libcef/browser/alloy/alloy_browser_context.h"
+#endif
+
using content::BrowserContext;
using content::BrowserThread;
using content::DownloadManager;
@@ -358,6 +363,11 @@ DownloadPrefs* DownloadPrefs::FromDownloadManager(
// static
DownloadPrefs* DownloadPrefs::FromBrowserContext(
content::BrowserContext* context) {
+#if BUILDFLAG(ENABLE_CEF)
+ if (cef::IsAlloyRuntimeEnabled()) {
+ return static_cast<AlloyBrowserContext*>(context)->GetDownloadPrefs();
+ }
+#endif
return FromDownloadManager(BrowserContext::GetDownloadManager(context));
}
diff --git chrome/browser/printing/print_preview_dialog_controller.cc chrome/browser/printing/print_preview_dialog_controller.cc
index 97cae92b96fa..6acf5188e1d6 100644
--- chrome/browser/printing/print_preview_dialog_controller.cc
+++ chrome/browser/printing/print_preview_dialog_controller.cc
@@ -17,6 +17,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"
@@ -452,8 +453,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 ae1ab34986d1..b742e9fffaf3 100644
--- chrome/browser/printing/print_view_manager_base.cc
+++ chrome/browser/printing/print_view_manager_base.cc
@@ -22,6 +22,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"
@@ -61,6 +62,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"
@@ -201,8 +206,11 @@ 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 (cef::IsAlloyRuntimeEnabled())
+ return CefPrintViewManager::FromWebContents(web_contents);
+ return PrintViewManager::FromWebContents(web_contents);
}
void NotifySystemDialogCancelled(int render_process_id, int routing_id) {
diff --git chrome/browser/printing/print_view_manager_base.h chrome/browser/printing/print_view_manager_base.h
index 93103940036e..1b12b91cdf4b 100644
--- chrome/browser/printing/print_view_manager_base.h
+++ chrome/browser/printing/print_view_manager_base.h
@@ -122,9 +122,6 @@ class PrintViewManagerBase : public content::NotificationObserver,
// Manages the low-level talk to the printer.
scoped_refptr<PrintJob> 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 df858712d3be..cd146ea0f26b 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/resources/print_preview/ui/destination_select.html chrome/browser/resources/print_preview/ui/destination_select.html
index 6d3d49c902e7..4769176b9550 100644
--- chrome/browser/resources/print_preview/ui/destination_select.html
+++ chrome/browser/resources/print_preview/ui/destination_select.html
@@ -20,10 +20,6 @@
<option value="[[pdfDestinationKey_]]" hidden$="[[pdfPrinterDisabled]]">
$i18n{printToPDF}
</option>
- <option value="[[driveDestinationKey]]"
- hidden$="[[!driveDestinationKey]]">
- $i18n{printToGoogleDrive}
- </option>
<option value="noDestinations"
hidden$="[[!noDestinations]]" selected$="[[noDestinations]]">
$i18n{noDestinationsMessage}
diff --git chrome/browser/ui/webui/constrained_web_dialog_ui.cc chrome/browser/ui/webui/constrained_web_dialog_ui.cc
index 3d415a60d436..807ab41ee6ef 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;
@@ -55,8 +57,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() {
diff --git chrome/browser/ui/webui/print_preview/pdf_printer_handler.cc chrome/browser/ui/webui/print_preview/pdf_printer_handler.cc
index 181a4132f1be..4344ceaf83e5 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"
@@ -54,6 +55,10 @@
#include "chrome/browser/chromeos/drive/drive_integration_service.h"
#endif
+#if BUILDFLAG(ENABLE_CEF)
+#include "cef/libcef/browser/alloy/alloy_browser_host_impl.h"
+#endif
+
namespace printing {
namespace {
@@ -377,10 +382,27 @@ void PdfPrinterHandler::SelectFile(const base::FilePath& default_filename,
// 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_);
@@ -388,8 +410,7 @@ void PdfPrinterHandler::SelectFile(const base::FilePath& default_filename,
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() {
@@ -430,6 +451,40 @@ 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) {
+ CefRefPtr<AlloyBrowserHostImpl> cef_browser =
+ AlloyBrowserHostImpl::GetBrowserForContents(initiator);
+ if (!cef_browser)
+ return;
+
+ base::FilePath path = directory.Append(filename);
+
+ CefFileDialogRunner::FileChooserParams params;
+ params.mode = blink::mojom::FileChooserParams::Mode::kSave;
+ params.default_file_name = path;
+ params.accept_types.push_back(CefString(path.Extension()));
+
+ cef_browser->RunFileChooser(
+ params, base::Bind(&PdfPrinterHandler::SaveAsDialogDismissed,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
+void PdfPrinterHandler::SaveAsDialogDismissed(
+ int selected_accept_filter,
+ const std::vector<base::FilePath>& 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 d796486f6b74..1a7b0d23128d 100644
--- chrome/browser/ui/webui/print_preview/pdf_printer_handler.h
+++ chrome/browser/ui/webui/print_preview/pdf_printer_handler.h
@@ -12,6 +12,7 @@
#include "base/memory/weak_ptr.h"
#include "base/strings/string16.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"
@@ -89,6 +90,15 @@ class PdfPrinterHandler : public PrinterHandler,
void OnDirectorySelected(const base::FilePath& filename,
const base::FilePath& directory);
+#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<base::FilePath>& 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_handler.cc chrome/browser/ui/webui/print_preview/print_preview_handler.cc
index 67aa6bc0d76e..0fecbd87423b 100644
--- chrome/browser/ui/webui/print_preview/print_preview_handler.cc
+++ chrome/browser/ui/webui/print_preview/print_preview_handler.cc
@@ -25,6 +25,7 @@
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
+#include "cef/libcef/features/features.h"
#include "chrome/browser/app_mode/app_mode_utils.h"
#include "chrome/browser/bad_message.h"
#include "chrome/browser/browser_process.h"
@@ -1080,7 +1081,7 @@ PrinterHandler* PrintPreviewHandler::GetPrinterHandler(
}
return extension_printer_handler_.get();
}
-#if BUILDFLAG(ENABLE_SERVICE_DISCOVERY)
+#if BUILDFLAG(ENABLE_SERVICE_DISCOVERY) && !BUILDFLAG(ENABLE_CEF)
if (printer_type == PrinterType::kPrivet &&
GetPrefs()->GetBoolean(prefs::kForceEnablePrivetPrinting)) {
if (!privet_printer_handler_) {
@@ -1089,6 +1090,9 @@ PrinterHandler* PrintPreviewHandler::GetPrinterHandler(
}
return privet_printer_handler_.get();
}
+#else // !BUILDFLAG(ENABLE_SERVICE_DISCOVERY)
+ if (printer_type == PrinterType::kPrivet)
+ return nullptr;
#endif
if (printer_type == PrinterType::kPdf) {
if (!pdf_printer_handler_) {
@@ -1151,6 +1155,7 @@ void PrintPreviewHandler::OnPrintResult(const std::string& callback_id,
}
void PrintPreviewHandler::RegisterForGaiaCookieChanges() {
+#if !BUILDFLAG(ENABLE_CEF)
DCHECK(!identity_manager_);
cloud_print_enabled_ =
!base::Contains(printer_type_deny_list_, PrinterType::kCloud) &&
@@ -1167,6 +1172,7 @@ void PrintPreviewHandler::RegisterForGaiaCookieChanges() {
identity_manager_ = IdentityManagerFactory::GetForProfile(profile);
identity_manager_->AddObserver(this);
+#endif
}
void PrintPreviewHandler::UnregisterForGaiaCookieChanges() {
diff --git chrome/browser/ui/webui/print_preview/print_preview_ui.cc chrome/browser/ui/webui/print_preview/print_preview_ui.cc
index fb3328d0d75b..4dd94d59e195 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/features.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/pdf/pdf_extension_util.h"
#include "chrome/browser/printing/background_printing_manager.h"
@@ -85,12 +86,16 @@ namespace printing {
namespace {
+#if BUILDFLAG(ENABLE_CEF)
+const char kBasicPrintShortcut[] = "";
+#else
#if defined(OS_MAC)
// U+0028 U+21E7 U+2318 U+0050 U+0029 in UTF8
const char kBasicPrintShortcut[] = "\x28\xE2\x8c\xA5\xE2\x8C\x98\x50\x29";
#elif !BUILDFLAG(IS_CHROMEOS_ASH)
const char kBasicPrintShortcut[] = "(Ctrl+Shift+P)";
#endif
+#endif // !BUILDFLAG(ENABLE_CEF)
PrintPreviewUI::TestDelegate* g_test_delegate = nullptr;