Merge wxWebView JavaScript improvements branch

This is a squashed commit of the SOC2017_WEBVIEW_JS branch from
https://github.com/joseeloren/wxWidgets.git

Closes https://github.com/wxWidgets/wxWidgets/pull/538
This commit is contained in:
Jose Lorenzo
2017-09-02 23:24:06 +01:00
committed by Vadim Zeitlin
parent 9f4f075034
commit af8f7f33c3
14 changed files with 757 additions and 49 deletions

View File

@@ -0,0 +1,57 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/gtk/private/webkit.h
// Purpose: wxWebKitGtk RAII wrappers declaration
// Author: Jose Lorenzo
// Created: 2017-08-21
// Copyright: (c) 2017 Jose Lorenzo <josee.loren@gmail.com>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_GTK_PRIVATE_WEBKIT_H_
#define _WX_GTK_PRIVATE_WEBKIT_H_
#include <webkit2/webkit2.h>
#include <JavaScriptCore/JSStringRef.h>
#include <wx/buffer.h>
// ----------------------------------------------------------------------------
// Convenience class for WebKitJavascriptResult on scope exit automatically
// ----------------------------------------------------------------------------
class wxWebKitJavascriptResult
{
public:
explicit wxWebKitJavascriptResult(WebKitJavascriptResult *r) : m_jsresult(r) { }
~wxWebKitJavascriptResult() { webkit_javascript_result_unref (m_jsresult); }
operator WebKitJavascriptResult *() const { return m_jsresult; }
private:
WebKitJavascriptResult *m_jsresult;
wxDECLARE_NO_COPY_CLASS(wxWebKitJavascriptResult);
};
class wxJSStringRef
{
public:
explicit wxJSStringRef(JSStringRef r) : m_jssref(r) { }
~wxJSStringRef() { JSStringRelease (m_jssref); }
const wxString ToWxString()
{
size_t length = JSStringGetMaximumUTF8CStringSize(m_jssref);
wxCharBuffer str(length);
JSStringGetUTF8CString(m_jssref, str.data(), length);
return wxString::FromUTF8(str);
}
private:
JSStringRef m_jssref;
wxDECLARE_NO_COPY_CLASS(wxJSStringRef);
};
#endif // _WX_GTK_PRIVATE_WEBKIT_H_