Commit 798e8038 authored by Allen Bauer's avatar Allen Bauer Committed by Commit Bot

Make sure the dangerous download dialog is 320px wide.

Bug: 654142
Change-Id: I0bd9cd4fcf4337b20809a99329e429f62f14994f
Reviewed-on: https://chromium-review.googlesource.com/896165
Commit-Queue: Bret Sepulveda <bsep@chromium.org>
Reviewed-by: default avatarBret Sepulveda <bsep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#534195}
parent 8f9dac25
...@@ -20,11 +20,8 @@ ...@@ -20,11 +20,8 @@
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_features.h" #include "ui/base/ui_features.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/layout/grid_layout.h" #include "ui/views/layout/fill_layout.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/dialog_client_view.h" #include "ui/views/window/dialog_client_view.h"
#include "ui/views/window/dialog_delegate.h" #include "ui/views/window/dialog_delegate.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -34,14 +31,12 @@ using safe_browsing::ClientSafeBrowsingReportRequest; ...@@ -34,14 +31,12 @@ using safe_browsing::ClientSafeBrowsingReportRequest;
namespace { namespace {
const int kMessageWidth = 320;
// Views-specific implementation of download danger prompt dialog. We use this // Views-specific implementation of download danger prompt dialog. We use this
// class rather than a TabModalConfirmDialog so that we can use custom // class rather than a TabModalConfirmDialog so that we can use custom
// formatting on the text in the body of the dialog. // formatting on the text in the body of the dialog.
class DownloadDangerPromptViews : public DownloadDangerPrompt, class DownloadDangerPromptViews : public DownloadDangerPrompt,
public content::DownloadItem::Observer, public content::DownloadItem::Observer,
public views::DialogDelegate { public views::DialogDelegateView {
public: public:
DownloadDangerPromptViews(content::DownloadItem* item, DownloadDangerPromptViews(content::DownloadItem* item,
bool show_context, bool show_context,
...@@ -51,17 +46,14 @@ class DownloadDangerPromptViews : public DownloadDangerPrompt, ...@@ -51,17 +46,14 @@ class DownloadDangerPromptViews : public DownloadDangerPrompt,
// DownloadDangerPrompt: // DownloadDangerPrompt:
void InvokeActionForTesting(Action action) override; void InvokeActionForTesting(Action action) override;
// views::DialogDelegate: // views::DialogDelegateView:
gfx::Size CalculatePreferredSize() const override;
base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
base::string16 GetWindowTitle() const override; base::string16 GetWindowTitle() const override;
void DeleteDelegate() override;
ui::ModalType GetModalType() const override; ui::ModalType GetModalType() const override;
bool Cancel() override; bool Cancel() override;
bool Accept() override; bool Accept() override;
bool Close() override; bool Close() override;
views::View* GetContentsView() override;
views::Widget* GetWidget() override;
const views::Widget* GetWidget() const override;
// content::DownloadItem::Observer: // content::DownloadItem::Observer:
void OnDownloadUpdated(content::DownloadItem* download) override; void OnDownloadUpdated(content::DownloadItem* download) override;
...@@ -80,38 +72,25 @@ class DownloadDangerPromptViews : public DownloadDangerPrompt, ...@@ -80,38 +72,25 @@ class DownloadDangerPromptViews : public DownloadDangerPrompt,
OnDone done_; OnDone done_;
std::unique_ptr<ExperienceSamplingEvent> sampling_event_; std::unique_ptr<ExperienceSamplingEvent> sampling_event_;
views::View* contents_view_;
}; };
DownloadDangerPromptViews::DownloadDangerPromptViews( DownloadDangerPromptViews::DownloadDangerPromptViews(
content::DownloadItem* item, content::DownloadItem* item,
bool show_context, bool show_context,
const OnDone& done) const OnDone& done)
: download_(item), : download_(item), show_context_(show_context), done_(done) {
show_context_(show_context),
done_(done),
contents_view_(NULL) {
download_->AddObserver(this); download_->AddObserver(this);
contents_view_ = new views::View;
set_margins(ChromeLayoutProvider::Get()->GetDialogInsetsForContentType( set_margins(ChromeLayoutProvider::Get()->GetDialogInsetsForContentType(
views::TEXT, views::TEXT)); views::TEXT, views::TEXT));
views::GridLayout* layout = contents_view_->SetLayoutManager( SetLayoutManager(std::make_unique<views::FillLayout>());
std::make_unique<views::GridLayout>(contents_view_));
views::ColumnSet* column_set = layout->AddColumnSet(0);
column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
views::GridLayout::FIXED, kMessageWidth, 0);
views::Label* message_body_label = new views::Label(GetMessageBody()); views::Label* message_body_label = new views::Label(GetMessageBody());
message_body_label->SetMultiLine(true); message_body_label->SetMultiLine(true);
message_body_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); message_body_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
message_body_label->SetAllowCharacterBreak(true); message_body_label->SetAllowCharacterBreak(true);
layout->StartRow(0, 0); AddChildView(message_body_label);
layout->AddView(message_body_label);
RecordOpenedDangerousConfirmDialog(download_->GetDangerType()); RecordOpenedDangerousConfirmDialog(download_->GetDangerType());
...@@ -186,11 +165,6 @@ base::string16 DownloadDangerPromptViews::GetWindowTitle() const { ...@@ -186,11 +165,6 @@ base::string16 DownloadDangerPromptViews::GetWindowTitle() const {
} }
} }
void DownloadDangerPromptViews::DeleteDelegate() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
delete this;
}
ui::ModalType DownloadDangerPromptViews::GetModalType() const { ui::ModalType DownloadDangerPromptViews::GetModalType() const {
return ui::MODAL_TYPE_CHILD; return ui::MODAL_TYPE_CHILD;
} }
...@@ -222,18 +196,6 @@ bool DownloadDangerPromptViews::Close() { ...@@ -222,18 +196,6 @@ bool DownloadDangerPromptViews::Close() {
return true; return true;
} }
views::View* DownloadDangerPromptViews::GetContentsView() {
return contents_view_;
}
views::Widget* DownloadDangerPromptViews::GetWidget() {
return contents_view_->GetWidget();
}
const views::Widget* DownloadDangerPromptViews::GetWidget() const {
return contents_view_->GetWidget();
}
// content::DownloadItem::Observer: // content::DownloadItem::Observer:
void DownloadDangerPromptViews::OnDownloadUpdated( void DownloadDangerPromptViews::OnDownloadUpdated(
content::DownloadItem* download) { content::DownloadItem* download) {
...@@ -246,6 +208,13 @@ void DownloadDangerPromptViews::OnDownloadUpdated( ...@@ -246,6 +208,13 @@ void DownloadDangerPromptViews::OnDownloadUpdated(
} }
} }
gfx::Size DownloadDangerPromptViews::CalculatePreferredSize() const {
int preferred_width = ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_BUBBLE_PREFERRED_WIDTH) -
margins().width();
return gfx::Size(preferred_width, GetHeightForWidth(preferred_width));
}
base::string16 DownloadDangerPromptViews::GetAcceptButtonTitle() const { base::string16 DownloadDangerPromptViews::GetAcceptButtonTitle() const {
return l10n_util::GetStringUTF16(IDS_CANCEL); return l10n_util::GetStringUTF16(IDS_CANCEL);
} }
......
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