Skip to content

Commit

Permalink
Uplift of #26953 (squashed) to beta
Browse files Browse the repository at this point in the history
  • Loading branch information
brave-builds committed Dec 17, 2024
1 parent 6371890 commit 9eafe8d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,7 @@ Or change later at <ph name="SETTINGS_EXTENIONS_LINK">$2<ex>brave://settings/ext
<ph name="SITE">$1<ex>http://foo.com</ex></ph> wants to open
</message>
<message name="IDS_BRAVE_FILE_SELECT_OPEN_TITLE_IFRAME" desc="">
An embedded page on <ph name="SITE">$1<ex>http://foo.com</ex></ph> wants to open
An embedded page at <ph name="SITE">$1<ex>http://foo.com</ex></ph> wants to open
</message>
<message name="IDS_BRAVE_FILE_SELECT_OPEN_TITLE_NONSTANDARD_URL" desc="">
This page wants to open
Expand All @@ -1339,7 +1339,7 @@ Or change later at <ph name="SETTINGS_EXTENIONS_LINK">$2<ex>brave://settings/ext
<ph name="SITE">$1<ex>http://foo.com</ex></ph> wants to save
</message>
<message name="IDS_BRAVE_FILE_SELECT_SAVE_TITLE_IFRAME" desc="">
An embedded page on <ph name="SITE">$1<ex>http://foo.com</ex></ph> wants to save
An embedded page at <ph name="SITE">$1<ex>http://foo.com</ex></ph> wants to save
</message>
<message name="IDS_BRAVE_FILE_SELECT_SAVE_TITLE_NONSTANDARD_URL" desc="">
This page wants to save
Expand Down
12 changes: 6 additions & 6 deletions browser/ui/brave_file_select_utils_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ TEST(BraveFileSelectUtilsUnitTest, GetSiteFrameTitleForFileSelect_Open) {
"foo.com wants to open"},
// Subframe alert from a different origin.
{"subframe different origin", "http://foo.com/", false, "http://bar.com/",
"An embedded page on bar.com wants to open"},
"An embedded page at bar.com wants to open"},

// file:
// - main frame:
Expand Down Expand Up @@ -175,7 +175,7 @@ TEST(BraveFileSelectUtilsUnitTest, GetSiteFrameTitleForFileSelect_Open) {
// - subframe:
{"blob subframe", "http://bar.com/", false,
"blob:http://foo.com/66666666-6666-6666-6666-666666666666",
"An embedded page on foo.com wants to open"},
"An embedded page at foo.com wants to open"},

// filesystem:
// - main frame:
Expand All @@ -184,7 +184,7 @@ TEST(BraveFileSelectUtilsUnitTest, GetSiteFrameTitleForFileSelect_Open) {
// - subframe:
{"filesystem subframe", "http://bar.com/", false,
"filesystem:http://foo.com/bar.html",
"An embedded page on foo.com wants to open"},
"An embedded page at foo.com wants to open"},
};

brave_l10n::test::ScopedDefaultLocale scoped_locale("en-US");
Expand Down Expand Up @@ -230,7 +230,7 @@ TEST(BraveFileSelectUtilsUnitTest, GetSiteFrameTitleForFileSelect_Save) {
"foo.com wants to save"},
// Subframe alert from a different origin.
{"subframe different origin", "http://foo.com/", false, "http://bar.com/",
"An embedded page on bar.com wants to save"},
"An embedded page at bar.com wants to save"},

// file:
// - main frame:
Expand Down Expand Up @@ -278,7 +278,7 @@ TEST(BraveFileSelectUtilsUnitTest, GetSiteFrameTitleForFileSelect_Save) {
// - subframe:
{"blob subframe", "http://bar.com/", false,
"blob:http://foo.com/66666666-6666-6666-6666-666666666666",
"An embedded page on foo.com wants to save"},
"An embedded page at foo.com wants to save"},

// filesystem:
// - main frame:
Expand All @@ -287,7 +287,7 @@ TEST(BraveFileSelectUtilsUnitTest, GetSiteFrameTitleForFileSelect_Save) {
// - subframe:
{"filesystem subframe", "http://bar.com/", false,
"filesystem:http://foo.com/bar.html",
"An embedded page on foo.com wants to save"},
"An embedded page at foo.com wants to save"},
};

brave_l10n::test::ScopedDefaultLocale scoped_locale("en-US");
Expand Down
17 changes: 10 additions & 7 deletions chromium_src/chrome/browser/download/download_file_picker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

#include <string>

#include "components/download/public/common/download_item.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "third_party/blink/public/mojom/choosers/file_chooser.mojom.h"
#include "ui/shell_dialogs/select_file_dialog.h"
#include "url/origin.h"

#if !BUILDFLAG(IS_ANDROID)
#include "brave/browser/ui/brave_file_select_utils.h"
Expand All @@ -17,27 +19,28 @@
namespace {

std::u16string GetTitle(content::RenderFrameHost* render_frame_host,
const std::u16string& original_title) {
const std::u16string& original_title,
const GURL* caller) {
#if BUILDFLAG(IS_ANDROID)
return original_title;
#else
if (!render_frame_host) {
return original_title;
}
CHECK(caller);
return brave::GetFileSelectTitle(
content::WebContents::FromRenderFrameHost(render_frame_host),
render_frame_host->GetLastCommittedOrigin(),
brave::FileSelectTitleType::kSave);
url::Origin::Create(*caller), brave::FileSelectTitleType::kSave);
#endif
}

} // namespace

// Override title of the file select dialog for downloads.
#define SelectFile(type, title, default_path, file_types, file_type_index, \
default_extension, owning_window, caller) \
SelectFile(type, GetTitle(render_frame_host, title), default_path, \
file_types, file_type_index, default_extension, owning_window, \
#define SelectFile(type, title, default_path, file_types, file_type_index, \
default_extension, owning_window, caller) \
SelectFile(type, GetTitle(render_frame_host, title, caller), default_path, \
file_types, file_type_index, default_extension, owning_window, \
caller)

#include "src/chrome/browser/download/download_file_picker.cc"
Expand Down

0 comments on commit 9eafe8d

Please sign in to comment.