Commit 8c9d5e78 authored by Danan S's avatar Danan S Committed by Commit Bot

Change Add Supervision web dialog to use CanCloseDialog()

The Add Supervision dialog was using OnCloseContents() and
OnDialogCloseRequested() to catch attempts to close the
dialog, for the purpose of showing the signout confirmation
dialog. This failed when OnCloseContents() was called,
because by the time that callback was called, the web contents
were already disposed of, resulting in dialog contents becoming
unusable if the user chose to return to the dialog rather than
signing out.

Instead, capturing the close event in CanCloseDialog() occurs
before the contents are invalidated, therefore it is the correct
place to stop the closing of the dialog

Bug: 1001732
Change-Id: I50262bd4606e3380700c81f98df925ea3a61f87c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1790130
Commit-Queue: Danan S <danan@chromium.org>
Reviewed-by: default avatarMichael Giuffrida <michaelpg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#694832}
parent 8dee6867
...@@ -42,11 +42,9 @@ class AddSupervisionMetricsRecorderTest : public InProcessBrowserTest { ...@@ -42,11 +42,9 @@ class AddSupervisionMetricsRecorderTest : public InProcessBrowserTest {
} }
void CloseAddSupervisionDialog() { void CloseAddSupervisionDialog() {
content::WebContents* web_contents = test_web_ui_.GetWebContents(); bool out_close_dialog =
bool out_close_dialog; AddSupervisionDialog::GetInstance()->OnDialogCloseRequested();
AddSupervisionDialog::GetInstance()->OnCloseContents(web_contents, EXPECT_TRUE(out_close_dialog);
&out_close_dialog);
ASSERT_TRUE(out_close_dialog);
AddSupervisionDialog::Close(); AddSupervisionDialog::Close();
} }
......
...@@ -119,29 +119,16 @@ void AddSupervisionDialog::GetDialogSize(gfx::Size* size) const { ...@@ -119,29 +119,16 @@ void AddSupervisionDialog::GetDialogSize(gfx::Size* size) const {
size->SetSize(kDialogWidthPx, kDialogHeightPx); size->SetSize(kDialogWidthPx, kDialogHeightPx);
} }
bool AddSupervisionDialog::OnDialogCloseRequested() { bool AddSupervisionDialog::CanCloseDialog() const {
bool showing_confirm_dialog = MaybeShowConfirmSignoutDialog(); bool showing_confirm_dialog = MaybeShowConfirmSignoutDialog();
return !showing_confirm_dialog; return !showing_confirm_dialog;
} }
void AddSupervisionDialog::OnCloseContents(content::WebContents* source, bool AddSupervisionDialog::OnDialogCloseRequested() {
bool* out_close_dialog) { // Record UMA metric that user has closed the Add Supervision dialog.
// This code gets called by a different path than OnDialogCloseRequested(), AddSupervisionMetricsRecorder::GetInstance()->RecordAddSupervisionEnrollment(
// and actually masks the call to OnDialogCloseRequested() the first time the AddSupervisionMetricsRecorder::EnrollmentState::kClosed);
// user clicks on the [x]. Because the first [x] click comes here, we need to return true;
// show the confirmation dialog here and signal the caller to possibly close
// the dialog. Subsequent clicks on [x] during the lifetime of the dialog
// will result in direct calls to OnDialogCloseRequested(), skipping this
// method.
*out_close_dialog = OnDialogCloseRequested();
// If |out_close_dialog|, then we are before the point of no return prior to
// completing enrollment, and that's the only time we want to record kClosed.
if (*out_close_dialog) {
// Record UMA metric that user has closed the Add Supervision dialog.
AddSupervisionMetricsRecorder::GetInstance()
->RecordAddSupervisionEnrollment(
AddSupervisionMetricsRecorder::EnrollmentState::kClosed);
}
} }
AddSupervisionDialog::AddSupervisionDialog() AddSupervisionDialog::AddSupervisionDialog()
......
...@@ -37,8 +37,7 @@ class AddSupervisionDialog : public SystemWebDialogDelegate { ...@@ -37,8 +37,7 @@ class AddSupervisionDialog : public SystemWebDialogDelegate {
ui::ModalType GetDialogModalType() const override; ui::ModalType GetDialogModalType() const override;
void GetDialogSize(gfx::Size* size) const override; void GetDialogSize(gfx::Size* size) const override;
bool OnDialogCloseRequested() override; bool OnDialogCloseRequested() override;
void OnCloseContents(content::WebContents* source, bool CanCloseDialog() const override;
bool* out_close_dialog) override;
protected: protected:
AddSupervisionDialog(); AddSupervisionDialog();
......
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