Browse Source

Add back SSL error detection that was removed, fixed static analysis warnings.

master
Anthony Restaino 9 years ago
parent
commit
1c96b62eb6
  1. 2
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  2. 1
      app/src/main/java/acr/browser/lightning/activity/IncognitoActivity.java
  3. 1
      app/src/main/java/acr/browser/lightning/activity/MainActivity.java
  4. 1
      app/src/main/java/acr/browser/lightning/activity/TabsManager.java
  5. 1
      app/src/main/java/acr/browser/lightning/activity/ThemableSettingsActivity.java
  6. 2
      app/src/main/java/acr/browser/lightning/controller/BrowserController.java
  7. 3
      app/src/main/java/acr/browser/lightning/database/HistoryDatabase.java
  8. 1
      app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java
  9. 1
      app/src/main/java/acr/browser/lightning/download/FetchUrlMimeType.java
  10. 3
      app/src/main/java/acr/browser/lightning/fragment/BookmarkSettingsFragment.java
  11. 7
      app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java
  12. 1
      app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java
  13. 13
      app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java
  14. 1
      app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java
  15. 3
      app/src/main/java/acr/browser/lightning/reading/ArticleTextExtractor.java
  16. 16
      app/src/main/java/acr/browser/lightning/reading/HtmlFetcher.java
  17. 1
      app/src/main/java/acr/browser/lightning/utils/AdBlock.java
  18. 1
      app/src/main/java/acr/browser/lightning/utils/IntentUtils.java
  19. 1
      app/src/main/java/acr/browser/lightning/utils/WebUtils.java
  20. 2
      app/src/main/java/acr/browser/lightning/view/LightningChromeClient.java
  21. 41
      app/src/main/java/acr/browser/lightning/view/LightningView.java
  22. 2
      app/src/main/java/acr/browser/lightning/view/LightningViewTitle.java
  23. 51
      app/src/main/java/acr/browser/lightning/view/LightningWebClient.java

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

