[Native File System] Update strings of write permission request dialog.
Bug: 985602
Change-Id: I7622cfcd23119e1323096b047e50eca0146abc33
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1710758
Commit-Queue: Marijn Kruisselbrink <mek@chromium.org>
Commit-Queue: Victor Costan <pwnall@chromium.org>
Reviewed-by: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#679330}
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index 1b88489..6f97479 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -9463,19 +9463,19 @@
<!-- Native File System permission dialog -->
<message name="IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_FILE_TITLE" desc="Title of dialog for confirming write access to a file using the Native File System API">
- Save changes to original file?
+ Save changes to <ph name="FILENAME">$1<ex>README.md</ex></ph>?
</message>
<message name="IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_DIRECTORY_TITLE" desc="Title of dialog for confirming write access to a directory and the files it contains using the Native File System API">
- Save changes to original files?
+ Save changes to files?
</message>
<message name="IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_FILE_TEXT" desc="Text of the dialog for confirming write access to files using the Native File System API">
- <ph name="ORIGIN">$1<ex>example.com</ex></ph> will be able to save your changes directly to the following file. This site can save changes only while this tab is open.
+ <ph name="ORIGIN">$1<ex>example.com</ex></ph> will be able to save your changes directly to <ph name="FILENAME">$2<ex>README.md</ex></ph>. The site can save changes until you close this tab.
</message>
<message name="IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_DIRECTORY_TEXT" desc="Text of the dialog for confirming write access to a directory using the Native File System API">
- <ph name="ORIGIN">$1<ex>example.com</ex></ph> will be able to save your changes directly to the files in the following folder. This site can save changes only while this tab is open.
+ <ph name="ORIGIN">$1<ex>example.com</ex></ph> will be able to save your changes directly to the files in <ph name="FOLDERNAME">$2<ex>My Project</ex></ph>. The site can save changes until you close this tab.
</message>
<message name="IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_ALLOW_TEXT" desc="Text of the 'allow' button in the dialog for confirming write access to files or directories using the Native File System API">
- Save to original file
+ Save changes
</message>
<!-- Native File System usage indicator -->
diff --git a/chrome/app/generated_resources_grd/IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_ALLOW_TEXT.png.sha1 b/chrome/app/generated_resources_grd/IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_ALLOW_TEXT.png.sha1
index 6a7c160d..4fcded83 100644
--- a/chrome/app/generated_resources_grd/IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_ALLOW_TEXT.png.sha1
+++ b/chrome/app/generated_resources_grd/IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_ALLOW_TEXT.png.sha1
@@ -1 +1 @@
-f88c5196f6a0b2de0569a82e7fd7cb15d05d995b
\ No newline at end of file
+4d38a4af9ba5cc2ceb9371cec583cdf4cba3a837
\ No newline at end of file
diff --git a/chrome/app/generated_resources_grd/IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_DIRECTORY_TEXT.png.sha1 b/chrome/app/generated_resources_grd/IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_DIRECTORY_TEXT.png.sha1
index 8658d58..2b70ad3d 100644
--- a/chrome/app/generated_resources_grd/IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_DIRECTORY_TEXT.png.sha1
+++ b/chrome/app/generated_resources_grd/IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_DIRECTORY_TEXT.png.sha1
@@ -1 +1 @@
-29a9ce8ff3e542bca3084cb4bb6516f4ad6c6ca1
\ No newline at end of file
+8ed3a2331e2b5c6d9c1ead047e9a580eb977c822
\ No newline at end of file
diff --git a/chrome/app/generated_resources_grd/IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_DIRECTORY_TITLE.png.sha1 b/chrome/app/generated_resources_grd/IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_DIRECTORY_TITLE.png.sha1
index 8658d58..2b70ad3d 100644
--- a/chrome/app/generated_resources_grd/IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_DIRECTORY_TITLE.png.sha1
+++ b/chrome/app/generated_resources_grd/IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_DIRECTORY_TITLE.png.sha1
@@ -1 +1 @@
-29a9ce8ff3e542bca3084cb4bb6516f4ad6c6ca1
\ No newline at end of file
+8ed3a2331e2b5c6d9c1ead047e9a580eb977c822
\ No newline at end of file
diff --git a/chrome/app/generated_resources_grd/IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_FILE_TEXT.png.sha1 b/chrome/app/generated_resources_grd/IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_FILE_TEXT.png.sha1
index 6a7c160d..4fcded83 100644
--- a/chrome/app/generated_resources_grd/IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_FILE_TEXT.png.sha1
+++ b/chrome/app/generated_resources_grd/IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_FILE_TEXT.png.sha1
@@ -1 +1 @@
-f88c5196f6a0b2de0569a82e7fd7cb15d05d995b
\ No newline at end of file
+4d38a4af9ba5cc2ceb9371cec583cdf4cba3a837
\ No newline at end of file
diff --git a/chrome/app/generated_resources_grd/IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_FILE_TITLE.png.sha1 b/chrome/app/generated_resources_grd/IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_FILE_TITLE.png.sha1
index 6a7c160d..4fcded83 100644
--- a/chrome/app/generated_resources_grd/IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_FILE_TITLE.png.sha1
+++ b/chrome/app/generated_resources_grd/IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_FILE_TITLE.png.sha1
@@ -1 +1 @@
-f88c5196f6a0b2de0569a82e7fd7cb15d05d995b
\ No newline at end of file
+4d38a4af9ba5cc2ceb9371cec583cdf4cba3a837
\ No newline at end of file
diff --git a/chrome/browser/ui/views/native_file_system/native_file_system_permission_view.cc b/chrome/browser/ui/views/native_file_system/native_file_system_permission_view.cc
index e542dba..9b05b9e 100644
--- a/chrome/browser/ui/views/native_file_system/native_file_system_permission_view.cc
+++ b/chrome/browser/ui/views/native_file_system/native_file_system_permission_view.cc
@@ -32,32 +32,10 @@
provider->GetDialogInsetsForContentType(views::TEXT, views::TEXT),
provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL)));
- AddChildView(native_file_system_ui_helper::CreateOriginLabel(
+ AddChildView(native_file_system_ui_helper::CreateOriginPathLabel(
is_directory ? IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_DIRECTORY_TEXT
: IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_FILE_TEXT,
- origin, CONTEXT_BODY_TEXT_SMALL));
-
- auto file_label_container = std::make_unique<views::View>();
- int indent =
- provider->GetDistanceMetric(DISTANCE_SUBSECTION_HORIZONTAL_INDENT);
- file_label_container->SetLayoutManager(std::make_unique<views::BoxLayout>(
- views::BoxLayout::Orientation::kHorizontal,
- gfx::Insets(/*vertical=*/0, indent),
- provider->GetDistanceMetric(views::DISTANCE_RELATED_LABEL_HORIZONTAL)));
- auto icon = std::make_unique<views::ImageView>();
- const gfx::VectorIcon& vector_id =
- is_directory ? vector_icons::kFolderOpenIcon
- : vector_icons::kInsertDriveFileOutlineIcon;
- const SkColor icon_color = icon->GetNativeTheme()->GetSystemColor(
- ui::NativeTheme::kColorId_DefaultIconColor);
- icon->SetImage(gfx::CreateVectorIcon(vector_id, /*dip_size=*/18, icon_color));
- file_label_container->AddChildView(std::move(icon));
- auto file_label = std::make_unique<views::Label>(path.LossyDisplayName(),
- CONTEXT_BODY_TEXT_SMALL,
- STYLE_EMPHASIZED_SECONDARY);
- file_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
- file_label_container->AddChildView(std::move(file_label));
- AddChildView(std::move(file_label_container));
+ origin, path, CONTEXT_BODY_TEXT_SMALL));
}
NativeFileSystemPermissionView::~NativeFileSystemPermissionView() {
@@ -79,9 +57,13 @@
}
base::string16 NativeFileSystemPermissionView::GetWindowTitle() const {
- return l10n_util::GetStringUTF16(
- is_directory_ ? IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_DIRECTORY_TITLE
- : IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_FILE_TITLE);
+ if (is_directory_) {
+ return l10n_util::GetStringUTF16(
+ IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_DIRECTORY_TITLE);
+ }
+ return l10n_util::GetStringFUTF16(
+ IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_FILE_TITLE,
+ path_.BaseName().LossyDisplayName());
}
int NativeFileSystemPermissionView::GetDefaultDialogButton() const {
diff --git a/chrome/browser/ui/views/native_file_system/native_file_system_permission_view_browsertest.cc b/chrome/browser/ui/views/native_file_system/native_file_system_permission_view_browsertest.cc
index 5a258dc..d7ff53e 100644
--- a/chrome/browser/ui/views/native_file_system/native_file_system_permission_view_browsertest.cc
+++ b/chrome/browser/ui/views/native_file_system/native_file_system_permission_view_browsertest.cc
@@ -9,46 +9,28 @@
#include "chrome/browser/permissions/permission_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/test/test_browser_dialog.h"
-#include "chrome/grit/generated_resources.h"
-#include "ui/base/resource/resource_bundle.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/window/dialog_client_view.h"
class NativeFileSystemPermissionViewTest : public DialogBrowserTest {
public:
- void SetUpOnMainThread() override {
- // Release builds may strip out unused string resources when
- // enable_resource_whitelist_generation is enabled. Manually override the
- // strings needed by the dialog to ensure they are available for tests.
- // TODO(https://crbug.com/979659): Remove these overrides once the strings
- // are referenced from the Chrome binary.
- auto& shared_resource_bundle = ui::ResourceBundle::GetSharedInstance();
- shared_resource_bundle.OverrideLocaleStringResource(
- IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_FILE_TITLE,
- base::ASCIIToUTF16("Edit file?"));
- shared_resource_bundle.OverrideLocaleStringResource(
- IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_DIRECTORY_TITLE,
- base::ASCIIToUTF16("Edit folder?"));
- shared_resource_bundle.OverrideLocaleStringResource(
- IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_FILE_TEXT,
- base::ASCIIToUTF16(
- "This will allow $1 to save or edit the following file(s) on your "
- "device. Only do this if you trust the app."));
- shared_resource_bundle.OverrideLocaleStringResource(
- IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_DIRECTORY_TEXT,
- base::ASCIIToUTF16(
- "This will allow $1 to make changes to the following folder on "
- "your device. Only do this if you trust the app."));
- shared_resource_bundle.OverrideLocaleStringResource(
- IDS_NATIVE_FILE_SYSTEM_WRITE_PERMISSION_ALLOW_TEXT,
- base::ASCIIToUTF16("Allow"));
- }
-
// DialogBrowserTest:
void ShowUi(const std::string& name) override {
+ base::FilePath path;
+ bool is_directory = false;
+ if (name == "LongFileName") {
+ path = base::FilePath(FILE_PATH_LITERAL(
+ "/foo/bar/Some Really Really Really Really Long File Name.txt"));
+ } else if (name == "Folder") {
+ path = base::FilePath(FILE_PATH_LITERAL("/bar/MyProject"));
+ is_directory = true;
+ } else if (name == "default") {
+ path = base::FilePath(FILE_PATH_LITERAL("/foo/README.txt"));
+ } else {
+ NOTREACHED() << "Unimplemented test: " << name;
+ }
widget_ = NativeFileSystemPermissionView::ShowDialog(
- kTestOrigin, base::FilePath(FILE_PATH_LITERAL("/foo/bar")),
- /*is_directory=*/false,
+ kTestOrigin, path, is_directory,
base::BindLambdaForTesting([&](PermissionAction result) {
callback_called_ = true;
callback_result_ = result;
@@ -68,7 +50,7 @@
IN_PROC_BROWSER_TEST_F(NativeFileSystemPermissionViewTest,
AcceptIsntDefaultFocused) {
- ShowUi(std::string());
+ ShowUi("default");
EXPECT_NE(widget_->client_view()->AsDialogClientView()->ok_button(),
widget_->GetFocusManager()->GetFocusedView());
widget_->Close();
@@ -76,7 +58,7 @@
}
IN_PROC_BROWSER_TEST_F(NativeFileSystemPermissionViewTest, AcceptRunsCallback) {
- ShowUi(std::string());
+ ShowUi("default");
widget_->client_view()->AsDialogClientView()->AcceptWindow();
EXPECT_TRUE(callback_called_);
EXPECT_EQ(PermissionAction::GRANTED, callback_result_);
@@ -84,7 +66,7 @@
}
IN_PROC_BROWSER_TEST_F(NativeFileSystemPermissionViewTest, CancelRunsCallback) {
- ShowUi(std::string());
+ ShowUi("default");
widget_->client_view()->AsDialogClientView()->CancelWindow();
EXPECT_TRUE(callback_called_);
EXPECT_EQ(PermissionAction::DISMISSED, callback_result_);
@@ -92,7 +74,7 @@
}
IN_PROC_BROWSER_TEST_F(NativeFileSystemPermissionViewTest, CancelsWhenClosed) {
- ShowUi(std::string());
+ ShowUi("default");
widget_->Close();
EXPECT_TRUE(callback_called_);
EXPECT_EQ(PermissionAction::DISMISSED, callback_result_);
@@ -102,3 +84,12 @@
IN_PROC_BROWSER_TEST_F(NativeFileSystemPermissionViewTest, InvokeUi_default) {
ShowAndVerifyUi();
}
+
+IN_PROC_BROWSER_TEST_F(NativeFileSystemPermissionViewTest,
+ InvokeUi_LongFileName) {
+ ShowAndVerifyUi();
+}
+
+IN_PROC_BROWSER_TEST_F(NativeFileSystemPermissionViewTest, InvokeUi_Folder) {
+ ShowAndVerifyUi();
+}
diff --git a/chrome/browser/ui/views/native_file_system/native_file_system_ui_helpers.cc b/chrome/browser/ui/views/native_file_system/native_file_system_ui_helpers.cc
index 9ec7722d..b0c8d14 100644
--- a/chrome/browser/ui/views/native_file_system/native_file_system_ui_helpers.cc
+++ b/chrome/browser/ui/views/native_file_system/native_file_system_ui_helpers.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/ui/views/native_file_system/native_file_system_ui_helpers.h"
+#include "base/files/file_path.h"
#include "chrome/browser/ui/views/chrome_typography.h"
#include "components/url_formatter/elide_url.h"
#include "ui/base/l10n/l10n_util.h"
@@ -32,4 +33,38 @@
return label;
}
+std::unique_ptr<views::View> CreateOriginPathLabel(int message_id,
+ const url::Origin& origin,
+ const base::FilePath& path,
+ int text_context) {
+ base::string16 formatted_origin =
+ url_formatter::FormatOriginForSecurityDisplay(
+ origin, url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC);
+ base::string16 formatted_path = path.BaseName().LossyDisplayName();
+ std::vector<size_t> offsets;
+ auto label = std::make_unique<views::StyledLabel>(
+ l10n_util::GetStringFUTF16(message_id, formatted_origin, formatted_path,
+ &offsets),
+ nullptr);
+ DCHECK_EQ(2U, offsets.size());
+
+ label->SetTextContext(text_context);
+ label->SetDefaultTextStyle(STYLE_SECONDARY);
+ label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+
+ views::StyledLabel::RangeStyleInfo origin_style;
+ origin_style.text_style = STYLE_EMPHASIZED_SECONDARY;
+ label->AddStyleRange(
+ gfx::Range(offsets[0], offsets[0] + formatted_origin.length()),
+ origin_style);
+
+ views::StyledLabel::RangeStyleInfo path_style;
+ path_style.text_style = STYLE_EMPHASIZED_SECONDARY;
+ path_style.tooltip = path.LossyDisplayName();
+ label->AddStyleRange(
+ gfx::Range(offsets[1], offsets[1] + formatted_path.length()), path_style);
+
+ return label;
+}
+
} // namespace native_file_system_ui_helper
diff --git a/chrome/browser/ui/views/native_file_system/native_file_system_ui_helpers.h b/chrome/browser/ui/views/native_file_system/native_file_system_ui_helpers.h
index ee726c1..aaed03c 100644
--- a/chrome/browser/ui/views/native_file_system/native_file_system_ui_helpers.h
+++ b/chrome/browser/ui/views/native_file_system/native_file_system_ui_helpers.h
@@ -7,6 +7,10 @@
#include <memory>
+namespace base {
+class FilePath;
+}
+
namespace url {
class Origin;
}
@@ -23,6 +27,13 @@
const url::Origin& origin,
int text_context);
+// Creates and returns a label where the place holders are replaced with
+// |origin| and |path|, while formatting the origin and path as emphasized text.
+std::unique_ptr<views::View> CreateOriginPathLabel(int message_id,
+ const url::Origin& origin,
+ const base::FilePath& path,
+ int text_context);
+
} // namespace native_file_system_ui_helper
#endif // CHROME_BROWSER_UI_VIEWS_NATIVE_FILE_SYSTEM_NATIVE_FILE_SYSTEM_UI_HELPERS_H_