From 11b831119affeb36bab461ffca6640d49cdf74fa Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Tue, 8 Mar 2011 03:54:50 +0000 Subject: [PATCH] Mac: - Fix compile errors. - Add support for creating hidden windows and TEST_REDIRECT_POPUP_URLS. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@201 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- include/cef_mac.h | 2 ++ include/cef_types_mac.h | 1 + libcef/browser_impl.cc | 2 +- libcef/browser_impl.h | 1 + libcef/browser_impl_mac.mm | 12 +++++-- libcef/browser_impl_win.cc | 6 ++++ libcef/scheme_impl.cc | 8 +++-- tests/cefclient/cefclient.cpp | 58 ------------------------------- tests/cefclient/cefclient.h | 39 +++++++++++++++++++++ tests/cefclient/cefclient_mac.mm | 21 +++++++++++ tests/cefclient/cefclient_win.cpp | 21 +++++++++++ 11 files changed, 107 insertions(+), 64 deletions(-) diff --git a/include/cef_mac.h b/include/cef_mac.h index 6242d5777..19c55bc61 100644 --- a/include/cef_mac.h +++ b/include/cef_mac.h @@ -125,6 +125,7 @@ public: m_y = y; m_nWidth = width; m_nHeight = height; + m_bHidden = false; } CefWindowInfo& operator=(const CefWindowInfo& r) @@ -140,6 +141,7 @@ public: m_y = r.m_y; m_nWidth = r.m_nWidth; m_nHeight = r.m_nHeight; + m_bHidden = r.m_bHidden; return *this; } diff --git a/include/cef_types_mac.h b/include/cef_types_mac.h index cfed4dce3..4afba9991 100644 --- a/include/cef_types_mac.h +++ b/include/cef_types_mac.h @@ -58,6 +58,7 @@ typedef struct _cef_window_info_t int m_y; int m_nWidth; int m_nHeight; + int m_bHidden; // NSView pointer for the parent view. cef_window_handle_t m_ParentView; diff --git a/libcef/browser_impl.cc b/libcef/browser_impl.cc index fde30db7e..fb45af706 100644 --- a/libcef/browser_impl.cc +++ b/libcef/browser_impl.cc @@ -775,7 +775,7 @@ bool CefBrowserImpl::UIT_Navigate(const BrowserNavigationEntry& entry, view->setFocusedFrame(frame); // Give focus to the window if it is currently visible. - if(IsWindowVisible(UIT_GetMainWndHandle())) + if(UIT_IsViewVisible(UIT_GetMainWndHandle())) UIT_SetFocus(UIT_GetWebViewHost(), true); } diff --git a/libcef/browser_impl.h b/libcef/browser_impl.h index 6af0caefe..b76018262 100644 --- a/libcef/browser_impl.h +++ b/libcef/browser_impl.h @@ -280,6 +280,7 @@ public: protected: static void UIT_CloseView(gfx::NativeView view); + static bool UIT_IsViewVisible(gfx::NativeView view); void UIT_CreateDevToolsClient(BrowserDevToolsAgent* agent); void UIT_DestroyDevToolsClient(); diff --git a/libcef/browser_impl_mac.mm b/libcef/browser_impl_mac.mm index b7469d007..29af5c6cd 100644 --- a/libcef/browser_impl_mac.mm +++ b/libcef/browser_impl_mac.mm @@ -91,7 +91,7 @@ void CefBrowserImpl::UIT_CreateBrowser(const CefString& url) Unlock(); - if (newWnd != nil) { + if (newWnd != nil && !window_info_.m_bHidden) { // Show the window. [newWnd makeKeyAndOrderFront: nil]; } @@ -156,5 +156,13 @@ int CefBrowserImpl::UIT_GetPagesCount(WebKit::WebFrame* frame) // static void CefBrowserImpl::UIT_CloseView(gfx::NativeView view) { - [view performSelector:@selector(performClose:) withObject:nil afterDelay:0]; + [[view window] performSelector:@selector(performClose:) + withObject:nil + afterDelay:0]; +} + +// static +bool CefBrowserImpl::UIT_IsViewVisible(gfx::NativeView view) +{ + return [[view window] isVisible]; } diff --git a/libcef/browser_impl_win.cc b/libcef/browser_impl_win.cc index 3a4790dfb..dff3358a8 100644 --- a/libcef/browser_impl_win.cc +++ b/libcef/browser_impl_win.cc @@ -488,3 +488,9 @@ void CefBrowserImpl::UIT_CloseView(gfx::NativeView view) { PostMessage(view, WM_CLOSE, 0, 0); } + +// static +bool CefBrowserImpl::UIT_IsViewVisible(gfx::NativeView view) +{ + return IsWindowVisible(view) ? true : false; +} diff --git a/libcef/scheme_impl.cc b/libcef/scheme_impl.cc index ca5a89e72..e711e6fe5 100644 --- a/libcef/scheme_impl.cc +++ b/libcef/scheme_impl.cc @@ -409,10 +409,12 @@ bool CefRegisterScheme(const CefString& scheme_name, // RunnableMethodTraits::RetainCallee() (originating from NewRunnableMethod) // will call AddRef() and Release() on the object in debug mode, resulting in // the object being deleted if it doesn't already have a reference. + std::string hostNameStr; + if (is_standard) + hostNameStr = host_name; CefRefPtr wrapper( - new SchemeRequestJobWrapper(scheme_name, - (is_standard?host_name:std::string()), - is_standard, factory)); + new SchemeRequestJobWrapper(scheme_name, hostNameStr, is_standard, + factory)); CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(wrapper.get(), &SchemeRequestJobWrapper::RegisterScheme)); diff --git a/tests/cefclient/cefclient.cpp b/tests/cefclient/cefclient.cpp index 61e97e440..7e48f516d 100644 --- a/tests/cefclient/cefclient.cpp +++ b/tests/cefclient/cefclient.cpp @@ -14,40 +14,6 @@ #include #include -// Define this value to redirect all popup URLs to the main application browser -// window. -//#define TEST_REDIRECT_POPUP_URLS - -#ifdef TEST_REDIRECT_POPUP_URLS -// Handler for popup windows that loads the request in an existing browser -// window. -class ClientPopupHandler : public ClientHandler -{ -public: - ClientPopupHandler(CefRefPtr parentBrowser) - : m_ParentBrowser(parentBrowser) - { - } - virtual ~ClientPopupHandler() - { - } - - virtual RetVal HandleBeforeBrowse(CefRefPtr browser, - CefRefPtr frame, - CefRefPtr request, - NavType navType, bool isRedirect) - { - REQUIRE_UI_THREAD(); - - m_ParentBrowser->GetMainFrame()->LoadRequest(request); - browser->CloseBrowser(); - return RV_HANDLED; - } - -protected: - CefRefPtr m_ParentBrowser; -}; -#endif // TEST_REDIRECT_POPUP_URLS // ClientHandler::ClientDownloadListener implementation @@ -80,30 +46,6 @@ ClientHandler::~ClientHandler() { } -CefHandler::RetVal ClientHandler::HandleBeforeCreated( - CefRefPtr parentBrowser, CefWindowInfo& createInfo, bool popup, - const CefPopupFeatures& popupFeatures, CefRefPtr& handler, - CefString& url, CefBrowserSettings& settings) -{ - REQUIRE_UI_THREAD(); - -#ifdef TEST_REDIRECT_POPUP_URLS - if(popup) { - std::string urlStr = url; - if(urlStr.find("resources/inspector/devtools.html") == std::string::npos) { - // Show all popup windows excluding DevTools in the current window. -#ifdef _WIN32 - // Make the popup window hidden. - createInfo.m_dwStyle &= ~WS_VISIBLE; -#endif - handler = new ClientPopupHandler(m_Browser); - } - } -#endif // TEST_REDIRECT_POPUP_URLS - - return RV_CONTINUE; -} - CefHandler::RetVal ClientHandler::HandleAfterCreated( CefRefPtr browser) { diff --git a/tests/cefclient/cefclient.h b/tests/cefclient/cefclient.h index ed47a1bf9..e3974be56 100644 --- a/tests/cefclient/cefclient.h +++ b/tests/cefclient/cefclient.h @@ -9,6 +9,10 @@ #include "download_handler.h" #include "util.h" +// Define this value to redirect all popup URLs to the main application browser +// window. +//s#define TEST_REDIRECT_POPUP_URLS + // Client implementation of the browser handler class class ClientHandler : public CefThreadSafeBase { @@ -420,6 +424,41 @@ protected: }; +#ifdef TEST_REDIRECT_POPUP_URLS +// Handler for popup windows that loads the request in an existing browser +// window. +class ClientPopupHandler : public ClientHandler +{ +public: + ClientPopupHandler(CefRefPtr parentBrowser) + : m_ParentBrowser(parentBrowser) + { + } + virtual ~ClientPopupHandler() + { + } + + virtual RetVal HandleBeforeBrowse(CefRefPtr browser, + CefRefPtr frame, + CefRefPtr request, + NavType navType, bool isRedirect) + { + REQUIRE_UI_THREAD(); + + if (m_ParentBrowser.get()) { + m_ParentBrowser->GetMainFrame()->LoadRequest(request); + browser->CloseBrowser(); + m_ParentBrowser = NULL; + } + return RV_HANDLED; + } + +protected: + CefRefPtr m_ParentBrowser; +}; +#endif // TEST_REDIRECT_POPUP_URLS + + // Returns the main browser window instance. CefRefPtr AppGetBrowser(); diff --git a/tests/cefclient/cefclient_mac.mm b/tests/cefclient/cefclient_mac.mm index 7be26090e..36835d993 100644 --- a/tests/cefclient/cefclient_mac.mm +++ b/tests/cefclient/cefclient_mac.mm @@ -481,6 +481,27 @@ int main(int argc, char* argv[]) // ClientHandler implementation +CefHandler::RetVal ClientHandler::HandleBeforeCreated( + CefRefPtr parentBrowser, CefWindowInfo& createInfo, bool popup, + const CefPopupFeatures& popupFeatures, CefRefPtr& handler, + CefString& url, CefBrowserSettings& settings) +{ + REQUIRE_UI_THREAD(); + +#ifdef TEST_REDIRECT_POPUP_URLS + if(popup) { + std::string urlStr = url; + if(urlStr.find("resources/inspector/devtools.html") == std::string::npos) { + // Show all popup windows excluding DevTools in the current window. + createInfo.m_bHidden = true; + handler = new ClientPopupHandler(m_Browser); + } + } +#endif // TEST_REDIRECT_POPUP_URLS + + return RV_CONTINUE; +} + CefHandler::RetVal ClientHandler::HandleAddressChange( CefRefPtr browser, CefRefPtr frame, const CefString& url) diff --git a/tests/cefclient/cefclient_win.cpp b/tests/cefclient/cefclient_win.cpp index 90a1b40d7..c140ae67f 100644 --- a/tests/cefclient/cefclient_win.cpp +++ b/tests/cefclient/cefclient_win.cpp @@ -651,6 +651,27 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) // ClientHandler implementation +CefHandler::RetVal ClientHandler::HandleBeforeCreated( + CefRefPtr parentBrowser, CefWindowInfo& createInfo, bool popup, + const CefPopupFeatures& popupFeatures, CefRefPtr& handler, + CefString& url, CefBrowserSettings& settings) +{ + REQUIRE_UI_THREAD(); + +#ifdef TEST_REDIRECT_POPUP_URLS + if(popup) { + std::string urlStr = url; + if(urlStr.find("resources/inspector/devtools.html") == std::string::npos) { + // Show all popup windows excluding DevTools in the current window. + createInfo.m_dwStyle &= ~WS_VISIBLE; + handler = new ClientPopupHandler(m_Browser); + } + } +#endif // TEST_REDIRECT_POPUP_URLS + + return RV_CONTINUE; +} + CefHandler::RetVal ClientHandler::HandleAddressChange( CefRefPtr browser, CefRefPtr frame, const CefString& url)