Switching to URLUtil where possible
This commit is contained in:
parent
12a93d208d
commit
003954773c
@ -61,6 +61,7 @@ import android.view.animation.Animation;
|
|||||||
import android.view.animation.Transformation;
|
import android.view.animation.Transformation;
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
import android.webkit.URLUtil;
|
||||||
import android.webkit.ValueCallback;
|
import android.webkit.ValueCallback;
|
||||||
import android.webkit.WebChromeClient.CustomViewCallback;
|
import android.webkit.WebChromeClient.CustomViewCallback;
|
||||||
import android.webkit.WebIconDatabase;
|
import android.webkit.WebIconDatabase;
|
||||||
@ -656,8 +657,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
switch (mPreferences.getSearchChoice()) {
|
switch (mPreferences.getSearchChoice()) {
|
||||||
case 0:
|
case 0:
|
||||||
mSearchText = mPreferences.getSearchUrl();
|
mSearchText = mPreferences.getSearchUrl();
|
||||||
if (!mSearchText.startsWith(Constants.HTTP)
|
if (!URLUtil.isNetworkUrl(mSearchText)) {
|
||||||
&& !mSearchText.startsWith(Constants.HTTPS)) {
|
|
||||||
mSearchText = Constants.GOOGLE_SEARCH;
|
mSearchText = Constants.GOOGLE_SEARCH;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -12,6 +12,7 @@ import android.support.annotation.Nullable;
|
|||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.webkit.URLUtil;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
|
||||||
import com.anthonycr.bonsai.Completable;
|
import com.anthonycr.bonsai.Completable;
|
||||||
@ -32,7 +33,6 @@ import javax.inject.Inject;
|
|||||||
import acr.browser.lightning.R;
|
import acr.browser.lightning.R;
|
||||||
import acr.browser.lightning.app.BrowserApp;
|
import acr.browser.lightning.app.BrowserApp;
|
||||||
import acr.browser.lightning.constant.BookmarkPage;
|
import acr.browser.lightning.constant.BookmarkPage;
|
||||||
import acr.browser.lightning.constant.Constants;
|
|
||||||
import acr.browser.lightning.constant.DownloadsPage;
|
import acr.browser.lightning.constant.DownloadsPage;
|
||||||
import acr.browser.lightning.constant.HistoryPage;
|
import acr.browser.lightning.constant.HistoryPage;
|
||||||
import acr.browser.lightning.constant.StartPage;
|
import acr.browser.lightning.constant.StartPage;
|
||||||
@ -214,7 +214,7 @@ public class TabsManager {
|
|||||||
@Override
|
@Override
|
||||||
public void onComplete() {
|
public void onComplete() {
|
||||||
if (url != null) {
|
if (url != null) {
|
||||||
if (url.startsWith(Constants.FILE)) {
|
if (URLUtil.isFileUrl(url)) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||||
Dialog dialog = builder.setCancelable(true)
|
Dialog dialog = builder.setCancelable(true)
|
||||||
.setTitle(R.string.title_warning)
|
.setTitle(R.string.title_warning)
|
||||||
|
@ -6,6 +6,7 @@ import android.content.Intent;
|
|||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.webkit.URLUtil;
|
||||||
|
|
||||||
import com.anthonycr.bonsai.CompletableOnSubscribe;
|
import com.anthonycr.bonsai.CompletableOnSubscribe;
|
||||||
import com.anthonycr.bonsai.Schedulers;
|
import com.anthonycr.bonsai.Schedulers;
|
||||||
@ -232,7 +233,7 @@ public class BrowserPresenter {
|
|||||||
tab.loadUrl(url);
|
tab.loadUrl(url);
|
||||||
}
|
}
|
||||||
} else if (url != null) {
|
} else if (url != null) {
|
||||||
if (url.startsWith(Constants.FILE)) {
|
if (URLUtil.isFileUrl(url)) {
|
||||||
mView.showBlockedLocalFileDialog(new DialogInterface.OnClickListener() {
|
mView.showBlockedLocalFileDialog(new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
@ -30,9 +30,9 @@ public final class Constants {
|
|||||||
public static final String YANDEX_SEARCH = "https://yandex.ru/yandsearch?lr=21411&text=";
|
public static final String YANDEX_SEARCH = "https://yandex.ru/yandsearch?lr=21411&text=";
|
||||||
|
|
||||||
// Custom local page schemes
|
// Custom local page schemes
|
||||||
public static final String SCHEME_HOMEPAGE = "about:home";
|
public static final String SCHEME_HOMEPAGE = Constants.ABOUT + "home";
|
||||||
public static final String SCHEME_BLANK = "about:blank";
|
public static final String SCHEME_BLANK = Constants.ABOUT + "blank";
|
||||||
public static final String SCHEME_BOOKMARKS = "about:bookmarks";
|
public static final String SCHEME_BOOKMARKS = Constants.ABOUT + "bookmarks";
|
||||||
|
|
||||||
// Miscellaneous JavaScript
|
// Miscellaneous JavaScript
|
||||||
public static final String JAVASCRIPT_INVERT_PAGE = "javascript:(function(){var e='img {-webkit-filter: invert(100%);'+'-moz-filter: invert(100%);'+'-o-filter: invert(100%);'+'-ms-filter: invert(100%); }',t=document.getElementsByTagName('head')[0],n=document.createElement('style');if(!window.counter){window.counter=1}else{window.counter++;if(window.counter%2==0){var e='html {-webkit-filter: invert(0%); -moz-filter: invert(0%); -o-filter: invert(0%); -ms-filter: invert(0%); }'}}n.type='text/css';if(n.styleSheet){n.styleSheet.cssText=e}else{n.appendChild(document.createTextNode(e))}t.appendChild(n)})();";
|
public static final String JAVASCRIPT_INVERT_PAGE = "javascript:(function(){var e='img {-webkit-filter: invert(100%);'+'-moz-filter: invert(100%);'+'-o-filter: invert(100%);'+'-ms-filter: invert(100%); }',t=document.getElementsByTagName('head')[0],n=document.createElement('style');if(!window.counter){window.counter=1}else{window.counter++;if(window.counter%2==0){var e='html {-webkit-filter: invert(0%); -moz-filter: invert(0%); -o-filter: invert(0%); -ms-filter: invert(0%); }'}}n.type='text/css';if(n.styleSheet){n.styleSheet.cssText=e}else{n.appendChild(document.createTextNode(e))}t.appendChild(n)})();";
|
||||||
|
@ -19,6 +19,7 @@ import android.text.InputFilter;
|
|||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.webkit.URLUtil;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
|
||||||
import acr.browser.lightning.BuildConfig;
|
import acr.browser.lightning.BuildConfig;
|
||||||
@ -422,7 +423,7 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
|
|||||||
private void homePicker() {
|
private void homePicker() {
|
||||||
String currentHomepage;
|
String currentHomepage;
|
||||||
mHomepage = mPreferenceManager.getHomepage();
|
mHomepage = mPreferenceManager.getHomepage();
|
||||||
if (!mHomepage.startsWith(Constants.ABOUT)) {
|
if (!URLUtil.isAboutUrl(mHomepage)) {
|
||||||
currentHomepage = mHomepage;
|
currentHomepage = mHomepage;
|
||||||
} else {
|
} else {
|
||||||
currentHomepage = "https://www.google.com";
|
currentHomepage = "https://www.google.com";
|
||||||
|
@ -32,6 +32,7 @@ import android.text.TextUtils;
|
|||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.webkit.URLUtil;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
@ -175,7 +176,7 @@ public final class Utils {
|
|||||||
public static String getDomainName(@Nullable String url) {
|
public static String getDomainName(@Nullable String url) {
|
||||||
if (url == null || url.isEmpty()) return "";
|
if (url == null || url.isEmpty()) return "";
|
||||||
|
|
||||||
boolean ssl = url.startsWith(Constants.HTTPS);
|
boolean ssl = URLUtil.isHttpsUrl(url);
|
||||||
int index = url.indexOf('/', 8);
|
int index = url.indexOf('/', 8);
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
url = url.substring(0, index);
|
url = url.substring(0, index);
|
||||||
|
@ -22,6 +22,7 @@ import android.view.View;
|
|||||||
import android.webkit.HttpAuthHandler;
|
import android.webkit.HttpAuthHandler;
|
||||||
import android.webkit.MimeTypeMap;
|
import android.webkit.MimeTypeMap;
|
||||||
import android.webkit.SslErrorHandler;
|
import android.webkit.SslErrorHandler;
|
||||||
|
import android.webkit.URLUtil;
|
||||||
import android.webkit.ValueCallback;
|
import android.webkit.ValueCallback;
|
||||||
import android.webkit.WebResourceRequest;
|
import android.webkit.WebResourceRequest;
|
||||||
import android.webkit.WebResourceResponse;
|
import android.webkit.WebResourceResponse;
|
||||||
@ -305,7 +306,7 @@ public class LightningWebClient extends WebViewClient {
|
|||||||
// If we are in incognito, immediately load, we don't want the url to leave the app
|
// If we are in incognito, immediately load, we don't want the url to leave the app
|
||||||
return continueLoadingUrl(view, url, headers);
|
return continueLoadingUrl(view, url, headers);
|
||||||
}
|
}
|
||||||
if (url.startsWith(Constants.ABOUT)) {
|
if (URLUtil.isAboutUrl(url)) {
|
||||||
// If this is an about page, immediately load, we don't need to leave the app
|
// If this is an about page, immediately load, we don't need to leave the app
|
||||||
return continueLoadingUrl(view, url, headers);
|
return continueLoadingUrl(view, url, headers);
|
||||||
}
|
}
|
||||||
@ -360,7 +361,7 @@ public class LightningWebClient extends WebViewClient {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (url.startsWith(Constants.FILE) && !UrlUtils.isSpecialUrl(url)) {
|
} else if (URLUtil.isFileUrl(url) && !UrlUtils.isSpecialUrl(url)) {
|
||||||
File file = new File(url.replace(Constants.FILE, ""));
|
File file = new File(url.replace(Constants.FILE, ""));
|
||||||
|
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user