@Test public void matches() throws Exception { final UrlMatcher matcher = new UrlMatcher(new String[] { "bcd.random" }); assertTrue(matcher.matches(Uri.parse("http: assertTrue(matcher.matches(Uri.parse("http: assertTrue(matcher.matches(Uri.parse("http: assertTrue(matcher.matches(Uri.parse("http: assertTrue(matcher.matches(Uri.parse("http: assertTrue(matcher.matches(Uri.parse("http: assertTrue(!matcher.matches(Uri.parse("http: assertTrue(!matcher.matches(Uri.parse("http: assertTrue(!matcher.matches(Uri.parse("http: assertTrue(!matcher.matches(Uri.parse("http: assertTrue(!matcher.matches(Uri.parse("http: assertTrue(!matcher.matches(Uri.parse("http: assertTrue(!matcher.matches(Uri.parse("http: assertTrue(!matcher.matches(Uri.parse("http: assertFalse(matcher.matches(Uri.parse("http: assertTrue(matcher.matches(Uri.parse("http: }
public boolean matches(final Uri resourceURI, final Uri pageURI) { final String path = resourceURI.getPath(); if (path == null) { return false; } if (blockWebfonts) { for (final String extension : WEBFONT_EXTENSIONS) { if (path.endsWith(extension)) { return true; } } } final String resourceURLString = resourceURI.toString(); if (previouslyUnmatched.contains(resourceURLString)) { return false; } if (entityList != null && entityList.isWhiteListed(pageURI, resourceURI)) { return false; } final String resourceHost = resourceURI.getHost(); final String pageHost = pageURI.getHost(); if (pageHost != null && pageHost.equals(resourceHost)) { return false; } if (previouslyMatched.contains(resourceURLString)) { return true; } final FocusString revhost = FocusString.create(resourceHost).reverse(); for (final Map.Entry<String, Trie> category : categories.entrySet()) { if (enabledCategories.contains(category.getKey()) && category.getValue().findNode(revhost) != null) { previouslyMatched.add(resourceURLString); return true; } } previouslyUnmatched.add(resourceURLString); return false; }
UrlMatcher implements  SharedPreferences.OnSharedPreferenceChangeListener { public boolean matches(final Uri resourceURI, final Uri pageURI) { final String path = resourceURI.getPath(); if (path == null) { return false; } if (blockWebfonts) { for (final String extension : WEBFONT_EXTENSIONS) { if (path.endsWith(extension)) { return true; } } } final String resourceURLString = resourceURI.toString(); if (previouslyUnmatched.contains(resourceURLString)) { return false; } if (entityList != null && entityList.isWhiteListed(pageURI, resourceURI)) { return false; } final String resourceHost = resourceURI.getHost(); final String pageHost = pageURI.getHost(); if (pageHost != null && pageHost.equals(resourceHost)) { return false; } if (previouslyMatched.contains(resourceURLString)) { return true; } final FocusString revhost = FocusString.create(resourceHost).reverse(); for (final Map.Entry<String, Trie> category : categories.entrySet()) { if (enabledCategories.contains(category.getKey()) && category.getValue().findNode(revhost) != null) { previouslyMatched.add(resourceURLString); return true; } } previouslyUnmatched.add(resourceURLString); return false; } }
UrlMatcher implements  SharedPreferences.OnSharedPreferenceChangeListener { public boolean matches(final Uri resourceURI, final Uri pageURI) { final String path = resourceURI.getPath(); if (path == null) { return false; } if (blockWebfonts) { for (final String extension : WEBFONT_EXTENSIONS) { if (path.endsWith(extension)) { return true; } } } final String resourceURLString = resourceURI.toString(); if (previouslyUnmatched.contains(resourceURLString)) { return false; } if (entityList != null && entityList.isWhiteListed(pageURI, resourceURI)) { return false; } final String resourceHost = resourceURI.getHost(); final String pageHost = pageURI.getHost(); if (pageHost != null && pageHost.equals(resourceHost)) { return false; } if (previouslyMatched.contains(resourceURLString)) { return true; } final FocusString revhost = FocusString.create(resourceHost).reverse(); for (final Map.Entry<String, Trie> category : categories.entrySet()) { if (enabledCategories.contains(category.getKey()) && category.getValue().findNode(revhost) != null) { previouslyMatched.add(resourceURLString); return true; } } previouslyUnmatched.add(resourceURLString); return false; } UrlMatcher(final Context context,
                                     @NonNull final Map<String, String> categoryPrefMap,
                                     @NonNull final Map<String, Trie> categoryMap,
                                     @Nullable final EntityList entityList); @VisibleForTesting  UrlMatcher(final String[] patterns); }
UrlMatcher implements  SharedPreferences.OnSharedPreferenceChangeListener { public boolean matches(final Uri resourceURI, final Uri pageURI) { final String path = resourceURI.getPath(); if (path == null) { return false; } if (blockWebfonts) { for (final String extension : WEBFONT_EXTENSIONS) { if (path.endsWith(extension)) { return true; } } } final String resourceURLString = resourceURI.toString(); if (previouslyUnmatched.contains(resourceURLString)) { return false; } if (entityList != null && entityList.isWhiteListed(pageURI, resourceURI)) { return false; } final String resourceHost = resourceURI.getHost(); final String pageHost = pageURI.getHost(); if (pageHost != null && pageHost.equals(resourceHost)) { return false; } if (previouslyMatched.contains(resourceURLString)) { return true; } final FocusString revhost = FocusString.create(resourceHost).reverse(); for (final Map.Entry<String, Trie> category : categories.entrySet()) { if (enabledCategories.contains(category.getKey()) && category.getValue().findNode(revhost) != null) { previouslyMatched.add(resourceURLString); return true; } } previouslyUnmatched.add(resourceURLString); return false; } UrlMatcher(final Context context,
                                     @NonNull final Map<String, String> categoryPrefMap,
                                     @NonNull final Map<String, Trie> categoryMap,
                                     @Nullable final EntityList entityList); @VisibleForTesting  UrlMatcher(final String[] patterns); static UrlMatcher loadMatcher(final Context context, final int blockListFile, final int[] blockListOverrides, final int entityListFile); @Override void onSharedPreferenceChanged(final SharedPreferences sharedPreferences, final String prefName); Set<String> getCategories(); void setCategoryEnabled(final String category, final boolean enabled); boolean matches(final Uri resourceURI, final Uri pageURI); }
UrlMatcher implements  SharedPreferences.OnSharedPreferenceChangeListener { public boolean matches(final Uri resourceURI, final Uri pageURI) { final String path = resourceURI.getPath(); if (path == null) { return false; } if (blockWebfonts) { for (final String extension : WEBFONT_EXTENSIONS) { if (path.endsWith(extension)) { return true; } } } final String resourceURLString = resourceURI.toString(); if (previouslyUnmatched.contains(resourceURLString)) { return false; } if (entityList != null && entityList.isWhiteListed(pageURI, resourceURI)) { return false; } final String resourceHost = resourceURI.getHost(); final String pageHost = pageURI.getHost(); if (pageHost != null && pageHost.equals(resourceHost)) { return false; } if (previouslyMatched.contains(resourceURLString)) { return true; } final FocusString revhost = FocusString.create(resourceHost).reverse(); for (final Map.Entry<String, Trie> category : categories.entrySet()) { if (enabledCategories.contains(category.getKey()) && category.getValue().findNode(revhost) != null) { previouslyMatched.add(resourceURLString); return true; } } previouslyUnmatched.add(resourceURLString); return false; } UrlMatcher(final Context context,
                                     @NonNull final Map<String, String> categoryPrefMap,
                                     @NonNull final Map<String, Trie> categoryMap,
                                     @Nullable final EntityList entityList); @VisibleForTesting  UrlMatcher(final String[] patterns); static UrlMatcher loadMatcher(final Context context, final int blockListFile, final int[] blockListOverrides, final int entityListFile); @Override void onSharedPreferenceChanged(final SharedPreferences sharedPreferences, final String prefName); Set<String> getCategories(); void setCategoryEnabled(final String category, final boolean enabled); boolean matches(final Uri resourceURI, final Uri pageURI);  }