- Respect the WS_VISIBLE flag when creating browser windows (issue #201).
- Add a CefBrowser::CloseBrowser() method. - Add a TEST_REDIRECT_POPUP_URLS test to cefclient. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@200 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
parent
1f01d6b2a8
commit
7b1166b18a
|
@ -414,6 +414,10 @@ public:
|
||||||
CefRefPtr<CefHandler> handler,
|
CefRefPtr<CefHandler> handler,
|
||||||
const CefString& url);
|
const CefString& url);
|
||||||
|
|
||||||
|
// Closes this browser window.
|
||||||
|
/*--cef()--*/
|
||||||
|
virtual void CloseBrowser() =0;
|
||||||
|
|
||||||
// Returns true if the browser can navigate backwards.
|
// Returns true if the browser can navigate backwards.
|
||||||
/*--cef()--*/
|
/*--cef()--*/
|
||||||
virtual bool CanGoBack() =0;
|
virtual bool CanGoBack() =0;
|
||||||
|
|
|
@ -231,6 +231,9 @@ typedef struct _cef_browser_t
|
||||||
// Base structure.
|
// Base structure.
|
||||||
cef_base_t base;
|
cef_base_t base;
|
||||||
|
|
||||||
|
// Closes this browser window.
|
||||||
|
void (CEF_CALLBACK *close_browser)(struct _cef_browser_t* self);
|
||||||
|
|
||||||
// Returns true (1) if the browser can navigate backwards.
|
// Returns true (1) if the browser can navigate backwards.
|
||||||
int (CEF_CALLBACK *can_go_back)(struct _cef_browser_t* self);
|
int (CEF_CALLBACK *can_go_back)(struct _cef_browser_t* self);
|
||||||
|
|
||||||
|
|
|
@ -126,8 +126,8 @@ public:
|
||||||
|
|
||||||
void SetAsChild(HWND hWndParent, RECT windowRect)
|
void SetAsChild(HWND hWndParent, RECT windowRect)
|
||||||
{
|
{
|
||||||
m_dwStyle = WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN
|
m_dwStyle = WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_TABSTOP |
|
||||||
| WS_CLIPSIBLINGS | WS_TABSTOP;
|
WS_VISIBLE;
|
||||||
m_hWndParent = hWndParent;
|
m_hWndParent = hWndParent;
|
||||||
m_x = windowRect.left;
|
m_x = windowRect.left;
|
||||||
m_y = windowRect.top;
|
m_y = windowRect.top;
|
||||||
|
@ -137,7 +137,8 @@ public:
|
||||||
|
|
||||||
void SetAsPopup(HWND hWndParent, const CefString& windowName)
|
void SetAsPopup(HWND hWndParent, const CefString& windowName)
|
||||||
{
|
{
|
||||||
m_dwStyle = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
|
m_dwStyle = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS |
|
||||||
|
WS_VISIBLE;
|
||||||
m_hWndParent = hWndParent;
|
m_hWndParent = hWndParent;
|
||||||
m_x = CW_USEDEFAULT;
|
m_x = CW_USEDEFAULT;
|
||||||
m_y = CW_USEDEFAULT;
|
m_y = CW_USEDEFAULT;
|
||||||
|
|
|
@ -146,6 +146,11 @@ CefBrowserImpl::CefBrowserImpl(const CefWindowInfo& windowInfo,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CefBrowserImpl::CloseBrowser()
|
||||||
|
{
|
||||||
|
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this,
|
||||||
|
&CefBrowserImpl::UIT_CloseBrowser));
|
||||||
|
}
|
||||||
void CefBrowserImpl::GoBack()
|
void CefBrowserImpl::GoBack()
|
||||||
{
|
{
|
||||||
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this,
|
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this,
|
||||||
|
@ -768,7 +773,10 @@ bool CefBrowserImpl::UIT_Navigate(const BrowserNavigationEntry& entry,
|
||||||
// thread for additional details:
|
// thread for additional details:
|
||||||
// http://groups.google.com/group/chromium-dev/browse_thread/thread/42bcd31b59e3a168
|
// http://groups.google.com/group/chromium-dev/browse_thread/thread/42bcd31b59e3a168
|
||||||
view->setFocusedFrame(frame);
|
view->setFocusedFrame(frame);
|
||||||
UIT_SetFocus(UIT_GetWebViewHost(), true);
|
|
||||||
|
// Give focus to the window if it is currently visible.
|
||||||
|
if(IsWindowVisible(UIT_GetMainWndHandle()))
|
||||||
|
UIT_SetFocus(UIT_GetWebViewHost(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -48,6 +48,7 @@ public:
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// CefBrowser methods
|
// CefBrowser methods
|
||||||
|
virtual void CloseBrowser();
|
||||||
virtual bool CanGoBack() { return can_go_back(); }
|
virtual bool CanGoBack() { return can_go_back(); }
|
||||||
virtual void GoBack();
|
virtual void GoBack();
|
||||||
virtual bool CanGoForward() { return can_go_forward(); }
|
virtual bool CanGoForward() { return can_go_forward(); }
|
||||||
|
|
|
@ -141,8 +141,16 @@ void CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
|
||||||
// Size the web view window to the browser window
|
// Size the web view window to the browser window
|
||||||
RECT cr;
|
RECT cr;
|
||||||
GetClientRect(window_info_.m_hWnd, &cr);
|
GetClientRect(window_info_.m_hWnd, &cr);
|
||||||
|
|
||||||
|
// Respect the WS_VISIBLE window style when setting the window's position
|
||||||
|
UINT flags = SWP_NOZORDER;
|
||||||
|
if (window_info_.m_dwStyle & WS_VISIBLE)
|
||||||
|
flags |= SWP_SHOWWINDOW;
|
||||||
|
else
|
||||||
|
flags |= SWP_NOACTIVATE;
|
||||||
|
|
||||||
SetWindowPos(UIT_GetWebViewWndHandle(), NULL, cr.left, cr.top, cr.right,
|
SetWindowPos(UIT_GetWebViewWndHandle(), NULL, cr.left, cr.top, cr.right,
|
||||||
cr.bottom, SWP_NOZORDER | SWP_SHOWWINDOW);
|
cr.bottom, flags);
|
||||||
|
|
||||||
if(handler_.get()) {
|
if(handler_.get()) {
|
||||||
// Notify the handler that we're done creating the new window
|
// Notify the handler that we're done creating the new window
|
||||||
|
|
|
@ -55,10 +55,13 @@ WebWidget* BrowserWebViewDelegate::createPopupMenu(
|
||||||
|
|
||||||
void BrowserWebViewDelegate::show(WebNavigationPolicy) {
|
void BrowserWebViewDelegate::show(WebNavigationPolicy) {
|
||||||
if (this == browser_->UIT_GetWebViewDelegate()) {
|
if (this == browser_->UIT_GetWebViewDelegate()) {
|
||||||
// Restore the window and bring it to the top.
|
// Restore the window and bring it to the top if the window is currently
|
||||||
|
// visible.
|
||||||
HWND root = GetAncestor(browser_->UIT_GetMainWndHandle(), GA_ROOT);
|
HWND root = GetAncestor(browser_->UIT_GetMainWndHandle(), GA_ROOT);
|
||||||
ShowWindow(root, SW_SHOWNORMAL);
|
if(IsWindowVisible(root)) {
|
||||||
SetWindowPos(root, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
|
ShowWindow(root, SW_SHOWNORMAL);
|
||||||
|
SetWindowPos(root, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
|
||||||
|
}
|
||||||
} else if (this == browser_->UIT_GetPopupDelegate()) {
|
} else if (this == browser_->UIT_GetPopupDelegate()) {
|
||||||
// Show popup widgets without activation.
|
// Show popup widgets without activation.
|
||||||
ShowWindow(browser_->UIT_GetPopupWndHandle(), SW_SHOWNA);
|
ShowWindow(browser_->UIT_GetPopupWndHandle(), SW_SHOWNA);
|
||||||
|
|
|
@ -55,6 +55,15 @@ CEF_EXPORT cef_browser_t* cef_browser_create_sync(cef_window_info_t* windowInfo,
|
||||||
|
|
||||||
// MEMBER FUNCTIONS - Body may be edited by hand.
|
// MEMBER FUNCTIONS - Body may be edited by hand.
|
||||||
|
|
||||||
|
void CEF_CALLBACK browser_close_browser(struct _cef_browser_t* self)
|
||||||
|
{
|
||||||
|
DCHECK(self);
|
||||||
|
if(!self)
|
||||||
|
return;
|
||||||
|
|
||||||
|
CefBrowserCppToC::Get(self)->CloseBrowser();
|
||||||
|
}
|
||||||
|
|
||||||
int CEF_CALLBACK browser_can_go_back(struct _cef_browser_t* self)
|
int CEF_CALLBACK browser_can_go_back(struct _cef_browser_t* self)
|
||||||
{
|
{
|
||||||
DCHECK(self);
|
DCHECK(self);
|
||||||
|
@ -282,6 +291,7 @@ void CEF_CALLBACK browser_close_dev_tools(struct _cef_browser_t* self)
|
||||||
CefBrowserCppToC::CefBrowserCppToC(CefBrowser* cls)
|
CefBrowserCppToC::CefBrowserCppToC(CefBrowser* cls)
|
||||||
: CefCppToC<CefBrowserCppToC, CefBrowser, cef_browser_t>(cls)
|
: CefCppToC<CefBrowserCppToC, CefBrowser, cef_browser_t>(cls)
|
||||||
{
|
{
|
||||||
|
struct_.struct_.close_browser = browser_close_browser;
|
||||||
struct_.struct_.can_go_back = browser_can_go_back;
|
struct_.struct_.can_go_back = browser_can_go_back;
|
||||||
struct_.struct_.go_back = browser_go_back;
|
struct_.struct_.go_back = browser_go_back;
|
||||||
struct_.struct_.can_go_forward = browser_can_go_forward;
|
struct_.struct_.can_go_forward = browser_can_go_forward;
|
||||||
|
|
|
@ -38,6 +38,14 @@ CefRefPtr<CefBrowser> CefBrowser::CreateBrowserSync(CefWindowInfo& windowInfo,
|
||||||
|
|
||||||
// VIRTUAL METHODS - Body may be edited by hand.
|
// VIRTUAL METHODS - Body may be edited by hand.
|
||||||
|
|
||||||
|
void CefBrowserCToCpp::CloseBrowser()
|
||||||
|
{
|
||||||
|
if(CEF_MEMBER_MISSING(struct_, close_browser))
|
||||||
|
return;
|
||||||
|
|
||||||
|
struct_->close_browser(struct_);
|
||||||
|
}
|
||||||
|
|
||||||
bool CefBrowserCToCpp::CanGoBack()
|
bool CefBrowserCToCpp::CanGoBack()
|
||||||
{
|
{
|
||||||
if(CEF_MEMBER_MISSING(struct_, can_go_back))
|
if(CEF_MEMBER_MISSING(struct_, can_go_back))
|
||||||
|
|
|
@ -31,6 +31,7 @@ public:
|
||||||
virtual ~CefBrowserCToCpp() {}
|
virtual ~CefBrowserCToCpp() {}
|
||||||
|
|
||||||
// CefBrowser methods
|
// CefBrowser methods
|
||||||
|
virtual void CloseBrowser();
|
||||||
virtual bool CanGoBack();
|
virtual bool CanGoBack();
|
||||||
virtual void GoBack();
|
virtual void GoBack();
|
||||||
virtual bool CanGoForward();
|
virtual bool CanGoForward();
|
||||||
|
|
|
@ -14,6 +14,40 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
// 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<CefBrowser> parentBrowser)
|
||||||
|
: m_ParentBrowser(parentBrowser)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
virtual ~ClientPopupHandler()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual RetVal HandleBeforeBrowse(CefRefPtr<CefBrowser> browser,
|
||||||
|
CefRefPtr<CefFrame> frame,
|
||||||
|
CefRefPtr<CefRequest> request,
|
||||||
|
NavType navType, bool isRedirect)
|
||||||
|
{
|
||||||
|
REQUIRE_UI_THREAD();
|
||||||
|
|
||||||
|
m_ParentBrowser->GetMainFrame()->LoadRequest(request);
|
||||||
|
browser->CloseBrowser();
|
||||||
|
return RV_HANDLED;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
CefRefPtr<CefBrowser> m_ParentBrowser;
|
||||||
|
};
|
||||||
|
#endif // TEST_REDIRECT_POPUP_URLS
|
||||||
|
|
||||||
// ClientHandler::ClientDownloadListener implementation
|
// ClientHandler::ClientDownloadListener implementation
|
||||||
|
|
||||||
|
@ -46,6 +80,30 @@ ClientHandler::~ClientHandler()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CefHandler::RetVal ClientHandler::HandleBeforeCreated(
|
||||||
|
CefRefPtr<CefBrowser> parentBrowser, CefWindowInfo& createInfo, bool popup,
|
||||||
|
const CefPopupFeatures& popupFeatures, CefRefPtr<CefHandler>& 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(
|
CefHandler::RetVal ClientHandler::HandleAfterCreated(
|
||||||
CefRefPtr<CefBrowser> browser)
|
CefRefPtr<CefBrowser> browser)
|
||||||
{
|
{
|
||||||
|
|
|
@ -30,7 +30,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
ClientHandler();
|
ClientHandler();
|
||||||
~ClientHandler();
|
virtual ~ClientHandler();
|
||||||
|
|
||||||
// Called on the UI thread before a new window is created. The |parentBrowser|
|
// Called on the UI thread before a new window is created. The |parentBrowser|
|
||||||
// parameter will point to the parent browser window, if any. The |popup|
|
// parameter will point to the parent browser window, if any. The |popup|
|
||||||
|
@ -47,11 +47,7 @@ public:
|
||||||
const CefPopupFeatures& popupFeatures,
|
const CefPopupFeatures& popupFeatures,
|
||||||
CefRefPtr<CefHandler>& handler,
|
CefRefPtr<CefHandler>& handler,
|
||||||
CefString& url,
|
CefString& url,
|
||||||
CefBrowserSettings& settings)
|
CefBrowserSettings& settings);
|
||||||
{
|
|
||||||
REQUIRE_UI_THREAD();
|
|
||||||
return RV_CONTINUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Called on the UI thread after a new window is created. The return value is
|
// Called on the UI thread after a new window is created. The return value is
|
||||||
// currently ignored.
|
// currently ignored.
|
||||||
|
|
Loading…
Reference in New Issue