Commit 1e338666 authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

cbuiv: migrate more DialogDelegate closure paths

These are largely straightforward.

Bug: 1011446
Change-Id: Ifaf8be23c5e64743beafa0025817e3e0271788e5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2033437
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737474}
parent 312b6bf9
......@@ -384,6 +384,9 @@ ContentSettingBubbleContents::ContentSettingBubbleContents(
ui::DIALOG_BUTTON_OK,
done_text.empty() ? l10n_util::GetStringUTF16(IDS_DONE) : done_text);
DialogDelegate::SetExtraView(CreateHelpAndManageView());
DialogDelegate::set_accept_callback(
base::BindOnce(&ContentSettingBubbleModel::OnDoneButtonClicked,
base::Unretained(content_setting_bubble_model_.get())));
}
ContentSettingBubbleContents::~ContentSettingBubbleContents() {
......@@ -552,16 +555,6 @@ void ContentSettingBubbleContents::Init() {
content_setting_bubble_model_->set_owner(this);
}
bool ContentSettingBubbleContents::Accept() {
content_setting_bubble_model_->OnDoneButtonClicked();
return true;
}
bool ContentSettingBubbleContents::Close() {
return true;
}
void ContentSettingBubbleContents::StyleLearnMoreButton() {
DCHECK(learn_more_button_);
SkColor text_color = GetNativeTheme()->GetSystemColor(
......
......@@ -66,8 +66,6 @@ class ContentSettingBubbleContents : public content::WebContentsObserver,
// views::BubbleDialogDelegateView:
void Init() override;
bool Accept() override;
bool Close() override;
void OnThemeChanged() override;
private:
......
......@@ -55,9 +55,6 @@ class DownloadDangerPromptViews : public DownloadDangerPrompt,
gfx::Size CalculatePreferredSize() const override;
base::string16 GetWindowTitle() const override;
ui::ModalType GetModalType() const override;
bool Cancel() override;
bool Accept() override;
bool Close() override;
// download::DownloadItem::Observer:
void OnDownloadUpdated(download::DownloadItem* download) override;
......@@ -93,6 +90,18 @@ DownloadDangerPromptViews::DownloadDangerPromptViews(
show_context_ ? l10n_util::GetStringUTF16(IDS_CONFIRM_DOWNLOAD)
: l10n_util::GetStringUTF16(IDS_CONFIRM_DOWNLOAD_AGAIN));
auto make_done_callback = [&](DownloadDangerPrompt::Action action) {
return base::BindOnce(&DownloadDangerPromptViews::RunDone,
base::Unretained(this), action);
};
// Note that the presentational concept of "Accept/Cancel" is inverted from
// the model's concept of ACCEPT/CANCEL. In the UI, the safe path is "Accept"
// and the dangerous path is "Cancel".
DialogDelegate::set_accept_callback(make_done_callback(CANCEL));
DialogDelegate::set_cancel_callback(make_done_callback(ACCEPT));
DialogDelegate::set_close_callback(make_done_callback(DISMISS));
download_->AddObserver(this);
set_margins(ChromeLayoutProvider::Get()->GetDialogInsetsForContentType(
......@@ -162,27 +171,6 @@ ui::ModalType DownloadDangerPromptViews::GetModalType() const {
return ui::MODAL_TYPE_CHILD;
}
bool DownloadDangerPromptViews::Accept() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// Note that the presentational concept of "Accept/Cancel" is inverted from
// the model's concept of ACCEPT/CANCEL. In the UI, the safe path is "Accept"
// and the dangerous path is "Cancel".
RunDone(CANCEL);
return true;
}
bool DownloadDangerPromptViews::Cancel() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
RunDone(ACCEPT);
return true;
}
bool DownloadDangerPromptViews::Close() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
RunDone(DISMISS);
return true;
}
// download::DownloadItem::Observer:
void DownloadDangerPromptViews::OnDownloadUpdated(
download::DownloadItem* download) {
......
......@@ -56,6 +56,16 @@ ChooserDialogView::ChooserDialogView(
DialogDelegate::SetExtraView(device_chooser_content_view_->CreateExtraView());
DialogDelegate::set_accept_callback(
base::BindOnce(&DeviceChooserContentView::Accept,
base::Unretained(device_chooser_content_view_)));
DialogDelegate::set_cancel_callback(
base::BindOnce(&DeviceChooserContentView::Cancel,
base::Unretained(device_chooser_content_view_)));
DialogDelegate::set_close_callback(
base::BindOnce(&DeviceChooserContentView::Close,
base::Unretained(device_chooser_content_view_)));
chrome::RecordDialogCreation(chrome::DialogIdentifier::CHOOSER);
}
......@@ -81,21 +91,6 @@ views::View* ChooserDialogView::GetInitiallyFocusedView() {
return GetCancelButton();
}
bool ChooserDialogView::Accept() {
device_chooser_content_view_->Accept();
return true;
}
bool ChooserDialogView::Cancel() {
device_chooser_content_view_->Cancel();
return true;
}
bool ChooserDialogView::Close() {
device_chooser_content_view_->Close();
return true;
}
views::View* ChooserDialogView::GetContentsView() {
return device_chooser_content_view_;
}
......
......@@ -31,9 +31,6 @@ class ChooserDialogView : public views::DialogDelegateView,
// views::DialogDelegate:
bool IsDialogButtonEnabled(ui::DialogButton button) const override;
views::View* GetInitiallyFocusedView() override;
bool Accept() override;
bool Cancel() override;
bool Close() override;
// views::DialogDelegateView:
views::View* GetContentsView() override;
......
......@@ -89,6 +89,16 @@ GlobalErrorBubbleView::GlobalErrorBubbleView(
error_->GetBubbleViewAcceptButtonLabel());
DialogDelegate::set_button_label(ui::DIALOG_BUTTON_CANCEL,
error_->GetBubbleViewCancelButtonLabel());
// Note that error is already a WeakPtr, so these callbacks will simply do
// nothing if they are invoked after its destruction.
DialogDelegate::set_accept_callback(base::BindOnce(
&GlobalErrorWithStandardBubble::BubbleViewAcceptButtonPressed, error,
base::Unretained(browser_)));
DialogDelegate::set_cancel_callback(base::BindOnce(
&GlobalErrorWithStandardBubble::BubbleViewCancelButtonPressed, error,
base::Unretained(browser_)));
if (!error_->GetBubbleViewDetailsButtonLabel().empty()) {
DialogDelegate::SetExtraView(views::MdTextButton::CreateSecondaryUiButton(
this, error_->GetBubbleViewDetailsButtonLabel()));
......@@ -177,23 +187,6 @@ void GlobalErrorBubbleView::OnDialogInitialized() {
}
}
bool GlobalErrorBubbleView::Cancel() {
if (error_)
error_->BubbleViewCancelButtonPressed(browser_);
return true;
}
bool GlobalErrorBubbleView::Accept() {
if (error_)
error_->BubbleViewAcceptButtonPressed(browser_);
return true;
}
bool GlobalErrorBubbleView::Close() {
// Don't fall through to either Cancel() or Accept().
return true;
}
void GlobalErrorBubbleView::CloseBubbleView() {
GetWidget()->Close();
}
......
......@@ -37,9 +37,6 @@ class GlobalErrorBubbleView : public views::BubbleDialogDelegateView,
void Init() override;
bool ShouldShowCloseButton() const override;
void OnDialogInitialized() override;
bool Cancel() override;
bool Accept() override;
bool Close() override;
// GlobalErrorBubbleViewBase implementation.
void CloseBubbleView() override;
......
......@@ -96,10 +96,6 @@ std::unique_ptr<OverlayMediaNotification> MediaDialogView::PopOut(
return active_sessions_view_->PopOut(id, bounds);
}
bool MediaDialogView::Close() {
return Cancel();
}
void MediaDialogView::AddedToWidget() {
int corner_radius =
views::LayoutProvider::Get()->GetCornerRadiusMetric(views::EMPHASIS_HIGH);
......
......@@ -36,9 +36,6 @@ class MediaDialogView : public views::BubbleDialogDelegateView,
std::unique_ptr<OverlayMediaNotification> PopOut(const std::string& id,
gfx::Rect bounds) override;
// views::DialogDelegate implementation.
bool Close() override;
// views::View implementation.
void AddedToWidget() override;
gfx::Size CalculatePreferredSize() const override;
......
......@@ -294,6 +294,14 @@ HungRendererDialogView::HungRendererDialogView() {
DialogDelegate::set_button_label(
ui::DIALOG_BUTTON_OK,
l10n_util::GetStringUTF16(IDS_BROWSER_HANGMONITOR_RENDERER_WAIT));
DialogDelegate::set_accept_callback(base::BindOnce(
&HungRendererDialogView::RestartHangTimer, base::Unretained(this)));
DialogDelegate::set_cancel_callback(base::BindOnce(
&HungRendererDialogView::ForceCrashHungRenderer, base::Unretained(this)));
DialogDelegate::set_close_callback(base::BindOnce(
&HungRendererDialogView::RestartHangTimer, base::Unretained(this)));
DialogModelChanged();
views::GridLayout* layout =
......@@ -407,7 +415,7 @@ void HungRendererDialogView::WindowClosing() {
g_instance_ = nullptr;
}
bool HungRendererDialogView::Cancel() {
void HungRendererDialogView::ForceCrashHungRenderer() {
auto* render_widget_host = hung_pages_table_model_->GetRenderWidgetHost();
bool currently_unresponsive =
render_widget_host && render_widget_host->IsCurrentlyUnresponsive();
......@@ -427,16 +435,6 @@ bool HungRendererDialogView::Cancel() {
rph->Shutdown(content::RESULT_CODE_HUNG);
#endif
}
return true;
}
bool HungRendererDialogView::Accept() {
RestartHangTimer();
return true;
}
bool HungRendererDialogView::Close() {
return Accept();
}
///////////////////////////////////////////////////////////////////////////////
......
......@@ -166,9 +166,6 @@ class HungRendererDialogView : public views::DialogDelegateView,
base::string16 GetWindowTitle() const override;
bool ShouldShowCloseButton() const override;
void WindowClosing() override;
bool Cancel() override;
bool Accept() override;
bool Close() override;
// HungPagesTableModel::Delegate overrides:
void TabUpdated() override;
......@@ -185,6 +182,7 @@ class HungRendererDialogView : public views::DialogDelegateView,
// Restart the hang timer, giving the page more time.
void RestartHangTimer();
void ForceCrashHungRenderer();
void UpdateLabels();
......
......@@ -216,17 +216,16 @@ void IntentPickerBubbleView::CloseBubble() {
LocationBarBubbleDelegateView::CloseBubble();
}
bool IntentPickerBubbleView::Accept() {
void IntentPickerBubbleView::OnDialogAccepted() {
bool should_persist = remember_selection_checkbox_ &&
remember_selection_checkbox_->GetChecked();
RunCallbackAndCloseBubble(app_info_[selected_app_tag_].launch_name,
app_info_[selected_app_tag_].type,
apps::IntentPickerCloseReason::OPEN_APP,
should_persist);
return true;
}
bool IntentPickerBubbleView::Cancel() {
void IntentPickerBubbleView::OnDialogCancelled() {
const char* launch_name =
#if defined(OS_CHROMEOS)
arc::ArcIntentHelperBridge::kArcIntentHelperPackageName;
......@@ -238,16 +237,14 @@ bool IntentPickerBubbleView::Cancel() {
RunCallbackAndCloseBubble(launch_name, apps::PickerEntryType::kUnknown,
apps::IntentPickerCloseReason::STAY_IN_CHROME,
should_persist);
return true;
}
bool IntentPickerBubbleView::Close() {
void IntentPickerBubbleView::OnDialogClosed() {
// Whenever closing the bubble without pressing |Just once| or |Always| we
// need to report back that the user didn't select anything.
RunCallbackAndCloseBubble(kInvalidLaunchName, apps::PickerEntryType::kUnknown,
apps::IntentPickerCloseReason::DIALOG_DEACTIVATED,
false);
return true;
}
bool IntentPickerBubbleView::ShouldShowCloseButton() const {
......@@ -295,6 +292,12 @@ IntentPickerBubbleView::IntentPickerBubbleView(
DialogDelegate::set_button_label(
ui::DIALOG_BUTTON_CANCEL,
l10n_util::GetStringUTF16(IDS_INTENT_PICKER_BUBBLE_VIEW_STAY_IN_CHROME));
DialogDelegate::set_accept_callback(base::Bind(
&IntentPickerBubbleView::OnDialogAccepted, base::Unretained(this)));
DialogDelegate::set_cancel_callback(base::Bind(
&IntentPickerBubbleView::OnDialogCancelled, base::Unretained(this)));
DialogDelegate::set_close_callback(base::Bind(
&IntentPickerBubbleView::OnDialogClosed, base::Unretained(this)));
set_close_on_main_frame_origin_navigation(true);
......
......@@ -91,9 +91,6 @@ class IntentPickerBubbleView : public LocationBarBubbleDelegateView,
static void CloseCurrentBubble();
// LocationBarBubbleDelegateView overrides:
bool Accept() override;
bool Cancel() override;
bool Close() override;
bool ShouldShowCloseButton() const override;
PageActionIconType icon_type() const { return icon_type_; }
......@@ -145,6 +142,10 @@ class IntentPickerBubbleView : public LocationBarBubbleDelegateView,
void Initialize();
void OnDialogAccepted();
void OnDialogCancelled();
void OnDialogClosed();
// Retrieves the IntentPickerLabelButton* contained at position |index| from
// the internal ScrollView.
IntentPickerLabelButton* GetIntentPickerLabelButtonAt(size_t index);
......
......@@ -163,6 +163,8 @@ void CookieControlsBubbleView::UpdateUi() {
status_ == CookieControlsController::Status::kDisabledForSite)
? ui::DIALOG_BUTTON_OK
: ui::DIALOG_BUTTON_NONE);
DialogDelegate::set_accept_callback(base::BindOnce(
&CookieControlsBubbleView::OnDialogAccepted, base::Unretained(this)));
DialogModelChanged();
Layout();
......@@ -267,7 +269,7 @@ void CookieControlsBubbleView::WindowClosing() {
controller_->OnBubbleUiClosing(web_contents());
}
bool CookieControlsBubbleView::Accept() {
void CookieControlsBubbleView::OnDialogAccepted() {
if (intermediate_step_ == IntermediateStep::kTurnOffButton) {
base::RecordAction(UserMetricsAction("CookieControls.Bubble.TurnOff"));
controller_->OnCookieBlockingEnabledForSite(false);
......@@ -277,11 +279,6 @@ bool CookieControlsBubbleView::Accept() {
base::RecordAction(UserMetricsAction("CookieControls.Bubble.TurnOn"));
controller_->OnCookieBlockingEnabledForSite(true);
}
return true;
}
bool CookieControlsBubbleView::Close() {
return Cancel();
}
void CookieControlsBubbleView::ShowCookiesLinkClicked() {
......
......@@ -60,13 +60,12 @@ class CookieControlsBubbleView : public LocationBarBubbleDelegateView,
bool ShouldShowWindowTitle() const override;
bool ShouldShowCloseButton() const override;
void WindowClosing() override;
bool Accept() override;
bool Close() override;
gfx::Size CalculatePreferredSize() const override;
void AddedToWidget() override;
void ShowCookiesLinkClicked();
void NotWorkingLinkClicked();
void OnDialogAccepted();
CookieControlsController* controller_ = nullptr;
......
......@@ -143,10 +143,6 @@ base::string16 CastDialogView::GetWindowTitle() const {
}
}
bool CastDialogView::Close() {
return Cancel();
}
void CastDialogView::OnModelUpdated(const CastDialogModel& model) {
if (model.media_sinks().empty()) {
scroll_position_ = 0;
......
......@@ -89,9 +89,6 @@ class CastDialogView : public views::BubbleDialogDelegateView,
// views::WidgetDelegate:
base::string16 GetWindowTitle() const override;
// views::DialogDelegate:
bool Close() override;
// CastDialogController::Observer:
void OnModelUpdated(const CastDialogModel& model) override;
void OnControllerInvalidated() override;
......
......@@ -82,20 +82,6 @@ base::string16 MediaRemotingDialogView::GetWindowTitle() const {
return dialog_title_;
}
bool MediaRemotingDialogView::Accept() {
ReportPermission(true);
return true;
}
bool MediaRemotingDialogView::Cancel() {
ReportPermission(false);
return true;
}
bool MediaRemotingDialogView::Close() {
return true;
}
gfx::Size MediaRemotingDialogView::CalculatePreferredSize() const {
const int width = ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_BUBBLE_PREFERRED_WIDTH) -
......@@ -123,6 +109,14 @@ MediaRemotingDialogView::MediaRemotingDialogView(
ui::DIALOG_BUTTON_CANCEL,
l10n_util::GetStringUTF16(
IDS_MEDIA_ROUTER_REMOTING_DIALOG_CANCEL_BUTTON));
DialogDelegate::set_accept_callback(
base::BindOnce(&MediaRemotingDialogView::ReportPermission,
base::Unretained(this), true));
DialogDelegate::set_cancel_callback(
base::BindOnce(&MediaRemotingDialogView::ReportPermission,
base::Unretained(this), false));
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical));
// Depress the Cast toolbar icon.
......
......@@ -45,11 +45,6 @@ class MediaRemotingDialogView : public views::BubbleDialogDelegateView {
// views::WidgetDelegate:
base::string16 GetWindowTitle() const override;
// views::DialogDelegate:
bool Accept() override;
bool Cancel() override;
bool Close() override;
// views::View:
gfx::Size CalculatePreferredSize() const override;
......
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