From a6ddf9146cac44ef73145021cc4a1125b01e67ba Mon Sep 17 00:00:00 2001 From: Johann Werner Date: Thu, 27 Apr 2017 14:37:35 +0200 Subject: [PATCH] add support for IE11 and Edge browser detection --- .../extensions/appserver/ERXBasicBrowser.java | 15 +++++++++++++++ .../er/extensions/appserver/ERXBrowser.java | 15 +++++++++++++++ .../appserver/ERXBrowserFactory.java | 19 +++++++++++++++++-- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXBasicBrowser.java b/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXBasicBrowser.java index ffb96832c71..929991ad67c 100644 --- a/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXBasicBrowser.java +++ b/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXBasicBrowser.java @@ -133,6 +133,7 @@ public class ERXBasicBrowser extends ERXBrowser { private final boolean _isRobot; private final boolean _isICab; + private final boolean _isEdge; private final boolean _isIE; private final boolean _isNetscape; private final boolean _isOmniWeb; @@ -147,6 +148,10 @@ public class ERXBasicBrowser extends ERXBrowser { private final boolean _isMozillaVersion45; private final boolean _isMozillaVersion40; + private final boolean _isVersion13; + private final boolean _isVersion12; + private final boolean _isVersion11; + private final boolean _isVersion10; private final boolean _isVersion9; private final boolean _isVersion8; private final boolean _isVersion7; @@ -187,6 +192,7 @@ public ERXBasicBrowser(String browserName, String version, String mozillaVersion _isRobot = _browserName.equals(ROBOT); _isICab = _browserName.equals(ICAB); _isIE = _browserName.equals(IE); + _isEdge = _browserName.equals(EDGE); _isNetscape = _browserName.equals(NETSCAPE); _isOmniWeb = _browserName.equals(OMNIWEB); _isOpera = _browserName.equals(OPERA); @@ -205,6 +211,10 @@ public ERXBasicBrowser(String browserName, String version, String mozillaVersion String normalizedVersion = ERXStringUtilities.removeExtraDotsFromVersionString(_version); + _isVersion13 = normalizedVersion.startsWith("13."); + _isVersion12 = normalizedVersion.startsWith("12."); + _isVersion11 = normalizedVersion.startsWith("11."); + _isVersion10 = normalizedVersion.startsWith("10."); _isVersion9 = normalizedVersion.startsWith("9."); _isVersion8 = normalizedVersion.startsWith("8."); _isVersion7 = normalizedVersion.startsWith("7."); @@ -306,6 +316,11 @@ public boolean isICab() { return _isICab; } + @Override + public boolean isEdge() { + return _isEdge; + } + @Override public boolean isIE() { return _isIE; diff --git a/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXBrowser.java b/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXBrowser.java index 4d0565d434a..dcedd323687 100644 --- a/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXBrowser.java +++ b/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXBrowser.java @@ -89,6 +89,7 @@ public abstract class ERXBrowser implements NSKeyValueCoding { public static final String ROBOT = "robot"; public static final String ICAB = "iCab"; + public static final String EDGE = "Edge"; public static final String IE = "IE"; public static final String NETSCAPE = "Netscape"; public static final String OMNIWEB = "OmniWeb"; @@ -240,6 +241,20 @@ public abstract class ERXBrowser implements NSKeyValueCoding { *
iCab の場合には true が戻ります
*/ public abstract boolean isICab(); + + /** + *
+ * Browser is Microsoft Edge? + *
+ + *
+ * ブラウザは Microsoft Edge ですか? + *
+ * + * @return
true if browser is Edge.
+ *
Edge の場合には true が戻ります
+ */ + public abstract boolean isEdge(); /** *
diff --git a/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXBrowserFactory.java b/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXBrowserFactory.java index 4d0f763ff17..53c56e02201 100644 --- a/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXBrowserFactory.java +++ b/Frameworks/Core/ERExtensions/Sources/er/extensions/appserver/ERXBrowserFactory.java @@ -587,8 +587,9 @@ public String parseBrowserName(String userAgent) { String browserString = _browserString(userAgent); String browser = ERXBrowser.UNKNOWN_BROWSER; if (isRobot(browserString)) browser = ERXBrowser.ROBOT; + else if (browserString.indexOf("Edge") > -1) browser = ERXBrowser.EDGE; else if (browserString.indexOf("Chrome") > -1) browser = ERXBrowser.CHROME; - else if (browserString.indexOf("MSIE") > -1) browser = ERXBrowser.IE; + else if (browserString.indexOf("MSIE") > -1 || browserString.indexOf("Trident") > -1) browser = ERXBrowser.IE; else if (browserString.indexOf("Safari") > -1) browser = ERXBrowser.SAFARI; else if (browserString.indexOf("Firefox") > -1) browser = ERXBrowser.FIREFOX; else if (browserString.indexOf("OmniWeb") > -1) browser = ERXBrowser.OMNIWEB; @@ -919,7 +920,21 @@ private String _versionString(String userAgent) { if (startpos > -1) { versionString = userAgent.substring(startpos); } else { - versionString = _browserString(userAgent); + startpos = userAgent.indexOf("rv:"); + if (startpos > -1) { + versionString = userAgent.substring(startpos); + int endpos = versionString.indexOf(')'); + if (endpos > -1) { + versionString = versionString.substring(0, endpos); + } + } else { + startpos = userAgent.indexOf("Edge/"); + if (startpos > -1) { + versionString = userAgent.substring(startpos); + } else { + versionString = _browserString(userAgent); + } + } } }