Two related WebView hygiene issues in src/itkach/aard2/ArticleWebView.java.
1. loadUrl("javascript:...") (D06)
onPageStarted and onPageFinished inject the style switcher script using the legacy form:
view.loadUrl("javascript:" + styleSwitcherJs);
...
view.loadUrl("javascript:" + styleSwitcherJs +
";$SLOB.setStyleTitles($styleSwitcher.getTitles())");
loadUrl("javascript:...") was deprecated in Android 4.4 in favour of WebView.evaluateJavascript. The legacy form adds a navigation entry to the back/forward history, so the style bootstrap runs on every page event and pollutes the article view's back stack.
2. startActivity inside shouldOverrideUrlLoading without try/catch (U04)
if (isExternal(uri)) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, uri);
getContext().startActivity(browserIntent);
return true;
}
...
if (scheme.equals("http") && host.equals(LOCALHOST) && uri.getQueryParameter("blob") == null) {
Intent intent = new Intent(getContext(), ArticleCollectionActivity.class);
intent.setData(uri);
getContext().startActivity(intent);
...
}
If the device has no app registered to handle ACTION_VIEW for a given scheme (mailto:, tel:, custom schemes from dictionaries) the first startActivity raises ActivityNotFoundException and the host activity crashes. The internal ArticleCollectionActivity case is less likely to throw but is still theoretically reachable.
Suggested fix
- Swap both
loadUrl("javascript:..") calls to view.evaluateJavascript(script, null).
- Wrap the two
startActivity calls in try { ... } catch (ActivityNotFoundException e) { Log.w(...) }. The external case falls through silently (the user sees no app open). The internal case logs and returns false so the WebView keeps the existing page.
A PR is open at #211.
Two related WebView hygiene issues in
src/itkach/aard2/ArticleWebView.java.1.
loadUrl("javascript:...")(D06)onPageStartedandonPageFinishedinject the style switcher script using the legacy form:loadUrl("javascript:...")was deprecated in Android 4.4 in favour ofWebView.evaluateJavascript. The legacy form adds a navigation entry to the back/forward history, so the style bootstrap runs on every page event and pollutes the article view's back stack.2.
startActivityinsideshouldOverrideUrlLoadingwithout try/catch (U04)If the device has no app registered to handle
ACTION_VIEWfor a given scheme (mailto:,tel:, custom schemes from dictionaries) the firststartActivityraisesActivityNotFoundExceptionand the host activity crashes. The internalArticleCollectionActivitycase is less likely to throw but is still theoretically reachable.Suggested fix
loadUrl("javascript:..")calls toview.evaluateJavascript(script, null).startActivitycalls intry { ... } catch (ActivityNotFoundException e) { Log.w(...) }. The external case falls through silently (the user sees no app open). The internal case logs and returnsfalseso the WebView keeps the existing page.A PR is open at #211.