Beispiel #1
0
 internal CertificateErrorEventArgs(CefErrorCode certError, string requestUrl, CefSslInfo sslInfo, CefRequestCallback callback)
 {
     CertError  = certError;
     RequestUrl = requestUrl;
     SslInfo    = sslInfo;
     _callback  = callback;
 }
 /// <summary>
 /// Called on the IO thread before a resource request is loaded. To redirect or change the resource load optionally modify |request|.
 /// Modification of the request URL will be treated as a redirect.
 /// </summary>
 /// <param name="browser">
 /// Represent the source browser of the request, and may be NULL for requests originating from service workers or CefURLRequest.
 /// </param>
 /// <param name="frame">
 /// Represent the source frame of the request, and may be NULL for requests originating from service workers or CefURLRequest.
 /// </param>
 /// <param name="request">
 /// The CefRequest object.
 /// </param>
 /// <param name="callback">
 /// </param>
 /// <returns>
 /// Return Continue to continue the request immediately. Return ContinueAsync and call CefRequestCallback:: Continue() at a later time to continue
 /// or cancel the request asynchronously. Return Cancel to cancel the request immediately.
 /// </returns>
 internal protected virtual CefReturnValue OnBeforeResourceLoad(CefBrowser browser, CefFrame frame, CefRequest request, CefRequestCallback callback)
 {
     return(CefReturnValue.Continue);
 }
        //protected override void OnProtocolExecution(CefBrowser browser, string url, out bool allowOSExecution)
        //{
        //    base.OnProtocolExecution(browser, url, out allowOSExecution);
        //}

        protected override bool OnQuotaRequest(CefBrowser browser, string originUrl, long newSize, CefRequestCallback callback)
        {
            return(base.OnQuotaRequest(browser, originUrl, newSize, callback));
        }
        // protected override bool CanGetCookies(CefBrowser browser, CefFrame frame, CefRequest request)
        //{
        //    return base.CanGetCookies(browser, frame, request);
        //}

        //protected override bool CanSetCookie(CefBrowser browser, CefFrame frame, CefRequest request, CefCookie cookie)
        //{
        //    return base.CanSetCookie(browser, frame, request, cookie);
        //}

        //protected override bool GetAuthCredentials(CefBrowser browser, CefFrame frame, bool isProxy, string host, int port, string realm, string scheme, CefAuthCallback callback)
        //{
        //    //isProxy = false;
        //    return base.GetAuthCredentials(browser, frame, isProxy, host, port, realm, scheme, callback);
        //}

        //protected override CefResourceHandler GetResourceHandler(CefBrowser browser, CefFrame frame, CefRequest request)
        //{

        //    //CefWebReadHandler cefWebRead = new CefWebReadHandler();


        //    return base.GetResourceHandler(browser, frame, request);
        //}
        //protected override bool OnBeforeBrowse(CefBrowser browser, CefFrame frame, CefRequest request, bool userGesture, bool isRedirect)
        //{
        //    return base.OnBeforeBrowse(browser, frame, request, userGesture, isRedirect);
        //}

        //protected override CefReturnValue OnBeforeResourceLoad(CefBrowser browser, CefFrame frame, CefRequest request, CefRequestCallback callback)
        //{
        //    Uri url;
        //    if (Uri.TryCreate(request.Url, UriKind.Absolute, out url) == false)
        //    {
        //        //If we're unable to parse the Uri then cancel the request
        //        // avoid throwing any exceptions here as we're being called by unmanaged code
        //        return CefReturnValue.Cancel;
        //    }

        //    if (_requestHeandler != null)
        //    {
        //        return base.OnBeforeResourceLoad(browser, frame, request, callback);
        //        //return base.OnBeforeResourceLoad(browserControl, browser, frame, request, callback);
        //    }

        //    return CefReturnValue.Continue;
        //    //return base.OnBeforeResourceLoad(browser, frame, request, callback);

        //}

        protected override bool OnCertificateError(CefBrowser browser, CefErrorCode certError, string requestUrl, CefSslInfo sslInfo, CefRequestCallback callback)
        {
            callback.Continue(true);
            return(base.OnCertificateError(browser, certError, requestUrl, sslInfo, callback));
        }
 protected internal unsafe override CefReturnValue OnBeforeResourceLoad(CefBrowser browser, CefFrame frame, CefRequest request, CefRequestCallback callback)
 {
     return(_implementation.OnBeforeResourceLoad(browser, frame, request, callback));
 }
        /// <summary>
        /// 请求资源的时候  Handler方法
        /// 如:js css 图片等资源
        /// </summary>
        /// <param name="browser"></param>
        /// <param name="frame"></param>
        /// <param name="request"></param>
        /// <param name="callback"></param>
        /// <returns></returns>
        protected override CefReturnValue OnBeforeResourceLoad(CefBrowser browser, CefFrame frame, CefRequest request, CefRequestCallback callback)
        {
            ///--------TODO:这些配置回头需要设置到配置文件中,暂时没时间实现 回头有时间再弄  ------------
            //if (request.Url.Contains("mtop.etao.fe.search/"))
            //{
            //    int x = 9;
            //    return true;
            //}

            ////监视一淘的请求数据的接口地址
            //string url = request.Url;
            //if (url.Contains("apie.m.etao.com/h5/mtop.etao.fe.search"))
            //{
            //    if (null != this.OnRequestTheMoniterdUrl)
            //    {
            //        //注意:必须开启在独立的线程任务上 去执行事件  ,如果在执行线程中,会导致线程死锁....
            //        Task.Factory.StartNew(() =>
            //        {
            //            this.OnRequestTheMoniterdUrl(this, new FilterSpecialUrlEventArgs { Browser = browser, Url = url });
            //            //不要返回取消 取消会出现在httpclient 异常
            //           // return CefReturnValue.Cancel;
            //        });
            //    }

            //}

            //var reg = new System.Text.RegularExpressions.Regex(@"(http:|https:).*\.(woff|css|jpg|jpeg|png|ttf|svg|ico)\?{0,}.*", System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase);

            //if (reg.IsMatch(url))
            //{
            //    return CefReturnValue.Cancel;
            //}

            //if (url.Contains("log.mmstat.com/v.gif"))
            //{
            //    return CefReturnValue.Cancel;
            //}

            //if (url.Contains("mo.m.taobao.com/etao/pc_search_hotwords"))
            //{
            //    return CefReturnValue.Cancel;
            //}
            //if (url.Contains("/h5/mtop.etao.fe.hotwords/"))
            //{
            //    return CefReturnValue.Cancel;
            //}

            //if (url.Contains("img.alicdn.com"))
            //{
            //    return CefReturnValue.Cancel;
            //}
            //if (url.Contains("qrlogin.taobao.com"))
            //{
            //    return CefReturnValue.Cancel;
            //}
            //if (url.Contains("tanx.com"))
            //{
            //    return CefReturnValue.Cancel;
            //}
            //if (url.Contains("wwc.alicdn.com"))
            //{
            //    return CefReturnValue.Cancel;
            //}
            //if (url.Contains("wwc.alicdn.com"))
            //{
            //    return CefReturnValue.Cancel;
            //}
            //if (url.Contains(".mogucdn.com"))
            //{
            //    return CefReturnValue.Cancel;
            //}
            return(base.OnBeforeResourceLoad(browser, frame, request, callback));
        }
 protected override bool OnCertificateError(CefBrowser browser, CefErrorCode certError, string requestUrl, CefSslInfo sslInfo, CefRequestCallback callback)
 {
     using (callback) {
         if (OwnerWebView.IgnoreCertificateErrors)
         {
             callback.Continue(true);
             return(true);
         }
         return(false);
     }
 }
