From c422ab5aa848311064653f319f4ebd836d52eb34 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Fri, 21 Oct 2011 21:00:59 +0000 Subject: [PATCH] Allow for cases where CefBrowserImpl::UIT_CreateBrowser() may fail (issue #322). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@336 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- libcef/browser_impl.cc | 6 ++++-- libcef/browser_impl.h | 2 +- libcef/browser_impl_gtk.cc | 4 +++- libcef/browser_impl_mac.mm | 4 +++- libcef/browser_impl_win.cc | 11 ++++++++++- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/libcef/browser_impl.cc b/libcef/browser_impl.cc index 373fad252..d27222cc3 100644 --- a/libcef/browser_impl.cc +++ b/libcef/browser_impl.cc @@ -153,7 +153,8 @@ CefRefPtr CefBrowser::CreateBrowserSync( CefRefPtr browser( new CefBrowserImpl(windowInfo, settings, NULL, client)); - static_cast(browser.get())->UIT_CreateBrowser(url); + if (!static_cast(browser.get())->UIT_CreateBrowser(url)) + return NULL; return browser; } @@ -1142,7 +1143,8 @@ CefRefPtr CefBrowserImpl::UIT_CreatePopupWindow( // Don't pass the URL to UIT_CreateBrowser for popup windows or the URL will // be loaded twice. - browser->UIT_CreateBrowser(CefString()); + if (!browser->UIT_CreateBrowser(CefString())) + return NULL; return browser; } diff --git a/libcef/browser_impl.h b/libcef/browser_impl.h index 12a567c69..0d39ccc0e 100644 --- a/libcef/browser_impl.h +++ b/libcef/browser_impl.h @@ -221,7 +221,7 @@ public: } // Create the native browser window and populate browser members. - void UIT_CreateBrowser(const CefString& url); + bool UIT_CreateBrowser(const CefString& url); // Destroy the browser members. This method should only be called after the // native browser window is not longer processing messages. diff --git a/libcef/browser_impl_gtk.cc b/libcef/browser_impl_gtk.cc index 361fedb44..ca4bdc878 100644 --- a/libcef/browser_impl_gtk.cc +++ b/libcef/browser_impl_gtk.cc @@ -42,7 +42,7 @@ gfx::NativeWindow CefBrowserImpl::UIT_GetMainWndHandle() { return GTK_IS_WINDOW(toplevel) ? GTK_WINDOW(toplevel) : NULL; } -void CefBrowserImpl::UIT_CreateBrowser(const CefString& url) +bool CefBrowserImpl::UIT_CreateBrowser(const CefString& url) { REQUIRE_UIT(); Lock(); @@ -79,6 +79,8 @@ void CefBrowserImpl::UIT_CreateBrowser(const CefString& url) if(url.size() > 0) UIT_LoadURL(GetMainFrame(), url); + + return true; } void CefBrowserImpl::UIT_SetFocus(WebWidgetHost* host, bool enable) diff --git a/libcef/browser_impl_mac.mm b/libcef/browser_impl_mac.mm index ac0320b59..d4f6ae38b 100644 --- a/libcef/browser_impl_mac.mm +++ b/libcef/browser_impl_mac.mm @@ -41,7 +41,7 @@ gfx::NativeView CefBrowserImpl::UIT_GetMainWndHandle() { return window_info_.m_View; } -void CefBrowserImpl::UIT_CreateBrowser(const CefString& url) +bool CefBrowserImpl::UIT_CreateBrowser(const CefString& url) { REQUIRE_UIT(); Lock(); @@ -119,6 +119,8 @@ void CefBrowserImpl::UIT_CreateBrowser(const CefString& url) if(url.size() > 0) UIT_LoadURL(GetMainFrame(), url); + + return true; } void CefBrowserImpl::UIT_SetFocus(WebWidgetHost* host, bool enable) diff --git a/libcef/browser_impl_win.cc b/libcef/browser_impl_win.cc index 853e998a6..32af717f7 100644 --- a/libcef/browser_impl_win.cc +++ b/libcef/browser_impl_win.cc @@ -163,7 +163,7 @@ gfx::NativeWindow CefBrowserImpl::UIT_GetMainWndHandle() { window_info_.m_hWndParent : window_info_.m_hWnd; } -void CefBrowserImpl::UIT_CreateBrowser(const CefString& url) +bool CefBrowserImpl::UIT_CreateBrowser(const CefString& url) { REQUIRE_UIT(); Lock(); @@ -177,7 +177,14 @@ void CefBrowserImpl::UIT_CreateBrowser(const CefString& url) window_info_.m_x, window_info_.m_y, window_info_.m_nWidth, window_info_.m_nHeight, window_info_.m_hWndParent, window_info_.m_hMenu, ::GetModuleHandle(NULL), NULL); + + // It's possible for CreateWindowEx to fail if the parent window was + // destroyed between the call to CreateBrowser and the above one. DCHECK(window_info_.m_hWnd != NULL); + if (!window_info_.m_hWnd) { + Unlock(); + return false; + } if (window_info_.m_bTransparentPainting && !(window_info_.m_dwStyle & WS_CHILD)) { @@ -248,6 +255,8 @@ void CefBrowserImpl::UIT_CreateBrowser(const CefString& url) if(url.length() > 0) UIT_LoadURL(GetMainFrame(), url); + + return true; } void CefBrowserImpl::UIT_SetFocus(WebWidgetHost* host, bool enable)