Skip to content

Commit

Permalink
Merge pull request #654 from le-jeu/fix/google-hostnames
Browse files Browse the repository at this point in the history
  • Loading branch information
modos189 authored Aug 1, 2023
2 parents fc3cec2 + 4160899 commit a730f6a
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public class IITC_Mobile extends AppCompatActivity
private String debugInputStore = "";
private Map<String, String> mAllowedHostnames = new HashMap<>();
private Set<String> mInternalHostnames = new HashSet<>();
private final Pattern mGoogleHostnamePattern = Pattern.compile("(^|\\.)google(\\.com|\\.co)?\\.\\w+$");

private String mIITCDefaultUA;
private final String mDesktopUA = "Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130810 Firefox/17.0 Iceweasel/17.0.8";
Expand Down Expand Up @@ -1287,11 +1288,26 @@ public boolean isInternalHostname(String hostname) {
return mInternalHostnames.contains(hostname);
}

/**
* @param hostname host name
* @return <code>true</code> if host name is google.* or google.com?.* domain
*/
public boolean isGoogleHostname(String hostname) {
if (hostname.startsWith("google.") || hostname.contains(".google.")) {
return mGoogleHostnamePattern.matcher(hostname).find();
}
return false;
}

/**
* @param hostname host name.
* @return <code>true</code> if a host name allowed to be load in IITC.
*/
public boolean isAllowedHostname(String hostname) {
// shortcut for .google.* hostnames
if (isGoogleHostname(hostname)) {
return true;
}
for (String key : mAllowedHostnames.keySet()) {
if (hostname.equals(key)) return true;
if (hostname.endsWith("." + key)) return true;
Expand All @@ -1306,6 +1322,10 @@ public boolean isAllowedHostname(String hostname) {
public String getUserAgentForHostname(String hostname) {
if (mSharedPrefs.getBoolean("pref_fake_user_agent", false))
return mDesktopUA;
// shortcut for .google.* hostnames
if (isGoogleHostname(hostname)) {
hostname = "google.com";
}
for (Map.Entry<String,String> e : mAllowedHostnames.entrySet()) {
final String key = e.getKey();
if (hostname.equals(key)) return e.getValue();
Expand Down

0 comments on commit a730f6a

Please sign in to comment.