@ -210,7 +210,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
private static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = new FrameLayout.LayoutParams( private static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = new FrameLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
public abstract boolean isIncognito(); protected abstract boolean isIncognito();
// abstract void initializeTabs(); // abstract void initializeTabs();

1
app/src/main/java/acr/browser/lightning/activity/IncognitoActivity.java

@ -7,7 +7,6 @@ import android.webkit.CookieManager;
import android.webkit.CookieSyncManager; import android.webkit.CookieSyncManager;
import acr.browser.lightning.R; import acr.browser.lightning.R;
import acr.browser.lightning.preference.PreferenceManager;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class IncognitoActivity extends BrowserActivity { public class IncognitoActivity extends BrowserActivity {

1
app/src/main/java/acr/browser/lightning/activity/MainActivity.java

@ -7,7 +7,6 @@ import android.webkit.CookieManager;
import android.webkit.CookieSyncManager; import android.webkit.CookieSyncManager;
import acr.browser.lightning.R; import acr.browser.lightning.R;
import acr.browser.lightning.preference.PreferenceManager;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class MainActivity extends BrowserActivity { public class MainActivity extends BrowserActivity {

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

@ -38,7 +38,6 @@ public class TabsManager {
final String mem = mPreferenceManager.getMemoryUrl(); final String mem = mPreferenceManager.getMemoryUrl();
mPreferenceManager.setMemoryUrl(""); mPreferenceManager.setMemoryUrl("");
String[] array = Utils.getArray(mem); String[] array = Utils.getArray(mem);
int count = 0;
for (String urlString : array) { for (String urlString : array) {
if (!urlString.isEmpty()) { if (!urlString.isEmpty()) {
newTab(activity, urlString, darkTheme, incognito); newTab(activity, urlString, darkTheme, incognito);

1
app/src/main/java/acr/browser/lightning/activity/ThemableSettingsActivity.java

@ -5,7 +5,6 @@ import android.os.Bundle;
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.preference.PreferenceManager;
import acr.browser.lightning.utils.ThemeUtils; import acr.browser.lightning.utils.ThemeUtils;
public abstract class ThemableSettingsActivity extends AppCompatPreferenceActivity { public abstract class ThemableSettingsActivity extends AppCompatPreferenceActivity {

2
app/src/main/java/acr/browser/lightning/controller/BrowserController.java

@ -3,13 +3,11 @@
*/ */
package acr.browser.lightning.controller; package acr.browser.lightning.controller;
import android.graphics.Bitmap;
import android.net.Uri; import android.net.Uri;
import android.os.Message; import android.os.Message;
import android.view.View; import android.view.View;
import android.webkit.ValueCallback; import android.webkit.ValueCallback;
import android.webkit.WebChromeClient.CustomViewCallback; import android.webkit.WebChromeClient.CustomViewCallback;
import android.webkit.WebView;
import acr.browser.lightning.view.LightningView; import acr.browser.lightning.view.LightningView;

3
app/src/main/java/acr/browser/lightning/database/HistoryDatabase.java

@ -16,7 +16,6 @@ import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import acr.browser.lightning.R; import acr.browser.lightning.R;
import acr.browser.lightning.app.BrowserApp;
@Singleton @Singleton
public class HistoryDatabase extends SQLiteOpenHelper { public class HistoryDatabase extends SQLiteOpenHelper {
@ -73,7 +72,7 @@ public class HistoryDatabase extends SQLiteOpenHelper {
mDatabase = this.getWritableDatabase(); mDatabase = this.getWritableDatabase();
} }
public boolean isClosed() { private boolean isClosed() {
return mDatabase == null || !mDatabase.isOpen(); return mDatabase == null || !mDatabase.isOpen();
} }

1
app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java

@ -6,7 +6,6 @@ import android.content.ClipboardManager;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.view.View; import android.view.View;

1
app/src/main/java/acr/browser/lightning/download/FetchUrlMimeType.java

@ -20,7 +20,6 @@ import java.net.URL;
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.bus.BrowserEvents; import acr.browser.lightning.bus.BrowserEvents;
import acr.browser.lightning.utils.Utils;
/** /**
* This class is used to pull down the http headers of a given URL so that we * This class is used to pull down the http headers of a given URL so that we

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

@ -5,7 +5,6 @@ package acr.browser.lightning.fragment;
import android.Manifest; import android.Manifest;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build; import android.os.Build;
@ -52,7 +51,7 @@ public class BookmarkSettingsFragment extends PreferenceFragment implements Pref
private class ImportBookmarksTask extends AsyncTask<Void, Void, Integer> { private class ImportBookmarksTask extends AsyncTask<Void, Void, Integer> {
private WeakReference<Activity> mActivityReference; private final WeakReference<Activity> mActivityReference;
public ImportBookmarksTask(Activity activity) { public ImportBookmarksTask(Activity activity) {
mActivityReference = new WeakReference<>(activity); mActivityReference = new WeakReference<>(activity);

7
app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java

@ -36,7 +36,6 @@ import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import acr.browser.lightning.R; import acr.browser.lightning.R;
import acr.browser.lightning.activity.BrowserActivity;
import acr.browser.lightning.activity.ReadingActivity; import acr.browser.lightning.activity.ReadingActivity;
import acr.browser.lightning.activity.TabsManager; import acr.browser.lightning.activity.TabsManager;
import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.app.BrowserApp;
@ -95,8 +94,6 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
// Colors // Colors
private int mIconColor, mScrollIndex; private int mIconColor, mScrollIndex;
private boolean mIsIncognito;
// Init asynchronously the bookmark manager // Init asynchronously the bookmark manager
private final Runnable mInitBookmarkManager = new Runnable() { private final Runnable mInitBookmarkManager = new Runnable() {
@Override @Override
@ -114,8 +111,8 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
BrowserApp.getAppComponent().inject(this); BrowserApp.getAppComponent().inject(this);
final Bundle arguments = getArguments(); final Bundle arguments = getArguments();
final Context context = getContext(); final Context context = getContext();
mIsIncognito = arguments.getBoolean(INCOGNITO_MODE, false); boolean isIncognito = arguments.getBoolean(INCOGNITO_MODE, false);
boolean darkTheme = mPreferenceManager.getUseTheme() != 0 || mIsIncognito; boolean darkTheme = mPreferenceManager.getUseTheme() != 0 || isIncognito;
mWebpageBitmap = ThemeUtils.getThemedBitmap(context, R.drawable.ic_webpage, darkTheme); mWebpageBitmap = ThemeUtils.getThemedBitmap(context, R.drawable.ic_webpage, darkTheme);
mFolderBitmap = ThemeUtils.getThemedBitmap(context, R.drawable.ic_folder, darkTheme); mFolderBitmap = ThemeUtils.getThemedBitmap(context, R.drawable.ic_folder, darkTheme);
mIconColor = darkTheme ? ThemeUtils.getIconDarkThemeColor(context) : mIconColor = darkTheme ? ThemeUtils.getIconDarkThemeColor(context) :

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

@ -22,7 +22,6 @@ import android.widget.LinearLayout;
import acr.browser.lightning.R; import acr.browser.lightning.R;
import acr.browser.lightning.constant.Constants; import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.download.DownloadHandler; import acr.browser.lightning.download.DownloadHandler;
import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.utils.ProxyUtils; import acr.browser.lightning.utils.ProxyUtils;
import acr.browser.lightning.utils.ThemeUtils; import acr.browser.lightning.utils.ThemeUtils;
import acr.browser.lightning.utils.Utils; import acr.browser.lightning.utils.Utils;

13
app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java

@ -21,6 +21,7 @@ import android.support.annotation.IdRes;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewCompat; import android.support.v4.view.ViewCompat;
import android.support.v7.graphics.Palette; import android.support.v7.graphics.Palette;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
@ -249,6 +250,9 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
ViewCompat.jumpDrawablesToCurrentState(holder.exitButton); ViewCompat.jumpDrawablesToCurrentState(holder.exitButton);
LightningView web = tabsManager.getTabAtPosition(position); LightningView web = tabsManager.getTabAtPosition(position);
if (web == null) {
return;
}
holder.txtTitle.setText(web.getTitle()); holder.txtTitle.setText(web.getTitle());
final Bitmap favicon = web.getFavicon(); final Bitmap favicon = web.getFavicon();
@ -326,14 +330,7 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
return; return;
} }
final int defaultColor; final int defaultColor = ContextCompat.getColor(getContext(), R.color.primary_color);
final Resources resources = getResources();
final ColorDrawable mBackground = new ColorDrawable();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
defaultColor = resources.getColor(R.color.primary_color, null);
} else {
defaultColor = resources.getColor(R.color.primary_color);
}
if (mCurrentUiColor == Color.BLACK) { if (mCurrentUiColor == Color.BLACK) {
mCurrentUiColor = defaultColor; mCurrentUiColor = defaultColor;
} }

1
app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java

@ -6,7 +6,6 @@ import android.content.SharedPreferences;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.constant.Constants; import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.download.DownloadHandler; import acr.browser.lightning.download.DownloadHandler;

3
app/src/main/java/acr/browser/lightning/reading/ArticleTextExtractor.java

@ -491,8 +491,7 @@ public class ArticleTextExtractor {
Element el = elems.get(0); Element el = elems.get(0);
if (el.hasAttr("content")) { if (el.hasAttr("content")) {
dateStr = el.attr("content"); dateStr = el.attr("content");
Date parsedDate = parseDate(dateStr); return parseDate(dateStr);
return parsedDate;
} }
} }

16
app/src/main/java/acr/browser/lightning/reading/HtmlFetcher.java

@ -33,6 +33,8 @@ import java.util.zip.GZIPInputStream;
import java.util.zip.Inflater; import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream; import java.util.zip.InflaterInputStream;
import acr.browser.lightning.utils.Utils;
/** /**
* Class to fetch articles. This class is thread safe. * Class to fetch articles. This class is thread safe.
* *
@ -49,7 +51,11 @@ public class HtmlFetcher {
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new FileReader("urls.txt")); BufferedReader reader = null;
BufferedWriter writer = null;
try {
reader = new BufferedReader(new FileReader("urls.txt"));
String line; String line;
Set<String> existing = new LinkedHashSet<>(); Set<String> existing = new LinkedHashSet<>();
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
@ -66,11 +72,13 @@ public class HtmlFetcher {
String html = new HtmlFetcher().fetchAsString(url, 2000); String html = new HtmlFetcher().fetchAsString(url, 2000);
String outFile = domainStr + counterStr + ".html"; String outFile = domainStr + counterStr + ".html";
BufferedWriter writer = new BufferedWriter(new FileWriter(outFile)); writer = new BufferedWriter(new FileWriter(outFile));
writer.write(html); writer.write(html);
writer.close();
} }
reader.close(); } finally {
Utils.close(reader);
Utils.close(writer);
}
} }
private String referrer = "http://jetsli.de/crawler"; private String referrer = "http://jetsli.de/crawler";

1
app/src/main/java/acr/browser/lightning/utils/AdBlock.java

@ -15,7 +15,6 @@ import java.util.Set;
import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.constant.Constants; import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.preference.PreferenceManager;
public class AdBlock { public class AdBlock {

1
app/src/main/java/acr/browser/lightning/utils/IntentUtils.java

@ -2,7 +2,6 @@ package acr.browser.lightning.utils;
import android.app.Activity; import android.app.Activity;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;

1
app/src/main/java/acr/browser/lightning/utils/WebUtils.java

@ -11,7 +11,6 @@ import android.webkit.WebView;
import android.webkit.WebViewDatabase; import android.webkit.WebViewDatabase;
import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.database.HistoryDatabase;
/** /**
* Copyright 8/4/2015 Anthony Restaino * Copyright 8/4/2015 Anthony Restaino

2
app/src/main/java/acr/browser/lightning/view/LightningChromeClient.java

@ -231,8 +231,8 @@ class LightningChromeClient extends WebChromeClient {
super.onShowCustomView(view, callback); super.onShowCustomView(view, callback);
} }
@SuppressWarnings("deprecation")
@Override @Override
@Deprecated
public void onShowCustomView(View view, int requestedOrientation, public void onShowCustomView(View view, int requestedOrientation,
CustomViewCallback callback) { CustomViewCallback callback) {
// While these lines might look like they work, in practice, // While these lines might look like they work, in practice,

41
app/src/main/java/acr/browser/lightning/view/LightningView.java

@ -4,7 +4,6 @@
package acr.browser.lightning.view; package acr.browser.lightning.view;
import android.Manifest;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
@ -36,13 +35,9 @@ import com.squareup.otto.Bus;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import javax.inject.Inject; import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import acr.browser.lightning.R; import acr.browser.lightning.R;
import acr.browser.lightning.activity.BrowserActivity; import acr.browser.lightning.activity.BrowserActivity;
import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.app.BrowserApp;
@ -53,7 +48,6 @@ import acr.browser.lightning.constant.StartPage;
import acr.browser.lightning.dialog.LightningDialogBuilder; import acr.browser.lightning.dialog.LightningDialogBuilder;
import acr.browser.lightning.download.LightningDownloadListener; import acr.browser.lightning.download.LightningDownloadListener;
import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.utils.PermissionsManager;
import acr.browser.lightning.utils.ProxyUtils; import acr.browser.lightning.utils.ProxyUtils;
import acr.browser.lightning.utils.ThemeUtils; import acr.browser.lightning.utils.ThemeUtils;
import acr.browser.lightning.utils.Utils; import acr.browser.lightning.utils.Utils;
@ -80,18 +74,16 @@ public class LightningView {
0, 0, -1.0f, 0, 255, // blue 0, 0, -1.0f, 0, 255, // blue
0, 0, 0, 1.0f, 0 // alpha 0, 0, 0, 1.0f, 0 // alpha
}; };
private final PermissionsManager mPermissionsManager; private final WebViewHandler mWebViewHandler = new WebViewHandler();
private static final String[] PERMISSIONS = new String[]{Manifest.permission.ACCESS_FINE_LOCATION};
private final WebViewHandler webViewHandler = new WebViewHandler();
@Inject @Inject
Bus eventBus; Bus mEventBus;
@Inject @Inject
PreferenceManager mPreferences; PreferenceManager mPreferences;
@Inject @Inject
LightningDialogBuilder bookmarksDialogBuilder; LightningDialogBuilder mBookmarksDialogBuilder;
@SuppressLint("NewApi") @SuppressLint("NewApi")
public LightningView(BrowserActivity activity, String url, boolean darkTheme, boolean isIncognito) { public LightningView(BrowserActivity activity, String url, boolean darkTheme, boolean isIncognito) {
@ -100,7 +92,6 @@ public class LightningView {
mWebView = new WebView(activity); mWebView = new WebView(activity);
mIsIncognitoTab = isIncognito; mIsIncognitoTab = isIncognito;
mTitle = new LightningViewTitle(activity, darkTheme); mTitle = new LightningViewTitle(activity, darkTheme);
mPermissionsManager = PermissionsManager.getInstance();
mMaxFling = ViewConfiguration.get(activity).getScaledMaximumFlingVelocity(); mMaxFling = ViewConfiguration.get(activity).getScaledMaximumFlingVelocity();
@ -410,7 +401,7 @@ public class LightningView {
public void setForegroundTab(boolean isForeground) { public void setForegroundTab(boolean isForeground) {
isForegroundTab = isForeground; isForegroundTab = isForeground;
eventBus.post(new BrowserEvents.TabsChanged()); mEventBus.post(new BrowserEvents.TabsChanged());
} }
public boolean isForegroundTab() { public boolean isForegroundTab() {
@ -568,7 +559,7 @@ public class LightningView {
} }
} }
public String getUserAgent() { private String getUserAgent() {
if (mWebView != null) { if (mWebView != null) {
return mWebView.getSettings().getUserAgentString(); return mWebView.getSettings().getUserAgentString();
} else { } else {
@ -620,36 +611,36 @@ public class LightningView {
if (currentUrl != null && currentUrl.startsWith(Constants.FILE)) { if (currentUrl != null && currentUrl.startsWith(Constants.FILE)) {
if (currentUrl.endsWith(HistoryPage.FILENAME)) { if (currentUrl.endsWith(HistoryPage.FILENAME)) {
if (url != null) { if (url != null) {
bookmarksDialogBuilder.showLongPressedHistoryLinkDialog(mActivity, url); mBookmarksDialogBuilder.showLongPressedHistoryLinkDialog(mActivity, url);
} else if (result != null && result.getExtra() != null) { } else if (result != null && result.getExtra() != null) {
final String newUrl = result.getExtra(); final String newUrl = result.getExtra();
bookmarksDialogBuilder.showLongPressedHistoryLinkDialog(mActivity, newUrl); mBookmarksDialogBuilder.showLongPressedHistoryLinkDialog(mActivity, newUrl);
} }
} else if (currentUrl.endsWith(Constants.BOOKMARKS_FILENAME)) { } else if (currentUrl.endsWith(Constants.BOOKMARKS_FILENAME)) {
if (url != null) { if (url != null) {
bookmarksDialogBuilder.showLongPressedDialogForBookmarkUrl(mActivity, url); mBookmarksDialogBuilder.showLongPressedDialogForBookmarkUrl(mActivity, url);
} else if (result != null && result.getExtra() != null) { } else if (result != null && result.getExtra() != null) {
final String newUrl = result.getExtra(); final String newUrl = result.getExtra();
bookmarksDialogBuilder.showLongPressedDialogForBookmarkUrl(mActivity, newUrl); mBookmarksDialogBuilder.showLongPressedDialogForBookmarkUrl(mActivity, newUrl);
} }
} }
} else { } else {
if (url != null) { if (url != null) {
if (result != null) { if (result != null) {
if (result.getType() == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE || result.getType() == WebView.HitTestResult.IMAGE_TYPE) { if (result.getType() == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE || result.getType() == WebView.HitTestResult.IMAGE_TYPE) {
bookmarksDialogBuilder.showLongPressImageDialog(mActivity, url, getUserAgent()); mBookmarksDialogBuilder.showLongPressImageDialog(mActivity, url, getUserAgent());
} else { } else {
bookmarksDialogBuilder.showLongPressLinkDialog(mActivity, url); mBookmarksDialogBuilder.showLongPressLinkDialog(mActivity, url);
} }
} else { } else {
bookmarksDialogBuilder.showLongPressLinkDialog(mActivity, url); mBookmarksDialogBuilder.showLongPressLinkDialog(mActivity, url);
} }
} else if (result != null && result.getExtra() != null) { } else if (result != null && result.getExtra() != null) {
final String newUrl = result.getExtra(); final String newUrl = result.getExtra();
if (result.getType() == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE || result.getType() == WebView.HitTestResult.IMAGE_TYPE) { if (result.getType() == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE || result.getType() == WebView.HitTestResult.IMAGE_TYPE) {
bookmarksDialogBuilder.showLongPressImageDialog(mActivity, newUrl, getUserAgent()); mBookmarksDialogBuilder.showLongPressImageDialog(mActivity, newUrl, getUserAgent());
} else { } else {
bookmarksDialogBuilder.showLongPressLinkDialog(mActivity, newUrl); mBookmarksDialogBuilder.showLongPressLinkDialog(mActivity, newUrl);
} }
} }
} }
@ -754,9 +745,9 @@ public class LightningView {
@Override @Override
public void onLongPress(MotionEvent e) { public void onLongPress(MotionEvent e) {
if (mCanTriggerLongPress) { if (mCanTriggerLongPress) {
Message msg = webViewHandler.obtainMessage(); Message msg = mWebViewHandler.obtainMessage();
if (msg != null) { if (msg != null) {
msg.setTarget(webViewHandler); msg.setTarget(mWebViewHandler);
mWebView.requestFocusNodeHref(msg); mWebView.requestFocusNodeHref(msg);
} }
} }

2
app/src/main/java/acr/browser/lightning/view/LightningViewTitle.java

@ -60,7 +60,7 @@ class LightningViewTitle {
return mFavicon; return mFavicon;
} }
public Bitmap getDefaultIcon() { public static Bitmap getDefaultIcon() {
return DEFAULT_ICON; return DEFAULT_ICON;
} }
} }

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

@ -27,6 +27,8 @@ import com.squareup.otto.Bus;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import acr.browser.lightning.R; import acr.browser.lightning.R;
import acr.browser.lightning.activity.BrowserActivity; import acr.browser.lightning.activity.BrowserActivity;
@ -42,7 +44,7 @@ import acr.browser.lightning.utils.Utils;
* @author Stefano Pacifici based on Anthony C. Restaino's code * @author Stefano Pacifici based on Anthony C. Restaino's code
* @date 2015/09/22 * @date 2015/09/22
*/ */
public class LightningWebClient extends WebViewClient { class LightningWebClient extends WebViewClient {
private final BrowserActivity mActivity; private final BrowserActivity mActivity;
private final LightningView mLightningView; private final LightningView mLightningView;
@ -70,6 +72,7 @@ public class LightningWebClient extends WebViewClient {
return super.shouldInterceptRequest(view, request); return super.shouldInterceptRequest(view, request);
} }
@SuppressWarnings("deprecation")
@Override @Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) { public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
if (mAdBlock.isAd(url)) { if (mAdBlock.isAd(url)) {
@ -180,11 +183,45 @@ public class LightningWebClient extends WebViewClient {
} }
} }
private static List<Integer> getAllSslErrorMessageCodes(SslError error) {
List<Integer> errorCodeMessageCodes = new ArrayList<>();
if (error.hasError(SslError.SSL_DATE_INVALID)) {
errorCodeMessageCodes.add(R.string.message_certificate_date_invalid);
}
if (error.hasError(SslError.SSL_EXPIRED)) {
errorCodeMessageCodes.add(R.string.message_certificate_expired);
}
if (error.hasError(SslError.SSL_IDMISMATCH)) {
errorCodeMessageCodes.add(R.string.message_certificate_domain_mismatch);
}
if (error.hasError(SslError.SSL_NOTYETVALID)) {
errorCodeMessageCodes.add(R.string.message_certificate_not_yet_valid);
}
if (error.hasError(SslError.SSL_UNTRUSTED)) {
errorCodeMessageCodes.add(R.string.message_certificate_untrusted);
}
if (error.hasError(SslError.SSL_INVALID)) {
errorCodeMessageCodes.add(R.string.message_certificate_invalid);
}
return errorCodeMessageCodes;
}
@Override @Override
public void onReceivedSslError(WebView view, @NonNull final SslErrorHandler handler, SslError error) { public void onReceivedSslError(WebView view, @NonNull final SslErrorHandler handler, SslError error) {
List<Integer> errorCodeMessageCodes = getAllSslErrorMessageCodes(error);
StringBuilder stringBuilder = new StringBuilder();
for (Integer messageCode : errorCodeMessageCodes) {
stringBuilder.append(" - ").append(mActivity.getString(messageCode)).append('\n');
}
String alertMessage =
mActivity.getString(R.string.message_insecure_connection, stringBuilder.toString());
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
builder.setTitle(mActivity.getString(R.string.title_warning)); builder.setTitle(mActivity.getString(R.string.title_warning));
builder.setMessage(mActivity.getString(R.string.message_untrusted_certificate)) builder.setMessage(alertMessage)
.setCancelable(true) .setCancelable(true)
.setPositiveButton(mActivity.getString(R.string.action_yes), .setPositiveButton(mActivity.getString(R.string.action_yes),
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@ -200,13 +237,7 @@ public class LightningWebClient extends WebViewClient {
handler.cancel(); handler.cancel();
} }
}); });
AlertDialog alert = builder.create(); builder.create().show();
if (error.getPrimaryError() == SslError.SSL_UNTRUSTED) {
alert.show();
} else {
handler.proceed();
}
} }
@Override @Override
@ -219,7 +250,6 @@ public class LightningWebClient extends WebViewClient {
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
resend.sendToTarget(); resend.sendToTarget();
} }
}) })
@ -227,7 +257,6 @@ public class LightningWebClient extends WebViewClient {
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
dontResend.sendToTarget(); dontResend.sendToTarget();
} }
}); });

Loading…
Cancel
Save