diff --git a/include/cef.h b/include/cef.h index 617bb35f9..ced662e41 100644 --- a/include/cef.h +++ b/include/cef.h @@ -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 diff --git a/include/cef_capi.h b/include/cef_capi.h index 203f9c6ed..e710833e3 100644 --- a/include/cef_capi.h +++ b/include/cef_capi.h @@ -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 diff --git a/libcef/browser_impl.cc b/libcef/browser_impl.cc index 3b5a6185f..b7ff4feff 100644 --- a/libcef/browser_impl.cc +++ b/libcef/browser_impl.cc @@ -425,7 +425,7 @@ CefRefPtr CefBrowserImpl::UIT_CreatePopupWindow(const std::wstri REQUIRE_UIT(); CefWindowInfo info; - info.SetAsPopup(UIT_GetMainWndHandle(), url.c_str()); + info.SetAsPopup(NULL, url.c_str()); CefRefPtr handler = handler_; std::wstring newUrl = url; diff --git a/libcef/context.cc b/libcef/context.cc index 3cd8d9903..9b954b3c6 100644 --- a/libcef/context.cc +++ b/libcef/context.cc @@ -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), diff --git a/libcef/context.h b/libcef/context.h index 6a9dc6a98..a3628e83e 100644 --- a/libcef/context.h +++ b/libcef/context.h @@ -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 browser); bool RemoveBrowser(CefRefPtr 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 _Context; // Macro for requiring that a function be called on the UI thread #define REQUIRE_UIT() DCHECK(_Context->RunningOnUIThread()) -#endif // _CONTEXT_H \ No newline at end of file +#endif // _CONTEXT_H diff --git a/libcef_dll/libcef_dll.cc b/libcef_dll/libcef_dll.cc index efdafb742..5eac33e24 100644 --- a/libcef_dll/libcef_dll.cc +++ b/libcef_dll/libcef_dll.cc @@ -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() diff --git a/libcef_dll/wrapper/libcef_dll_wrapper.cc b/libcef_dll/wrapper/libcef_dll_wrapper.cc index 38ba2081e..b2b6e5bb0 100644 --- a/libcef_dll/wrapper/libcef_dll_wrapper.cc +++ b/libcef_dll/wrapper/libcef_dll_wrapper.cc @@ -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() diff --git a/tests/cefclient/cefclient.cpp b/tests/cefclient/cefclient.cpp index bf92efd42..98f6a15b2 100644 --- a/tests/cefclient/cefclient.cpp +++ b/tests/cefclient/cefclient.cpp @@ -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 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; diff --git a/tests/cefclient/cefclient.rc b/tests/cefclient/cefclient.rc index fb83795dc..6aa50c307 100644 --- a/tests/cefclient/cefclient.rc +++ b/tests/cefclient/cefclient.rc @@ -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 diff --git a/tests/cefclient/resource.h b/tests/cefclient/resource.h index cc7fd3dba..bc12351c0 100644 --- a/tests/cefclient/resource.h +++ b/tests/cefclient/resource.h @@ -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