Skip to content

Commit

Permalink
separate alerting origin from download origin (#27049)
Browse files Browse the repository at this point in the history
  • Loading branch information
diracdeltas authored Dec 20, 2024
1 parent 144e1e4 commit be37556
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 29 deletions.
5 changes: 3 additions & 2 deletions browser/ui/brave_browser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
30 changes: 4 additions & 26 deletions browser/ui/brave_file_select_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, static_cast<size_t>(SiteFrameTitleType::kSize)>,
Expand Down Expand Up @@ -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<size_t>(file_select_type)]
Expand Down
1 change: 1 addition & 0 deletions browser/ui/brave_file_select_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion chromium_src/chrome/browser/download/download_file_picker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit be37556

Please sign in to comment.