- Add support for specifying the cache location (file path or in-memory) via a new 'cache_path' parameter to CefInitialize().
- Create popup windows with a NULL parent window handle so that they don't stay on top of the original application window.

cefclient:
- Properly handle address change and title change for popup windows.
- Add a test for creating a popup window.
- Define TEST_SINGLE_THREADED_MESSAGE_LOOP by default.


git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@18 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2009-03-06 19:20:44 +00:00
parent a5bdcddd1e
commit 3aa0d4c0fa
10 changed files with 61 additions and 24 deletions

View File

@ -44,7 +44,10 @@
// |multi_threaded_message_loop| to true to have the message loop run in // |multi_threaded_message_loop| to true to have the message loop run in
// a separate thread. If |multi_threaded_message_loop| is false than // a separate thread. If |multi_threaded_message_loop| is false than
// the CefDoMessageLoopWork() function must be called from your message loop. // the CefDoMessageLoopWork() function must be called from your message loop.
bool CefInitialize(bool multi_threaded_message_loop); // Set |cache_path| to the location where cache data will be stored on disk.
// If |cache_path| is empty an in-memory cache will be used for cache data.
bool CefInitialize(bool multi_threaded_message_loop,
const std::wstring& cache_path);
// This function should only be called once before the application exits. // This function should only be called once before the application exits.
// Shut down the thread hosting the UI message loop and destroy any created // Shut down the thread hosting the UI message loop and destroy any created

View File

