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. 40
      app/src/main/java/acr/browser/lightning/view/LightningWebClient.java

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

@ -280,14 +280,48 @@ public class LightningWebClient extends WebViewClient { @@ -280,14 +280,48 @@ public class LightningWebClient extends WebViewClient {
Map<String, String> headers = mLightningView.getRequestHeaders();
// If the headers are empty, the user has not expressed the desire
// to use them and therefore we can revert back to the old way of loading
if (headers.isEmpty()) {
if (mLightningView.isIncognito()) {
// If we are in incognito, immediately load, we don't want the url to leave the app
return super.shouldOverrideUrlLoading(view, url);
}
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:")) {
MailTo mailTo = MailTo.parse(url);
Intent i = Utils.newEmailIntent(mailTo.getTo(), mailTo.getSubject(),
@ -316,10 +350,6 @@ public class LightningWebClient extends WebViewClient { @@ -316,10 +350,6 @@ public class LightningWebClient extends WebViewClient {
return true;
}
}
if (!mIntentUtils.startActivityForUrl(view, url) && Utils.doesSupportHeaders()) {
view.loadUrl(url, headers);
}
return Utils.doesSupportHeaders() || super.shouldOverrideUrlLoading(view, url);
return false;
}
}

Loading…
Cancel
Save