From e3dc50cee3f863573283b21ebdb55ff7dcb50791 Mon Sep 17 00:00:00 2001 From: brave-builds Date: Fri, 20 Dec 2024 16:23:31 +0000 Subject: [PATCH] Uplift of #27049 (squashed) to beta --- browser/ui/brave_browser.cc | 5 ++-- browser/ui/brave_file_select_utils.cc | 30 +++---------------- browser/ui/brave_file_select_utils.h | 1 + .../browser/download/download_file_picker.cc | 3 +- 4 files changed, 10 insertions(+), 29 deletions(-) diff --git a/browser/ui/brave_browser.cc b/browser/ui/brave_browser.cc index 350f9f2cef03..c574d5b9648e 100644 --- a/browser/ui/brave_browser.cc +++ b/browser/ui/brave_browser.cc @@ -153,9 +153,10 @@ void BraveBrowser::RunFileChooser( // DownloadFilePicker::DownloadFilePicker directly. // https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/public/mojom/choosers/file_chooser.mojom;l=27;drc=047c7dc4ee1ce908d7fea38ca063fa2f80f92c77 CHECK(render_frame_host); + const url::Origin& origin = render_frame_host->GetLastCommittedOrigin(); new_params->title = brave::GetFileSelectTitle( - content::WebContents::FromRenderFrameHost(render_frame_host), - render_frame_host->GetLastCommittedOrigin(), + content::WebContents::FromRenderFrameHost(render_frame_host), origin, + origin, params.mode == blink::mojom::FileChooserParams::Mode::kSave ? brave::FileSelectTitleType::kSave : brave::FileSelectTitleType::kOpen); diff --git a/browser/ui/brave_file_select_utils.cc b/browser/ui/brave_file_select_utils.cc index bd588b6fd9a0..fd56154bbb7f 100644 --- a/browser/ui/brave_file_select_utils.cc +++ b/browser/ui/brave_file_select_utils.cc @@ -46,41 +46,19 @@ url::Origin UnwrapOriginIfOpaque(const url::Origin& origin) { std::u16string GetFileSelectTitle(content::WebContents* web_contents, const url::Origin& alerting_frame_origin, + const url::Origin& download_origin, FileSelectTitleType file_select_type) { - // This implementation partially mirrors - // ChromeAppModalDialogManagerDelegate::GetTitle(). - // TODO(sko) It's hard to test this behavior is in sync at this moment. Even - // upstream tests aren't covering this. Need to figure out how we can test - // extension and isolated web app case. CHECK(web_contents); - Profile* profile = - Profile::FromBrowserContext(web_contents->GetBrowserContext()); - - UrlIdentity url_identity = UrlIdentity::CreateFromUrl( - profile, alerting_frame_origin.GetURL(), - /*allowed_types*/ - {UrlIdentity::Type::kDefault, UrlIdentity::Type::kFile, - UrlIdentity::Type::kIsolatedWebApp, UrlIdentity::Type::kChromeExtension}, - /*default_options*/ {.default_options = {}}); - - if (url_identity.type == UrlIdentity::Type::kChromeExtension) { - return url_identity.name; - } - - if (url_identity.type == UrlIdentity::Type::kIsolatedWebApp) { - return url_identity.name; - } - const auto main_frame_origin = web_contents->GetPrimaryMainFrame()->GetLastCommittedOrigin(); return GetSiteFrameTitleForFileSelect( GetSiteFrameTitleType(main_frame_origin, alerting_frame_origin), - alerting_frame_origin, file_select_type); + download_origin, file_select_type); } std::u16string GetSiteFrameTitleForFileSelect( SiteFrameTitleType frame_type, - const url::Origin& alerting_frame_origin, + const url::Origin& download_origin, FileSelectTitleType file_select_type) { constexpr std::array< std::array(SiteFrameTitleType::kSize)>, @@ -112,7 +90,7 @@ std::u16string GetSiteFrameTitleForFileSelect( frame_type == SiteFrameTitleType::kStandardDifferentOrigin) { std::u16string origin_string = url_formatter::FormatOriginForSecurityDisplay( - UnwrapOriginIfOpaque(alerting_frame_origin), + UnwrapOriginIfOpaque(download_origin), url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS); return l10n_util::GetStringFUTF16( kResourceIDs[static_cast(file_select_type)] diff --git a/browser/ui/brave_file_select_utils.h b/browser/ui/brave_file_select_utils.h index 9147c836f129..5088dc95ff10 100644 --- a/browser/ui/brave_file_select_utils.h +++ b/browser/ui/brave_file_select_utils.h @@ -47,6 +47,7 @@ enum class FileSelectTitleType { std::u16string GetFileSelectTitle(content::WebContents* contents, const url::Origin& alerting_frame_origin, + const url::Origin& download_origin, FileSelectTitleType file_select_type); std::u16string GetSiteFrameTitleForFileSelect( diff --git a/chromium_src/chrome/browser/download/download_file_picker.cc b/chromium_src/chrome/browser/download/download_file_picker.cc index 01fffc5c53f0..7979890eabfb 100644 --- a/chromium_src/chrome/browser/download/download_file_picker.cc +++ b/chromium_src/chrome/browser/download/download_file_picker.cc @@ -30,7 +30,8 @@ std::u16string GetTitle(content::RenderFrameHost* render_frame_host, CHECK(caller); return brave::GetFileSelectTitle( content::WebContents::FromRenderFrameHost(render_frame_host), - url::Origin::Create(*caller), brave::FileSelectTitleType::kSave); + render_frame_host->GetLastCommittedOrigin(), url::Origin::Create(*caller), + brave::FileSelectTitleType::kSave); #endif }