diff --git a/libcef/browser_drag_delegate_win.cc b/libcef/browser_drag_delegate_win.cc index 075e4c939..339ff648e 100644 --- a/libcef/browser_drag_delegate_win.cc +++ b/libcef/browser_drag_delegate_win.cc @@ -127,7 +127,9 @@ void BrowserDragDelegate::StartDragging(const WebDropData& drop_data, // If it is not drag-out, do the drag-and-drop in the current UI thread. if (drop_data.download_metadata.empty()) { DoDragging(drop_data, ops, page_url, page_encoding, image, image_offset); - EndDragging(false); + CefThread::PostTask( + CefThread::UI, FROM_HERE, + base::Bind(&BrowserDragDelegate::EndDragging, this, false)); return; } diff --git a/libcef/browser_impl_win.cc b/libcef/browser_impl_win.cc index 909e0c35b..0b4e6e015 100644 --- a/libcef/browser_impl_win.cc +++ b/libcef/browser_impl_win.cc @@ -88,8 +88,15 @@ LRESULT CALLBACK CefBrowserImpl::WndProc(HWND hwnd, UINT message, // Clear the user data pointer. ui::SetWindowUserData(hwnd, NULL); - // Destroy the browser. - browser->UIT_DestroyBrowser(); + BrowserWebViewDelegate* delegate = browser->UIT_GetWebViewDelegate(); + if (delegate && delegate->drag_delegate()) { + // Don't destroy the browser while a drag operation is pending. Instead, + // destroy the browser once the drag operation completes. + delegate->set_destroy_on_drag_end(true); + } else { + // Destroy the browser. + browser->UIT_DestroyBrowser(); + } } return 0; diff --git a/libcef/browser_webview_delegate.cc b/libcef/browser_webview_delegate.cc index 9f3fdf9a7..896ce87d0 100644 --- a/libcef/browser_webview_delegate.cc +++ b/libcef/browser_webview_delegate.cc @@ -1003,6 +1003,9 @@ BrowserWebViewDelegate::BrowserWebViewDelegate(CefBrowserImpl* browser) browser_(browser), page_id_(-1), last_page_id_updated_(-1), +#if defined(OS_WIN) + destroy_on_drag_end_(false), +#endif smart_insert_delete_enabled_(true), #if defined(OS_WIN) select_trailing_whitespace_enabled_(true), diff --git a/libcef/browser_webview_delegate.h b/libcef/browser_webview_delegate.h index 312d4c9b0..ad28785fd 100644 --- a/libcef/browser_webview_delegate.h +++ b/libcef/browser_webview_delegate.h @@ -248,7 +248,9 @@ class BrowserWebViewDelegate : public WebKit::WebViewClient, BrowserDragDelegate* drag_delegate() { return drag_delegate_.get(); } WebDropTarget* drop_target() { return drop_target_.get(); } -#endif + + void set_destroy_on_drag_end(bool val) { destroy_on_drag_end_ = val; } +#endif // defined(OS_WIN) void set_pending_extra_data(BrowserExtraData* extra_data) { pending_extra_data_.reset(extra_data); @@ -352,6 +354,7 @@ class BrowserWebViewDelegate : public WebKit::WebViewClient, #if defined(OS_WIN) // Classes needed by drag and drop. scoped_refptr drag_delegate_; + bool destroy_on_drag_end_; #endif #if defined(OS_WIN) || defined(OS_LINUX) scoped_refptr drop_target_; diff --git a/libcef/browser_webview_delegate_win.cc b/libcef/browser_webview_delegate_win.cc index de0f779f6..cc061c5b7 100644 --- a/libcef/browser_webview_delegate_win.cc +++ b/libcef/browser_webview_delegate_win.cc @@ -533,6 +533,9 @@ void BrowserWebViewDelegate::EndDragging() { if (browser_->UIT_GetWebView()) browser_->UIT_GetWebView()->dragSourceSystemDragEnded(); drag_delegate_ = NULL; + + if (destroy_on_drag_end_) + browser_->UIT_DestroyBrowser(); } void BrowserWebViewDelegate::ShowJavaScriptAlert(WebFrame* webframe, diff --git a/libcef/webwidget_host_win.cc b/libcef/webwidget_host_win.cc index 92db81b66..15810f6e2 100644 --- a/libcef/webwidget_host_win.cc +++ b/libcef/webwidget_host_win.cc @@ -358,7 +358,6 @@ WebWidgetHost::~WebWidgetHost() { if (view_) { ui::SetWindowUserData(view_, 0); - ui::SetWindowProc(view_, DefWindowProc); view_ = NULL; } }