Skip to content

Commit

Permalink
The changes continue...
Browse files Browse the repository at this point in the history
  • Loading branch information
rassilon committed Jun 9, 2015
1 parent 3a330f4 commit a7ba17f
Show file tree
Hide file tree
Showing 13 changed files with 235 additions and 81 deletions.
36 changes: 32 additions & 4 deletions CefSharp.Core/Internals/CefFrameWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,24 @@ Int64 CefFrameWrapper::Identifier::get()
IFrame^ CefFrameWrapper::Parent::get()
{
ThrowIfDisposed();
auto parent = _frame->GetParent();
if (parent != nullptr)
if (_parentFrame != nullptr)
{
return gcnew CefFrameWrapper(parent, _browserAdapter);
// Be paranoid about creating the cached IBrowser.
lock sync(_syncRoot);

auto parent = _frame->GetParent();
if (parent != nullptr && _parentFrame != nullptr)
{
_parentFrame = gcnew CefFrameWrapper(parent, _browserAdapter);
}
else if (parent == nullptr)
{
return nullptr;
}
}
else
{
return _parentFrame;
}
return nullptr;
}
Expand All @@ -259,7 +273,21 @@ String^ CefFrameWrapper::Url::get()
IBrowser^ CefFrameWrapper::Browser::get()
{
ThrowIfDisposed();
return dynamic_cast<IBrowser^>(gcnew CefSharpBrowserWrapper(_frame->GetBrowser(), _browserAdapter));
if (_owningBrowser != nullptr)
{
return _owningBrowser;
}

// Be paranoid about creating the cached IBrowser.
lock sync(_syncRoot);

if (_owningBrowser != nullptr)
{
return _owningBrowser;
}

_owningBrowser = gcnew CefSharpBrowserWrapper(_frame->GetBrowser(), _browserAdapter);
return _owningBrowser;
}

void CefFrameWrapper::ThrowIfDisposed()
Expand Down
11 changes: 10 additions & 1 deletion CefSharp.Core/Internals/CefFrameWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,26 @@ namespace CefSharp
private:
MCefRefPtr<CefFrame> _frame;
IBrowserAdapter^ _browserAdapter;
IFrame^ _parentFrame;
IBrowser^ _owningBrowser;
Object^ _syncRoot;
bool _disposed;

internal:
CefFrameWrapper::CefFrameWrapper(CefRefPtr<CefFrame> &frame, IBrowserAdapter^ browserAdapter)
: _frame(frame), _browserAdapter(browserAdapter), _disposed(false)
: _frame(frame), _browserAdapter(browserAdapter), _disposed(false),
_parentFrame(nullptr), _owningBrowser(nullptr), _syncRoot(gcnew Object())
{
}

~CefFrameWrapper()
{
_browserAdapter = nullptr;
delete _parentFrame;
delete _owningBrowser;
_parentFrame = nullptr;
_owningBrowser = nullptr;
_syncRoot = nullptr;
_disposed = true;
}

Expand Down
Loading

0 comments on commit a7ba17f

Please sign in to comment.