Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/shared/IE_version.cpp

Issue 5171515343503360: Issue #41 - Bring method of determining IE version up to date (Closed)
Patch Set: simplify Registry_Key Created July 26, 2014, 5 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/shared/IE_version.cpp
===================================================================
new file mode 100644
--- /dev/null
+++ b/src/shared/IE_version.cpp
@@ -0,0 +1,89 @@
+#include "IE_version.h"
sergei 2014/07/28 11:46:27 I don't think it should be in shared, because it's
Eric 2014/07/29 12:42:25 See #404. This code is destined to move again soon
sergei 2014/07/29 14:45:56 Clear, it should be here. But why will it be moved
Eric 2014/07/29 15:17:22 Go read #404 again. Fixing that ticket requires a
sergei 2014/07/30 10:42:04 In #404 there is nothing about any problems with l
Eric 2014/07/30 13:02:04 Yes, that's because the ticket states what the pro
+#include "Registry.h"
+
+using namespace AdblockPlus;
+
+/**
+ * Internal implementation of the IE version string.
+ *
+ * This version throws exceptions for its errors, relying on its caller to handle them.
+ *
+ * Quoting http://support.microsoft.com/kb/969393:
+ * "Note The version string value for Internet Explorer 10 is 9.10.9200.16384, and the svcVersion string value is 10.0.9200.16384."
+ * [EH 2014-06-20] My current version of IE 11 is reporting these values:
+ * Version 9.11.9600.17041
+ * svcVersion 11.0.9600.17041
+ *
+ * Warning: IE version 12 and later might not behave the same, so this function should be reviewed with each new release.
sergei 2014/07/28 11:46:27 Tests should run on all machines with all IE versi
Eric 2014/07/29 12:42:25 If that's the case, the best you can get is a sani
+ */
+std::wstring IE_version_string()
+{
+ Registry_Key IE_key(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Internet Explorer");
+ std::wstring version(IE_key.value_wstring(L"Version"));
+ /*
+ * We're expecting a version string that matches the regex "^[1-9]\.".
sergei 2014/07/28 11:46:27 It's also mentioned in tests, why do we need the p
Eric 2014/07/29 12:42:25 We're validating the format of the version string.
+ * Since IE versions 10 and 11 use a version string that begins with "9.", this simplistic parsing method works adequately.
+ */
+ if (version[1] != '.' || version[0] < L'0' || version[0] > L'9')
sergei 2014/07/28 11:46:27 strictly speaking we have to check the length of `
Eric 2014/07/29 12:42:25 You're right; this is a defect, since if the regis
sergei 2014/07/29 14:45:56 How can you make an assumption that the most likel
Eric 2014/07/29 15:17:22 It's beyond the scope of this class to defend agai
sergei 2014/07/30 10:42:04 All code should be safe.
Eric 2014/07/30 13:02:04 OK. That's what I'll agree with. But "safe" and "d
+ {
+ throw std::runtime_error("IE version string has unexpected format");
+ }
+ if (version[0] != L'9')
+ {
+ return version;
+ }
+ // Assert the major version in the "Version" value is 9.
+ /*
+ * Version 9 might either be an actual version 9 or it might represent a version >= 10
+ * If the value named "svcVersion" exists, we'll report that instead.
+ */
+ try
+ {
+ return IE_key.value_wstring(L"svcVersion");
+ }
+ catch (...)
+ {
+ return version;
+ }
+}
+
+std::wstring AdblockPlus::IE::installed_version_string()
sergei 2014/07/28 11:46:27 What is the aim of this method? I think we can get
Eric 2014/07/29 12:42:25 It's called in engine/Main.cpp to fix #41.
sergei 2014/07/29 14:45:56 If it's only the place, then do try-catch where it
+{
+ try
+ {
+ return IE_version_string();
+ }
+ catch (...)
+ {
+ return L"";
+ }
+}
+
+int AdblockPlus::IE::installed_major_version()
+{
+ try
+ {
+ std::wstring version = IE_version_string();
+ /*
+ * If the second character is a period, we assume that the major version is a single digit.
+ */
+ if (version[ 1 ] == L'.')
Oleksandr 2014/07/27 22:13:30 Nit: The array index should not be enclosed in whi
sergei 2014/07/28 11:46:27 I would like to check the size.
Eric 2014/07/28 11:48:43 I reformatted this code with Artistic Style. (It's
Eric 2014/07/29 12:42:25 Yes; same kind of defect as above.
+ {
+ return version[ 0 ] - L'0';
+ }
+ // Assert IE_version_string() did not verify the syntax of the version string.
+ /*
+ * In this case, we'll assume that the version returned is two digits followed by a period.
+ * If not, we'll assume an error.
+ */
+ if (version[ 0 ] < L'0' || version[ 0 ] > L'9' || version[ 1 ] < L'0' || version[ 1 ] > L'9' || version[ 2 ] != L'.')
sergei 2014/07/28 11:46:27 Is it really better than atoi?
Eric 2014/07/29 12:42:25 The condition is validating the format, which we n
sergei 2014/07/29 14:45:56 We don't need to truncate it, anyway it looks good
+ {
+ return 0;
+ }
+ return 10 * (version[ 0 ] - L'0') + (version[ 1 ] - L'0');
+ }
+ catch (...)
+ {
+ return 0;
+ }
+}

Powered by Google App Engine
This is Rietveld