Skip to content

Commit

Permalink
Merge pull request #8736 from hansemannn/TIMOB-24288
Browse files Browse the repository at this point in the history
[TIMOB-24288] iOS/Android: Deprecate "onStopBlacklistedUrl" WebView event in favor of cross-platform "blacklisturl" event
  • Loading branch information
Lokesh Choudhary committed Feb 8, 2017
2 parents 5fbf08f + 751e0e6 commit 48c8c29
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,20 @@ public boolean shouldOverrideUrlLoading(final WebView view, String url)
return super.shouldOverrideUrlLoading(view, url);
}
if (proxy.hasProperty(TiC.PROPERTY_BLACKLISTED_URLS)) {
String [] blacklistedSites = TiConvert.toStringArray((Object[])proxy.getProperty(TiC.PROPERTY_BLACKLISTED_URLS));
for(String site : blacklistedSites) {
if (url.equalsIgnoreCase(site) || (url.indexOf(site) > -1)) {
KrollDict data = new KrollDict();
data.put("url", url);
data.put("message", "Webview did not load blacklisted url.");
proxy.fireEvent(TiC.PROPERTY_ON_STOP_BLACKISTED_URL, data);
return true;
}
}
String [] blacklistedSites = TiConvert.toStringArray((Object[])proxy.getProperty(TiC.PROPERTY_BLACKLISTED_URLS));
for (String site : blacklistedSites) {
if (url.equalsIgnoreCase(site) || (url.indexOf(site) > -1)) {
KrollDict data = new KrollDict();
data.put("url", url);
data.put("message", "Webview did not load blacklisted url.");
proxy.fireEvent(TiC.PROPERTY_BLACKLIST_URL, data);

// Deprecated since 6.1.0, leave here until we remove it (7.0.0?)
proxy.fireEvent(TiC.PROPERTY_ON_STOP_BLACKLISTED_URL, data);

return true;
}
}
}

if (URLUtil.isAssetUrl(url) || URLUtil.isContentUrl(url) || URLUtil.isFileUrl(url)) {
Expand Down
7 changes: 6 additions & 1 deletion android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,11 @@ public class TiC
*/
public static final String PROPERTY_BIRTHDAY = "birthday";

/**
* @module.api
*/
public static final String PROPERTY_BLACKLIST_URL = "blacklisturl";

/**
* @module.api
*/
Expand Down Expand Up @@ -2015,7 +2020,7 @@ public class TiC
/**
* @module.api
*/
public static final String PROPERTY_ON_STOP_BLACKISTED_URL = "onStopBlacklistedUrl";
public static final String PROPERTY_ON_STOP_BLACKLISTED_URL = "onStopBlacklistedUrl"; // Deprecated in 6.1.0

/**
* @module.api
Expand Down
19 changes: 14 additions & 5 deletions apidoc/Titanium/UI/WebView.yml
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,23 @@ events:
type: Number

- name: onStopBlacklistedUrl
summary: Fired when a blacklisted Url is stopped
description: |
This event is fired when a blacklisted Url is stopped
summary: Fired when a blacklisted URL is stopped.
platforms: [android]
since: 5.4.0
properties:
- name: url
summary: The URL of the web document that is stopped.
deprecated:
since: "6.1.0"
notes: Use the cross-platform `blacklisturl` event instead.

- name: blacklisturl
summary: Fired when a blacklisted URL is stopped.
platforms: [android, iphone, ipad]
since: {android: "5.4.0", iphone: "6.1.0", ipad: "6.1.0"}
since: {android: "6.1.0", iphone: "6.1.0", ipad: "6.1.0"}
properties:
- name: url
summary: URL of the web document that is stopped.
summary: The URL of the web document that is stopped.

properties:

Expand Down
12 changes: 7 additions & 5 deletions iphone/Classes/TiUIWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -769,12 +769,14 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)

for (NSString *blackListedUrl in blacklistedURLs) {
if ([urlAbsoluteString rangeOfString:blackListedUrl options:NSCaseInsensitiveSearch].location != NSNotFound) {
if ([self.proxy _hasListeners:@"onStopBlacklistedUrl"]) {
NSDictionary *eventDict = [NSDictionary dictionaryWithObjectsAndKeys:urlAbsoluteString,@"url",@"Webview did not load blacklisted url.", @"messsage", nil];
[self.proxy fireEvent:@"onStopBlacklistedUrl" withObject:eventDict];
if ([[self proxy] _hasListeners:@"blacklisturl"]) {
[[self proxy] fireEvent:@"blacklisturl" withObject:@{
@"url": urlAbsoluteString,
@"message": @"Webview did not load blacklisted url."
}];
}
[self stopSpinner];

[self stopSpinner];
return NO;
}
}
Expand Down

0 comments on commit 48c8c29

Please sign in to comment.