Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

separate alerting origin from download origin #27049

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion 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(),
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;
}

Copy link
Member Author

@diracdeltas diracdeltas Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

took out the code above because i'm not sure we actually need it

  • it only returns the name of an extension/app, not a proper message like "$app wants to download...", which seems like a bug
  • i think the chromium version is just intended to return a human-friendly name for extensions/etc. it's nice to have but without it, probably we would just show the generic "this page" message, which is ok.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is how it looks with this change
image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@goodov thanks for testing it out. i think we can live with that and open a follow up unless you want to address it in this PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security wise i think this view is better because an extension/app could name themselves "google.com" or something

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice to have it like Extension <...> wants to save. For consistency a similar change should be done for "wants to open" dialog and also for apps(?). A follow up sounds reasonable here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ std::u16string GetTitle(content::RenderFrameHost* render_frame_host,
CHECK(caller);
return brave::GetFileSelectTitle(
content::WebContents::FromRenderFrameHost(render_frame_host),
render_frame_host->GetLastCommittedOrigin(),
url::Origin::Create(*caller), brave::FileSelectTitleType::kSave);
#endif
}
Expand Down
Loading