@ -47,7 +47,11 @@ extern "C" {
// |multi_threaded_message_loop| to true to have the message loop run in // |multi_threaded_message_loop| to true to have the message loop run in
// a separate thread. If |multi_threaded_message_loop| is false than // a separate thread. If |multi_threaded_message_loop| is false than
// the CefDoMessageLoopWork() function must be called from your message loop. // the CefDoMessageLoopWork() function must be called from your message loop.
CEF_EXPORT int cef_initialize(int multi_threaded_message_loop); // Set |cache_path| to the location where cache data will be stored on disk.
// If |cache_path| is NULL or empty an in-memory cache will be used for cache
// data.
CEF_EXPORT int cef_initialize(int multi_threaded_message_loop,
const wchar_t* cache_path);
// This function should only be called once before the application exits. // This function should only be called once before the application exits.
// Shut down the thread hosting the UI message loop and destroy any created // Shut down the thread hosting the UI message loop and destroy any created

View File

@ -425,7 +425,7 @@ CefRefPtr<CefBrowserImpl> CefBrowserImpl::UIT_CreatePopupWindow(const std::wstri
REQUIRE_UIT(); REQUIRE_UIT();
CefWindowInfo info; CefWindowInfo info;
info.SetAsPopup(UIT_GetMainWndHandle(), url.c_str()); info.SetAsPopup(NULL, url.c_str());
CefRefPtr<CefHandler> handler = handler_; CefRefPtr<CefHandler> handler = handler_;
std::wstring newUrl = url; std::wstring newUrl = url;

View File

@ -56,7 +56,8 @@ public:
}; };
bool CefInitialize(bool multi_threaded_message_loop) bool CefInitialize(bool multi_threaded_message_loop,
const std::wstring& cache_path)
{ {
// Return true if the context is already initialized // Return true if the context is already initialized
if(_Context.get()) if(_Context.get())
@ -65,7 +66,7 @@ bool CefInitialize(bool multi_threaded_message_loop)
// Create the new global context object // Create the new global context object
_Context = new CefContext(); _Context = new CefContext();
// Initialize the glboal context // Initialize the glboal context
return _Context->Initialize(multi_threaded_message_loop); return _Context->Initialize(multi_threaded_message_loop, cache_path);
} }
void CefShutdown() void CefShutdown()
@ -175,12 +176,9 @@ bool CefContext::DoInitialize()
// Initializing with a default context, which means no on-disk cookie DB, // Initializing with a default context, which means no on-disk cookie DB,
// and no support for directory listings. // and no support for directory listings.
// TODO(cef): Either disable caching or send the cache files to a reasonable //PathService::Get(base::DIR_EXE, &cache_path);
// temporary directory
std::wstring cache_path;
PathService::Get(base::DIR_EXE, &cache_path);
BrowserResourceLoaderBridge::Init( BrowserResourceLoaderBridge::Init(
new BrowserRequestContext(cache_path, net::HttpCache::NORMAL, false)); new BrowserRequestContext(cache_path_, net::HttpCache::NORMAL, false));
// Load ICU data tables. // Load ICU data tables.
bool ret = icu_util::Initialize(); bool ret = icu_util::Initialize();
@ -267,7 +265,8 @@ CefContext::~CefContext()
DoUninitialize(); DoUninitialize();
} }
bool CefContext::Initialize(bool multi_threaded_message_loop) bool CefContext::Initialize(bool multi_threaded_message_loop,
const std::wstring& cache_path)
{ {
bool initialized = false, intransition = false; bool initialized = false, intransition = false;
@ -282,6 +281,8 @@ bool CefContext::Initialize(bool multi_threaded_message_loop)
// We are now in a transitional state // We are now in a transitional state
in_transition_ = true; in_transition_ = true;
cache_path_ = cache_path;
// Register the window class // Register the window class
WNDCLASSEX wcex = { WNDCLASSEX wcex = {
/* cbSize = */ sizeof(WNDCLASSEX), /* cbSize = */ sizeof(WNDCLASSEX),

View File

@ -23,7 +23,8 @@ public:
CefContext(); CefContext();
~CefContext(); ~CefContext();
bool Initialize(bool multi_threaded_message_loop); bool Initialize(bool multi_threaded_message_loop,
const std::wstring& cache_path);
void Shutdown(); void Shutdown();
MessageLoopForUI* GetMessageLoopForUI() { return messageloopui_; } MessageLoopForUI* GetMessageLoopForUI() { return messageloopui_; }
@ -33,6 +34,10 @@ public:
DWORD GetUIThreadId() { return idthreadui_; } DWORD GetUIThreadId() { return idthreadui_; }
WebPreferences* GetWebPreferences() { return webprefs_; } WebPreferences* GetWebPreferences() { return webprefs_; }
// Retrieve the path at which cache data will be stored on disk. If empty,
// cache data will be stored in-memory.
std::wstring GetCachePath() { return cache_path_; }
bool AddBrowser(CefRefPtr<CefBrowserImpl> browser); bool AddBrowser(CefRefPtr<CefBrowserImpl> browser);
bool RemoveBrowser(CefRefPtr<CefBrowserImpl> browser); bool RemoveBrowser(CefRefPtr<CefBrowserImpl> browser);
BrowserList* GetBrowserList() { return &browserlist_; } BrowserList* GetBrowserList() { return &browserlist_; }
@ -68,6 +73,7 @@ protected:
BrowserList browserlist_; BrowserList browserlist_;
WebPreferences* webprefs_; WebPreferences* webprefs_;
StatsTable* statstable_; StatsTable* statstable_;
std::wstring cache_path_;
// Initialize the AtExitManager to avoid asserts and possible memory leaks. // Initialize the AtExitManager to avoid asserts and possible memory leaks.
base::AtExitManager at_exit_manager_; base::AtExitManager at_exit_manager_;

View File

@ -14,9 +14,13 @@
#include "base/string_util.h" #include "base/string_util.h"
CEF_EXPORT int cef_initialize(int multi_threaded_message_loop) CEF_EXPORT int cef_initialize(int multi_threaded_message_loop,
const wchar_t* cache_path)
{ {
return CefInitialize(multi_threaded_message_loop); std::wstring cachePath;
if(cache_path)
cachePath = cache_path;
return CefInitialize(multi_threaded_message_loop, cachePath);
} }
CEF_EXPORT void cef_shutdown() CEF_EXPORT void cef_shutdown()

View File

@ -12,9 +12,10 @@
#include "../ctocpp/stream_ctocpp.h" #include "../ctocpp/stream_ctocpp.h"
bool CefInitialize(bool multi_threaded_message_loop) bool CefInitialize(bool multi_threaded_message_loop,
const std::wstring& cache_path)
{ {
return (bool)cef_initialize(multi_threaded_message_loop); return (bool)cef_initialize(multi_threaded_message_loop, cache_path.c_str());
} }
void CefShutdown() void CefShutdown()

View File

@ -17,7 +17,7 @@
// Define this value to run CEF with messages processed using the current // Define this value to run CEF with messages processed using the current
// application's message loop. // application's message loop.
//#define TEST_SINGLE_THREADED_MESSAGE_LOOP #define TEST_SINGLE_THREADED_MESSAGE_LOOP
// Global Variables: // Global Variables:
HINSTANCE hInst; // current instance HINSTANCE hInst; // current instance
@ -41,10 +41,10 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
#ifdef TEST_SINGLE_THREADED_MESSAGE_LOOP #ifdef TEST_SINGLE_THREADED_MESSAGE_LOOP
// Initialize the CEF with messages processed using the current application's // Initialize the CEF with messages processed using the current application's
// message loop. // message loop.
CefInitialize(false); CefInitialize(false, std::wstring());
#else #else
// Initialize the CEF with messages processed using a separate UI thread. // Initialize the CEF with messages processed using a separate UI thread.
CefInitialize(true); CefInitialize(true, std::wstring());
#endif #endif
// Structure providing information about the client plugin. // Structure providing information about the client plugin.
@ -383,9 +383,12 @@ public:
// ignored. // ignored.
virtual RetVal HandleAddressChange(CefRefPtr<CefBrowser> browser, virtual RetVal HandleAddressChange(CefRefPtr<CefBrowser> browser,
const std::wstring& url) const std::wstring& url)
{
if(m_BrowserHwnd == browser->GetWindowHandle())
{ {
// Set the edit window text // Set the edit window text
SetWindowText(m_EditHwnd, url.c_str()); SetWindowText(m_EditHwnd, url.c_str());
}
return RV_CONTINUE; return RV_CONTINUE;
} }
@ -395,7 +398,13 @@ public:
const std::wstring& title) const std::wstring& title)
{ {
// Set the frame window title bar // Set the frame window title bar
SetWindowText(m_MainHwnd, title.c_str()); HWND hwnd = browser->GetWindowHandle();
if(!browser->IsPopup())
{
// The frame window will be the parent of the browser window
hwnd = GetParent(hwnd);
}
SetWindowText(hwnd, title.c_str());
return RV_CONTINUE; return RV_CONTINUE;
} }
@ -835,6 +844,13 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
browser->LoadString(html, L"about:blank"); browser->LoadString(html, L"about:blank");
} }
return 0; return 0;
case ID_TESTS_POPUP: // Test a popup window
if(browser.get())
{
browser->ExecuteJavaScript(L"window.open('http://www.google.com');",
L"about:blank", 0, TF_MAIN);
}
return 0;
} }
} }
break; break;