Beispiel #8
0
 protected internal unsafe override bool OnCertificateError(CefBrowser browser, CefErrorCode certError, string requestUrl, CefSSLInfo sSLInfo, CefRequestCallback callback)
 {
     return(_implementation.OnCertificateError(browser, certError, requestUrl, sSLInfo, callback));
 }
Beispiel #9
0
 internal protected virtual bool OnQuotaRequest(CefBrowser browser, string originUrl, long newSize, CefRequestCallback callback)
 {
     return(false);
 }
 public ResourceLoadEventArgs(string url, CefResourceType resourceType, CefRequestCallback callback)
 {
     Url          = url;
     ResourceType = resourceType;
     Callback     = callback;
 }
Beispiel #11
0
 protected internal unsafe override bool OnQuotaRequest(CefBrowser browser, string originUrl, long newSize, CefRequestCallback callback)
 {
     return(_implementation.OnQuotaRequest(browser, originUrl, newSize, callback));
 }
Beispiel #12
0
        protected override CefReturnValue OnBeforeResourceLoad(CefBrowser browser, CefFrame frame, CefRequest request, CefRequestCallback callback)
        {
            var sc = DI.Get <CloudServiceClientBase>();

            if (request.Url.StartsWith(sc.ApiBaseUrl, StringComparison.OrdinalIgnoreCase))
            {
                request.SetHeaderByName(Headers.Request.AppVersion, sc.Settings.AppVersionStr, true);
                if (webView.IsSecurity)
                {
                    if (webView.Aes == null)
                    {
                        webView.Aes = AESUtils.Create();
                    }
                    var skey_bytes  = webView.Aes.ToParamsByteArray();
                    var conn_helper = DI.Get <IApiConnectionPlatformHelper>();
                    var skey_str    = conn_helper.RSA.EncryptToString(skey_bytes);
                    request.SetHeaderByName(Headers.Request.SecurityKey, skey_str, true);
                }
            }
            var returnValue = base.OnBeforeResourceLoad(browser, frame, request, callback);

            return(returnValue);
        }
 protected override bool OnCertificateError(CefBrowser browser, CefErrorCode certError, string requestUrl, CefSslInfo sslInfo, CefRequestCallback callback)
 {
     // Note that OnCertificateError is only called when the top-level resource (the html page being loaded)
     // has a certificate problem. Any additional resources loaded by the main frame will not trigger this callback.
     _core.OnCertificateError();
     Logger.Error("Failed to load resource due to an invalid certificate: " + requestUrl);
     return(base.OnCertificateError(browser, certError, requestUrl, sslInfo, callback));
 }
        protected override CefReturnValue OnBeforeResourceLoad(CefBrowser browser, CefFrame frame, CefRequest request, CefRequestCallback callback)
        {
            var ea = new ResourceLoadEventArgs(request.Url, request.ResourceType, callback);

            _core.OnBeforeResourceLoad(ea);
            return(ea.Cancel ? CefReturnValue.Cancel : CefReturnValue.Continue);
        }
