Skip to content

Commit 3cc0d75

Browse files
author
Cong Liu
committed
ColorChooserWin::End should act like the dialog has closed
Bug fix copied from 5ecc8d42ff888ff8b459df566208e7e01a3be5ba
1 parent 710bb8a commit 3cc0d75

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

src/browser/color_chooser_dialog.cc

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "content/public/browser/browser_thread.h"
1313
#include "skia/ext/skia_utils_win.h"
1414
#include "ui/views/color_chooser/color_chooser_listener.h"
15+
#include "ui/views/win/hwnd_util.h"
1516

1617
using content::BrowserThread;
1718

@@ -32,17 +33,19 @@ ColorChooserDialog::ColorChooserDialog(views::ColorChooserListener* listener,
3233
: listener_(listener) {
3334
DCHECK(listener_);
3435
CopyCustomColors(g_custom_colors, custom_colors_);
35-
ExecuteOpenParams execute_params(initial_color, BeginRun((HWND)owning_window),
36-
(HWND)owning_window);
36+
HWND owning_hwnd = views::HWNDForNativeWindow(owning_window);
37+
ExecuteOpenParams execute_params(initial_color, BeginRun(owning_hwnd),
38+
owning_hwnd);
3739
execute_params.run_state.dialog_thread->message_loop()->PostTask(FROM_HERE,
3840
base::Bind(&ColorChooserDialog::ExecuteOpen, this, execute_params));
3941
}
4042

4143
ColorChooserDialog::~ColorChooserDialog() {
4244
}
4345

44-
bool ColorChooserDialog::IsRunning(gfx::NativeWindow owning_hwnd) const {
45-
return listener_ && IsRunningDialogForOwner((HWND)owning_hwnd);
46+
bool ColorChooserDialog::IsRunning(gfx::NativeWindow owning_window) const {
47+
return listener_ && IsRunningDialogForOwner(
48+
views::HWNDForNativeWindow(owning_window));
4649
}
4750

4851
void ColorChooserDialog::ListenerDestroyed() {
@@ -68,13 +71,13 @@ void ColorChooserDialog::ExecuteOpen(const ExecuteOpenParams& params) {
6871
void ColorChooserDialog::DidCloseDialog(bool chose_color,
6972
SkColor color,
7073
RunState run_state) {
71-
if (!listener_)
72-
return;
7374
EndRun(run_state);
7475
CopyCustomColors(custom_colors_, g_custom_colors);
75-
if (chose_color)
76-
listener_->OnColorChosen(color);
77-
listener_->OnColorChooserDialogClosed();
76+
if (listener_) {
77+
if (chose_color)
78+
listener_->OnColorChosen(color);
79+
listener_->OnColorChooserDialogClosed();
80+
}
7881
}
7982

8083
void ColorChooserDialog::CopyCustomColors(COLORREF* src, COLORREF* dst) {

src/browser/color_chooser_dialog.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
#ifndef CHROME_BROWSER_UI_VIEWS_COLOR_CHOOSER_DIALOG_H_
6-
#define CHROME_BROWSER_UI_VIEWS_COLOR_CHOOSER_DIALOG_H_
5+
#ifndef NW_BROWSER_COLOR_CHOOSER_DIALOG_H_
6+
#define NW_BROWSER_COLOR_CHOOSER_DIALOG_H_
77

88
#include "base/memory/ref_counted.h"
99
#include "content/nw/src/browser/color_chooser_dialog.h"
@@ -70,4 +70,4 @@ class ColorChooserDialog
7070
DISALLOW_COPY_AND_ASSIGN(ColorChooserDialog);
7171
};
7272

73-
#endif // CHROME_BROWSER_UI_VIEWS_COLOR_CHOOSER_DIALOG_H_
73+
#endif // NW_BROWSER_COLOR_CHOOSER_DIALOG_H_

src/browser/color_chooser_win.cc

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ColorChooserWin : public content::ColorChooser,
2424
~ColorChooserWin();
2525

2626
// content::ColorChooser overrides:
27-
virtual void End() OVERRIDE {}
27+
virtual void End() OVERRIDE;
2828
virtual void SetSelectedColor(SkColor color) OVERRIDE {}
2929

3030
// views::ColorChooserListener overrides:
@@ -46,8 +46,9 @@ ColorChooserWin* ColorChooserWin::current_color_chooser_ = NULL;
4646

4747
ColorChooserWin* ColorChooserWin::Open(content::WebContents* web_contents,
4848
SkColor initial_color) {
49-
if (!current_color_chooser_)
50-
current_color_chooser_ = new ColorChooserWin(web_contents, initial_color);
49+
if (current_color_chooser_)
50+
return NULL;
51+
current_color_chooser_ = new ColorChooserWin(web_contents, initial_color);
5152
return current_color_chooser_;
5253
}
5354

@@ -66,6 +67,16 @@ ColorChooserWin::~ColorChooserWin() {
6667
DCHECK(!color_chooser_dialog_);
6768
}
6869

70+
void ColorChooserWin::End() {
71+
// The ColorChooserDialog's listener is going away. Ideally we'd
72+
// programmatically close the dialog at this point. Since that's impossible,
73+
// we instead tell the dialog its listener is going away, so that the dialog
74+
// doesn't try to communicate with a destroyed listener later. (We also tell
75+
// the renderer the dialog is closed, since from the renderer's perspective
76+
// it effectively is.)
77+
OnColorChooserDialogClosed();
78+
}
79+
6980
void ColorChooserWin::OnColorChosen(SkColor color) {
7081
if (web_contents_)
7182
web_contents_->DidChooseColorInColorChooser(color);

0 commit comments

Comments
 (0)