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