Browse Source

Fixed new bug where browser wouldn't close on new intent. Fixed potential vuln in downloading code. Formatted some code.

master
Anthony Restaino 9 years ago
parent
commit
e707e338ef
  1. 3
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  2. 11
      app/src/main/java/acr/browser/lightning/app/BrowserApp.java
  3. 6
      app/src/main/java/acr/browser/lightning/download/DownloadHandler.java
  4. 7
      app/src/main/java/acr/browser/lightning/download/LightningDownloadListener.java

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

@ -992,6 +992,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
mPreferences.setSavedUrl(tabToDelete.getUrl()); mPreferences.setSavedUrl(tabToDelete.getUrl());
} }
final boolean isShown = tabToDelete.isShown(); final boolean isShown = tabToDelete.isShown();
boolean shouldClose = mIsNewIntent && isShown;
if (isShown) { if (isShown) {
mBrowserFrame.setBackgroundColor(mBackgroundColor); mBrowserFrame.setBackgroundColor(mBackgroundColor);
} }
@ -1031,7 +1032,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
} }
mEventBus.post(new BrowserEvents.TabsChanged()); mEventBus.post(new BrowserEvents.TabsChanged());
if (mIsNewIntent && isShown) { if (shouldClose) {
mIsNewIntent = false; mIsNewIntent = false;
closeActivity(); closeActivity();
} }

11
app/src/main/java/acr/browser/lightning/app/BrowserApp.java

@ -7,19 +7,24 @@ import com.squareup.leakcanary.LeakCanary;
public class BrowserApp extends Application { public class BrowserApp extends Application {
private static Context context; private static Context sContext;
private static AppComponent appComponent; private static AppComponent appComponent;
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
context = getApplicationContext();
LeakCanary.install(this); LeakCanary.install(this);
buildDepencyGraph(); buildDepencyGraph();
} }
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
sContext = base;
}
public static Context getAppContext() { public static Context getAppContext() {
return context; return sContext;
} }
public static AppComponent getAppComponent() { public static AppComponent getAppComponent() {

6
app/src/main/java/acr/browser/lightning/download/DownloadHandler.java

@ -10,6 +10,7 @@ import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.net.Uri; import android.net.Uri;
import android.os.Build;
import android.os.Environment; import android.os.Environment;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.text.TextUtils; import android.text.TextUtils;
@ -63,6 +64,11 @@ public class DownloadHandler {
Intent intent = new Intent(Intent.ACTION_VIEW); Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(url), mimetype); intent.setDataAndType(Uri.parse(url), mimetype);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setComponent(null);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
intent.setSelector(null);
}
ResolveInfo info = context.getPackageManager().resolveActivity(intent, ResolveInfo info = context.getPackageManager().resolveActivity(intent,
PackageManager.MATCH_DEFAULT_ONLY); PackageManager.MATCH_DEFAULT_ONLY);
if (info != null) { if (info != null) {

7
app/src/main/java/acr/browser/lightning/download/LightningDownloadListener.java

@ -26,8 +26,9 @@ public class LightningDownloadListener implements DownloadListener {
@Override @Override
public void onDownloadStart(final String url, final String userAgent, public void onDownloadStart(final String url, final String userAgent,
final String contentDisposition, final String mimetype, long contentLength) { final String contentDisposition, final String mimetype, long contentLength) {
PermissionsManager.getInstance().requestPermissionsIfNecessaryForResult(mActivity, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, PermissionsManager.getInstance().requestPermissionsIfNecessaryForResult(mActivity,
Manifest.permission.WRITE_EXTERNAL_STORAGE}, new PermissionsManager.PermissionResult() { new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE},
new PermissionsManager.PermissionResult() {
@Override @Override
public void onGranted() { public void onGranted() {
String fileName = URLUtil.guessFileName(url, contentDisposition, mimetype); String fileName = URLUtil.guessFileName(url, contentDisposition, mimetype);
@ -61,7 +62,5 @@ public class LightningDownloadListener implements DownloadListener {
//TODO show message //TODO show message
} }
}); });
} }
} }

Loading…
Cancel
Save