Browse Source

Add workaround for occasionally buggy header loading code

If custom headers (block identifying headers and DNT) are not being
used, we call super. This way, if the user turns on those options and
experiences problems on a site, they can turn off the option so that the
site works correctly.
master
Anthony Restaino 8 years ago
parent
commit
0b2ba8fbf3
  1. 158
      app/src/main/java/acr/browser/lightning/view/LightningWebClient.java

158
app/src/main/java/acr/browser/lightning/view/LightningWebClient.java

@ -101,7 +101,7 @@ public class LightningWebClient extends WebViewClient {
mLightningView.getTitleInfo().setTitle(view.getTitle()); mLightningView.getTitleInfo().setTitle(view.getTitle());
} }
if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT && if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT &&
mLightningView.getInvertePage()) { mLightningView.getInvertePage()) {
view.evaluateJavascript(Constants.JAVASCRIPT_INVERT_PAGE, null); view.evaluateJavascript(Constants.JAVASCRIPT_INVERT_PAGE, null);
} }
mUIController.tabChanged(mLightningView); mUIController.tabChanged(mLightningView);
@ -139,24 +139,24 @@ public class LightningWebClient extends WebViewClient {
builder.setTitle(mActivity.getString(R.string.title_sign_in)); builder.setTitle(mActivity.getString(R.string.title_sign_in));
builder.setView(passLayout); builder.setView(passLayout);
builder.setCancelable(true) builder.setCancelable(true)
.setPositiveButton(mActivity.getString(R.string.title_sign_in), .setPositiveButton(mActivity.getString(R.string.title_sign_in),
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
String user = name.getText().toString(); String user = name.getText().toString();
String pass = password.getText().toString(); String pass = password.getText().toString();
handler.proceed(user.trim(), pass.trim()); handler.proceed(user.trim(), pass.trim());
Log.d(Constants.TAG, "Request Login"); Log.d(Constants.TAG, "Request Login");
} }
}) })
.setNegativeButton(mActivity.getString(R.string.action_cancel), .setNegativeButton(mActivity.getString(R.string.action_cancel),
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
handler.cancel(); handler.cancel();
} }
}); });
AlertDialog alert = builder.create(); AlertDialog alert = builder.create();
alert.show(); alert.show();
@ -169,7 +169,7 @@ public class LightningWebClient extends WebViewClient {
@Override @Override
public void onScaleChanged(@NonNull final WebView view, final float oldScale, final float newScale) { public void onScaleChanged(@NonNull final WebView view, final float oldScale, final float newScale) {
if (view.isShown() && mLightningView.mPreferences.getTextReflowEnabled() && if (view.isShown() && mLightningView.mPreferences.getTextReflowEnabled() &&
Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
if (mIsRunning) if (mIsRunning)
return; return;
if (Math.abs(mZoomScale - newScale) > 0.01f) { if (Math.abs(mZoomScale - newScale) > 0.01f) {
@ -223,26 +223,26 @@ public class LightningWebClient extends WebViewClient {
stringBuilder.append(" - ").append(mActivity.getString(messageCode)).append('\n'); stringBuilder.append(" - ").append(mActivity.getString(messageCode)).append('\n');
} }
String alertMessage = String alertMessage =
mActivity.getString(R.string.message_insecure_connection, stringBuilder.toString()); mActivity.getString(R.string.message_insecure_connection, stringBuilder.toString());
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
builder.setTitle(mActivity.getString(R.string.title_warning)); builder.setTitle(mActivity.getString(R.string.title_warning));
builder.setMessage(alertMessage) builder.setMessage(alertMessage)
.setCancelable(true) .setCancelable(true)
.setPositiveButton(mActivity.getString(R.string.action_yes), .setPositiveButton(mActivity.getString(R.string.action_yes),
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
handler.proceed(); handler.proceed();
} }
}) })
.setNegativeButton(mActivity.getString(R.string.action_no), .setNegativeButton(mActivity.getString(R.string.action_no),
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
handler.cancel(); handler.cancel();
} }
}); });
builder.create().show(); builder.create().show();
} }
@ -251,21 +251,21 @@ public class LightningWebClient extends WebViewClient {
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
builder.setTitle(mActivity.getString(R.string.title_form_resubmission)); builder.setTitle(mActivity.getString(R.string.title_form_resubmission));
builder.setMessage(mActivity.getString(R.string.message_form_resubmission)) builder.setMessage(mActivity.getString(R.string.message_form_resubmission))
.setCancelable(true) .setCancelable(true)
.setPositiveButton(mActivity.getString(R.string.action_yes), .setPositiveButton(mActivity.getString(R.string.action_yes),
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
resend.sendToTarget(); resend.sendToTarget();
} }
}) })
.setNegativeButton(mActivity.getString(R.string.action_no), .setNegativeButton(mActivity.getString(R.string.action_no),
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
dontResend.sendToTarget(); dontResend.sendToTarget();
} }
}); });
AlertDialog alert = builder.create(); AlertDialog alert = builder.create();
alert.show(); alert.show();
} }
@ -280,18 +280,52 @@ public class LightningWebClient extends WebViewClient {
Map<String, String> headers = mLightningView.getRequestHeaders(); Map<String, String> headers = mLightningView.getRequestHeaders();
if (mLightningView.isIncognito() && Utils.doesSupportHeaders()) { // If the headers are empty, the user has not expressed the desire
view.loadUrl(url, headers); // to use them and therefore we can revert back to the old way of loading
return true; if (headers.isEmpty()) {
} if (mLightningView.isIncognito()) {
if (url.startsWith("about:") && Utils.doesSupportHeaders()) { // If we are in incognito, immediately load, we don't want the url to leave the app
view.loadUrl(url, headers); return super.shouldOverrideUrlLoading(view, url);
return true; }
if (url.startsWith("about:")) {
// If this is an about page, immediately load, we don't need to leave the app
return super.shouldOverrideUrlLoading(view, url);
}
if (isMailOrIntent(url, view) || mIntentUtils.startActivityForUrl(view, url)) {
// If it was a mailto: link, or an intent, or could be launched elsewhere, do that
return true;
}
} else {
if (mLightningView.isIncognito() && Utils.doesSupportHeaders()) {
// If we are in incognito, immediately load, we don't want the url to leave the app
view.loadUrl(url, headers);
return true;
}
if (url.startsWith("about:") && Utils.doesSupportHeaders()) {
// If this is an about page, immediately load, we don't need to leave the app
view.loadUrl(url, headers);
return true;
}
if (isMailOrIntent(url, view) || mIntentUtils.startActivityForUrl(view, url)) {
// If it was a mailto: link, or an intent, or could be launched elsewhere, do that
return true;
} else if (Utils.doesSupportHeaders()) {
// Otherwise, load the headers.
view.loadUrl(url, headers);
return true;
}
} }
// If none of those instances was true, revert back to the old way of loading
return super.shouldOverrideUrlLoading(view, url);
}
private boolean isMailOrIntent(@NonNull String url, @NonNull WebView view) {
if (url.startsWith("mailto:")) { if (url.startsWith("mailto:")) {
MailTo mailTo = MailTo.parse(url); MailTo mailTo = MailTo.parse(url);
Intent i = Utils.newEmailIntent(mailTo.getTo(), mailTo.getSubject(), Intent i = Utils.newEmailIntent(mailTo.getTo(), mailTo.getSubject(),
mailTo.getBody(), mailTo.getCc()); mailTo.getBody(), mailTo.getCc());
mActivity.startActivity(i); mActivity.startActivity(i);
view.reload(); view.reload();
return true; return true;
@ -316,10 +350,6 @@ public class LightningWebClient extends WebViewClient {
return true; return true;
} }
} }
return false;
if (!mIntentUtils.startActivityForUrl(view, url) && Utils.doesSupportHeaders()) {
view.loadUrl(url, headers);
}
return Utils.doesSupportHeaders() || super.shouldOverrideUrlLoading(view, url);
} }
} }

Loading…
Cancel
Save