• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1diff --git chrome/browser/download/download_prefs.cc chrome/browser/download/download_prefs.cc
2index a95103026c8c..ae6c676defcc 100644
3--- chrome/browser/download/download_prefs.cc
4+++ chrome/browser/download/download_prefs.cc
5@@ -24,6 +24,7 @@
6 #include "base/strings/utf_string_conversions.h"
7 #include "build/build_config.h"
8 #include "build/chromeos_buildflags.h"
9+#include "cef/libcef/features/runtime.h"
10 #include "chrome/browser/download/chrome_download_manager_delegate.h"
11 #include "chrome/browser/download/download_core_service_factory.h"
12 #include "chrome/browser/download/download_core_service_impl.h"
13@@ -58,6 +59,10 @@
14 #include "chrome/browser/ui/pdf/adobe_reader_info_win.h"
15 #endif
16
17+#if BUILDFLAG(ENABLE_CEF)
18+#include "cef/libcef/browser/alloy/alloy_browser_context.h"
19+#endif
20+
21 using content::BrowserContext;
22 using content::BrowserThread;
23 using content::DownloadManager;
24@@ -358,6 +363,11 @@ DownloadPrefs* DownloadPrefs::FromDownloadManager(
25 // static
26 DownloadPrefs* DownloadPrefs::FromBrowserContext(
27     content::BrowserContext* context) {
28+#if BUILDFLAG(ENABLE_CEF)
29+  if (cef::IsAlloyRuntimeEnabled()) {
30+    return static_cast<AlloyBrowserContext*>(context)->GetDownloadPrefs();
31+  }
32+#endif
33   return FromDownloadManager(BrowserContext::GetDownloadManager(context));
34 }
35
36diff --git chrome/browser/printing/print_preview_dialog_controller.cc chrome/browser/printing/print_preview_dialog_controller.cc
37index 74536431f664..3fc69b656029 100644
38--- chrome/browser/printing/print_preview_dialog_controller.cc
39+++ chrome/browser/printing/print_preview_dialog_controller.cc
40@@ -17,6 +17,7 @@
41 #include "build/branding_buildflags.h"
42 #include "build/build_config.h"
43 #include "build/chromeos_buildflags.h"
44+#include "cef/libcef/features/features.h"
45 #include "chrome/browser/browser_process.h"
46 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
47 #include "chrome/browser/printing/print_view_manager.h"
48@@ -410,8 +411,11 @@ WebContents* PrintPreviewDialogController::CreatePrintPreviewDialog(
49   content::HostZoomMap::Get(preview_dialog->GetSiteInstance())
50       ->SetZoomLevelForHostAndScheme(print_url.scheme(), print_url.host(), 0);
51   PrintViewManager::CreateForWebContents(preview_dialog);
52+
53+#if !BUILDFLAG(ENABLE_CEF)
54   extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
55       preview_dialog);
56+#endif
57
58   // Add an entry to the map.
59   preview_dialog_map_[preview_dialog] = initiator;
60diff --git chrome/browser/printing/print_view_manager_base.cc chrome/browser/printing/print_view_manager_base.cc
61index 9aa99b764ad8..c45424d20315 100644
62--- chrome/browser/printing/print_view_manager_base.cc
63+++ chrome/browser/printing/print_view_manager_base.cc
64@@ -21,6 +21,7 @@
65 #include "base/timer/timer.h"
66 #include "build/build_config.h"
67 #include "build/chromeos_buildflags.h"
68+#include "cef/libcef/features/runtime.h"
69 #include "chrome/browser/browser_process.h"
70 #include "chrome/browser/chrome_notification_types.h"
71 #include "chrome/browser/printing/print_job.h"
72@@ -58,6 +59,10 @@
73 #include "printing/printing_features.h"
74 #endif
75
76+#if BUILDFLAG(ENABLE_CEF)
77+#include "cef/libcef/browser/printing/print_view_manager.h"
78+#endif
79+
80 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
81 #include "chrome/browser/printing/print_error_dialog.h"
82 #include "chrome/browser/printing/print_view_manager.h"
83@@ -198,8 +203,13 @@ PrintViewManager* GetPrintViewManager(int render_process_id,
84   DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
85   content::WebContents* web_contents =
86       GetWebContentsForRenderFrame(render_process_id, render_frame_id);
87-  return web_contents ? PrintViewManager::FromWebContents(web_contents)
88-                      : nullptr;
89+  if (!web_contents)
90+    return nullptr;
91+#if BUILDFLAG(ENABLE_CEF)
92+  if (cef::IsAlloyRuntimeEnabled())
93+    return CefPrintViewManager::FromWebContents(web_contents);
94+#endif
95+  return PrintViewManager::FromWebContents(web_contents);
96 }
97
98 void NotifySystemDialogCancelled(int render_process_id, int routing_id) {
99diff --git chrome/browser/printing/print_view_manager_base.h chrome/browser/printing/print_view_manager_base.h
100index a96e5a33643e..def5bced1c96 100644
101--- chrome/browser/printing/print_view_manager_base.h
102+++ chrome/browser/printing/print_view_manager_base.h
103@@ -122,9 +122,6 @@ class PrintViewManagerBase : public content::NotificationObserver,
104   // Manages the low-level talk to the printer.
105   scoped_refptr<PrintJob> print_job_;
106
107- private:
108-  friend class TestPrintViewManager;
109-
110   // content::NotificationObserver implementation.
111   void Observe(int type,
112                const content::NotificationSource& source,
113diff --git chrome/browser/resources/print_preview/ui/destination_dialog.html chrome/browser/resources/print_preview/ui/destination_dialog.html
114index 920f646f0648..76c0b5e5ee04 100644
115--- chrome/browser/resources/print_preview/ui/destination_dialog.html
116+++ chrome/browser/resources/print_preview/ui/destination_dialog.html
117@@ -25,10 +25,7 @@
118     </print-preview-destination-list>
119   </div>
120   <div slot="button-container">
121-    <cr-button on-click="onManageButtonClick_">
122-      $i18n{manage}
123-      <iron-icon icon="cr:open-in-new" id="manageIcon"></iron-icon>
124-    </cr-button>
125+    <div></div>
126     <cr-button class="cancel-button" on-click="onCancelButtonClick_">
127       $i18n{cancel}
128     </cr-button>
129diff --git chrome/browser/ui/webui/constrained_web_dialog_ui.cc chrome/browser/ui/webui/constrained_web_dialog_ui.cc
130index 3d415a60d436..807ab41ee6ef 100644
131--- chrome/browser/ui/webui/constrained_web_dialog_ui.cc
132+++ chrome/browser/ui/webui/constrained_web_dialog_ui.cc
133@@ -26,6 +26,8 @@
134 #include "chrome/browser/extensions/tab_helper.h"
135 #endif
136
137+#include "cef/libcef/features/features.h"
138+
139 using content::RenderFrameHost;
140 using content::WebContents;
141 using content::WebUIMessageHandler;
142@@ -55,8 +57,10 @@ class ConstrainedWebDialogDelegateUserData
143 ConstrainedWebDialogUI::ConstrainedWebDialogUI(content::WebUI* web_ui)
144     : WebUIController(web_ui) {
145 #if BUILDFLAG(ENABLE_EXTENSIONS)
146+#if !BUILDFLAG(ENABLE_CEF)
147   extensions::TabHelper::CreateForWebContents(web_ui->GetWebContents());
148 #endif
149+#endif
150 }
151
152 ConstrainedWebDialogUI::~ConstrainedWebDialogUI() {
153diff --git chrome/browser/ui/webui/print_preview/pdf_printer_handler.cc chrome/browser/ui/webui/print_preview/pdf_printer_handler.cc
154index 6c43d5381f7c..d5373865c985 100644
155--- chrome/browser/ui/webui/print_preview/pdf_printer_handler.cc
156+++ chrome/browser/ui/webui/print_preview/pdf_printer_handler.cc
157@@ -22,6 +22,7 @@
158 #include "base/values.h"
159 #include "build/build_config.h"
160 #include "build/chromeos_buildflags.h"
161+#include "cef/libcef/features/runtime.h"
162 #include "chrome/browser/app_mode/app_mode_utils.h"
163 #include "chrome/browser/browser_process.h"
164 #include "chrome/browser/download/download_prefs.h"
165@@ -55,6 +56,10 @@
166 #include "chrome/browser/ash/drive/drive_integration_service.h"
167 #endif
168
169+#if BUILDFLAG(ENABLE_CEF)
170+#include "cef/libcef/browser/alloy/alloy_browser_host_impl.h"
171+#endif
172+
173 namespace printing {
174
175 namespace {
176@@ -378,10 +383,27 @@ void PdfPrinterHandler::SelectFile(const base::FilePath& default_filename,
177   // If the directory is empty there is no reason to create it or use the
178   // default location.
179   if (path.empty()) {
180+#if BUILDFLAG(ENABLE_CEF)
181+    if (cef::IsAlloyRuntimeEnabled()) {
182+      ShowCefSaveAsDialog(initiator, default_filename, path);
183+      return;
184+    }
185+#endif
186     OnDirectorySelected(default_filename, path);
187     return;
188   }
189
190+  auto callback = base::BindOnce(&PdfPrinterHandler::OnDirectorySelected,
191+                                 weak_ptr_factory_.GetWeakPtr(),
192+                                 default_filename);
193+#if BUILDFLAG(ENABLE_CEF)
194+  if (cef::IsAlloyRuntimeEnabled()) {
195+    callback = base::BindOnce(&PdfPrinterHandler::ShowCefSaveAsDialog,
196+                              weak_ptr_factory_.GetWeakPtr(), initiator,
197+                              default_filename);
198+  }
199+#endif
200+
201   // Get default download directory. This will be used as a fallback if the
202   // save directory does not exist.
203   DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext(profile_);
204@@ -389,8 +411,7 @@ void PdfPrinterHandler::SelectFile(const base::FilePath& default_filename,
205   base::ThreadPool::PostTaskAndReplyWithResult(
206       FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT},
207       base::BindOnce(&SelectSaveDirectory, path, default_path),
208-      base::BindOnce(&PdfPrinterHandler::OnDirectorySelected,
209-                     weak_ptr_factory_.GetWeakPtr(), default_filename));
210+      std::move(callback));
211 }
212
213 void PdfPrinterHandler::PostPrintToPdfTask() {
214@@ -431,6 +452,40 @@ void PdfPrinterHandler::OnDirectorySelected(const base::FilePath& filename,
215       platform_util::GetTopLevel(preview_web_contents_->GetNativeView()), NULL);
216 }
217
218+#if BUILDFLAG(ENABLE_CEF)
219+
220+void PdfPrinterHandler::ShowCefSaveAsDialog(content::WebContents* initiator,
221+                                            const base::FilePath& filename,
222+                                            const base::FilePath& directory) {
223+  CefRefPtr<AlloyBrowserHostImpl> cef_browser =
224+      AlloyBrowserHostImpl::GetBrowserForContents(initiator);
225+  if (!cef_browser)
226+    return;
227+
228+  base::FilePath path = directory.Append(filename);
229+
230+  CefFileDialogRunner::FileChooserParams params;
231+  params.mode = blink::mojom::FileChooserParams::Mode::kSave;
232+  params.default_file_name = path;
233+  params.accept_types.push_back(CefString(path.Extension()));
234+
235+  cef_browser->RunFileChooser(
236+      params, base::Bind(&PdfPrinterHandler::SaveAsDialogDismissed,
237+                         weak_ptr_factory_.GetWeakPtr()));
238+}
239+
240+void PdfPrinterHandler::SaveAsDialogDismissed(
241+    int selected_accept_filter,
242+    const std::vector<base::FilePath>& file_paths) {
243+  if (file_paths.size() == 1) {
244+    FileSelected(file_paths[0], 0, nullptr);
245+  } else {
246+    FileSelectionCanceled(nullptr);
247+  }
248+}
249+
250+#endif  // BUILDFLAG(ENABLE_CEF)
251+
252 base::FilePath PdfPrinterHandler::GetSaveLocation() const {
253 #if BUILDFLAG(IS_CHROMEOS_ASH)
254   drive::DriveIntegrationService* drive_service =
255diff --git chrome/browser/ui/webui/print_preview/pdf_printer_handler.h chrome/browser/ui/webui/print_preview/pdf_printer_handler.h
256index 9730721279ef..cd3ec0c7e0af 100644
257--- chrome/browser/ui/webui/print_preview/pdf_printer_handler.h
258+++ chrome/browser/ui/webui/print_preview/pdf_printer_handler.h
259@@ -11,6 +11,7 @@
260 #include "base/memory/ref_counted.h"
261 #include "base/memory/weak_ptr.h"
262 #include "build/chromeos_buildflags.h"
263+#include "cef/libcef/features/features.h"
264 #include "chrome/browser/ui/webui/print_preview/printer_handler.h"
265 #include "ui/shell_dialogs/select_file_dialog.h"
266
267@@ -88,6 +89,15 @@ class PdfPrinterHandler : public PrinterHandler,
268   void OnDirectorySelected(const base::FilePath& filename,
269                            const base::FilePath& directory);
270
271+#if BUILDFLAG(ENABLE_CEF)
272+  void ShowCefSaveAsDialog(content::WebContents* initiator,
273+                           const base::FilePath& filename,
274+                           const base::FilePath& directory);
275+
276+  void SaveAsDialogDismissed(int selected_accept_filter,
277+                             const std::vector<base::FilePath>& file_paths);
278+#endif
279+
280   // Return save location as the Drive mount or fetch from Download Preferences.
281   base::FilePath GetSaveLocation() const;
282
283diff --git chrome/browser/ui/webui/print_preview/print_preview_handler.cc chrome/browser/ui/webui/print_preview/print_preview_handler.cc
284index 82a2ac9bc0e5..280e465d2aea 100644
285--- chrome/browser/ui/webui/print_preview/print_preview_handler.cc
286+++ chrome/browser/ui/webui/print_preview/print_preview_handler.cc
287@@ -24,6 +24,7 @@
288 #include "base/values.h"
289 #include "build/build_config.h"
290 #include "build/chromeos_buildflags.h"
291+#include "cef/libcef/features/features.h"
292 #include "chrome/browser/account_manager_facade_factory.h"
293 #include "chrome/browser/app_mode/app_mode_utils.h"
294 #include "chrome/browser/bad_message.h"
295@@ -1025,7 +1026,7 @@ PrinterHandler* PrintPreviewHandler::GetPrinterHandler(
296     }
297     return extension_printer_handler_.get();
298   }
299-#if BUILDFLAG(ENABLE_SERVICE_DISCOVERY)
300+#if BUILDFLAG(ENABLE_SERVICE_DISCOVERY) && !BUILDFLAG(ENABLE_CEF)
301   if (printer_type == PrinterType::kPrivet &&
302       GetPrefs()->GetBoolean(prefs::kForceEnablePrivetPrinting)) {
303     if (!privet_printer_handler_) {
304@@ -1034,6 +1035,9 @@ PrinterHandler* PrintPreviewHandler::GetPrinterHandler(
305     }
306     return privet_printer_handler_.get();
307   }
308+#else  // !BUILDFLAG(ENABLE_SERVICE_DISCOVERY)
309+  if (printer_type == PrinterType::kPrivet)
310+    return nullptr;
311 #endif
312   if (printer_type == PrinterType::kPdf) {
313     if (!pdf_printer_handler_) {
314diff --git chrome/browser/ui/webui/print_preview/print_preview_ui.cc chrome/browser/ui/webui/print_preview/print_preview_ui.cc
315index a6cd4b390fed..00d6e5c3d024 100644
316--- chrome/browser/ui/webui/print_preview/print_preview_ui.cc
317+++ chrome/browser/ui/webui/print_preview/print_preview_ui.cc
318@@ -30,6 +30,7 @@
319 #include "base/values.h"
320 #include "build/build_config.h"
321 #include "build/chromeos_buildflags.h"
322+#include "cef/libcef/features/features.h"
323 #include "chrome/browser/browser_process.h"
324 #include "chrome/browser/pdf/pdf_extension_util.h"
325 #include "chrome/browser/printing/background_printing_manager.h"
326@@ -91,12 +92,16 @@ namespace printing {
327
328 namespace {
329
330+#if BUILDFLAG(ENABLE_CEF)
331+const char kBasicPrintShortcut[] = "";
332+#else
333 #if defined(OS_MAC)
334 // U+0028 U+21E7 U+2318 U+0050 U+0029 in UTF8
335 const char kBasicPrintShortcut[] = "\x28\xE2\x8c\xA5\xE2\x8C\x98\x50\x29";
336 #elif !BUILDFLAG(IS_CHROMEOS_ASH)
337 const char kBasicPrintShortcut[] = "(Ctrl+Shift+P)";
338 #endif
339+#endif  // !BUILDFLAG(ENABLE_CEF)
340
341 constexpr char kInvalidArgsForDidStartPreview[] =
342     "Invalid arguments for DidStartPreview";
343