From bc298f6415711e34bde3147f9668bc930a7ab7ff Mon Sep 17 00:00:00 2001 From: amaitland Date: Sun, 29 May 2016 22:21:32 +1000 Subject: [PATCH] Add GetSource and GetText methods that take an IStringVisitor --- CefSharp.Core/Internals/CefFrameWrapper.cpp | 28 ++++++++++++++++++++- CefSharp.Core/Internals/CefFrameWrapper.h | 14 +++++++++++ CefSharp.Core/Internals/StringVisitor.h | 1 + CefSharp/IFrame.cs | 14 +++++++++++ CefSharp/IStringVisitor.cs | 4 ++- CefSharp/TaskStringVisitor.cs | 5 ++++ 6 files changed, 64 insertions(+), 2 deletions(-) diff --git a/CefSharp.Core/Internals/CefFrameWrapper.cpp b/CefSharp.Core/Internals/CefFrameWrapper.cpp index fe25cabad..bfaa3fd48 100644 --- a/CefSharp.Core/Internals/CefFrameWrapper.cpp +++ b/CefSharp.Core/Internals/CefFrameWrapper.cpp @@ -135,6 +135,19 @@ Task^ CefFrameWrapper::GetSourceAsync() return taskStringVisitor->Task; } +/// +// Retrieve this frame's HTML source as a string sent to the specified +// visitor. +/// +/*--cef()--*/ +void CefFrameWrapper::GetSource(IStringVisitor^ visitor) +{ + ThrowIfDisposed(); + ThrowIfFrameInvalid(); + + _frame->GetSource(new StringVisitor(visitor)); +} + /// // Retrieve this frame's display text as a string sent to the specified // visitor. @@ -150,7 +163,20 @@ Task^ CefFrameWrapper::GetTextAsync() return taskStringVisitor->Task; } -// TODO: Do we need this? +/// +// Retrieve this frame's display text as a string sent to the specified +// visitor. +/// +/*--cef()--*/ +void CefFrameWrapper::GetText(IStringVisitor^ visitor) +{ + ThrowIfDisposed(); + ThrowIfFrameInvalid(); + + _frame->GetText(new StringVisitor(visitor)); +} + + /// // Load the request represented by the |request| object. /// diff --git a/CefSharp.Core/Internals/CefFrameWrapper.h b/CefSharp.Core/Internals/CefFrameWrapper.h index b0e605a87..678c91468 100644 --- a/CefSharp.Core/Internals/CefFrameWrapper.h +++ b/CefSharp.Core/Internals/CefFrameWrapper.h @@ -122,6 +122,13 @@ namespace CefSharp /*--cef()--*/ virtual Task^ GetSourceAsync(); + /// + // Retrieve this frame's HTML source as a string sent to the specified + // visitor. + /// + /*--cef()--*/ + virtual void GetSource(IStringVisitor^ visitor); + /// // Retrieve this frame's display text as a string sent to the specified // visitor. @@ -129,6 +136,13 @@ namespace CefSharp /*--cef()--*/ virtual Task^ GetTextAsync(); + /// + // Retrieve this frame's display text as a string sent to the specified + // visitor. + /// + /*--cef()--*/ + virtual void GetText(IStringVisitor^ visitor); + /// /// Load the request represented by the |request| object. /// diff --git a/CefSharp.Core/Internals/StringVisitor.h b/CefSharp.Core/Internals/StringVisitor.h index f89d01b27..8d749a9be 100644 --- a/CefSharp.Core/Internals/StringVisitor.h +++ b/CefSharp.Core/Internals/StringVisitor.h @@ -22,6 +22,7 @@ namespace CefSharp ~StringVisitor() { + delete _visitor; _visitor = nullptr; } diff --git a/CefSharp/IFrame.cs b/CefSharp/IFrame.cs index c19e5e543..f43cf2432 100644 --- a/CefSharp/IFrame.cs +++ b/CefSharp/IFrame.cs @@ -67,6 +67,13 @@ namespace CefSharp /// Task GetSourceAsync(); + /// + /// Retrieve this frame's HTML source as a string sent to the specified visitor. + /// Use the method for a Task based async wrapper + /// + /// visitor will recieve string values asynchronously + void GetSource(IStringVisitor visitor); + /// /// Retrieve this frame's display text as a string sent to the specified visitor. /// @@ -75,6 +82,13 @@ namespace CefSharp /// Task GetTextAsync(); + /// + /// Retrieve this frame's display text as a string sent to the specified visitor. + /// Use the method for a Task based async wrapper + /// + /// visitor will recieve string values asynchronously + void GetText(IStringVisitor visitor); + /// /// Load the custom request. /// diff --git a/CefSharp/IStringVisitor.cs b/CefSharp/IStringVisitor.cs index c067aa54b..d4bd0d351 100644 --- a/CefSharp/IStringVisitor.cs +++ b/CefSharp/IStringVisitor.cs @@ -2,12 +2,14 @@ // // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. +using System; + namespace CefSharp { /// /// Implement this interface to receive string values asynchronously. /// - public interface IStringVisitor + public interface IStringVisitor : IDisposable { /// /// Method that will be executed. diff --git a/CefSharp/TaskStringVisitor.cs b/CefSharp/TaskStringVisitor.cs index 53f4a3dc8..3957c27c7 100644 --- a/CefSharp/TaskStringVisitor.cs +++ b/CefSharp/TaskStringVisitor.cs @@ -39,5 +39,10 @@ namespace CefSharp { get { return taskCompletionSource.Task; } } + + public void Dispose() + { + + } } }