Skip to content

Commit

Permalink
Merge pull request #7954 from ashcoding/TIMOB-23186
Browse files Browse the repository at this point in the history
[TIMOB-23186] Android: Webview has blacklistedURLs property implemented
  • Loading branch information
hieupham007 committed Apr 21, 2016
2 parents ca31cf1 + 5d2af60 commit f57dcc2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import android.webkit.WebView;

@Kroll.proxy(creatableInModule=UIModule.class, propertyAccessors = {
TiC.PROPERTY_BLACKLISTED_URLS,
TiC.PROPERTY_DATA,
TiC.PROPERTY_ON_CREATE_WINDOW,
TiC.PROPERTY_SCALES_PAGE_TO_FIT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ public boolean shouldOverrideUrlLoading(final WebView view, String url)
{
Log.d(TAG, "url=" + url, Log.DEBUG_MODE);

if (webView.getProxy().hasProperty(TiC.PROPERTY_BLACKLISTED_URLS)) {
String [] blacklistedSites = TiConvert.toStringArray((Object[])webView.getProxy().getProperty(TiC.PROPERTY_BLACKLISTED_URLS));
for(String site : blacklistedSites) {
if (url.equalsIgnoreCase(site) || (url.indexOf(site) > -1)) {
return true;
}
}
}

if (URLUtil.isAssetUrl(url) || URLUtil.isContentUrl(url) || URLUtil.isFileUrl(url)) {
// go through the proxy to ensure we're on the UI thread
webView.getProxy().setPropertyAndFire(TiC.PROPERTY_URL, url);
Expand Down
5 changes: 5 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,11 @@ public class TiC
*/
public static final String PROPERTY_BIRTHDAY = "birthday";

/**
* @module.api
*/
public static final String PROPERTY_BLACKLISTED_URLS = "blacklistedURLs";

/**
* @module.api
*/
Expand Down
11 changes: 11 additions & 0 deletions apidoc/Titanium/UI/WebView.yml
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,17 @@ methods:
summary: Forces the web view to destroy the iFrame (Mobile Web only).
type: Boolean

- name: blacklistedURLs
summary: |
An array of url strings to blacklist.
description: |
An array of url strings to blacklist. This will stop the webview from going to urls listed in
the blacklist.
type: Array<String>
since: "5.4.0"
platforms: [android]
availability: creation


events:

Expand Down

0 comments on commit f57dcc2

Please sign in to comment.