android.webkit.WebResourceRequest Java Examples

The following examples show how to use android.webkit.WebResourceRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AdvanceWebClient.java    From cloudflare-scrape-Android with MIT License 6 votes vote down vote up
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
    Log.e("cookie", mCookieManager.getCookie(mUrl));
    if (mTimer != null){
        mTimer.cancel();
        mTimerTask.cancel();
    }
    if (mCookieManager.getCookie(mUrl).contains("cf_clearance")) {
        if (!isSuccess) {
            setSuccess(true);
            mWebView.stopLoading();
            mListener.onSuccess(mCookieManager.getCookie(mUrl));
            return true;
        }
    }
    setCanTimeOut(true);
    return super.shouldOverrideUrlLoading(view, request);
}
 
Example #2
Source File: InnerFastClient.java    From FastWebView with MIT License 6 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
    if (mDelegate != null) {
        mDelegate.onReceivedHttpError(view, request, errorResponse);
        return;
    }
    super.onReceivedHttpError(view, request, errorResponse);
}
 
Example #3
Source File: WebViewActivity.java    From mobile-messaging-sdk-android with Apache License 2.0 6 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.webview);

    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    setupActionBar();

    Intent webViewIntent = getIntent();
    String url = webViewIntent.getStringExtra(EXTRA_URL);

    webView = findViewById(R.id.webview);
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            return false;
        }
    });
    WebSettings webSettings = webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webView.loadUrl(url);
}
 
Example #4
Source File: DocumentationFragment.java    From android-showcase-template with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
    WebView webview = new WebView(this.getActivity());

    webview.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            view.loadUrl(request.getUrl().toString());
            return false;
        }
    });

    webview.getSettings().setJavaScriptEnabled(true);
    webview.loadUrl(this.url);

    return webview;
}
 
Example #5
Source File: BaseWebActivity.java    From Hentoid with Apache License 2.0 5 votes vote down vote up
/**
 * Note : this method is called by a non-UI thread
 */
@Override
public WebResourceResponse shouldInterceptRequest(@NonNull WebView view,
                                                  @NonNull WebResourceRequest request) {
    // Data fetched with POST is out of scope of analysis and adblock
    if (!request.getMethod().equalsIgnoreCase("get")) {
        Timber.d("[%s] ignoring; method = %s", request.getUrl().toString(), request.getMethod());
        return super.shouldInterceptRequest(view, request);
    }

    String url = request.getUrl().toString();
    WebResourceResponse result = shouldInterceptRequestInternal(url, request.getRequestHeaders());
    if (result != null) return result;
    else return super.shouldInterceptRequest(view, request);
}
 
Example #6
Source File: VenvyWebView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
    if (mIwebViewClient != null) {
        mIwebViewClient.onReceivedError(view, request, error);
    } else {
        super.onReceivedError(view, request, error);
    }
}
 
Example #7
Source File: BrowserDelegateOption.java    From CoreModule with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceivedError(final WebView view, WebResourceRequest request,
                            WebResourceError error) {
    super.onReceivedError(view, request, error);
    final EmptyLayout emptyLayout = viewDelegate.get(R.id.emptylayout);
    emptyLayout.setOnLayoutClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            view.loadUrl(view.getUrl());
            emptyLayout.setErrorType(EmptyLayout.NETWORK_LOADING);
        }
    });
    emptyLayout.setErrorType(EmptyLayout.NETWORK_ERROR);
}
 
Example #8
Source File: WebViewApp.java    From unity-ads-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceivedError(android.webkit.WebView view, WebResourceRequest request, WebResourceError error) {
	super.onReceivedError(view, request, error);
	if (view != null) {
		DeviceLog.error("WEBVIEW_ERROR: " + view.toString());
	}
	if (request != null) {
		DeviceLog.error("WEBVIEW_ERROR: " + request.toString());
	}
	if (error != null) {
		DeviceLog.error("WEBVIEW_ERROR: " + error.toString());
	}
}
 
Example #9
Source File: LightningWebClient.java    From Xndroid with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, @NonNull WebResourceRequest request) {
    if (mAdBlock.isAd(request.getUrl().toString())) {
        ByteArrayInputStream EMPTY = new ByteArrayInputStream("".getBytes());
        return new WebResourceResponse("text/plain", "utf-8", EMPTY);
    }
    return super.shouldInterceptRequest(view, request);
}
 
Example #10
Source File: WebViewClientDelegate.java    From AgentWeb with Apache License 2.0 5 votes vote down vote up
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
    if (mDelegate != null) {
        return mDelegate.shouldOverrideUrlLoading(view, request);
    }
    return super.shouldOverrideUrlLoading(view, request);
}
 
