- Fix a leak of CachedResource objects due to the Cache never being cleared (issue #15).
- Fix a crash when the main application exits while popup windows exist due to a race condition when deleting CefBrowser objects.

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@49 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt
2009-09-26 01:22:33 +00:00
parent 07e81ab0a0
commit 8635aeb5cf
5 changed files with 45 additions and 4 deletions

View File

@@ -64,6 +64,11 @@ LRESULT CALLBACK CefBrowserImpl::WndProc(HWND hwnd, UINT message,
// Clean up anything associated with the WebViewHost widget. // Clean up anything associated with the WebViewHost widget.
browser->GetWebViewHost()->webwidget()->close(); browser->GetWebViewHost()->webwidget()->close();
// Clear the user data pointer.
win_util::SetWindowUserData(hwnd, NULL);
// Remove the reference added in UIT_CreateBrowser().
browser->Release();
// Remove the browser from the list maintained by the context // Remove the browser from the list maintained by the context
_Context->RemoveBrowser(browser); _Context->RemoveBrowser(browser);
} }
@@ -255,6 +260,8 @@ void CefBrowserImpl::UIT_CreateBrowser(const std::wstring& url)
// Set window user data to this object for future reference from the window // Set window user data to this object for future reference from the window
// procedure // procedure
win_util::SetWindowUserData(window_info_.m_hWnd, this); win_util::SetWindowUserData(window_info_.m_hWnd, this);
// Add a reference that will be released on WM_DESTROY.
AddRef();
// Add the new browser to the list maintained by the context // Add the new browser to the list maintained by the context
_Context->AddBrowser(this); _Context->AddBrowser(this);

View File

@@ -11,6 +11,7 @@
#undef LOG #undef LOG
#include "config.h" #include "config.h"
MSVC_PUSH_WARNING_LEVEL(0); MSVC_PUSH_WARNING_LEVEL(0);
#include "Cache.h"
#include "TextEncoding.h" #include "TextEncoding.h"
#include "webkit/glue/webframe_impl.h" #include "webkit/glue/webframe_impl.h"
MSVC_POP_WARNING(); MSVC_POP_WARNING();
@@ -204,4 +205,11 @@ void SetCacheMode(bool enabled) {
// Used in benchmarking, Ignored for CEF. // Used in benchmarking, Ignored for CEF.
} }
void ClearCache()
{
// Clear the cache by disabling it and then re-enabling it.
WebCore::cache()->setDisabled(true);
WebCore::cache()->setDisabled(false);
}
} // namespace webkit_glue } // namespace webkit_glue

View File

@@ -35,4 +35,7 @@ base::StringPiece NetResourceProvider(int key);
// Retrieve the V8 context associated with the frame. // Retrieve the V8 context associated with the frame.
v8::Handle<v8::Context> GetV8Context(WebKit::WebFrame* frame); v8::Handle<v8::Context> GetV8Context(WebKit::WebFrame* frame);
// Clear all cached data.
void ClearCache();
} // namespace webkit_glue } // namespace webkit_glue

View File

@@ -398,6 +398,7 @@ bool CefContext::Initialize(bool multi_threaded_message_loop,
void CefContext::Shutdown() void CefContext::Shutdown()
{ {
bool shutdown = false, intransition = false; bool shutdown = false, intransition = false;
BrowserList browserlist;
Lock(); Lock();
@@ -411,8 +412,8 @@ void CefContext::Shutdown()
// We are now in a transitional state // We are now in a transitional state
in_transition_ = true; in_transition_ = true;
if(browserlist_.size() > 0) browserlist = browserlist_;
browserlist_.clear(); browserlist_.empty();
if(webprefs_) { if(webprefs_) {
delete webprefs_; delete webprefs_;
@@ -429,6 +430,14 @@ void CefContext::Shutdown()
Unlock(); Unlock();
if(shutdown) { if(shutdown) {
if (browserlist.size() > 0) {
// Close any remaining browser windows
BrowserList::const_iterator it = browserlist.begin();
for (; it != browserlist.end(); ++it)
PostMessage((*it)->GetWindowHandle(), WM_CLOSE, 0, 0);
browserlist.empty();
}
if (hthreadui_) { if (hthreadui_) {
// Wait for the UI thread to exit // Wait for the UI thread to exit
WaitForSingleObject(hthreadui_, INFINITE); WaitForSingleObject(hthreadui_, INFINITE);
@@ -483,9 +492,15 @@ bool CefContext::AddBrowser(CefRefPtr<CefBrowserImpl> browser)
return !found; return !found;
} }
void CefContext::UIT_ClearCache()
{
webkit_glue::ClearCache();
}
bool CefContext::RemoveBrowser(CefRefPtr<CefBrowserImpl> browser) bool CefContext::RemoveBrowser(CefRefPtr<CefBrowserImpl> browser)
{ {
bool deleted = false; bool deleted = false;
bool empty = false;
Lock(); Lock();
@@ -498,11 +513,18 @@ bool CefContext::RemoveBrowser(CefRefPtr<CefBrowserImpl> browser)
} }
} }
if (browserlist_.empty()) if (browserlist_.empty()) {
next_browser_id_ = 1; next_browser_id_ = 1;
empty = true;
}
Unlock(); Unlock();
if (empty) {
PostTask(FROM_HERE, NewRunnableMethod(_Context.get(),
&CefContext::UIT_ClearCache));
}
return deleted; return deleted;
} }

View File

@@ -53,6 +53,7 @@ public:
void UIT_RegisterPlugin(struct CefPluginInfo* plugin_info); void UIT_RegisterPlugin(struct CefPluginInfo* plugin_info);
void UIT_UnregisterPlugin(struct CefPluginInfo* plugin_info); void UIT_UnregisterPlugin(struct CefPluginInfo* plugin_info);
void UIT_ClearCache();
bool DoWork(); bool DoWork();
bool DoDelayedWork(); bool DoDelayedWork();