• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1diff --git chrome/browser/download/download_prefs.cc chrome/browser/download/download_prefs.cc
2index dbfae7b5e3d2c..bf18a6fbddf6d 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@@ -60,6 +61,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_download_util.h"
19+#endif
20+
21 using content::BrowserContext;
22 using content::BrowserThread;
23 using content::DownloadManager;
24@@ -340,6 +345,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 alloy::GetDownloadPrefsFromBrowserContext(context);
31+  }
32+#endif
33   return FromDownloadManager(context->GetDownloadManager());
34 }
35
36diff --git chrome/browser/printing/print_preview_dialog_controller.cc chrome/browser/printing/print_preview_dialog_controller.cc
37index 332fbc21aa0e3..1286fc203d6cd 100644
38--- chrome/browser/printing/print_preview_dialog_controller.cc
39+++ chrome/browser/printing/print_preview_dialog_controller.cc
40@@ -15,6 +15,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/printing/print_view_manager.h"
47 #include "chrome/browser/task_manager/web_contents_tags.h"
48diff --git chrome/browser/printing/print_view_manager_base.cc chrome/browser/printing/print_view_manager_base.cc
49index c759b7a7c9d19..c63900f5d1686 100644
50--- chrome/browser/printing/print_view_manager_base.cc
51+++ chrome/browser/printing/print_view_manager_base.cc
52@@ -248,12 +248,13 @@ void UpdatePrintSettingsOnIO(
53     mojom::PrintManagerHost::UpdatePrintSettingsCallback callback,
54     scoped_refptr<PrintQueriesQueue> queue,
55     base::Value job_settings,
56-    base::WeakPtr<PrintViewManagerBase> manager) {
57+    base::WeakPtr<PrintViewManagerBase> manager,
58+    int process_id,
59+    int routing_id) {
60   DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
61   std::unique_ptr<PrinterQuery> printer_query = queue->PopPrinterQuery(cookie);
62   if (!printer_query) {
63-    printer_query = queue->CreatePrinterQuery(
64-        content::ChildProcessHost::kInvalidUniqueID, MSG_ROUTING_NONE);
65+    printer_query = queue->CreatePrinterQuery(process_id, routing_id);
66   }
67   auto* printer_query_ptr = printer_query.get();
68   printer_query_ptr->SetSettings(
69@@ -675,6 +676,7 @@ void PrintViewManagerBase::UpdatePrintSettings(
70       job_settings.SetIntKey(kSettingRasterizePdfDpi, value);
71   }
72
73+  content::RenderFrameHost* render_frame_host = GetCurrentTargetFrame();
74   auto callback_wrapper =
75       base::BindOnce(&PrintViewManagerBase::UpdatePrintSettingsReply,
76                      weak_ptr_factory_.GetWeakPtr(), std::move(callback));
77@@ -682,7 +684,9 @@ void PrintViewManagerBase::UpdatePrintSettings(
78       FROM_HERE,
79       base::BindOnce(&UpdatePrintSettingsOnIO, cookie,
80                      std::move(callback_wrapper), queue_,
81-                     std::move(job_settings), weak_ptr_factory_.GetWeakPtr()));
82+                     std::move(job_settings), weak_ptr_factory_.GetWeakPtr(),
83+                     render_frame_host->GetProcess()->GetID(),
84+                     render_frame_host->GetRoutingID()));
85 }
86 #endif  // BUILDFLAG(ENABLE_PRINT_PREVIEW)
87
88diff --git chrome/browser/printing/print_view_manager_base.h chrome/browser/printing/print_view_manager_base.h
89index aa7915ac042fe..ab4d9a8ac6e24 100644
90--- chrome/browser/printing/print_view_manager_base.h
91+++ chrome/browser/printing/print_view_manager_base.h
92@@ -146,9 +146,6 @@ class PrintViewManagerBase : public PrintManager, public PrintJob::Observer {
93   // Manages the low-level talk to the printer.
94   scoped_refptr<PrintJob> print_job_;
95
96- private:
97-  friend class TestPrintViewManager;
98-
99   // content::WebContentsObserver implementation.
100   void RenderFrameHostStateChanged(
101       content::RenderFrameHost* render_frame_host,
102diff --git chrome/browser/resources/print_preview/ui/destination_dialog.html chrome/browser/resources/print_preview/ui/destination_dialog.html
103index 920f646f06484..76c0b5e5ee04b 100644
104--- chrome/browser/resources/print_preview/ui/destination_dialog.html
105+++ chrome/browser/resources/print_preview/ui/destination_dialog.html
106@@ -25,10 +25,7 @@
107     </print-preview-destination-list>
108   </div>
109   <div slot="button-container">
110-    <cr-button on-click="onManageButtonClick_">
111-      $i18n{manage}
112-      <iron-icon icon="cr:open-in-new" id="manageIcon"></iron-icon>
113-    </cr-button>
114+    <div></div>
115     <cr-button class="cancel-button" on-click="onCancelButtonClick_">
116       $i18n{cancel}
117     </cr-button>
118diff --git chrome/browser/ui/webui/constrained_web_dialog_ui.cc chrome/browser/ui/webui/constrained_web_dialog_ui.cc
119index 8c5ba47779d24..91a70d8715f33 100644
120--- chrome/browser/ui/webui/constrained_web_dialog_ui.cc
121+++ chrome/browser/ui/webui/constrained_web_dialog_ui.cc
122@@ -13,6 +13,7 @@
123 #include "base/memory/ptr_util.h"
124 #include "base/memory/raw_ptr.h"
125 #include "base/values.h"
126+#include "cef/libcef/features/runtime.h"
127 #include "content/public/browser/notification_service.h"
128 #include "content/public/browser/render_frame_host.h"
129 #include "content/public/browser/web_contents.h"
130@@ -57,7 +58,9 @@ class ConstrainedWebDialogDelegateUserData
131 ConstrainedWebDialogUI::ConstrainedWebDialogUI(content::WebUI* web_ui)
132     : WebUIController(web_ui) {
133 #if BUILDFLAG(ENABLE_EXTENSIONS)
134+  if (!cef::IsAlloyRuntimeEnabled()) {
135   extensions::TabHelper::CreateForWebContents(web_ui->GetWebContents());
136+  }
137 #endif
138 }
139
140diff --git chrome/browser/ui/webui/print_preview/pdf_printer_handler.cc chrome/browser/ui/webui/print_preview/pdf_printer_handler.cc
141index e5dfa76d26d86..b7dcf7a11479f 100644
142--- chrome/browser/ui/webui/print_preview/pdf_printer_handler.cc
143+++ chrome/browser/ui/webui/print_preview/pdf_printer_handler.cc
144@@ -21,6 +21,7 @@
145 #include "base/values.h"
146 #include "build/build_config.h"
147 #include "build/chromeos_buildflags.h"
148+#include "cef/libcef/features/runtime.h"
149 #include "chrome/browser/app_mode/app_mode_utils.h"
150 #include "chrome/browser/browser_process.h"
151 #include "chrome/browser/download/download_prefs.h"
152@@ -62,6 +63,10 @@
153 #include "chromeos/lacros/lacros_service.h"
154 #endif
155
156+#if BUILDFLAG(ENABLE_CEF)
157+#include "cef/libcef/browser/alloy/alloy_dialog_util.h"
158+#endif
159+
160 namespace printing {
161
162 namespace {
163@@ -414,16 +419,18 @@ void PdfPrinterHandler::SelectFile(const base::FilePath& default_filename,
164     service->GetRemote<crosapi::mojom::DriveIntegrationService>()
165         ->GetMountPointPath(
166             base::BindOnce(&PdfPrinterHandler::OnSaveLocationReady,
167-                           weak_ptr_factory_.GetWeakPtr(),
168+                           weak_ptr_factory_.GetWeakPtr(), initiator,
169                            std::move(default_filename), prompt_user));
170     return;
171   }
172 #endif
173
174-  OnSaveLocationReady(default_filename, prompt_user, GetSaveLocation());
175+  OnSaveLocationReady(initiator, default_filename, prompt_user,
176+                      GetSaveLocation());
177 }
178
179 void PdfPrinterHandler::OnSaveLocationReady(
180+    content::WebContents* initiator,
181     const base::FilePath& default_filename,
182     bool prompt_user,
183     const base::FilePath& path) {
184@@ -441,10 +448,27 @@ void PdfPrinterHandler::OnSaveLocationReady(
185   // If the directory is empty there is no reason to create it or use the
186   // default location.
187   if (path.empty()) {
188+#if BUILDFLAG(ENABLE_CEF)
189+    if (cef::IsAlloyRuntimeEnabled()) {
190+      ShowCefSaveAsDialog(initiator, default_filename, path);
191+      return;
192+    }
193+#endif
194     OnDirectorySelected(default_filename, path);
195     return;
196   }
197
198+  auto callback = base::BindOnce(&PdfPrinterHandler::OnDirectorySelected,
199+                                 weak_ptr_factory_.GetWeakPtr(),
200+                                 default_filename);
201+#if BUILDFLAG(ENABLE_CEF)
202+  if (cef::IsAlloyRuntimeEnabled()) {
203+    callback = base::BindOnce(&PdfPrinterHandler::ShowCefSaveAsDialog,
204+                              weak_ptr_factory_.GetWeakPtr(), initiator,
205+                              default_filename);
206+  }
207+#endif
208+
209   // Get default download directory. This will be used as a fallback if the
210   // save directory does not exist.
211   DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext(profile_);
212@@ -452,8 +476,7 @@ void PdfPrinterHandler::OnSaveLocationReady(
213   base::ThreadPool::PostTaskAndReplyWithResult(
214       FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT},
215       base::BindOnce(&SelectSaveDirectory, path, default_path),
216-      base::BindOnce(&PdfPrinterHandler::OnDirectorySelected,
217-                     weak_ptr_factory_.GetWeakPtr(), default_filename));
218+      std::move(callback));
219 }
220
221 void PdfPrinterHandler::PostPrintToPdfTask() {
222@@ -499,6 +522,36 @@ void PdfPrinterHandler::OnDirectorySelected(const base::FilePath& filename,
223       platform_util::GetTopLevel(preview_web_contents_->GetNativeView()), NULL);
224 }
225
226+#if BUILDFLAG(ENABLE_CEF)
227+
228+void PdfPrinterHandler::ShowCefSaveAsDialog(content::WebContents* initiator,
229+                                            const base::FilePath& filename,
230+                                            const base::FilePath& directory) {
231+  base::FilePath path = directory.Append(filename);
232+
233+  blink::mojom::FileChooserParams params;
234+  params.mode = blink::mojom::FileChooserParams::Mode::kSave;
235+  params.default_file_name = path;
236+  params.accept_types.push_back(
237+      alloy::FilePathTypeToString16(path.Extension()));
238+
239+  alloy::RunFileChooser(initiator, params,
240+      base::BindOnce(&PdfPrinterHandler::SaveAsDialogDismissed,
241+                     weak_ptr_factory_.GetWeakPtr()));
242+}
243+
244+void PdfPrinterHandler::SaveAsDialogDismissed(
245+    int selected_accept_filter,
246+    const std::vector<base::FilePath>& file_paths) {
247+  if (file_paths.size() == 1) {
248+    FileSelected(file_paths[0], 0, nullptr);
249+  } else {
250+    FileSelectionCanceled(nullptr);
251+  }
252+}
253+
254+#endif  // BUILDFLAG(ENABLE_CEF)
255+
256 base::FilePath PdfPrinterHandler::GetSaveLocation() const {
257 #if BUILDFLAG(IS_CHROMEOS_ASH)
258   drive::DriveIntegrationService* drive_service =
259diff --git chrome/browser/ui/webui/print_preview/pdf_printer_handler.h chrome/browser/ui/webui/print_preview/pdf_printer_handler.h
260index 46c8b1d08b075..1ee95cd7c3240 100644
261--- chrome/browser/ui/webui/print_preview/pdf_printer_handler.h
262+++ chrome/browser/ui/webui/print_preview/pdf_printer_handler.h
263@@ -12,6 +12,7 @@
264 #include "base/memory/ref_counted.h"
265 #include "base/memory/weak_ptr.h"
266 #include "build/chromeos_buildflags.h"
267+#include "cef/libcef/features/features.h"
268 #include "chrome/browser/ui/webui/print_preview/printer_handler.h"
269 #include "ui/shell_dialogs/select_file_dialog.h"
270
271@@ -95,10 +96,20 @@ class PdfPrinterHandler : public PrinterHandler,
272   void OnDirectorySelected(const base::FilePath& filename,
273                            const base::FilePath& directory);
274
275-  void OnSaveLocationReady(const base::FilePath& default_filename,
276+  void OnSaveLocationReady(content::WebContents* initiator,
277+                           const base::FilePath& default_filename,
278                            bool prompt_user,
279                            const base::FilePath& path);
280
281+#if BUILDFLAG(ENABLE_CEF)
282+  void ShowCefSaveAsDialog(content::WebContents* initiator,
283+                           const base::FilePath& filename,
284+                           const base::FilePath& directory);
285+
286+  void SaveAsDialogDismissed(int selected_accept_filter,
287+                             const std::vector<base::FilePath>& file_paths);
288+#endif
289+
290   // Return save location as the Drive mount or fetch from Download Preferences.
291   base::FilePath GetSaveLocation() const;
292
293diff --git chrome/browser/ui/webui/print_preview/print_preview_ui.cc chrome/browser/ui/webui/print_preview/print_preview_ui.cc
294index da70f602899a9..ca99c7d2ec09f 100644
295--- chrome/browser/ui/webui/print_preview/print_preview_ui.cc
296+++ chrome/browser/ui/webui/print_preview/print_preview_ui.cc
297@@ -22,6 +22,7 @@
298 #include "base/values.h"
299 #include "build/build_config.h"
300 #include "build/chromeos_buildflags.h"
301+#include "cef/libcef/features/runtime.h"
302 #include "chrome/browser/browser_process.h"
303 #include "chrome/browser/pdf/pdf_extension_util.h"
304 #include "chrome/browser/printing/background_printing_manager.h"
305@@ -97,6 +98,13 @@ const char16_t kBasicPrintShortcut[] = u"\u0028\u21e7\u2318\u0050\u0029";
306 const char16_t kBasicPrintShortcut[] = u"(Ctrl+Shift+P)";
307 #endif
308
309+const char16_t* GetBasicPrintShortcut() {
310+  if (cef::IsAlloyRuntimeEnabled()) {
311+    return u"";
312+  }
313+  return kBasicPrintShortcut;
314+}
315+
316 constexpr char kInvalidArgsForDidStartPreview[] =
317     "Invalid arguments for DidStartPreview";
318 constexpr char kInvalidPageNumberForDidPreviewPage[] =
319@@ -342,7 +350,7 @@ void AddPrintPreviewStrings(content::WebUIDataSource* source) {
320                     chrome::kCloudPrintCertificateErrorLearnMoreURL);
321
322 #if !BUILDFLAG(IS_CHROMEOS)
323-  const std::u16string shortcut_text(kBasicPrintShortcut);
324+  const std::u16string shortcut_text(GetBasicPrintShortcut());
325   source->AddString("systemDialogOption",
326                     l10n_util::GetStringFUTF16(
327                         IDS_PRINT_PREVIEW_SYSTEM_DIALOG_OPTION, shortcut_text));
328