Browse Source

Switching to URLUtil where possible

master
anthony restaino 8 years ago
parent
commit
003954773c
  1. 4
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  2. 22
      app/src/main/java/acr/browser/lightning/activity/TabsManager.java
  3. 3
      app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java
  4. 6
      app/src/main/java/acr/browser/lightning/constant/Constants.java
  5. 3
      app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java
  6. 3
      app/src/main/java/acr/browser/lightning/utils/Utils.java
  7. 5
      app/src/main/java/acr/browser/lightning/view/LightningWebClient.java

4
app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java

@ -61,6 +61,7 @@ import android.view.animation.Animation; @@ -61,6 +61,7 @@ import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.webkit.URLUtil;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient.CustomViewCallback;
import android.webkit.WebIconDatabase;
@ -656,8 +657,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -656,8 +657,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
switch (mPreferences.getSearchChoice()) {
case 0:
mSearchText = mPreferences.getSearchUrl();
if (!mSearchText.startsWith(Constants.HTTP)
&& !mSearchText.startsWith(Constants.HTTPS)) {
if (!URLUtil.isNetworkUrl(mSearchText)) {
mSearchText = Constants.GOOGLE_SEARCH;
}
break;

22
app/src/main/java/acr/browser/lightning/activity/TabsManager.java

@ -12,6 +12,7 @@ import android.support.annotation.Nullable; @@ -12,6 +12,7 @@ import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.util.Log;
import android.webkit.URLUtil;
import android.webkit.WebView;
import com.anthonycr.bonsai.Completable;
@ -32,7 +33,6 @@ import javax.inject.Inject; @@ -32,7 +33,6 @@ import javax.inject.Inject;
import acr.browser.lightning.R;
import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.constant.BookmarkPage;
import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.constant.DownloadsPage;
import acr.browser.lightning.constant.HistoryPage;
import acr.browser.lightning.constant.StartPage;
@ -174,15 +174,15 @@ public class TabsManager { @@ -174,15 +174,15 @@ public class TabsManager {
});
} else if (UrlUtils.isDownloadsUrl(url)) {
new DownloadsPage().getDownloadsPage()
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.main())
.subscribe(new SingleOnSubscribe<String>() {
@Override
public void onItem(@Nullable String item) {
Preconditions.checkNonNull(item);
tab.loadUrl(item);
}
});
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.main())
.subscribe(new SingleOnSubscribe<String>() {
@Override
public void onItem(@Nullable String item) {
Preconditions.checkNonNull(item);
tab.loadUrl(item);
}
});
} else if (UrlUtils.isStartPageUrl(url)) {
new StartPage().getHomepage()
.subscribeOn(Schedulers.io())
@ -214,7 +214,7 @@ public class TabsManager { @@ -214,7 +214,7 @@ public class TabsManager {
@Override
public void onComplete() {
if (url != null) {
if (url.startsWith(Constants.FILE)) {
if (URLUtil.isFileUrl(url)) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
Dialog dialog = builder.setCancelable(true)
.setTitle(R.string.title_warning)

3
app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java

@ -6,6 +6,7 @@ import android.content.Intent; @@ -6,6 +6,7 @@ import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import android.webkit.URLUtil;
import com.anthonycr.bonsai.CompletableOnSubscribe;
import com.anthonycr.bonsai.Schedulers;
@ -232,7 +233,7 @@ public class BrowserPresenter { @@ -232,7 +233,7 @@ public class BrowserPresenter {
tab.loadUrl(url);
}
} else if (url != null) {
if (url.startsWith(Constants.FILE)) {
if (URLUtil.isFileUrl(url)) {
mView.showBlockedLocalFileDialog(new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {

6
app/src/main/java/acr/browser/lightning/constant/Constants.java

@ -30,9 +30,9 @@ public final class Constants { @@ -30,9 +30,9 @@ public final class Constants {
public static final String YANDEX_SEARCH = "https://yandex.ru/yandsearch?lr=21411&text=";
// Custom local page schemes
public static final String SCHEME_HOMEPAGE = "about:home";
public static final String SCHEME_BLANK = "about:blank";
public static final String SCHEME_BOOKMARKS = "about:bookmarks";
public static final String SCHEME_HOMEPAGE = Constants.ABOUT + "home";
public static final String SCHEME_BLANK = Constants.ABOUT + "blank";
public static final String SCHEME_BOOKMARKS = Constants.ABOUT + "bookmarks";
// 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)})();";

3
app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java

@ -19,6 +19,7 @@ import android.text.InputFilter; @@ -19,6 +19,7 @@ import android.text.InputFilter;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.webkit.URLUtil;
import android.widget.EditText;
import acr.browser.lightning.BuildConfig;
@ -422,7 +423,7 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme @@ -422,7 +423,7 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
private void homePicker() {
String currentHomepage;
mHomepage = mPreferenceManager.getHomepage();
if (!mHomepage.startsWith(Constants.ABOUT)) {
if (!URLUtil.isAboutUrl(mHomepage)) {
currentHomepage = mHomepage;
} else {
currentHomepage = "https://www.google.com";

3
app/src/main/java/acr/browser/lightning/utils/Utils.java

@ -32,6 +32,7 @@ import android.text.TextUtils; @@ -32,6 +32,7 @@ import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.webkit.URLUtil;
import android.widget.Toast;
import java.io.Closeable;
@ -175,7 +176,7 @@ public final class Utils { @@ -175,7 +176,7 @@ public final class Utils {
public static String getDomainName(@Nullable String url) {
if (url == null || url.isEmpty()) return "";
boolean ssl = url.startsWith(Constants.HTTPS);
boolean ssl = URLUtil.isHttpsUrl(url);
int index = url.indexOf('/', 8);
if (index != -1) {
url = url.substring(0, index);

5
app/src/main/java/acr/browser/lightning/view/LightningWebClient.java

@ -22,6 +22,7 @@ import android.view.View; @@ -22,6 +22,7 @@ import android.view.View;
import android.webkit.HttpAuthHandler;
import android.webkit.MimeTypeMap;
import android.webkit.SslErrorHandler;
import android.webkit.URLUtil;
import android.webkit.ValueCallback;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
@ -305,7 +306,7 @@ public class LightningWebClient extends WebViewClient { @@ -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
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
return continueLoadingUrl(view, url, headers);
}
@ -360,7 +361,7 @@ public class LightningWebClient extends WebViewClient { @@ -360,7 +361,7 @@ public class LightningWebClient extends WebViewClient {
}
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, ""));
if (file.exists()) {

Loading…
Cancel
Save