Protect incognito activity from intents, clean up some code analysis warnings, simplify LightningView settings methods
This commit is contained in:
parent
46b1269730
commit
a60ae614d9
@ -22,11 +22,6 @@ public class IncognitoActivity extends BrowserActivity {
|
|||||||
cookieManager.setAcceptCookie(mPreferences.getIncognitoCookiesEnabled());
|
cookieManager.setAcceptCookie(mPreferences.getIncognitoCookiesEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
|
||||||
// public synchronized void initializeTabs() {
|
|
||||||
// newTab(null, true);
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
getMenuInflater().inflate(R.menu.incognito, menu);
|
getMenuInflater().inflate(R.menu.incognito, menu);
|
||||||
|
@ -43,22 +43,37 @@ public class TabsManager {
|
|||||||
@Inject
|
@Inject
|
||||||
public TabsManager() {}
|
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,
|
public synchronized void restoreTabsAndHandleIntent(final Activity activity,
|
||||||
final Intent intent,
|
final Intent intent,
|
||||||
final boolean incognito) {
|
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;
|
String url = null;
|
||||||
if (intent != null) {
|
if (intent != null) {
|
||||||
url = intent.getDataString();
|
url = intent.getDataString();
|
||||||
}
|
}
|
||||||
mWebViewList.clear();
|
mWebViewList.clear();
|
||||||
mCurrentTab = null;
|
mCurrentTab = null;
|
||||||
if (!incognito && mPreferenceManager.getRestoreLostTabsEnabled()) {
|
if (mPreferenceManager.getRestoreLostTabsEnabled()) {
|
||||||
final String mem = mPreferenceManager.getMemoryUrl();
|
final String mem = mPreferenceManager.getMemoryUrl();
|
||||||
mPreferenceManager.setMemoryUrl("");
|
mPreferenceManager.setMemoryUrl("");
|
||||||
String[] array = Utils.getArray(mem);
|
String[] array = Utils.getArray(mem);
|
||||||
for (String urlString : array) {
|
for (String urlString : array) {
|
||||||
if (!urlString.isEmpty()) {
|
if (!urlString.isEmpty()) {
|
||||||
newTab(activity, urlString, incognito);
|
newTab(activity, urlString, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,29 +88,19 @@ public class TabsManager {
|
|||||||
.setPositiveButton(R.string.action_open, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.action_open, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
newTab(activity, urlToLoad, incognito);
|
newTab(activity, urlToLoad, false);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.show();
|
.show();
|
||||||
} else {
|
} else {
|
||||||
newTab(activity, url, incognito);
|
newTab(activity, url, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mWebViewList.size() == 0) {
|
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
|
* Return the tab at the given position in tabs list, or null if position is not in tabs list
|
||||||
* range.
|
* range.
|
||||||
@ -139,7 +144,7 @@ public class TabsManager {
|
|||||||
*/
|
*/
|
||||||
public synchronized void resume(final Context context) {
|
public synchronized void resume(final Context context) {
|
||||||
for (LightningView tab : mWebViewList) {
|
for (LightningView tab : mWebViewList) {
|
||||||
tab.initializePreferences(null, context);
|
tab.initializePreferences(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,7 +190,6 @@ public class TabsManager {
|
|||||||
*
|
*
|
||||||
* @param position The position of the tab to remove
|
* @param position The position of the tab to remove
|
||||||
*/
|
*/
|
||||||
@Nullable
|
|
||||||
private synchronized void removeTab(final int position) {
|
private synchronized void removeTab(final int position) {
|
||||||
if (position >= mWebViewList.size()) {
|
if (position >= mWebViewList.size()) {
|
||||||
return;
|
return;
|
||||||
@ -205,7 +209,7 @@ public class TabsManager {
|
|||||||
if (current == position) {
|
if (current == position) {
|
||||||
if (size() == 1) {
|
if (size() == 1) {
|
||||||
mCurrentTab = null;
|
mCurrentTab = null;
|
||||||
} else if (current < size() - 1 ) {
|
} else if (current < size() - 1) {
|
||||||
// There is another tab after this one
|
// There is another tab after this one
|
||||||
mCurrentTab = getTabAtPosition(current + 1);
|
mCurrentTab = getTabAtPosition(current + 1);
|
||||||
} else {
|
} else {
|
||||||
@ -231,7 +235,7 @@ public class TabsManager {
|
|||||||
* @return A string representation of the currently opened tabs
|
* @return A string representation of the currently opened tabs
|
||||||
*/
|
*/
|
||||||
public String tabsString() {
|
public String tabsString() {
|
||||||
final StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder(mWebViewList.size());
|
||||||
for (LightningView tab : mWebViewList) {
|
for (LightningView tab : mWebViewList) {
|
||||||
final String url = tab.getUrl();
|
final String url = tab.getUrl();
|
||||||
if (!url.isEmpty()) {
|
if (!url.isEmpty()) {
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package acr.browser.lightning.app;
|
package acr.browser.lightning.app;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import com.squareup.otto.Bus;
|
import com.squareup.otto.Bus;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
@ -38,19 +36,18 @@ public interface AppComponent {
|
|||||||
|
|
||||||
void inject(TabsFragment fragment);
|
void inject(TabsFragment fragment);
|
||||||
|
|
||||||
PreferenceManager getPreferenceManager();
|
void inject(LightningView lightningView);
|
||||||
|
|
||||||
|
void inject(ThemableBrowserActivity activity);
|
||||||
|
|
||||||
void inject(LightningPreferenceFragment fragment);
|
void inject(LightningPreferenceFragment fragment);
|
||||||
|
|
||||||
|
PreferenceManager getPreferenceManager();
|
||||||
|
|
||||||
BookmarkPage getBookmarkPage();
|
BookmarkPage getBookmarkPage();
|
||||||
|
|
||||||
Bus getBus();
|
Bus getBus();
|
||||||
|
|
||||||
HistoryDatabase getHistoryDatabase();
|
HistoryDatabase getHistoryDatabase();
|
||||||
|
|
||||||
Context getApplicationContext();
|
|
||||||
|
|
||||||
void inject(LightningView lightningView);
|
|
||||||
|
|
||||||
void inject(ThemableBrowserActivity activity);
|
|
||||||
}
|
}
|
||||||
|
@ -194,11 +194,6 @@ public final class Utils {
|
|||||||
return domain.startsWith("www.") ? domain.substring(4) : domain;
|
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) {
|
public static String[] getArray(String input) {
|
||||||
return input.split(Constants.SEPARATOR);
|
return input.split(Constants.SEPARATOR);
|
||||||
}
|
}
|
||||||
|
@ -136,8 +136,8 @@ public class LightningView {
|
|||||||
mGestureDetector = new GestureDetector(activity, new CustomGestureListener());
|
mGestureDetector = new GestureDetector(activity, new CustomGestureListener());
|
||||||
mWebView.setOnTouchListener(new TouchListener());
|
mWebView.setOnTouchListener(new TouchListener());
|
||||||
mDefaultUserAgent = mWebView.getSettings().getUserAgentString();
|
mDefaultUserAgent = mWebView.getSettings().getUserAgentString();
|
||||||
initializeSettings(mWebView.getSettings());
|
initializeSettings();
|
||||||
initializePreferences(mWebView.getSettings(), activity);
|
initializePreferences(activity);
|
||||||
|
|
||||||
if (url != null) {
|
if (url != null) {
|
||||||
if (!url.trim().isEmpty()) {
|
if (!url.trim().isEmpty()) {
|
||||||
@ -233,19 +233,17 @@ public class LightningView {
|
|||||||
* Initialize the preference driven settings of the WebView. This method
|
* Initialize the preference driven settings of the WebView. This method
|
||||||
* must be called whenever the preferences are changed within SharedPreferences.
|
* must be called whenever the preferences are changed within SharedPreferences.
|
||||||
*
|
*
|
||||||
* @param settings the WebSettings object to use, you can pass in null
|
* @param context the context in which the WebView was created, it is used
|
||||||
* if you don't have a reference to them.
|
* to get the default UserAgent for the WebView.
|
||||||
* @param context the context in which the WebView was created, it is used
|
|
||||||
* to get the default UserAgent for the WebView.
|
|
||||||
*/
|
*/
|
||||||
@SuppressLint({"NewApi", "SetJavaScriptEnabled"})
|
@SuppressLint({"NewApi", "SetJavaScriptEnabled"})
|
||||||
public synchronized void initializePreferences(@Nullable WebSettings settings, Context context) {
|
public synchronized void initializePreferences(Context context) {
|
||||||
if (settings == null && mWebView == null) {
|
if (mWebView == null) {
|
||||||
return;
|
return;
|
||||||
} else if (settings == null) {
|
|
||||||
settings = mWebView.getSettings();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WebSettings settings = mWebView.getSettings();
|
||||||
|
|
||||||
if (mPreferences.getDoNotTrackEnabled()) {
|
if (mPreferences.getDoNotTrackEnabled()) {
|
||||||
mRequestHeaders.put(HEADER_DNT, "1");
|
mRequestHeaders.put(HEADER_DNT, "1");
|
||||||
} else {
|
} else {
|
||||||
@ -365,10 +363,10 @@ public class LightningView {
|
|||||||
* Initialize the settings of the WebView that are intrinsic to Lightning and cannot
|
* 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.
|
* be altered by the user. Distinguish between Incognito and Regular tabs here.
|
||||||
*
|
*
|
||||||
* @param settings the WebSettings object to use.
|
|
||||||
*/
|
*/
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
private void initializeSettings(WebSettings settings) {
|
private void initializeSettings() {
|
||||||
|
WebSettings settings = mWebView.getSettings();
|
||||||
if (API < Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
if (API < Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||||
//noinspection deprecation
|
//noinspection deprecation
|
||||||
settings.setAppCacheMaxSize(Long.MAX_VALUE);
|
settings.setAppCacheMaxSize(Long.MAX_VALUE);
|
||||||
|
@ -125,8 +125,4 @@
|
|||||||
<item name="android:textStyle">normal</item>
|
<item name="android:textStyle">normal</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="TwoWayView">
|
|
||||||
<item name="android:orientation">horizontal</item>
|
|
||||||
</style>
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
Loading…
x
Reference in New Issue
Block a user