Don't define unnecessary constants in public webview_ie.h
There is no need to check that calling MSWSetModernEmulationLevel() changed the registry key in the test, this is just an implementation detail of this function. This makes it unnecessary to define wxIE_EMULATION_LEVEL and wxREGISTRY_IE_PATH (which are both badly named) in the public header. Finally, improve the error message in MSWSetModernEmulationLevel() and add another one for failing to reset the emulation level too.
This commit is contained in:
@@ -36,11 +36,6 @@ class DocHostUIHandler;
|
|||||||
class wxFindPointers;
|
class wxFindPointers;
|
||||||
class wxIInternetProtocol;
|
class wxIInternetProtocol;
|
||||||
|
|
||||||
#define wxIE_EMULATION_LEVEL 8000
|
|
||||||
|
|
||||||
//Registry key where emulation level for programs are set
|
|
||||||
#define wxREGISTRY_IE_PATH wxT("SOFTWARE\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION")
|
|
||||||
|
|
||||||
class WXDLLIMPEXP_WEBVIEW wxWebViewIE : public wxWebView
|
class WXDLLIMPEXP_WEBVIEW wxWebViewIE : public wxWebView
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -149,7 +144,8 @@ public:
|
|||||||
void onActiveXEvent(wxActiveXEvent& evt);
|
void onActiveXEvent(wxActiveXEvent& evt);
|
||||||
void onEraseBg(wxEraseEvent&) {}
|
void onEraseBg(wxEraseEvent&) {}
|
||||||
|
|
||||||
//Establish EmulationLevel for RunScript IE
|
// Establish sufficiently modern emulation level for the browser control to
|
||||||
|
// allow RunScript() to return any kind of values.
|
||||||
static bool MSWSetModernEmulationLevel(bool modernLevel = true);
|
static bool MSWSetModernEmulationLevel(bool modernLevel = true);
|
||||||
|
|
||||||
wxDECLARE_EVENT_TABLE();
|
wxDECLARE_EVENT_TABLE();
|
||||||
|
@@ -857,26 +857,40 @@ wxString wxWebViewIE::GetPageText() const
|
|||||||
|
|
||||||
bool wxWebViewIE::MSWSetModernEmulationLevel(bool modernLevel)
|
bool wxWebViewIE::MSWSetModernEmulationLevel(bool modernLevel)
|
||||||
{
|
{
|
||||||
wxRegKey key(wxRegKey::HKCU, wxREGISTRY_IE_PATH);
|
// Registry key where emulation level for programs are set
|
||||||
if ( key.Exists() )
|
static const wxChar* IE_EMULATION_KEY =
|
||||||
|
wxT("SOFTWARE\\Microsoft\\Internet Explorer\\Main")
|
||||||
|
wxT("\\FeatureControl\\FEATURE_BROWSER_EMULATION");
|
||||||
|
|
||||||
|
wxRegKey key(wxRegKey::HKCU, IE_EMULATION_KEY);
|
||||||
|
if ( !key.Exists() )
|
||||||
{
|
{
|
||||||
wxString programName = wxGetFullModuleName().AfterLast('\\');
|
wxLogWarning(_("Failed to find web view emulation level in the registry"));
|
||||||
if ( modernLevel )
|
return false;
|
||||||
{
|
|
||||||
if ( !key.SetValue(programName, wxIE_EMULATION_LEVEL) )
|
|
||||||
{
|
|
||||||
wxLogWarning(_("Failed to set the current browser control emulation level"));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
key.DeleteValue(programName);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
wxLogWarning(_("Failed to find current browser control emulation level"));
|
|
||||||
return false;
|
const wxString programName = wxGetFullModuleName().AfterLast('\\');
|
||||||
|
if ( modernLevel )
|
||||||
|
{
|
||||||
|
// IE8 (8000) is sufficiently modern for our needs, see
|
||||||
|
// https://msdn.microsoft.com/library/ee330730.aspx#browser_emulation
|
||||||
|
// for other values that could be used here.
|
||||||
|
if ( !key.SetValue(programName, 8000) )
|
||||||
|
{
|
||||||
|
wxLogWarning(_("Failed to set web view to modern emulation level"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( !key.DeleteValue(programName) )
|
||||||
|
{
|
||||||
|
wxLogWarning(_("Failed to reset web view to standard emulation level"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
|
@@ -23,8 +23,7 @@
|
|||||||
#include "wx/webview.h"
|
#include "wx/webview.h"
|
||||||
#include "asserthelper.h"
|
#include "asserthelper.h"
|
||||||
#if wxUSE_WEBVIEW_IE
|
#if wxUSE_WEBVIEW_IE
|
||||||
#include "wx/msw/registry.h"
|
#include "wx/msw/webview_ie.h"
|
||||||
#include "wx/msw/webview_ie.h"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class WebTestCase : public CppUnit::TestCase
|
class WebTestCase : public CppUnit::TestCase
|
||||||
@@ -276,11 +275,32 @@ void WebTestCase::RunScript()
|
|||||||
wxString result;
|
wxString result;
|
||||||
#if wxUSE_WEBVIEW_IE
|
#if wxUSE_WEBVIEW_IE
|
||||||
CPPUNIT_ASSERT(wxWebViewIE::MSWSetModernEmulationLevel());
|
CPPUNIT_ASSERT(wxWebViewIE::MSWSetModernEmulationLevel());
|
||||||
wxRegKey key(wxRegKey::HKCU, wxREGISTRY_IE_PATH);
|
|
||||||
long val = 0;
|
// Define a specialized scope guard ensuring that we reset the emulation
|
||||||
wxString programName = wxGetFullModuleName().AfterLast('\\');
|
// level to its default value even if any asserts below fail.
|
||||||
key.QueryValue(programName, &val);
|
class ResetEmulationLevel
|
||||||
CPPUNIT_ASSERT_EQUAL(val, wxIE_EMULATION_LEVEL);
|
{
|
||||||
|
public:
|
||||||
|
ResetEmulationLevel()
|
||||||
|
{
|
||||||
|
m_reset = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DoReset()
|
||||||
|
{
|
||||||
|
m_reset = false;
|
||||||
|
return wxWebViewIE::MSWSetModernEmulationLevel(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
~ResetEmulationLevel()
|
||||||
|
{
|
||||||
|
if ( m_reset )
|
||||||
|
DoReset();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_reset;
|
||||||
|
} resetEmulationLevel;
|
||||||
|
|
||||||
CPPUNIT_ASSERT(m_browser->RunScript("function f(){var person = new Object();person.name = 'Bar'; \
|
CPPUNIT_ASSERT(m_browser->RunScript("function f(){var person = new Object();person.name = 'Bar'; \
|
||||||
person.lastName = 'Foo';return person;}f();", &result));
|
person.lastName = 'Foo';return person;}f();", &result));
|
||||||
@@ -294,11 +314,8 @@ void WebTestCase::RunScript()
|
|||||||
&result));
|
&result));
|
||||||
CPPUNIT_ASSERT_EQUAL("\"2017-10-08T21:30:40.000Z\"", result);
|
CPPUNIT_ASSERT_EQUAL("\"2017-10-08T21:30:40.000Z\"", result);
|
||||||
|
|
||||||
CPPUNIT_ASSERT(wxWebViewIE::MSWSetModernEmulationLevel(false));
|
CPPUNIT_ASSERT(resetEmulationLevel.DoReset());
|
||||||
val = 0;
|
#endif // wxUSE_WEBVIEW_IE
|
||||||
key.QueryValue(programName, &val);
|
|
||||||
CPPUNIT_ASSERT_EQUAL(val, 0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
CPPUNIT_ASSERT(m_browser->RunScript("document.write(\"Hello World!\");"));
|
CPPUNIT_ASSERT(m_browser->RunScript("document.write(\"Hello World!\");"));
|
||||||
CPPUNIT_ASSERT_EQUAL("Hello World!", m_browser->GetPageText());
|
CPPUNIT_ASSERT_EQUAL("Hello World!", m_browser->GetPageText());
|
||||||
|
Reference in New Issue
Block a user