Github user solomax commented on a diff in the pull request: https://github.com/apache/wicket/pull/275#discussion_r181293318 --- Diff: wicket-core/src/main/java/org/apache/wicket/protocol/http/request/WebClientInfo.java --- @@ -147,6 +149,93 @@ private String getUserAgentStringLc() return (getUserAgent() != null) ? getUserAgent().toLowerCase() : ""; } + /** + * Initializes the {@link WebClientInfo} user agent detection. This can be overridden to choose + * a different detection as YAUAA (https://github.com/nielsbasjes/yauaa) - if you do so, you + * might exclude the maven dependency from your project in favor of a different framework. + */ + public void initialize() + { + UserAgentAnalyzer userAgentAnalyzer = Application.get().getMetaData(UAA_META_DATA_KEY); + if (userAgentAnalyzer == null) + { + userAgentAnalyzer = UserAgentAnalyzer.newBuilder() + .hideMatcherLoadStats() + .withCache(25000) + .build(); + Application.get().setMetaData(UAA_META_DATA_KEY, userAgentAnalyzer); + } + detectBrowserProperties(userAgentAnalyzer); + } + + /** + * Detects browser properties like versions or the type of the browser and applies them to the + * {@link ClientProperties}, override this method if there are errors within the browser / + * version detection due to newer browsers + * + * @param userAgentAnalyzer + * the user agent analyzer to detect browsers and versions + */ + protected void detectBrowserProperties(UserAgentAnalyzer userAgentAnalyzer) + { + + nl.basjes.parse.useragent.UserAgent parsedUserAgent = userAgentAnalyzer + .parse(getUserAgent()); + String userAgentName = parsedUserAgent.getValue("AgentName"); + + // Konqueror + properties.setBrowserKonqueror(UserAgent.KONQUEROR.getUaStrings().contains(userAgentName)); + + // Chrome + properties.setBrowserChrome(UserAgent.CHROME.getUaStrings().contains(userAgentName)); + + // Edge + properties.setBrowserEdge(UserAgent.EDGE.getUaStrings().contains(userAgentName)); + + // Safari + properties.setBrowserSafari(UserAgent.SAFARI.getUaStrings().contains(userAgentName)); + + // Opera + properties.setBrowserOpera(UserAgent.OPERA.getUaStrings().contains(userAgentName)); + + // Internet Explorer + properties.setBrowserInternetExplorer( + UserAgent.INTERNET_EXPLORER.getUaStrings().contains(userAgentName)); + + // FireFox + boolean isFireFox = UserAgent.FIREFOX.getUaStrings() + .contains(parsedUserAgent.getValue("AgentName")); --- End diff -- `userAgentName`
---