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.
This commit is contained in:
parent
097e127407
commit
0b2ba8fbf3
@ -280,14 +280,48 @@ public class LightningWebClient extends WebViewClient {
|
|||||||
|
|
||||||
Map<String, String> headers = mLightningView.getRequestHeaders();
|
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 (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);
|
view.loadUrl(url, headers);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (url.startsWith("about:") && Utils.doesSupportHeaders()) {
|
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);
|
view.loadUrl(url, headers);
|
||||||
return true;
|
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(),
|
||||||
@ -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…
x
Reference in New Issue
Block a user