23
23
#include < sddl.h>
24
24
#include < shlguid.h>
25
25
#include < shlobj.h>
26
+ #include < VersionHelpers.h>
26
27
#include < WinInet.h>
28
+ #include " FileUtilities.h"
27
29
#include " logging.h"
28
30
#include " psapi.h"
29
31
#include " RegistryUtilities.h"
@@ -34,7 +36,6 @@ BrowserFactory::BrowserFactory(void) {
34
36
// Must be done in the constructor. Do not move to Initialize().
35
37
this ->GetExecutableLocation ();
36
38
this ->GetIEVersion ();
37
- this ->GetOSVersion ();
38
39
}
39
40
40
41
BrowserFactory::~BrowserFactory (void ) {
@@ -63,7 +64,7 @@ void BrowserFactory::Initialize(BrowserFactorySettings settings) {
63
64
void BrowserFactory::ClearCache () {
64
65
LOG (TRACE) << " Entering BrowserFactory::ClearCache" ;
65
66
if (this ->clear_cache_ ) {
66
- if (this -> windows_major_version_ >= 6 ) {
67
+ if (:: IsWindowsVistaOrGreater () ) {
67
68
LOG (DEBUG) << " Clearing cache with low mandatory integrity level as required on Windows Vista or later." ;
68
69
this ->InvokeClearCacheUtility (true );
69
70
}
@@ -634,7 +635,7 @@ IWebBrowser2* BrowserFactory::CreateBrowser() {
634
635
635
636
IWebBrowser2* browser = NULL ;
636
637
DWORD context = CLSCTX_LOCAL_SERVER;
637
- if (this ->ie_major_version_ == 7 && this -> windows_major_version_ >= 6 ) {
638
+ if (this ->ie_major_version_ == 7 && :: IsWindowsVistaOrGreater () ) {
638
639
// ONLY for IE 7 on Windows Vista. XP and below do not have Protected Mode;
639
640
// Windows 7 shipped with IE8.
640
641
context = context | CLSCTX_ENABLE_CLOAKING;
@@ -972,15 +973,9 @@ void BrowserFactory::GetExecutableLocation() {
972
973
void BrowserFactory::GetIEVersion () {
973
974
LOG (TRACE) << " Entering BrowserFactory::GetIEVersion" ;
974
975
975
- struct LANGANDCODEPAGE {
976
- WORD language;
977
- WORD code_page;
978
- } *lpTranslate;
979
-
980
- DWORD dummy = 0 ;
981
- DWORD length = ::GetFileVersionInfoSize (this ->ie_executable_location_ .c_str (),
982
- &dummy);
983
- if (length == 0 ) {
976
+ std::string ie_version = FileUtilities::GetFileVersion (this ->ie_executable_location_ );
977
+
978
+ if (ie_version.size () == 0 ) {
984
979
// 64-bit Windows 8 has a bug where it does not return the executable location properly
985
980
this ->ie_major_version_ = -1 ;
986
981
LOG (WARN) << " Couldn't find IE version for executable "
@@ -989,60 +984,25 @@ void BrowserFactory::GetIEVersion() {
989
984
<< this ->ie_major_version_ ;
990
985
return ;
991
986
}
992
- std::vector<BYTE> version_buffer (length);
993
- ::GetFileVersionInfo (this ->ie_executable_location_.c_str(),
994
- 0, /* ignored */
995
- length,
996
- &version_buffer[0]);
997
-
998
- UINT page_count;
999
- BOOL query_result = ::VerQueryValue (&version_buffer[0 ],
1000
- FILE_LANGUAGE_INFO,
1001
- reinterpret_cast <void **>(&lpTranslate),
1002
- &page_count);
1003
-
1004
- wchar_t sub_block[MAX_PATH];
1005
- _snwprintf_s (sub_block,
1006
- MAX_PATH,
1007
- MAX_PATH,
1008
- FILE_VERSION_INFO,
1009
- lpTranslate->language ,
1010
- lpTranslate->code_page );
1011
- LPVOID value = NULL ;
1012
- UINT size;
1013
- query_result = ::VerQueryValue (&version_buffer[0 ],
1014
- sub_block,
1015
- &value,
1016
- &size);
1017
- std::wstring ie_version;
1018
- ie_version.assign (static_cast <wchar_t *>(value));
1019
- std::wstringstream version_stream (ie_version);
1020
- version_stream >> this ->ie_major_version_ ;
1021
- }
1022
-
1023
- void BrowserFactory::GetOSVersion () {
1024
- LOG (TRACE) << " Entering BrowserFactory::GetOSVersion" ;
1025
987
1026
- OSVERSIONINFO osVersion;
1027
- osVersion.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
1028
- ::GetVersionEx (&osVersion);
1029
- this ->windows_major_version_ = osVersion.dwMajorVersion ;
1030
- this ->windows_minor_version_ = osVersion.dwMinorVersion ;
988
+ std::stringstream version_stream (ie_version);
989
+ version_stream >> this ->ie_major_version_ ;
1031
990
}
1032
991
1033
992
bool BrowserFactory::ProtectedModeSettingsAreValid () {
1034
993
LOG (TRACE) << " Entering BrowserFactory::ProtectedModeSettingsAreValid" ;
1035
994
1036
995
bool settings_are_valid = true ;
1037
996
LOG (DEBUG) << " Detected IE version: " << this ->ie_major_version_
1038
- << " , detected Windows version: " << this ->windows_major_version_ ;
997
+ << " , Windows version supports Protected Mode: "
998
+ << ::IsWindowsVistaOrGreater () ? " true" : " false" ;
1039
999
// Only need to check Protected Mode settings on IE 7 or higher
1040
1000
// and on Windows Vista or higher. Otherwise, Protected Mode
1041
1001
// doesn't come into play, and are valid.
1042
1002
// Documentation of registry settings can be found at the following
1043
1003
// Microsoft KnowledgeBase article:
1044
1004
// http://support.microsoft.com/kb/182569
1045
- if (this ->ie_major_version_ >= 7 && this -> windows_major_version_ >= 6 ) {
1005
+ if (this ->ie_major_version_ >= 7 && :: IsWindowsVistaOrGreater () ) {
1046
1006
HKEY key_handle;
1047
1007
if (ERROR_SUCCESS == ::RegOpenKeyEx (HKEY_CURRENT_USER,
1048
1008
IE_SECURITY_ZONES_REGISTRY_KEY,
0 commit comments