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. 20
      app/src/main/java/acr/browser/lightning/download/DownloadHandler.java
  4. 65
      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() {

20
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;
@ -46,11 +47,11 @@ public class DownloadHandler {
* Notify the host application a download should be done, or that the data * Notify the host application a download should be done, or that the data
* should be streamed if a streaming viewer is available. * should be streamed if a streaming viewer is available.
* *
* @param context The context in which the download was requested. * @param context The context in which the download was requested.
* @param url The full url to the content that should be downloaded * @param url The full url to the content that should be downloaded
* @param userAgent User agent of the downloading application. * @param userAgent User agent of the downloading application.
* @param contentDisposition Content-disposition http header, if present. * @param contentDisposition Content-disposition http header, if present.
* @param mimetype The mimetype of the content reported by the server * @param mimetype The mimetype of the content reported by the server
*/ */
public static void onDownloadStart(Context context, String url, String userAgent, public static void onDownloadStart(Context context, String url, String userAgent,
String contentDisposition, String mimetype) { String contentDisposition, String mimetype) {
@ -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) {
@ -321,12 +327,12 @@ public class DownloadHandler {
} catch (IOException ignored) { } catch (IOException ignored) {
return false; return false;
} }
} }
public static String addNecessarySlashes(String originalPath) { public static String addNecessarySlashes(String originalPath) {
if (originalPath == null || originalPath.length() == 0) { if (originalPath == null || originalPath.length() == 0) {
return "/"; return "/";
} }
if (originalPath.charAt(originalPath.length() - 1) != '/') { if (originalPath.charAt(originalPath.length() - 1) != '/') {
originalPath = originalPath + '/'; originalPath = originalPath + '/';
} }

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

@ -26,42 +26,41 @@ 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},
@Override new PermissionsManager.PermissionResult() {
public void onGranted() {
String fileName = URLUtil.guessFileName(url, contentDisposition, mimetype);
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onGranted() {
switch (which) { String fileName = URLUtil.guessFileName(url, contentDisposition, mimetype);
case DialogInterface.BUTTON_POSITIVE: DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
DownloadHandler.onDownloadStart(mActivity, url, userAgent, @Override
contentDisposition, mimetype); public void onClick(DialogInterface dialog, int which) {
break; switch (which) {
case DialogInterface.BUTTON_POSITIVE:
DownloadHandler.onDownloadStart(mActivity, url, userAgent,
contentDisposition, mimetype);
break;
case DialogInterface.BUTTON_NEGATIVE: case DialogInterface.BUTTON_NEGATIVE:
break; break;
} }
} }
}; };
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); // dialog
builder.setTitle(fileName)
.setMessage(mActivity.getResources().getString(R.string.dialog_download))
.setPositiveButton(mActivity.getResources().getString(R.string.action_download),
dialogClickListener)
.setNegativeButton(mActivity.getResources().getString(R.string.action_cancel),
dialogClickListener).show();
Log.i(Constants.TAG, "Downloading" + fileName);
}
@Override
public void onDenied(String permission) {
//TODO show message
}
});
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); // dialog
builder.setTitle(fileName)
.setMessage(mActivity.getResources().getString(R.string.dialog_download))
.setPositiveButton(mActivity.getResources().getString(R.string.action_download),
dialogClickListener)
.setNegativeButton(mActivity.getResources().getString(R.string.action_cancel),
dialogClickListener).show();
Log.i(Constants.TAG, "Downloading" + fileName);
}
@Override
public void onDenied(String permission) {
//TODO show message
}
});
} }
} }

Loading…
Cancel
Save