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

View File

@ -23,7 +23,8 @@ public:
CefContext();
~CefContext();
bool Initialize(bool multi_threaded_message_loop);
bool Initialize(bool multi_threaded_message_loop,
const std::wstring& cache_path);
void Shutdown();
MessageLoopForUI* GetMessageLoopForUI() { return messageloopui_; }
@ -32,6 +33,10 @@ public:
HANDLE GetUIThreadHandle() { return hthreadui_; }
DWORD GetUIThreadId() { return idthreadui_; }
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 RemoveBrowser(CefRefPtr<CefBrowserImpl> browser);
@ -68,12 +73,13 @@ protected:
BrowserList browserlist_;
WebPreferences* webprefs_;
StatsTable* statstable_;
std::wstring cache_path_;
// Initialize the AtExitManager to avoid asserts and possible memory leaks.
base::AtExitManager at_exit_manager_;
// Initialize WebKit for this scope.
BrowserWebKitInit webkit_init_;
friend DWORD WINAPI ThreadHandlerUI(LPVOID lpParam);
};
@ -86,4 +92,4 @@ extern CefRefPtr<CefContext> _Context;
// Macro for requiring that a function be called on the UI thread
#define REQUIRE_UIT() DCHECK(_Context->RunningOnUIThread())
#endif // _CONTEXT_H
#endif // _CONTEXT_H

View File

@ -14,9 +14,13 @@
#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()

View File

@ -12,9 +12,10 @@
#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()

View File

@ -17,7 +17,7 @@
// Define this value to run CEF with messages processed using the current
// application's message loop.
//#define TEST_SINGLE_THREADED_MESSAGE_LOOP
#define TEST_SINGLE_THREADED_MESSAGE_LOOP
// Global Variables:
HINSTANCE hInst; // current instance
@ -41,10 +41,10 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
#ifdef TEST_SINGLE_THREADED_MESSAGE_LOOP
// Initialize the CEF with messages processed using the current application's
// message loop.
CefInitialize(false);
CefInitialize(false, std::wstring());
#else
// Initialize the CEF with messages processed using a separate UI thread.
CefInitialize(true);
CefInitialize(true, std::wstring());
#endif
// Structure providing information about the client plugin.
@ -384,8 +384,11 @@ public:
virtual RetVal HandleAddressChange(CefRefPtr<CefBrowser> browser,
const std::wstring& url)
{
// Set the edit window text
SetWindowText(m_EditHwnd, url.c_str());
if(m_BrowserHwnd == browser->GetWindowHandle())
{
// Set the edit window text
SetWindowText(m_EditHwnd, url.c_str());
}
return RV_CONTINUE;
}
@ -395,7 +398,13 @@ public:
const std::wstring& title)
{
// 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;
}
@ -835,6 +844,13 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
browser->LoadString(html, L"about:blank");
}
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;

View File

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

View File

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