use of android.webkit.WebResourceError in project incubator-weex by apache.
the class WXWebView method initWebView.
private void initWebView(WebView wv) {
WebSettings settings = wv.getSettings();
settings.setJavaScriptEnabled(true);
settings.setAppCacheEnabled(true);
settings.setUseWideViewPort(true);
settings.setDomStorageEnabled(true);
settings.setSupportZoom(false);
settings.setBuiltInZoomControls(false);
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
WXLogUtils.v("tag", "onPageOverride " + url);
return true;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
WXLogUtils.v("tag", "onPageStarted " + url);
if (mOnPageListener != null) {
mOnPageListener.onPageStart(url);
}
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
WXLogUtils.v("tag", "onPageFinished " + url);
if (mOnPageListener != null) {
mOnPageListener.onPageFinish(url, view.canGoBack(), view.canGoForward());
}
if (mOnMessageListener != null) {
evaluateJS("javascript:(window.postMessage = function(message, targetOrigin) {" + "if (message == null || !targetOrigin) return;" + (DOWNGRADE_JS_INTERFACE ? "prompt('" + BRIDGE_NAME + "://postMessage?message=' + JSON.stringify(message) + '&targetOrigin=' + targetOrigin)" : BRIDGE_NAME + ".postMessage(JSON.stringify(message), targetOrigin);") + "})");
}
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
if (mOnErrorListener != null) {
// mOnErrorListener.onError("error", "page error code:" + error.getErrorCode() + ", desc:" + error.getDescription() + ", url:" + request.getUrl());
mOnErrorListener.onError("error", "page error");
}
}
@Override
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
super.onReceivedHttpError(view, request, errorResponse);
if (mOnErrorListener != null) {
mOnErrorListener.onError("error", "http error");
}
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
super.onReceivedSslError(view, handler, error);
if (mOnErrorListener != null) {
mOnErrorListener.onError("error", "ssl error");
}
}
});
wv.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
showWebView(newProgress == 100);
showProgressBar(newProgress != 100);
WXLogUtils.v("tag", "onPageProgressChanged " + newProgress);
}
@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
if (mOnPageListener != null) {
mOnPageListener.onReceivedTitle(view.getTitle());
}
}
@Override
public boolean onJsPrompt(WebView view, String url, String text, String defaultValue, JsPromptResult result) {
Uri uri = Uri.parse(text);
String scheme = uri.getScheme();
if (TextUtils.equals(scheme, BRIDGE_NAME)) {
if (TextUtils.equals(uri.getAuthority(), "postMessage")) {
String message = uri.getQueryParameter("message");
String targetOrigin = uri.getQueryParameter("targetOrigin");
onMessage(message, targetOrigin);
result.confirm("success");
} else {
result.confirm("fail");
}
return true;
}
return super.onJsPrompt(view, url, text, defaultValue, result);
}
});
if (!DOWNGRADE_JS_INTERFACE) {
wv.addJavascriptInterface(new Object() {
@JavascriptInterface
public void postMessage(String message, String targetOrigin) {
onMessage(message, targetOrigin);
}
}, BRIDGE_NAME);
}
}
use of android.webkit.WebResourceError in project incubator-weex by apache.
the class WXWebView method initWebView.
@SuppressLint({ "SetJavaScriptEnabled", "AddJavascriptInterface" })
private void initWebView(WebView wv) {
WebSettings settings = wv.getSettings();
settings.setJavaScriptEnabled(true);
settings.setAppCacheEnabled(true);
settings.setUseWideViewPort(true);
settings.setDomStorageEnabled(true);
settings.setSupportZoom(false);
settings.setBuiltInZoomControls(false);
settings.setAllowFileAccess(false);
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
WXLogUtils.v("tag", "onPageOverride " + url);
return true;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
WXLogUtils.v("tag", "onPageStarted " + url);
if (mOnPageListener != null) {
mOnPageListener.onPageStart(url);
}
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
WXLogUtils.v("tag", "onPageFinished " + url);
if (mOnPageListener != null) {
mOnPageListener.onPageFinish(url, view.canGoBack(), view.canGoForward());
}
if (mOnMessageListener != null) {
evaluateJS("javascript:(window.postMessage = function(message, targetOrigin) {" + "if (message == null || !targetOrigin) return;" + (DOWNGRADE_JS_INTERFACE ? "prompt('" + BRIDGE_NAME + "://postMessage?message=' + JSON.stringify(message) + '&targetOrigin=' + targetOrigin)" : BRIDGE_NAME + ".postMessage(JSON.stringify(message), targetOrigin);") + "})");
}
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
if (mOnErrorListener != null) {
// mOnErrorListener.onError("error", "page error code:" + error.getErrorCode() + ", desc:" + error.getDescription() + ", url:" + request.getUrl());
mOnErrorListener.onError("error", "page error");
}
}
@Override
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
super.onReceivedHttpError(view, request, errorResponse);
if (mOnErrorListener != null) {
mOnErrorListener.onError("error", "http error");
}
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
super.onReceivedSslError(view, handler, error);
if (mOnErrorListener != null) {
mOnErrorListener.onError("error", "ssl error");
}
}
});
wv.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
showWebView(newProgress == 100);
showProgressBar(newProgress != 100);
WXLogUtils.v("tag", "onPageProgressChanged " + newProgress);
}
@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
if (mOnPageListener != null) {
mOnPageListener.onReceivedTitle(view.getTitle());
}
}
@Override
public boolean onJsPrompt(WebView view, String url, String text, String defaultValue, JsPromptResult result) {
Uri uri = Uri.parse(text);
String scheme = uri.getScheme();
if (TextUtils.equals(scheme, BRIDGE_NAME)) {
if (TextUtils.equals(uri.getAuthority(), "postMessage")) {
String message = uri.getQueryParameter("message");
String targetOrigin = uri.getQueryParameter("targetOrigin");
onMessage(message, targetOrigin);
result.confirm("success");
} else {
result.confirm("fail");
}
return true;
}
return super.onJsPrompt(view, url, text, defaultValue, result);
}
});
if (!DOWNGRADE_JS_INTERFACE) {
wv.addJavascriptInterface(new Object() {
@JavascriptInterface
public void postMessage(String message, String targetOrigin) {
onMessage(message, targetOrigin);
}
}, BRIDGE_NAME);
}
}
use of android.webkit.WebResourceError in project AppCenter-SDK-Android by Microsoft.
the class MSALoginActivity method signIn.
@SuppressWarnings("unused")
public void signIn(View view) {
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
checkSignInCompletion(url);
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
failSignIn(errorCode, description);
}
@Override
@TargetApi(Build.VERSION_CODES.M)
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
failSignIn(error.getErrorCode(), error.getDescription());
}
});
boolean compactTicket = mAuthType == AuthenticationProvider.Type.MSA_COMPACT;
String responseType = compactTicket ? "token" : "code";
String[] scopes = compactTicket ? SCOPES_COMPACT : SCOPES_DELEGATE;
mWebView.loadUrl(AUTHORIZE_URL + REDIRECT_URI_PARAM + CLIENT_ID_PARAM + "&response_type=" + responseType + "&scope=" + TextUtils.join("+", scopes));
}
use of android.webkit.WebResourceError in project AppCenter-SDK-Android by Microsoft.
the class MSALoginActivity method signOut.
@SuppressWarnings("unused")
public void signOut(View view) {
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
if (url.startsWith(REDIRECT_URL)) {
clearCookies();
Uri uri = Uri.parse(url);
sSharedPreferences.edit().remove(MSA_REFRESH_TOKEN_SCOPE_KEY).apply();
sSharedPreferences.edit().remove(MSA_REFRESH_TOKEN_KEY).apply();
sSharedPreferences.edit().remove(MSA_AUTH_TYPE_KEY).apply();
sSharedPreferences.edit().remove(MSA_TOKEN_KEY).apply();
String error = uri.getQueryParameter("error");
if (error != null) {
failSignOut(0, error);
} else {
signIn(null);
}
}
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
clearCookies();
failSignOut(errorCode, description);
}
@Override
@TargetApi(Build.VERSION_CODES.M)
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
clearCookies();
failSignOut(error.getErrorCode(), error.getDescription());
}
});
mWebView.loadUrl(SIGN_OUT_URL + REDIRECT_URI_PARAM + CLIENT_ID_PARAM);
}
use of android.webkit.WebResourceError in project android-sdk by testpress.
the class WebViewUtils method initWebViewAndPostUrl.
@SuppressLint({ "AddJavascriptInterface", "SetJavaScriptEnabled" })
public void initWebViewAndPostUrl(String url, String json, final Activity activity) {
initWebView(webView);
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
WebViewUtils.this.onPageStarted();
hasError = false;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if (!hasError) {
onLoadFinished();
}
}
@SuppressWarnings("deprecation")
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return WebViewUtils.this.shouldOverrideUrlLoading(activity, url);
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
if (InternetConnectivityChecker.isConnected(activity)) {
return;
}
onNetworkError();
hasError = true;
}
});
postUrl(url, json);
}
Aggregations