Skip to content

Commit

Permalink
add support for IE11 and Edge browser detection
Browse files Browse the repository at this point in the history
  • Loading branch information
darkv committed Apr 27, 2017
1 parent 19bca0b commit a6ddf91
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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.");
Expand Down Expand Up @@ -306,6 +316,11 @@ public boolean isICab() {
return _isICab;
}

@Override
public boolean isEdge() {
return _isEdge;
}

@Override
public boolean isIE() {
return _isIE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -240,6 +241,20 @@ public abstract class ERXBrowser implements NSKeyValueCoding {
* <div class="ja">iCab の場合には true が戻ります</div>
*/
public abstract boolean isICab();

/**
* <div class="en">
* Browser is Microsoft Edge?
* </div>
* <div class="ja">
* ブラウザは Microsoft Edge ですか?
* </div>
*
* @return <div class="en">true if browser is Edge.</div>
* <div class="ja">Edge の場合には true が戻ります</div>
*/
public abstract boolean isEdge();

/**
* <div class="en">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
}

Expand Down

0 comments on commit a6ddf91

Please sign in to comment.