use of android.webkit.RenderProcessGoneDetail in project android-browser-helper by GoogleChrome.
the class WebViewFallbackActivity method createWebViewClient.
private WebViewClient createWebViewClient() {
return new WebViewClient() {
@Override
public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail) {
ViewGroup vg = (ViewGroup) view.getParent();
// Remove crashed WebView from the hierarchy
// and ensure it is destroyed.
vg.removeView(view);
view.destroy();
// Create a new instance, and ensure it also
// handles crashes - in this case, re-using
// the current WebViewClient
mWebView = new WebView(view.getContext());
mWebView.setWebViewClient(this);
WebSettings webSettings = mWebView.getSettings();
setupWebSettings(webSettings);
vg.addView(mWebView);
// With the crash recovered, decide what to do next.
// We are sending a toast and loading the origin
// URL, in this example.
Toast.makeText(view.getContext(), "Recovering from crash", Toast.LENGTH_LONG).show();
mWebView.loadUrl(mLaunchUrl.toString());
return true;
}
private boolean shouldOverrideUrlLoading(Uri navigationUrl) {
Uri launchUrl = WebViewFallbackActivity.this.mLaunchUrl;
// usage
if (!"data".equals(navigationUrl.getScheme()) && !uriOriginsMatch(navigationUrl, launchUrl) && !matchExtraOrigins(navigationUrl)) {
// to try to handle it.
try {
CustomTabsIntent intent = new CustomTabsIntent.Builder().setToolbarColor(mStatusBarColor).build();
intent.launchUrl(WebViewFallbackActivity.this, navigationUrl);
return true;
} catch (ActivityNotFoundException ex) {
Log.e(TAG, String.format("ActivityNotFoundException while launching '%s'", navigationUrl));
return false;
}
}
return false;
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return this.shouldOverrideUrlLoading(Uri.parse(url));
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
return this.shouldOverrideUrlLoading(request.getUrl());
}
private boolean matchExtraOrigins(Uri navigationUri) {
for (Uri uri : mExtraOrigins) {
if (uriOriginsMatch(uri, navigationUri)) {
return true;
}
}
return false;
}
private boolean uriOriginsMatch(Uri uriA, Uri uriB) {
return uriA.getScheme().equalsIgnoreCase(uriB.getScheme()) && uriA.getHost().equalsIgnoreCase(uriB.getHost()) && uriA.getPort() == uriB.getPort();
}
};
}
use of android.webkit.RenderProcessGoneDetail in project Anki-Android by ankidroid.
the class OnRenderProcessGoneDelegateTest method getCrashDetail.
protected RenderProcessGoneDetail getCrashDetail() {
RenderProcessGoneDetail mock = mock(RenderProcessGoneDetail.class);
// this value doesn't matter for now as it only defines a string
when(mock.didCrash()).thenReturn(true);
return mock;
}
Aggregations