From d4e8a9e54902b96ad63216198467a5d21208e3ab Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Wed, 19 Dec 2012 16:49:35 +0000 Subject: [PATCH] Merge revision 953 changes: - Add new CefBrowser::GetIdentifier method (issue #811). git-svn-id: https://chromiumembedded.googlecode.com/svn/branches/1271@954 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- cef1/include/capi/cef_browser_capi.h | 5 +++ cef1/include/cef_browser.h | 6 ++++ cef1/libcef/browser_impl.cc | 2 +- cef1/libcef/browser_impl.h | 11 +++--- cef1/libcef/browser_webview_delegate.cc | 4 +-- cef1/libcef/cef_context.cc | 45 ++++++------------------ cef1/libcef/cef_context.h | 8 +++-- cef1/libcef_dll/cpptoc/browser_cpptoc.cc | 15 ++++++++ cef1/libcef_dll/ctocpp/browser_ctocpp.cc | 13 +++++++ cef1/libcef_dll/ctocpp/browser_ctocpp.h | 1 + 10 files changed, 64 insertions(+), 46 deletions(-) diff --git a/cef1/include/capi/cef_browser_capi.h b/cef1/include/capi/cef_browser_capi.h index f1fea55ed..18ded305b 100644 --- a/cef1/include/capi/cef_browser_capi.h +++ b/cef1/include/capi/cef_browser_capi.h @@ -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. /// diff --git a/cef1/include/cef_browser.h b/cef1/include/cef_browser.h index 7e34e50c2..9e0786d1b 100644 --- a/cef1/include/cef_browser.h +++ b/cef1/include/cef_browser.h @@ -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. /// diff --git a/cef1/libcef/browser_impl.cc b/cef1/libcef/browser_impl.cc index 96d5fc325..dcd9d60c9 100644 --- a/cef1/libcef/browser_impl.cc +++ b/cef1/libcef/browser_impl.cc @@ -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) diff --git a/cef1/libcef/browser_impl.h b/cef1/libcef/browser_impl.h index eb8b85bec..b2ea92075 100644 --- a/cef1/libcef/browser_impl.h +++ b/cef1/libcef/browser_impl.h @@ -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 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); @@ -491,7 +490,7 @@ class CefFrameImpl : public CefFrame { private: CefRefPtr browser_; CefString name_; - + // The below values must be protected by the lock. base::Lock lock_; int64 id_; diff --git a/cef1/libcef/browser_webview_delegate.cc b/cef1/libcef/browser_webview_delegate.cc index 9f33b491a..6cd494c6c 100644 --- a/cef1/libcef/browser_webview_delegate.cc +++ b/cef1/libcef/browser_webview_delegate.cc @@ -190,7 +190,7 @@ WebKit::WebGraphicsContext3D* BrowserWebViewDelegate::createGraphicsContext3D( WebKit::WebView* web_view = browser_->UIT_GetWebView(); if (!web_view) return NULL; - + const CefSettings& settings = _Context->settings(); return webkit_glue::CreateGraphicsContext3D(settings.graphics_implementation, attributes, web_view, true); @@ -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( diff --git a/cef1/libcef/cef_context.cc b/cef1/libcef/cef_context.cc index c2ee5a56d..454e205de 100644 --- a/cef1/libcef/cef_context.cc +++ b/cef1/libcef/cef_context.cc @@ -34,10 +34,6 @@ CefRefPtr _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 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 browser) { - bool deleted = false; +void CefContext::AddBrowser(CefRefPtr browser) { + AutoLock lock_scope(this); + + browserlist_.push_back(browser); +} + +void CefContext::RemoveBrowser(CefRefPtr browser) { bool empty = false; { @@ -341,15 +323,12 @@ bool CefContext::RemoveBrowser(CefRefPtr 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 browser) { base::Bind(webkit_glue::ClearCache)); } } - - return deleted; } CefRefPtr CefContext::GetBrowserByID(int id) { @@ -369,7 +346,7 @@ CefRefPtr 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(); } diff --git a/cef1/libcef/cef_context.h b/cef1/libcef/cef_context.h index be93aa94c..838a67751 100644 --- a/cef1/libcef/cef_context.h +++ b/cef1/libcef/cef_context.h @@ -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/scoped_temp_dir.h" @@ -49,8 +50,9 @@ class CefContext : public CefBase { CefProcess* process() { return process_.get(); } - bool AddBrowser(CefRefPtr browser); - bool RemoveBrowser(CefRefPtr browser); + int GetNextBrowserID(); + void AddBrowser(CefRefPtr browser); + void RemoveBrowser(CefRefPtr browser); CefRefPtr 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_; diff --git a/cef1/libcef_dll/cpptoc/browser_cpptoc.cc b/cef1/libcef_dll/cpptoc/browser_cpptoc.cc index 3d9107a2a..e8ecc591f 100644 --- a/cef1/libcef_dll/cpptoc/browser_cpptoc.cc +++ b/cef1/libcef_dll/cpptoc/browser_cpptoc.cc @@ -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; diff --git a/cef1/libcef_dll/ctocpp/browser_ctocpp.cc b/cef1/libcef_dll/ctocpp/browser_ctocpp.cc index d0ff5583d..069fdb128 100644 --- a/cef1/libcef_dll/ctocpp/browser_ctocpp.cc +++ b/cef1/libcef_dll/ctocpp/browser_ctocpp.cc @@ -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; diff --git a/cef1/libcef_dll/ctocpp/browser_ctocpp.h b/cef1/libcef_dll/ctocpp/browser_ctocpp.h index ceafa4c42..3872cc528 100644 --- a/cef1/libcef_dll/ctocpp/browser_ctocpp.h +++ b/cef1/libcef_dll/ctocpp/browser_ctocpp.h @@ -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 GetClient() OVERRIDE;