Browse Source

Protect incognito activity from intents, clean up some code analysis warnings, simplify LightningView settings methods

master
Anthony Restaino 9 years ago
parent
commit
a60ae614d9
  1. 5
      app/src/main/java/acr/browser/lightning/activity/IncognitoActivity.java
  2. 42
      app/src/main/java/acr/browser/lightning/activity/TabsManager.java
  3. 13
      app/src/main/java/acr/browser/lightning/app/AppComponent.java
  4. 5
      app/src/main/java/acr/browser/lightning/utils/Utils.java
  5. 18
      app/src/main/java/acr/browser/lightning/view/LightningView.java
  6. 4
      app/src/main/res/values/styles.xml

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

@ -22,11 +22,6 @@ public class IncognitoActivity extends BrowserActivity { @@ -22,11 +22,6 @@ public class IncognitoActivity extends BrowserActivity {
cookieManager.setAcceptCookie(mPreferences.getIncognitoCookiesEnabled());
}
// @Override
// public synchronized void initializeTabs() {
// newTab(null, true);
// }
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.incognito, menu);

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

@ -43,22 +43,37 @@ public class TabsManager { @@ -43,22 +43,37 @@ public class TabsManager {
@Inject
public TabsManager() {}
/**
* Restores old tabs that were open before the browser
* was closed. Handles the intent used to open the browser.
*
* @param activity the activity needed to create tabs.
* @param intent the intent that started the browser activity.
* @param incognito whether or not we are in incognito mode.
*/
public synchronized void restoreTabsAndHandleIntent(final Activity activity,
final Intent intent,
final boolean incognito) {
// If incognito, only create one tab, do not handle intent
// in order to protect user privacy
if (incognito && mWebViewList.isEmpty()) {
newTab(activity, null, true);
return;
}
String url = null;
if (intent != null) {
url = intent.getDataString();
}
mWebViewList.clear();
mCurrentTab = null;
if (!incognito && mPreferenceManager.getRestoreLostTabsEnabled()) {
if (mPreferenceManager.getRestoreLostTabsEnabled()) {
final String mem = mPreferenceManager.getMemoryUrl();
mPreferenceManager.setMemoryUrl("");
String[] array = Utils.getArray(mem);
for (String urlString : array) {
if (!urlString.isEmpty()) {
newTab(activity, urlString, incognito);
newTab(activity, urlString, false);
}
}
}
@ -73,29 +88,19 @@ public class TabsManager { @@ -73,29 +88,19 @@ public class TabsManager {
.setPositiveButton(R.string.action_open, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
newTab(activity, urlToLoad, incognito);
newTab(activity, urlToLoad, false);
}
})
.show();
} else {
newTab(activity, url, incognito);
newTab(activity, url, false);
}
}
if (mWebViewList.size() == 0) {
newTab(activity, null, incognito);
newTab(activity, null, false);
}
}
/**
* Return a clone of the current tabs list. The list will not be updated, the user has to fetch
* a new copy when notified.
*
* @return a copy of the current tabs list
*/
public List<LightningView> getTabsList() {
return new ArrayList<>(mWebViewList);
}
/**
* Return the tab at the given position in tabs list, or null if position is not in tabs list
* range.
@ -139,7 +144,7 @@ public class TabsManager { @@ -139,7 +144,7 @@ public class TabsManager {
*/
public synchronized void resume(final Context context) {
for (LightningView tab : mWebViewList) {
tab.initializePreferences(null, context);
tab.initializePreferences(context);
}
}
@ -185,7 +190,6 @@ public class TabsManager { @@ -185,7 +190,6 @@ public class TabsManager {
*
* @param position The position of the tab to remove
*/
@Nullable
private synchronized void removeTab(final int position) {
if (position >= mWebViewList.size()) {
return;
@ -205,7 +209,7 @@ public class TabsManager { @@ -205,7 +209,7 @@ public class TabsManager {
if (current == position) {
if (size() == 1) {
mCurrentTab = null;
} else if (current < size() - 1 ) {
} else if (current < size() - 1) {
// There is another tab after this one
mCurrentTab = getTabAtPosition(current + 1);
} else {
@ -231,7 +235,7 @@ public class TabsManager { @@ -231,7 +235,7 @@ public class TabsManager {
* @return A string representation of the currently opened tabs
*/
public String tabsString() {
final StringBuilder builder = new StringBuilder();
final StringBuilder builder = new StringBuilder(mWebViewList.size());
for (LightningView tab : mWebViewList) {
final String url = tab.getUrl();
if (!url.isEmpty()) {

13
app/src/main/java/acr/browser/lightning/app/AppComponent.java

@ -1,7 +1,5 @@ @@ -1,7 +1,5 @@
package acr.browser.lightning.app;
import android.content.Context;
import com.squareup.otto.Bus;
import javax.inject.Singleton;
@ -38,19 +36,18 @@ public interface AppComponent { @@ -38,19 +36,18 @@ public interface AppComponent {
void inject(TabsFragment fragment);
PreferenceManager getPreferenceManager();
void inject(LightningView lightningView);
void inject(ThemableBrowserActivity activity);
void inject(LightningPreferenceFragment fragment);
PreferenceManager getPreferenceManager();
BookmarkPage getBookmarkPage();
Bus getBus();
HistoryDatabase getHistoryDatabase();
Context getApplicationContext();
void inject(LightningView lightningView);
void inject(ThemableBrowserActivity activity);
}

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

@ -194,11 +194,6 @@ public final class Utils { @@ -194,11 +194,6 @@ public final class Utils {
return domain.startsWith("www.") ? domain.substring(4) : domain;
}
public static String getProtocol(String url) {
int index = url.indexOf('/');
return url.substring(0, index + 2);
}
public static String[] getArray(String input) {
return input.split(Constants.SEPARATOR);
}

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

@ -136,8 +136,8 @@ public class LightningView { @@ -136,8 +136,8 @@ public class LightningView {
mGestureDetector = new GestureDetector(activity, new CustomGestureListener());
mWebView.setOnTouchListener(new TouchListener());
mDefaultUserAgent = mWebView.getSettings().getUserAgentString();
initializeSettings(mWebView.getSettings());
initializePreferences(mWebView.getSettings(), activity);
initializeSettings();
initializePreferences(activity);
if (url != null) {
if (!url.trim().isEmpty()) {
@ -233,19 +233,17 @@ public class LightningView { @@ -233,19 +233,17 @@ public class LightningView {
* Initialize the preference driven settings of the WebView. This method
* must be called whenever the preferences are changed within SharedPreferences.
*
* @param settings the WebSettings object to use, you can pass in null
* if you don't have a reference to them.
* @param context the context in which the WebView was created, it is used
* to get the default UserAgent for the WebView.
*/
@SuppressLint({"NewApi", "SetJavaScriptEnabled"})
public synchronized void initializePreferences(@Nullable WebSettings settings, Context context) {
if (settings == null && mWebView == null) {
public synchronized void initializePreferences(Context context) {
if (mWebView == null) {
return;
} else if (settings == null) {
settings = mWebView.getSettings();
}
WebSettings settings = mWebView.getSettings();
if (mPreferences.getDoNotTrackEnabled()) {
mRequestHeaders.put(HEADER_DNT, "1");
} else {
@ -365,10 +363,10 @@ public class LightningView { @@ -365,10 +363,10 @@ public class LightningView {
* Initialize the settings of the WebView that are intrinsic to Lightning and cannot
* be altered by the user. Distinguish between Incognito and Regular tabs here.
*
* @param settings the WebSettings object to use.
*/
@SuppressLint("NewApi")
private void initializeSettings(WebSettings settings) {
private void initializeSettings() {
WebSettings settings = mWebView.getSettings();
if (API < Build.VERSION_CODES.JELLY_BEAN_MR2) {
//noinspection deprecation
settings.setAppCacheMaxSize(Long.MAX_VALUE);

4
app/src/main/res/values/styles.xml

@ -125,8 +125,4 @@ @@ -125,8 +125,4 @@
<item name="android:textStyle">normal</item>
</style>
<style name="TwoWayView">
<item name="android:orientation">horizontal</item>
</style>
</resources>
Loading…
Cancel
Save