mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
- Move frame-related methods from CefBrowser into a new CefFrame class.
- Add CefBrowser::Get*Frame() methods for retrieving the appropriate CefFrame instance. - Add a CefFrame attribute to CefHandler callback methods where appropriate. - Add support for V8 JavaScript extensions and values via CefV8Value and CefV8Handler. Native C++ and user-defined JavaScript object hierarchies may now be created and accessed using the CEF API. - Remove the CefHandler and CefVariant classes and related CefBrowser methods that have been obsoleted by the addition of CEF V8 support. - Add the CefRegisterExtension() function for registering system-wide V8 extensions. - Add the CefHandler::HandleJSBinding() callback method for attaching V8 values to the global frame JavaScript object. This method replaces the previous technique of calling CefBrowser::AddJSHandler(). - Add new wrapper template methods for simplifying DLL wrapper implementations. - Move cef_string* files from libcef_dll to libcef so that projects can link libcef statically without errors. - Fix crashes when CEF exits due to object constructors being executed on non-UI threads if the application is closed while a page is still loading. - Update the cefclient project to reflect changes and demonstrate the new APIs. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@26 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
136
libcef/tracker.h
Normal file
136
libcef/tracker.h
Normal file
@@ -0,0 +1,136 @@
|
||||
// Copyright (c) 2009 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#ifndef _TRACKER_H
|
||||
#define _TRACKER_H
|
||||
|
||||
#include "include/cef.h"
|
||||
|
||||
// Class extended by objects that must be tracked. After creating a tracked
|
||||
// object you should add it to the appropriate track manager.
|
||||
class CefTrackObject
|
||||
{
|
||||
public:
|
||||
CefTrackObject()
|
||||
{
|
||||
track_next_ = NULL;
|
||||
track_prev_ = NULL;
|
||||
}
|
||||
virtual ~CefTrackObject()
|
||||
{
|
||||
}
|
||||
|
||||
// Returns true if the object is currently being tracked.
|
||||
bool IsTracked() { return (track_prev_ || track_next_); }
|
||||
|
||||
private:
|
||||
CefTrackObject* GetTrackPrev() { return track_prev_; }
|
||||
void SetTrackPrev(CefTrackObject* base) { track_prev_ = base; }
|
||||
CefTrackObject* GetTrackNext() { return track_next_; }
|
||||
void SetTrackNext(CefTrackObject* base) { track_next_ = base; }
|
||||
|
||||
// Insert a new object into the tracking list before this object.
|
||||
void InsertTrackPrev(CefTrackObject* object)
|
||||
{
|
||||
if(track_prev_)
|
||||
track_prev_->SetTrackNext(object);
|
||||
object->SetTrackNext(this);
|
||||
object->SetTrackPrev(track_prev_);
|
||||
track_prev_ = object;
|
||||
}
|
||||
|
||||
// Insert a new object into the tracking list after this object.
|
||||
void InsertTrackNext(CefTrackObject* object)
|
||||
{
|
||||
if(track_next_)
|
||||
track_next_->SetTrackPrev(object);
|
||||
object->SetTrackPrev(this);
|
||||
object->SetTrackNext(track_next_);
|
||||
track_next_ = object;
|
||||
}
|
||||
|
||||
// Remove this object from the tracking list.
|
||||
void RemoveTracking()
|
||||
{
|
||||
if(track_next_)
|
||||
track_next_->SetTrackPrev(track_prev_);
|
||||
if(track_prev_)
|
||||
track_prev_->SetTrackNext(track_next_);
|
||||
track_next_ = NULL;
|
||||
track_prev_ = NULL;
|
||||
}
|
||||
|
||||
private:
|
||||
CefTrackObject* track_next_;
|
||||
CefTrackObject* track_prev_;
|
||||
|
||||
friend class CefTrackManager;
|
||||
};
|
||||
|
||||
// Class used to manage tracked objects. A single instance of this class
|
||||
// should be created for each intended usage. Any objects that have not been
|
||||
// removed by explicit calls to the Destroy() method will be removed when the
|
||||
// manager object is destroyed. A manager object can be created as either a
|
||||
// member variable of another class or by using lazy initialization:
|
||||
// base::LazyInstance<CefTrackManager> g_singleton(base::LINKER_INITIALIZED);
|
||||
class CefTrackManager : public CefThreadSafeBase<CefBase>
|
||||
{
|
||||
public:
|
||||
CefTrackManager() : object_count_(0) {}
|
||||
virtual ~CefTrackManager()
|
||||
{
|
||||
DeleteAll();
|
||||
}
|
||||
|
||||
// Add an object to be tracked by this manager.
|
||||
void Add(CefTrackObject* object)
|
||||
{
|
||||
Lock();
|
||||
if(!object->IsTracked()) {
|
||||
tracker_.InsertTrackNext(object);
|
||||
++object_count_;
|
||||
}
|
||||
Unlock();
|
||||
}
|
||||
|
||||
// Delete an object tracked by this manager.
|
||||
bool Delete(CefTrackObject* object)
|
||||
{
|
||||
bool rv = false;
|
||||
Lock();
|
||||
if(object->IsTracked()) {
|
||||
object->RemoveTracking();
|
||||
delete object;
|
||||
--object_count_;
|
||||
rv = true;
|
||||
}
|
||||
Unlock();
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Delete all objects tracked by this manager.
|
||||
void DeleteAll()
|
||||
{
|
||||
Lock();
|
||||
CefTrackObject* next;
|
||||
do {
|
||||
next = tracker_.GetTrackNext();
|
||||
if(next) {
|
||||
next->RemoveTracking();
|
||||
delete next;
|
||||
}
|
||||
} while(next != NULL);
|
||||
object_count_ = 0;
|
||||
Unlock();
|
||||
}
|
||||
|
||||
// Returns the number of objects currently being tracked.
|
||||
long GetCount() { return object_count_; }
|
||||
|
||||
private:
|
||||
CefTrackObject tracker_;
|
||||
long object_count_;
|
||||
};
|
||||
|
||||
#endif // _TRACKER_H
|
Reference in New Issue
Block a user