Example #11
Source File: BaseWebView.java    From AndroidWallet with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
@Override
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
    super.onReceivedHttpError(view, request, errorResponse);
    if (mClient == null) {
        return;
    }
    mClient.onReceivedHttpError(view, request, errorResponse);
}
 
Example #12
Source File: ResultsActivity.java    From ZbarCode with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
    super.onReceivedError(view, request, error);
    if (_dialog != null) {
        _dialog.dismiss();
        _dialog=null;
    }
    mTxtTitle.setVisibility(View.GONE);
    mTxtContent.setVisibility(View.VISIBLE);
    mTxtContent.setText("链接有问题");
}
 
Example #13
Source File: MiddlewareWebViewClient.java    From TemplateAppProject with Apache License 2.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
    Log.i("Info", "MiddlewareWebViewClient -- >  shouldOverrideUrlLoading:" + request.getUrl().toString() + "  c:" + (count++));
    if (shouldOverrideUrlLoadingByApp(view, request.getUrl().toString())) {
        return true;
    }
    return super.shouldOverrideUrlLoading(view, request);

}
 
Example #14
Source File: VenvyWebView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
@Override
        public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
            if (mIwebViewClient != null) {
                mIwebViewClient.onReceivedHttpError(view, request, errorResponse);
            } else {
                super.onReceivedHttpError(view, request, errorResponse);
            }

//			Log.i(TAG, "onReceivedHttpError:" + 3 + "  request:" + mGson.toJson(request) + "  errorResponse:" + mGson.toJson(errorResponse));
        }
 
Example #15
Source File: WebViewJavaScriptBridge.java    From WebViewJavaScriptBridge with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public WebResourceResponse shouldInterceptRequest(WebView webView, WebResourceRequest webResourceRequest) {
    String url = null != webResourceRequest.getUrl() ? webResourceRequest.getUrl().toString() : null;
    if (!TextUtils.isEmpty(url) && url.startsWith(LOCAL_FILE_SCHEMA)) {
        return getLocalResource(url);
    }

    if (null != _webViewDelegate && null != _webViewDelegate.get()) {
        return _webViewDelegate.get().shouldInterceptRequest(webView, webResourceRequest);
    }
    return super.shouldInterceptRequest(webView, webResourceRequest);
}
 
Example #16
Source File: CommonRefreshWebViewActivity.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
@Override
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
    super.onReceivedHttpError(view, request, errorResponse);
    String errRespStr = "";
    if (errorResponse != null) {
        if (Util.isCompateApi(21)) {
            errRespStr += "status code =" + errorResponse.getStatusCode() + " | reason : " + errorResponse.getReasonPhrase();
        }
    }
    e(null, "--> onReceivedHttpError() request url = " + request.getUrl() + "  errRespStr = " + errRespStr);
}
 
Example #17
Source File: WebPlayerView.java    From unity-ads-android with Apache License 2.0 5 votes vote down vote up
@TargetApi(21)
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
	WebResourceResponse returnValue = null;

	if (shouldCallSuper("shouldInterceptRequest")) {
		returnValue = super.shouldInterceptRequest(view, request);
	}
	if (shouldSendEvent("shouldInterceptRequest")) {
		WebViewApp.getCurrentApp().sendEvent(WebViewEventCategory.WEBPLAYER, WebPlayerEvent.SHOULD_INTERCEPT_REQUEST,  request.getUrl().toString(), viewId);
	}

	return returnValue;
}
 
Example #18
Source File: ProbeWebClient.java    From pre-dem-android with MIT License 5 votes vote down vote up
@SuppressLint("NewApi")
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
    if (request != null && request.getUrl() != null) {
        try {
            if (!GlobalConfig.isExcludeHost(request.getUrl().getHost())) {
                return getResponseFromUrl(new URL(request.getUrl().toString()));
            }
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
    return null;
}
 
Example #19
Source File: BrowserFragment.java    From CoreModule with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
    super.onReceivedError(view, request, error);
    mEmptyLayout.setErrorType(EmptyLayout.NODATA);
    if (callback != null) {
        callback.onReceivedError(view, request, error);
    }
}
 
