Commit 041f6b60 authored by Marijn Kruisselbrink's avatar Marijn Kruisselbrink Committed by Commit Bot

[Native File System] Add dialog to inform user they picked a blocked directory.

Actually hooking this up to a blocklist etc will be done in future CLs.
See https://storage.cloud.google.com/chromium-translation-screenshots/8f6df1b3e036b7d1ff3f02ffb177ce99865ad7cb
for what this dialog looks like.

Bug: 968851
Change-Id: I20930d63e1e799da92dd9784678bb12f6b8e2f74
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1680950
Commit-Queue: Marijn Kruisselbrink <mek@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarOvidio de Jesús Ruiz-Henríquez <odejesush@chromium.org>
Cr-Commit-Position: refs/heads/master@{#676132}
parent 365a24a2
...@@ -9543,6 +9543,17 @@ Please help our engineers fix this problem. Tell us what happened right before y ...@@ -9543,6 +9543,17 @@ Please help our engineers fix this problem. Tell us what happened right before y
} }
</message> </message>
<!-- Native File System restricted directory dialog. -->
<message name="IDS_NATIVE_FILE_SYSTEM_RESTRICTED_DIRECTORY_TITLE" desc="Title of dialog explaining that the user selected a directory that chrome doesn't want to expose to the web">
Can't save to this folder
</message>
<message name="IDS_NATIVE_FILE_SYSTEM_RESTRICTED_DIRECTORY_TEXT" desc="Text of dialog explaining that the user selected a directory that chrome doesn't want to expose to the web">
<ph name="ORIGIN">$1<ex>example.com</ex></ph> can't save your changes to this folder because it contains system files.
</message>
<message name="IDS_NATIVE_FILE_SYSTEM_RESTRICTED_DIRECTORY_BUTTON" desc="Text of the button in dialog explaining that the user selected a directory that chrome doesn't want to expose to the web">
Choose a different folder
</message>
<!-- Relaunch notification bubble and dialog. --> <!-- Relaunch notification bubble and dialog. -->
<if expr="not is_android"> <if expr="not is_android">
<if expr="not chromeos"> <if expr="not chromeos">
......
8f6df1b3e036b7d1ff3f02ffb177ce99865ad7cb
\ No newline at end of file
8f6df1b3e036b7d1ff3f02ffb177ce99865ad7cb
\ No newline at end of file
8f6df1b3e036b7d1ff3f02ffb177ce99865ad7cb
\ No newline at end of file
...@@ -2822,6 +2822,8 @@ jumbo_split_static_library("ui") { ...@@ -2822,6 +2822,8 @@ jumbo_split_static_library("ui") {
"views/native_file_system/native_file_system_access_icon_view.h", "views/native_file_system/native_file_system_access_icon_view.h",
"views/native_file_system/native_file_system_permission_view.cc", "views/native_file_system/native_file_system_permission_view.cc",
"views/native_file_system/native_file_system_permission_view.h", "views/native_file_system/native_file_system_permission_view.h",
"views/native_file_system/native_file_system_restricted_directory_dialog_view.cc",
"views/native_file_system/native_file_system_restricted_directory_dialog_view.h",
"views/native_file_system/native_file_system_ui_helpers.cc", "views/native_file_system/native_file_system_ui_helpers.cc",
"views/native_file_system/native_file_system_ui_helpers.h", "views/native_file_system/native_file_system_ui_helpers.h",
"views/native_file_system/native_file_system_usage_bubble_view.cc", "views/native_file_system/native_file_system_usage_bubble_view.cc",
......
...@@ -37,4 +37,14 @@ void ShowNativeFileSystemPermissionDialog( ...@@ -37,4 +37,14 @@ void ShowNativeFileSystemPermissionDialog(
// if the dialog was instantly cancelled. // if the dialog was instantly cancelled.
std::move(callback).Run(PermissionAction::DISMISSED); std::move(callback).Run(PermissionAction::DISMISSED);
} }
void ShowNativeFileSystemRestrictedDirectoryDialog(
const url::Origin& origin,
const base::FilePath& path,
base::OnceClosure callback,
content::WebContents* web_contents) {
// There's no dialog version of this available outside views, run callback as
// if the dialog was instantly dismissed.
std::move(callback).Run();
}
#endif // !defined(TOOLKIT_VIEWS) #endif // !defined(TOOLKIT_VIEWS)
...@@ -313,4 +313,13 @@ void ShowNativeFileSystemPermissionDialog( ...@@ -313,4 +313,13 @@ void ShowNativeFileSystemPermissionDialog(
base::OnceCallback<void(PermissionAction result)> callback, base::OnceCallback<void(PermissionAction result)> callback,
content::WebContents* web_contents); content::WebContents* web_contents);
// Displays a dialog to inform the user that the directory |path| they picked
// using the native file system API is blocked by chrome.
// |callback| is called when the user has dismissed the dialog.
void ShowNativeFileSystemRestrictedDirectoryDialog(
const url::Origin& origin,
const base::FilePath& path,
base::OnceClosure callback,
content::WebContents* web_contents);
#endif // CHROME_BROWSER_UI_BROWSER_DIALOGS_H_ #endif // CHROME_BROWSER_UI_BROWSER_DIALOGS_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/native_file_system/native_file_system_restricted_directory_dialog_view.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/chrome_typography.h"
#include "chrome/grit/generated_resources.h"
#include "components/constrained_window/constrained_window_views.h"
#include "components/url_formatter/elide_url.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/window/dialog_client_view.h"
NativeFileSystemRestrictedDirectoryDialogView::
~NativeFileSystemRestrictedDirectoryDialogView() {
// Make sure the dialog ends up calling the callback no matter what.
if (!callback_.is_null())
Accept();
}
// static
views::Widget* NativeFileSystemRestrictedDirectoryDialogView::ShowDialog(
const url::Origin& origin,
const base::FilePath& path,
base::OnceClosure callback,
content::WebContents* web_contents) {
auto delegate =
base::WrapUnique(new NativeFileSystemRestrictedDirectoryDialogView(
origin, path, std::move(callback)));
return constrained_window::ShowWebModalDialogViews(delegate.release(),
web_contents);
}
base::string16 NativeFileSystemRestrictedDirectoryDialogView::GetWindowTitle()
const {
return l10n_util::GetStringUTF16(
IDS_NATIVE_FILE_SYSTEM_RESTRICTED_DIRECTORY_TITLE);
}
int NativeFileSystemRestrictedDirectoryDialogView::GetDialogButtons() const {
return ui::DIALOG_BUTTON_OK;
}
base::string16
NativeFileSystemRestrictedDirectoryDialogView::GetDialogButtonLabel(
ui::DialogButton button) const {
return l10n_util::GetStringUTF16(
IDS_NATIVE_FILE_SYSTEM_RESTRICTED_DIRECTORY_BUTTON);
}
bool NativeFileSystemRestrictedDirectoryDialogView::ShouldShowCloseButton()
const {
return false;
}
bool NativeFileSystemRestrictedDirectoryDialogView::Accept() {
std::move(callback_).Run();
return true;
}
bool NativeFileSystemRestrictedDirectoryDialogView::Cancel() {
std::move(callback_).Run();
return true;
}
gfx::Size
NativeFileSystemRestrictedDirectoryDialogView::CalculatePreferredSize() const {
const int width = ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH) -
margins().width();
return gfx::Size(width, GetHeightForWidth(width));
}
ui::ModalType NativeFileSystemRestrictedDirectoryDialogView::GetModalType()
const {
return ui::MODAL_TYPE_CHILD;
}
NativeFileSystemRestrictedDirectoryDialogView::
NativeFileSystemRestrictedDirectoryDialogView(const url::Origin& origin,
const base::FilePath& path,
base::OnceClosure callback)
: callback_(std::move(callback)) {
SetLayoutManager(std::make_unique<views::FillLayout>());
auto label = std::make_unique<views::Label>(
l10n_util::GetStringFUTF16(
IDS_NATIVE_FILE_SYSTEM_RESTRICTED_DIRECTORY_TEXT,
url_formatter::FormatOriginForSecurityDisplay(
origin, url_formatter::SchemeDisplay::OMIT_CRYPTOGRAPHIC)),
CONTEXT_BODY_TEXT_LARGE, STYLE_SECONDARY);
label->SetMultiLine(true);
label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
AddChildView(label.release());
set_margins(ChromeLayoutProvider::Get()->GetDialogInsetsForContentType(
views::TEXT, views::TEXT));
}
void ShowNativeFileSystemRestrictedDirectoryDialog(
const url::Origin& origin,
const base::FilePath& path,
base::OnceClosure callback,
content::WebContents* web_contents) {
NativeFileSystemRestrictedDirectoryDialogView::ShowDialog(
origin, path, std::move(callback), web_contents);
}
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_NATIVE_FILE_SYSTEM_NATIVE_FILE_SYSTEM_RESTRICTED_DIRECTORY_DIALOG_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_NATIVE_FILE_SYSTEM_NATIVE_FILE_SYSTEM_RESTRICTED_DIRECTORY_DIALOG_VIEW_H_
#include "base/macros.h"
#include "base/strings/string16.h"
#include "ui/views/window/dialog_delegate.h"
namespace base {
class FilePath;
}
namespace content {
class WebContents;
} // namespace content
namespace url {
class Origin;
} // namespace url
namespace views {
class Widget;
} // namespace views
// A dialog that informs the user that they can't give a website access to a
// specific folder.
class NativeFileSystemRestrictedDirectoryDialogView
: public views::DialogDelegateView {
public:
~NativeFileSystemRestrictedDirectoryDialogView() override;
// Creates and shows the dialog. The |callback| is called when the dialog is
// dismissed.
static views::Widget* ShowDialog(const url::Origin& origin,
const base::FilePath& path,
base::OnceClosure callback,
content::WebContents* web_contents);
// views::DialogDelegateView:
base::string16 GetWindowTitle() const override;
int GetDialogButtons() const override;
base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
bool ShouldShowCloseButton() const override;
bool Accept() override;
bool Cancel() override;
gfx::Size CalculatePreferredSize() const override;
ui::ModalType GetModalType() const override;
private:
NativeFileSystemRestrictedDirectoryDialogView(const url::Origin& origin,
const base::FilePath& path,
base::OnceClosure callback);
base::OnceClosure callback_;
DISALLOW_COPY_AND_ASSIGN(NativeFileSystemRestrictedDirectoryDialogView);
};
#endif // CHROME_BROWSER_UI_VIEWS_NATIVE_FILE_SYSTEM_NATIVE_FILE_SYSTEM_RESTRICTED_DIRECTORY_DIALOG_VIEW_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/native_file_system/native_file_system_restricted_directory_dialog_view.h"
#include "base/files/file_path.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"
class NativeFileSystemRestrictedDirectoryDialogViewTest
: 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_RESTRICTED_DIRECTORY_TITLE,
base::ASCIIToUTF16("Can't save to this folder"));
shared_resource_bundle.OverrideLocaleStringResource(
IDS_NATIVE_FILE_SYSTEM_RESTRICTED_DIRECTORY_TEXT,
base::ASCIIToUTF16("$1 can't save your changes to this folder because "
"it contains system files."));
shared_resource_bundle.OverrideLocaleStringResource(
IDS_NATIVE_FILE_SYSTEM_RESTRICTED_DIRECTORY_BUTTON,
base::ASCIIToUTF16("Choose a different folder"));
}
// DialogBrowserTest:
void ShowUi(const std::string& name) override {
NativeFileSystemRestrictedDirectoryDialogView::ShowDialog(
kTestOrigin, base::FilePath(FILE_PATH_LITERAL("/foo/bar")),
base::DoNothing(),
browser()->tab_strip_model()->GetActiveWebContents());
}
protected:
const url::Origin kTestOrigin =
url::Origin::Create(GURL("https://example.com"));
};
IN_PROC_BROWSER_TEST_F(NativeFileSystemRestrictedDirectoryDialogViewTest,
InvokeUi_default) {
ShowAndVerifyUi();
}
...@@ -1807,6 +1807,7 @@ if (!is_android) { ...@@ -1807,6 +1807,7 @@ if (!is_android) {
"../browser/ui/views/media_router/media_router_ui_browsertest.cc", "../browser/ui/views/media_router/media_router_ui_browsertest.cc",
"../browser/ui/views/media_router/presentation_receiver_window_view_browsertest.cc", "../browser/ui/views/media_router/presentation_receiver_window_view_browsertest.cc",
"../browser/ui/views/native_file_system/native_file_system_permission_view_browsertest.cc", "../browser/ui/views/native_file_system/native_file_system_permission_view_browsertest.cc",
"../browser/ui/views/native_file_system/native_file_system_restricted_directory_dialog_view_browsertest.cc",
"../browser/ui/views/omnibox/omnibox_popup_contents_view_browsertest.cc", "../browser/ui/views/omnibox/omnibox_popup_contents_view_browsertest.cc",
"../browser/ui/views/page_action/pwa_install_view_browsertest.cc", "../browser/ui/views/page_action/pwa_install_view_browsertest.cc",
"../browser/ui/views/page_action/zoom_view_browsertest.cc", "../browser/ui/views/page_action/zoom_view_browsertest.cc",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment