Commit 56f8225c authored by Bret Sepulveda's avatar Bret Sepulveda Committed by Commit Bot

Fix long extension install dialog titles from laying out on one line.

Versions of the dialog with long titles, like the "re-enable with new
permissions" or the "extension installed externally" dialogs, are
affected by this change. Instead of wrapping, their titles would all
be on one big line, making the dialog extremely wide. This is fixed.

This patch also adds interactive browser tests for "withheld"
permissions and for the "re-enable" version of the dialog.

Bug: 654124
Change-Id: Iaffdede6a9977952f83a4393425a4df58007d05e
Reviewed-on: https://chromium-review.googlesource.com/885104Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Commit-Queue: Bret Sepulveda <bsep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532559}
parent 996812e1
......@@ -193,13 +193,6 @@ class CustomScrollableView : public views::View {
: parent_(parent) {}
~CustomScrollableView() override {}
gfx::Size CalculatePreferredSize() const override {
const int content_width = ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH) -
GetInsets().width();
return gfx::Size(content_width, GetHeightForWidth(content_width));
}
// views::View:
void ChildPreferredSizeChanged(views::View* child) override {
PreferredSizeChanged();
......@@ -283,8 +276,8 @@ void ExtensionInstallDialogView::CreateContents() {
extension_info_container->SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::kVertical, gfx::Insets(),
provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL)));
const int content_width =
extension_info_container->GetPreferredSize().width();
const int content_width = GetPreferredSize().width() -
extension_info_container->GetInsets().width();
std::vector<ExtensionInfoSection> sections;
if (prompt_->ShouldShowPermissions()) {
......@@ -455,6 +448,13 @@ void ExtensionInstallDialogView::ResizeWidget() {
GetWidget()->SetSize(GetWidget()->non_client_view()->GetPreferredSize());
}
gfx::Size ExtensionInstallDialogView::CalculatePreferredSize() const {
const int width = ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH) -
margins().width();
return gfx::Size(width, GetHeightForWidth(width));
}
void ExtensionInstallDialogView::AddedToWidget() {
auto title_container = std::make_unique<views::View>();
......@@ -466,11 +466,14 @@ void ExtensionInstallDialogView::AddedToWidget() {
constexpr int icon_size = extension_misc::EXTENSION_ICON_SMALL;
column_set->AddColumn(views::GridLayout::CENTER, views::GridLayout::LEADING,
0, views::GridLayout::FIXED, icon_size, 0);
// Equalize padding on the left and the right of the icon.
column_set->AddPaddingColumn(
0, provider->GetInsetsMetric(views::INSETS_DIALOG).left());
column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING,
0, views::GridLayout::USE_PREF, 0, 0);
// Set a resize weight so that the title label will be expanded to the
// available width.
column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::LEADING, 1,
views::GridLayout::USE_PREF, 0, 0);
// Scale down to icon size, but allow smaller icons (don't scale up).
const gfx::ImageSkia* image = prompt_->icon().ToImageSkia();
......@@ -486,6 +489,9 @@ void ExtensionInstallDialogView::AddedToWidget() {
std::unique_ptr<views::Label> title_label =
views::BubbleFrameView::CreateDefaultTitleLabel(
prompt_->GetDialogTitle());
// Setting the title's preferred size to 0 ensures it won't influence the
// overall size of the dialog. It will be expanded by GridLayout.
title_label->SetPreferredSize(gfx::Size(0, 0));
if (prompt_->has_webstore_data()) {
auto webstore_data_container = std::make_unique<views::View>();
webstore_data_container->SetLayoutManager(
......
......@@ -53,6 +53,7 @@ class ExtensionInstallDialogView : public views::DialogDelegateView,
private:
// views::DialogDelegateView:
gfx::Size CalculatePreferredSize() const override;
void AddedToWidget() override;
void VisibilityChanged(views::View* starting_from, bool is_visible) override;
int GetDialogButtons() const override;
......
......@@ -245,11 +245,11 @@ class ExtensionInstallDialogViewInteractiveBrowserTest
icon.allocN32Pixels(800, 800);
icon.eraseARGB(255, 128, 255, 128);
auto prompt = std::make_unique<ExtensionInstallPrompt::Prompt>(
external_install_ ? ExtensionInstallPrompt::EXTERNAL_INSTALL_PROMPT
: ExtensionInstallPrompt::INLINE_INSTALL_PROMPT);
auto prompt = std::make_unique<ExtensionInstallPrompt::Prompt>(type_);
prompt->AddPermissions(permissions_,
ExtensionInstallPrompt::REGULAR_PERMISSIONS);
prompt->AddPermissions(withheld_permissions_,
ExtensionInstallPrompt::WITHHELD_PERMISSIONS);
prompt->set_retained_files(retained_files_);
prompt->set_retained_device_messages(retained_devices_);
......@@ -264,14 +264,20 @@ class ExtensionInstallDialogViewInteractiveBrowserTest
&icon, std::move(prompt), ExtensionInstallPrompt::ShowDialogCallback());
}
void set_external_install() { external_install_ = true; }
void set_from_webstore() { from_webstore_ = true; }
void set_type(ExtensionInstallPrompt::PromptType type) { type_ = type; }
void AddPermission(std::string permission) {
permissions_.push_back(
PermissionMessage(base::ASCIIToUTF16(permission), PermissionIDSet()));
}
void AddWithheldPermission(std::string permission) {
withheld_permissions_.push_back(
PermissionMessage(base::ASCIIToUTF16(permission), PermissionIDSet()));
}
void AddRetainedFile(const base::FilePath& path) {
retained_files_.push_back(path);
}
......@@ -289,9 +295,11 @@ class ExtensionInstallDialogViewInteractiveBrowserTest
}
private:
bool external_install_ = false;
ExtensionInstallPrompt::PromptType type_ =
ExtensionInstallPrompt::INLINE_INSTALL_PROMPT;
bool from_webstore_ = false;
PermissionMessages permissions_;
PermissionMessages withheld_permissions_;
std::vector<base::FilePath> retained_files_;
std::vector<base::string16> retained_devices_;
......@@ -305,13 +313,20 @@ IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewInteractiveBrowserTest,
IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewInteractiveBrowserTest,
InvokeUi_External) {
set_external_install();
set_type(ExtensionInstallPrompt::EXTERNAL_INSTALL_PROMPT);
ShowAndVerifyUi();
}
IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewInteractiveBrowserTest,
InvokeUi_ExternalWithPermission) {
set_external_install();
set_type(ExtensionInstallPrompt::EXTERNAL_INSTALL_PROMPT);
AddPermission("Example permission");
ShowAndVerifyUi();
}
IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewInteractiveBrowserTest,
InvokeUi_ReEnable) {
set_type(ExtensionInstallPrompt::RE_ENABLE_PROMPT);
AddPermission("Example permission");
ShowAndVerifyUi();
}
......@@ -356,6 +371,12 @@ IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewInteractiveBrowserTest,
ShowAndVerifyUi();
}
IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewInteractiveBrowserTest,
InvokeUi_WithheldPermission) {
AddWithheldPermission("Example permission");
ShowAndVerifyUi();
}
IN_PROC_BROWSER_TEST_F(ExtensionInstallDialogViewInteractiveBrowserTest,
InvokeUi_WithRetainedFiles) {
AddRetainedFile(base::FilePath(FILE_PATH_LITERAL("/dev/null")));
......
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