Add new CefBrowser::GetIdentifier method (issue #811).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@953 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2012-12-19 16:47:38 +00:00
parent f782b4b1e0
commit 991a513473
10 changed files with 64 additions and 46 deletions

View File

@ -122,6 +122,11 @@ typedef struct _cef_browser_t {
cef_window_handle_t (CEF_CALLBACK *get_opener_window_handle)(
struct _cef_browser_t* self);
///
// Returns the globally unique identifier for this browser.
///
int (CEF_CALLBACK *get_identifier)(struct _cef_browser_t* self);
///
// Returns true (1) if the window is a popup window.
///

View File

@ -147,6 +147,12 @@ class CefBrowser : public virtual CefBase {
/*--cef()--*/
virtual CefWindowHandle GetOpenerWindowHandle() =0;
///
// Returns the globally unique identifier for this browser.
///
/*--cef()--*/
virtual int GetIdentifier() =0;
///
// Returns true if the window is a popup window.
///

View File

@ -170,7 +170,7 @@ CefBrowserImpl::CefBrowserImpl(const CefWindowInfo& windowInfo,
has_document_(false),
is_dropping_(false),
is_in_onsetfocus_(false),
unique_id_(0)
browser_id_(_Context->GetNextBrowserID())
#if defined(OS_WIN)
, opener_was_disabled_by_modal_loop_(false),
internal_modal_message_loop_is_active_(false)

View File

@ -83,6 +83,7 @@ class CefBrowserImpl : public CefBrowser {
virtual CefWindowHandle GetWindowHandle() OVERRIDE;
virtual CefWindowHandle GetOpenerWindowHandle() OVERRIDE
{ return opener_window(); }
virtual int GetIdentifier() OVERRIDE { return browser_id(); }
virtual bool IsPopup() OVERRIDE { return is_popup(); }
virtual bool HasDocument() OVERRIDE { return has_document(); }
virtual CefRefPtr<CefClient> GetClient() OVERRIDE { return client_; }
@ -303,9 +304,6 @@ class CefBrowserImpl : public CefBrowser {
const gfx::Size& canvas_size, WebKit::WebFrame* frame);
int UIT_GetPagesCount(WebKit::WebFrame* frame);
void UIT_SetUniqueID(int id) { unique_id_ = id; }
int UIT_GetUniqueID() { return unique_id_; }
void UIT_Find(int identifier, const CefString& search_text,
const WebKit::WebFindOptions& options);
void UIT_StopFinding(bool clear_selection);
@ -328,6 +326,7 @@ class CefBrowserImpl : public CefBrowser {
// These variables are read-only.
const CefBrowserSettings& settings() const { return settings_; }
gfx::NativeView opener_window() { return opener_; }
int browser_id() const { return browser_id_; }
bool is_popup() { return (opener_ != NULL); }
// These variables may be read/written from multiple threads.
@ -425,8 +424,8 @@ class CefBrowserImpl : public CefBrowser {
FrameObjectMap;
FrameObjectMap frame_objects_;
// Unique browser ID assigned by the context.
int unique_id_;
// Globally unique identifier for this browser.
int browser_id_;
IMPLEMENT_REFCOUNTING(CefBrowserImpl);
IMPLEMENT_LOCKING(CefBrowserImpl);

View File

@ -981,7 +981,7 @@ void BrowserWebViewDelegate::willSendRequest(
// The requestor ID is used by the resource loader bridge to locate the
// browser that originated the request.
request.setRequestorID(browser_->UIT_GetUniqueID());
request.setRequestorID(browser_->browser_id());
}
void BrowserWebViewDelegate::didChangeContentsSize(

View File

@ -34,10 +34,6 @@ CefRefPtr<CefContext> _Context;
namespace {
// Both the CefContext constuctor and the CefContext::RemoveBrowser method need
// to initialize or reset to the same value.
const int kNextBrowserIdReset = 1;
// Used in multi-threaded message loop mode to observe shutdown of the UI
// thread.
class DestructionObserver : public MessageLoop::DestructionObserver {
@ -226,7 +222,6 @@ CefContext::CefContext()
: initialized_(false),
shutting_down_(false),
request_context_(NULL),
next_browser_id_(kNextBrowserIdReset),
current_webviewhost_(NULL),
dev_tools_client_count_(0) {
}
@ -308,30 +303,17 @@ void CefContext::Shutdown() {
}
}
bool CefContext::AddBrowser(CefRefPtr<CefBrowserImpl> browser) {
bool found = false;
AutoLock lock_scope(this);
// check that the browser isn't already in the list before adding
BrowserList::const_iterator it = browserlist_.begin();
for (; it != browserlist_.end(); ++it) {
if (it->get() == browser.get()) {
found = true;
break;
}
}
if (!found) {
browser->UIT_SetUniqueID(next_browser_id_++);
browserlist_.push_back(browser);
}
return !found;
int CefContext::GetNextBrowserID() {
return next_browser_id_.GetNext() + 1;
}
bool CefContext::RemoveBrowser(CefRefPtr<CefBrowserImpl> browser) {
bool deleted = false;
void CefContext::AddBrowser(CefRefPtr<CefBrowserImpl> browser) {
AutoLock lock_scope(this);
browserlist_.push_back(browser);
}
void CefContext::RemoveBrowser(CefRefPtr<CefBrowserImpl> browser) {
bool empty = false;
{
@ -341,15 +323,12 @@ bool CefContext::RemoveBrowser(CefRefPtr<CefBrowserImpl> browser) {
for (; it != browserlist_.end(); ++it) {
if (it->get() == browser.get()) {
browserlist_.erase(it);
deleted = true;
break;
}
}
if (browserlist_.empty()) {
next_browser_id_ = kNextBrowserIdReset;
if (browserlist_.empty())
empty = true;
}
}
if (empty) {
@ -360,8 +339,6 @@ bool CefContext::RemoveBrowser(CefRefPtr<CefBrowserImpl> browser) {
base::Bind(webkit_glue::ClearCache));
}
}
return deleted;
}
CefRefPtr<CefBrowserImpl> CefContext::GetBrowserByID(int id) {
@ -369,7 +346,7 @@ CefRefPtr<CefBrowserImpl> CefContext::GetBrowserByID(int id) {
BrowserList::const_iterator it = browserlist_.begin();
for (; it != browserlist_.end(); ++it) {
if (it->get()->UIT_GetUniqueID() == id)
if (it->get()->browser_id() == id)
return it->get();
}

View File

@ -17,6 +17,7 @@
#include "libcef/cef_process.h"
#include "base/at_exit.h"
#include "base/atomic_sequence_num.h"
#include "base/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/files/scoped_temp_dir.h"
@ -49,8 +50,9 @@ class CefContext : public CefBase {
CefProcess* process() { return process_.get(); }
bool AddBrowser(CefRefPtr<CefBrowserImpl> browser);
bool RemoveBrowser(CefRefPtr<CefBrowserImpl> browser);
int GetNextBrowserID();
void AddBrowser(CefRefPtr<CefBrowserImpl> browser);
void RemoveBrowser(CefRefPtr<CefBrowserImpl> browser);
CefRefPtr<CefBrowserImpl> GetBrowserByID(int id);
BrowserList* GetBrowserList() { return &browserlist_; }
@ -131,7 +133,7 @@ class CefContext : public CefBase {
BrowserList browserlist_;
// Used for assigning unique IDs to browser instances.
int next_browser_id_;
base::AtomicSequenceNumber next_browser_id_;
WebViewHost* current_webviewhost_;

View File

@ -256,6 +256,20 @@ cef_window_handle_t CEF_CALLBACK browser_get_opener_window_handle(
return _retval;
}
int CEF_CALLBACK browser_get_identifier(struct _cef_browser_t* self) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Execute
int _retval = CefBrowserCppToC::Get(self)->GetIdentifier();
// Return type: simple
return _retval;
}
int CEF_CALLBACK browser_is_popup(struct _cef_browser_t* self) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
@ -733,6 +747,7 @@ CefBrowserCppToC::CefBrowserCppToC(CefBrowser* cls)
struct_.struct_.set_focus = browser_set_focus;
struct_.struct_.get_window_handle = browser_get_window_handle;
struct_.struct_.get_opener_window_handle = browser_get_opener_window_handle;
struct_.struct_.get_identifier = browser_get_identifier;
struct_.struct_.is_popup = browser_is_popup;
struct_.struct_.has_document = browser_has_document;
struct_.struct_.get_client = browser_get_client;

View File

@ -198,6 +198,19 @@ CefWindowHandle CefBrowserCToCpp::GetOpenerWindowHandle() {
return _retval;
}
int CefBrowserCToCpp::GetIdentifier() {
if (CEF_MEMBER_MISSING(struct_, get_identifier))
return 0;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Execute
int _retval = struct_->get_identifier(struct_);
// Return type: simple
return _retval;
}
bool CefBrowserCToCpp::IsPopup() {
if (CEF_MEMBER_MISSING(struct_, is_popup))
return false;

View File

@ -47,6 +47,7 @@ class CefBrowserCToCpp
virtual void SetFocus(bool enable) OVERRIDE;
virtual CefWindowHandle GetWindowHandle() OVERRIDE;
virtual CefWindowHandle GetOpenerWindowHandle() OVERRIDE;
virtual int GetIdentifier() OVERRIDE;
virtual bool IsPopup() OVERRIDE;
virtual bool HasDocument() OVERRIDE;
virtual CefRefPtr<CefClient> GetClient() OVERRIDE;