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 (uplift to 1.74.x) #27079

Open
wants to merge 1 commit into
base: 1.74.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
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
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
Loading