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

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

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

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

@ -10,6 +10,7 @@ import android.content.Intent; @@ -10,6 +10,7 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
@ -46,11 +47,11 @@ public class DownloadHandler { @@ -46,11 +47,11 @@ public class DownloadHandler {
* Notify the host application a download should be done, or that the data
* should be streamed if a streaming viewer is available.
*
* @param context The context in which the download was requested.
* @param url The full url to the content that should be downloaded
* @param userAgent User agent of the downloading application.
* @param contentDisposition Content-disposition http header, if present.
* @param mimetype The mimetype of the content reported by the server
* @param context The context in which the download was requested.
* @param url The full url to the content that should be downloaded
* @param userAgent User agent of the downloading application.
* @param contentDisposition Content-disposition http header, if present.
* @param mimetype The mimetype of the content reported by the server
*/
public static void onDownloadStart(Context context, String url, String userAgent,
String contentDisposition, String mimetype) {
@ -63,6 +64,11 @@ public class DownloadHandler { @@ -63,6 +64,11 @@ public class DownloadHandler {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(url), mimetype);
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,
PackageManager.MATCH_DEFAULT_ONLY);
if (info != null) {
@ -321,12 +327,12 @@ public class DownloadHandler { @@ -321,12 +327,12 @@ public class DownloadHandler {
} catch (IOException ignored) {
return false;
}
}
}
public static String addNecessarySlashes(String originalPath) {
if (originalPath == null || originalPath.length() == 0) {
return "/";
}
}
if (originalPath.charAt(originalPath.length() - 1) != '/') {
originalPath = originalPath + '/';
}

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

@ -26,42 +26,41 @@ public class LightningDownloadListener implements DownloadListener { @@ -26,42 +26,41 @@ public class LightningDownloadListener implements DownloadListener {
@Override
public void onDownloadStart(final String url, final String userAgent,
final String contentDisposition, final String mimetype, long contentLength) {
PermissionsManager.getInstance().requestPermissionsIfNecessaryForResult(mActivity, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE}, new PermissionsManager.PermissionResult() {
@Override
public void onGranted() {
String fileName = URLUtil.guessFileName(url, contentDisposition, mimetype);
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
PermissionsManager.getInstance().requestPermissionsIfNecessaryForResult(mActivity,
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE},
new PermissionsManager.PermissionResult() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
DownloadHandler.onDownloadStart(mActivity, url, userAgent,
contentDisposition, mimetype);
break;
public void onGranted() {
String fileName = URLUtil.guessFileName(url, contentDisposition, mimetype);
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
DownloadHandler.onDownloadStart(mActivity, url, userAgent,
contentDisposition, mimetype);
break;
case DialogInterface.BUTTON_NEGATIVE:
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
}
});
case DialogInterface.BUTTON_NEGATIVE:
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
}
});
}
}

Loading…
Cancel
Save