Beispiel #15
0
 protected override CefReturnValue OnBeforeResourceLoad(CefBrowser browser, CefFrame frame, CefRequest request, CefRequestCallback callback)
 {
     request.SetReferrer(request.ReferrerURL, CefReferrerPolicy.Origin);
     return(CefReturnValue.Continue);
 }
Beispiel #16
0
 internal protected virtual bool OnCertificateError(CefBrowser browser, CefErrorCode certError, string requestUrl, CefSSLInfo sslInfo, CefRequestCallback callback)
 {
     return(false);
 }
Beispiel #17
0
        protected override CefReturnValue OnBeforeResourceLoad(CefBrowser browser, CefFrame frame, CefRequest request, CefRequestCallback callback)
        {
            var sc = DI.Get <CloudServiceClientBase>();

            if (request.Url.StartsWith(sc.ApiBaseUrl, StringComparison.OrdinalIgnoreCase))
            {
                request.SetHeaderByName(Headers.Request.AppVersion, sc.Settings.AppVersionStr, true);
            }
            var returnValue = base.OnBeforeResourceLoad(browser, frame, request, callback);

            return(returnValue);
        }
        protected override CefReturnValue OnBeforeResourceLoad(CefBrowser browser, CefFrame frame, CefRequest request, CefRequestCallback callback)
        {
            var sc = DI.Get <CloudServiceClientBase>();

            if (request.Url.StartsWith(sc.ApiBaseUrl, StringComparison.OrdinalIgnoreCase))
            {
                var conn_helper = DI.Get <IApiConnectionPlatformHelper>();
                request.SetHeaderByName(Headers.Request.AppVersion, sc.Settings.AppVersionStr, true);
                if (webView.IsSecurity)
                {
                    if (webView.Aes == null)
                    {
                        webView.Aes = AESUtils.Create();
                    }
                    var skey_bytes = webView.Aes.ToParamsByteArray();
                    var skey_str   = conn_helper.RSA.EncryptToString(skey_bytes);
                    request.SetHeaderByName(Headers.Request.SecurityKey, skey_str, true);
                }
                Func <Task <JWTEntity?> > getAuthTokenAsync = () => conn_helper.Auth.GetAuthTokenAsync().AsTask();
                var authToken       = getAuthTokenAsync.RunSync();
                var authHeaderValue = conn_helper.GetAuthenticationHeaderValue(authToken);
                if (authHeaderValue != null)
                {
                    var authHeaderValueStr = authHeaderValue.ToString();
                    request.SetHeaderByName("Authorization", authHeaderValueStr, true);
                }
            }
            var returnValue = base.OnBeforeResourceLoad(browser, frame, request, callback);

            return(returnValue);
        }
Beispiel #19
0
        protected override bool OnCertificateError(CefBrowser browser, CefErrorCode certError, string requestUrl, CefSslInfo sslInfo, CefRequestCallback callback)
        {
            var e = new CertificateErrorEventArgs(certError, requestUrl, sslInfo, callback);

            _owner.InvokeIfRequired(() => _owner.OnCertificateError(e));

            return(!e.CancelRequestImmediately);
        }
 protected override bool OnQuotaRequest(CefBrowser browser, string originUrl, long newSize, CefRequestCallback callback)
 {
     using (callback) {
         callback.Continue(true);
         return(true);
     }
 }