View File

@ -60,6 +60,7 @@ BEGIN
MENUITEM "JavaScript Handler", ID_TESTS_JAVASCRIPT_HANDLER MENUITEM "JavaScript Handler", ID_TESTS_JAVASCRIPT_HANDLER
MENUITEM "JavaScript Execute", ID_TESTS_JAVASCRIPT_EXECUTE MENUITEM "JavaScript Execute", ID_TESTS_JAVASCRIPT_EXECUTE
MENUITEM "Plugin", ID_TESTS_PLUGIN MENUITEM "Plugin", ID_TESTS_PLUGIN
MENUITEM "Popup Window", ID_TESTS_POPUP
END END
END END

View File

@ -24,6 +24,7 @@
#define ID_TESTS_JAVASCRIPT_HANDLER 32771 #define ID_TESTS_JAVASCRIPT_HANDLER 32771
#define ID_TESTS_JAVASCRIPT_EXECUTE 32772 #define ID_TESTS_JAVASCRIPT_EXECUTE 32772
#define ID_TESTS_PLUGIN 32773 #define ID_TESTS_PLUGIN 32773
#define ID_TESTS_POPUP 32774
#define IDC_STATIC -1 #define IDC_STATIC -1
#define IDS_LOGO 1000 #define IDS_LOGO 1000