Example #20
Source File: GoogleRecaptchaVerifyActivity.java    From v9porn with MIT License 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
    String url = request.getUrl().toString();
    if (url.contains("?__cf_chl_captcha_tk__")) {
        runOnUiThread(() -> webView.evaluateJavascript("javascript:getPostData()", value -> {
            String postData = value.replace("\"", "");
            Logger.t(TAG).d(postData);
            String[] data = postData.split(",");
            Logger.t(TAG).d(data);
            if (data.length >= 4) {
                doPost(data[0], data[1], data[2], data[3]);
            } else {
                showMessage("无法获取POST数据,请刷新重试", TastyToast.ERROR);
                btnRefresh.setText("刷新重试");
            }
        }));
        synchronized (lock) {
            try {
                //等待验证结果
                lock.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return new WebResourceResponse("", "", null);
    }
    Log.d(TAG, url);
    return super.shouldInterceptRequest(view, request);
}
 
Example #21
Source File: WebViewActivity.java    From YCAudioPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
    super.onReceivedError(view, request, error);
    LogUtils.e("WebViewActivity-----onReceivedError-------" + error.toString());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        LogUtils.e("服务器异常" + error.getDescription().toString());
    }
    ToastUtils.showRoundRectToast("服务器异常6.0之后");
    //当加载错误时,就让它加载本地错误网页文件
    //mWebView.loadUrl("file:///android_asset/errorpage/error.html");

    showErrorPage();//显示错误页面
}
 
Example #22
Source File: WebViewHook.java    From AdBlocker_Reborn with GNU General Public License v3.0 5 votes vote down vote up
private String checkURL(XC_MethodHook.MethodHookParam param) {
    if (param.args[1] instanceof String) {
        return param.args[1].toString();
    } else {
        WebResourceRequest request = (WebResourceRequest) param.args[1];
        return request.getUrl().toString();
    }
}
 
Example #23
Source File: MyWebViewClient.java    From ByWebView with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
    super.onReceivedError(view, request, error);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (request.isForMainFrame()) {//是否是为 main frame创建
            String mErrorUrl = "file:///android_asset/404_error.html";
            view.loadUrl(mErrorUrl);
        }
    }
}
 
Example #24
Source File: BridgeWebViewClient.java    From JsBridge with MIT License 5 votes vote down vote up
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
    String url = request.getUrl().toString();
    //modify:hjhrq1991,web为渲染即跳转导致系统未调用onPageStarted就调用onPageFinished方法引起的js桥初始化失败
    if (onPageStartedCount < 2) {
        isRedirected = true;
    }
    onPageStartedCount = 0;

    try {
        url = URLDecoder.decode(url, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    if (url.startsWith(BridgeUtil.YY_RETURN_DATA)) { // 如果是返回数据
        webView.handlerReturnData(url);
        return true;
    } else if (url.startsWith(BridgeUtil.YY_OVERRIDE_SCHEMA)) { //
        webView.flushMessageQueue();
        return true;
    } else {
        if (bridgeWebViewClientListener != null) {
            return bridgeWebViewClientListener.shouldOverrideUrlLoading(view, request);
        } else {
            return super.shouldOverrideUrlLoading(view, request);
        }
    }
}
 
Example #25
Source File: ByWebViewClient.java    From ByWebView with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
    super.onReceivedError(view, request, error);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (request.isForMainFrame()) {//是否是为 main frame创建
            String mErrorUrl = "file:///android_asset/404_error.html";
            view.loadUrl(mErrorUrl);
        }
    }
}
 
Example #26
Source File: MyWebViewClient.java    From ByWebView with Apache License 2.0 5 votes vote down vote up
@Override
    public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
        super.onReceivedHttpError(view, request, errorResponse);
//        WebTools.handleReceivedHttpError(view, errorResponse);
        // 这个方法在 android 6.0才出现
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            int statusCode = errorResponse.getStatusCode();
            if (404 == statusCode || 500 == statusCode) {
                String mErrorUrl = "file:///android_asset/404_error.html";
                view.loadUrl(mErrorUrl);
            }
        }
    }
 
Example #27
Source File: BrowserView.java    From AndroidProject with Apache License 2.0 5 votes vote down vote up
/**
 * 同名 API 兼容
 */
@TargetApi(Build.VERSION_CODES.M)
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
    if (request.isForMainFrame()) {
        onReceivedError(view,
                error.getErrorCode(), error.getDescription().toString(),
                request.getUrl().toString());
    }
}
 
Example #28
Source File: ConsentForm.java    From GDPR-Admob-Android with MIT License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.N)
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
    String url = request.getUrl().toString();
    if (isConsentFormUrl(url)) {
        handleUrl(url);
        return true;
    }
    return false;
}
 
Example #29
Source File: RideRequestView.java    From rides-android-sdk with MIT License 5 votes vote down vote up
@TargetApi(23)
@Override
public void onReceivedError(WebView view,
        WebResourceRequest request,
        WebResourceError error) {
    receivedError();
}
 
Example #30
Source File: FileViewFragment.java    From lbry-android with MIT License 5 votes vote down vote up
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
    Uri url = request.getUrl();
    if (context != null) {
        Intent intent = new Intent(Intent.ACTION_VIEW, url);
        context.startActivity(intent);
    }
    return true;
}