mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-03-16 12:00:13 +01:00
Issue #307:
- Add a CefBrowser::HasDocument() method that tests if a document has been loaded in the browser window. - Modify ClientHandler::GetDownloadHandler() to demonstrate how to close a download popup window. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@282 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
parent
16e468bb8c
commit
f636510101
@ -635,6 +635,10 @@ public:
|
||||
/*--cef()--*/
|
||||
virtual bool IsPopup() =0;
|
||||
|
||||
// Returns true if a document has been loaded in the browser.
|
||||
/*--cef()--*/
|
||||
virtual bool HasDocument() =0;
|
||||
|
||||
///
|
||||
// Returns the client for this browser.
|
||||
///
|
||||
|
@ -471,6 +471,9 @@ typedef struct _cef_browser_t
|
||||
///
|
||||
int (CEF_CALLBACK *is_popup)(struct _cef_browser_t* self);
|
||||
|
||||
// Returns true (1) if a document has been loaded in the browser.
|
||||
int (CEF_CALLBACK *has_document)(struct _cef_browser_t* self);
|
||||
|
||||
///
|
||||
// Returns the client for this browser.
|
||||
///
|
||||
|
@ -165,7 +165,7 @@ CefBrowserImpl::CefBrowserImpl(const CefWindowInfo& windowInfo,
|
||||
: window_info_(windowInfo), settings_(settings), opener_(opener),
|
||||
is_modal_(false), client_(client), webviewhost_(NULL), popuphost_(NULL),
|
||||
zoom_level_(0.0), can_go_back_(false), can_go_forward_(false),
|
||||
main_frame_(NULL), unique_id_(0)
|
||||
has_document_(false), main_frame_(NULL), unique_id_(0)
|
||||
#if defined(OS_WIN)
|
||||
, opener_was_disabled_by_modal_loop_(false),
|
||||
internal_modal_message_loop_is_active_(false)
|
||||
@ -1533,6 +1533,18 @@ bool CefBrowserImpl::can_go_forward()
|
||||
return can_go_forward_;
|
||||
}
|
||||
|
||||
void CefBrowserImpl::set_has_document(bool has_document)
|
||||
{
|
||||
AutoLock lock_scope(this);
|
||||
has_document_ = has_document;
|
||||
}
|
||||
|
||||
bool CefBrowserImpl::has_document()
|
||||
{
|
||||
AutoLock lock_scope(this);
|
||||
return has_document_;
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_CreateDevToolsClient(BrowserDevToolsAgent *agent)
|
||||
{
|
||||
dev_tools_client_.reset(new BrowserDevToolsClient(this, agent));
|
||||
|
@ -76,6 +76,7 @@ public:
|
||||
virtual CefWindowHandle GetOpenerWindowHandle() OVERRIDE
|
||||
{ return opener_window(); }
|
||||
virtual bool IsPopup() OVERRIDE { return is_popup(); }
|
||||
virtual bool HasDocument() OVERRIDE { return has_document(); }
|
||||
virtual CefRefPtr<CefClient> GetClient() OVERRIDE { return client_; }
|
||||
virtual CefRefPtr<CefFrame> GetMainFrame() OVERRIDE
|
||||
{ return GetMainCefFrame(); }
|
||||
@ -322,6 +323,8 @@ public:
|
||||
void set_nav_state(bool can_go_back, bool can_go_forward);
|
||||
bool can_go_back();
|
||||
bool can_go_forward();
|
||||
void set_has_document(bool has_document);
|
||||
bool has_document();
|
||||
|
||||
#if defined(OS_WIN)
|
||||
void set_opener_was_disabled_by_modal_loop(bool disabled)
|
||||
@ -368,6 +371,7 @@ protected:
|
||||
double zoom_level_;
|
||||
bool can_go_back_;
|
||||
bool can_go_forward_;
|
||||
bool has_document_;
|
||||
|
||||
#if defined(OS_WIN)
|
||||
// Context object used to manage printing.
|
||||
|
@ -1055,6 +1055,14 @@ void BrowserWebViewDelegate::UpdateURL(WebFrame* frame) {
|
||||
DCHECK(ds);
|
||||
|
||||
const WebURLRequest& request = ds->request();
|
||||
BrowserNavigationController* controller =
|
||||
browser_->UIT_GetNavigationController();
|
||||
|
||||
if (controller->GetEntryCount() == 0) {
|
||||
// This is the first navigation for the browser. Indicate that the browser
|
||||
// now has a document.
|
||||
browser_->set_has_document(true);
|
||||
}
|
||||
|
||||
// Type is unused.
|
||||
scoped_ptr<BrowserNavigationEntry> entry(new BrowserNavigationEntry);
|
||||
@ -1084,9 +1092,6 @@ void BrowserWebViewDelegate::UpdateURL(WebFrame* frame) {
|
||||
if (!history_item.isNull())
|
||||
entry->SetContentState(webkit_glue::HistoryItemToString(history_item));
|
||||
|
||||
BrowserNavigationController* controller =
|
||||
browser_->UIT_GetNavigationController();
|
||||
|
||||
bool old_can_go_back = !controller->IsAtStart();
|
||||
bool old_can_go_forward = !controller->IsAtEnd();
|
||||
controller->DidNavigateToEntry(entry.release());
|
||||
|
@ -188,6 +188,15 @@ int CEF_CALLBACK browser_is_popup(struct _cef_browser_t* self)
|
||||
return CefBrowserCppToC::Get(self)->IsPopup();
|
||||
}
|
||||
|
||||
int CEF_CALLBACK browser_has_document(struct _cef_browser_t* self)
|
||||
{
|
||||
DCHECK(self);
|
||||
if(!self)
|
||||
return 0;
|
||||
|
||||
return CefBrowserCppToC::Get(self)->HasDocument();
|
||||
}
|
||||
|
||||
struct _cef_client_t* CEF_CALLBACK browser_get_client(
|
||||
struct _cef_browser_t* self)
|
||||
{
|
||||
@ -472,6 +481,7 @@ CefBrowserCppToC::CefBrowserCppToC(CefBrowser* cls)
|
||||
struct_.struct_.get_window_handle = browser_get_window_handle;
|
||||
struct_.struct_.get_opener_window_handle = browser_get_opener_window_handle;
|
||||
struct_.struct_.is_popup = browser_is_popup;
|
||||
struct_.struct_.has_document = browser_has_document;
|
||||
struct_.struct_.get_client = browser_get_client;
|
||||
struct_.struct_.get_main_frame = browser_get_main_frame;
|
||||
struct_.struct_.get_focused_frame = browser_get_focused_frame;
|
||||
|
@ -144,6 +144,14 @@ bool CefBrowserCToCpp::IsPopup()
|
||||
return struct_->is_popup(struct_)?true:false;
|
||||
}
|
||||
|
||||
bool CefBrowserCToCpp::HasDocument()
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, has_document))
|
||||
return false;
|
||||
|
||||
return struct_->has_document(struct_)?true:false;
|
||||
}
|
||||
|
||||
CefRefPtr<CefClient> CefBrowserCToCpp::GetClient()
|
||||
{
|
||||
if (CEF_MEMBER_MISSING(struct_, get_client))
|
||||
|
@ -44,6 +44,7 @@ public:
|
||||
virtual CefWindowHandle GetWindowHandle() OVERRIDE;
|
||||
virtual CefWindowHandle GetOpenerWindowHandle() OVERRIDE;
|
||||
virtual bool IsPopup() OVERRIDE;
|
||||
virtual bool HasDocument() OVERRIDE;
|
||||
virtual CefRefPtr<CefClient> GetClient() OVERRIDE;
|
||||
virtual CefRefPtr<CefFrame> GetMainFrame() OVERRIDE;
|
||||
virtual CefRefPtr<CefFrame> GetFocusedFrame() OVERRIDE;
|
||||
|
@ -140,6 +140,11 @@ bool ClientHandler::GetDownloadHandler(CefRefPtr<CefBrowser> browser,
|
||||
|
||||
// Create the handler for the file download.
|
||||
handler = CreateDownloadHandler(this, fileName);
|
||||
|
||||
// Close the browser window if it is a popup with no other document contents.
|
||||
if (browser->IsPopup() && !browser->HasDocument())
|
||||
browser->CloseBrowser();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user