Skip to content

Commit 005a97e

Browse files
committed
final fix for login dialog: AddRef and Platform changes
1 parent aec6069 commit 005a97e

File tree

5 files changed

+33
-14
lines changed

5 files changed

+33
-14
lines changed

src/browser/shell_login_dialog.cc

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "content/public/browser/notification_registrar.h"
2929
#include "content/public/browser/notification_service.h"
3030
#include "content/public/browser/resource_dispatcher_host.h"
31+
#include "content/public/browser/resource_request_info.h"
3132
#include "net/base/auth.h"
3233
#include "net/url_request/url_request.h"
3334
#include "ui/base/text/text_elider.h"
@@ -51,10 +52,23 @@ ShellLoginDialog::ShellLoginDialogList ShellLoginDialog::dialog_queue_;
5152

5253
ShellLoginDialog::ShellLoginDialog(
5354
net::AuthChallengeInfo* auth_info,
54-
net::URLRequest* request) : auth_info_(auth_info),
55-
request_(request),
56-
handled_auth_(false) {
55+
net::URLRequest* request)
56+
: render_process_id_(0),
57+
render_view_id_(0),
58+
auth_info_(auth_info),
59+
request_(request),
60+
handled_auth_(false) {
5761
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
62+
63+
if (!ResourceRequestInfo::ForRequest(request_)->GetAssociatedRenderView(
64+
&render_process_id_, &render_view_id_)) {
65+
NOTREACHED();
66+
}
67+
68+
// prevent object destruction on wrong (IO) thread
69+
// paired with ReleaseSoon()
70+
AddRef();
71+
5872
BrowserThread::PostTask(
5973
BrowserThread::UI, FROM_HERE,
6074
base::Bind(&ShellLoginDialog::PrepDialog, this,

src/browser/shell_login_dialog.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ class ShellLoginDialog : public ResourceDispatcherHostLoginDelegate,
9595
// Threading: any
9696
virtual ~ShellLoginDialog();
9797

98+
int render_process_id_;
99+
int render_view_id_;
100+
98101
private:
99102

100103
// popup next dialog in queue on closing of this dialog

src/browser/shell_login_dialog_gtk.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ void ShellLoginDialog::PlatformCreateDialog(const string16& message) {
9494
gtk_box_pack_start(GTK_BOX(content_area), table, FALSE, FALSE, 0);
9595

9696
g_signal_connect(root_, "response", G_CALLBACK(OnResponseThunk), this);
97+
g_signal_connect(root_, "destroy", G_CALLBACK(OnDestroyThunk), this);
98+
9799
gtk_widget_grab_focus(username_entry_);
98100
}
99101

src/browser/shell_login_dialog_mac.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ - (void)cancel {
134134
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
135135
[helper_ release];
136136
helper_ = nil;
137+
ReleaseSoon();
137138
}
138139

139140
void ShellLoginDialog::PlatformRequestCancelled() {

src/browser/shell_login_dialog_win.cc

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,15 @@ INT_PTR CALLBACK ShellLoginDialog::DialogProc(HWND dialog,
5252
GetWindowLongPtr(dialog, DWL_USER));
5353
owner->UserCancelledAuth();
5454
DestroyWindow(owner->dialog_win_);
55-
owner->dialog_win_ = NULL;
56-
ReleaseSoon();
5755
break;
5856
}
57+
case WM_DESTROY: {
58+
ShellLoginDialog* owner = reinterpret_cast<ShellLoginDialog*>(
59+
GetWindowLongPtr(dialog, DWL_USER));
60+
owner->dialog_win_ = NULL;
61+
owner->ReleaseSoon();
62+
break;
63+
}
5964
case WM_COMMAND: {
6065
ShellLoginDialog* owner = reinterpret_cast<ShellLoginDialog*>(
6166
GetWindowLongPtr(dialog, DWL_USER));
@@ -73,7 +78,8 @@ INT_PTR CALLBACK ShellLoginDialog::DialogProc(HWND dialog,
7378
} else if (LOWORD(wparam) == IDCANCEL) {
7479
owner->UserCancelledAuth();
7580
} else {
76-
NOTREACHED();
81+
DLOG(INFO) << "wparam is " << LOWORD(wparam);
82+
// NOTREACHED();
7783
}
7884

7985
break;
@@ -88,16 +94,9 @@ INT_PTR CALLBACK ShellLoginDialog::DialogProc(HWND dialog,
8894
void ShellLoginDialog::PlatformCreateDialog(const string16& message) {
8995
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
9096

91-
int render_process_id;
92-
int render_view_id;
93-
if (!ResourceRequestInfo::ForRequest(request_)->GetAssociatedRenderView(
94-
&render_process_id, &render_view_id)) {
95-
NOTREACHED();
96-
}
97-
9897
WebContents* web_contents = NULL;
9998
RenderViewHost* render_view_host =
100-
RenderViewHost::FromID(render_process_id, render_view_id);
99+
RenderViewHost::FromID(render_process_id_, render_view_id_);
101100
if (render_view_host)
102101
web_contents = WebContents::FromRenderViewHost(render_view_host);
103102
DCHECK(web_contents);

0 commit comments

Comments
 (0)