コード例 #1
0
        public async void LoadUrl(bool fullRefresh = false, bool needCheckEtag = true)
        {
            if (Native == null || WebViewer == null)
            {
                return;
            }

            try
            {
                if (WebViewer.BrowserType == BrowserType.NewLogin)
                {
                    if (WebViewer.Uri == null)
                    {
                        return;
                    }
                    Native.LoadUrl(WebViewer.Uri);
                    return;
                }

                if (needCheckEtag)
                {
                    if (!fullRefresh && WebViewer.BrowserType != BrowserType.Background)
                    {
                        ShowLoadingOverlay();
                        //  fullRefresh = await PGService.IsWebPageContentChanged(WebViewer?.Uri);
                    }
                }

                string baseUrl = string.Empty, query = string.Empty;
                if (WebViewer == null)
                {
                    return;
                }
                if (WebViewer.BrowserType == BrowserType.Standard || WebViewer.BrowserType == BrowserType.Cached || WebViewer.BrowserType == BrowserType.Background)
                {
                    var urldata = UrlParser.Parse(WebViewer.Uri);
                    if (string.IsNullOrEmpty(homeUrl))
                    {
                        homeUrl = urldata.AbsoluteUrl;
                    }

                    /*  Native.Settings.CacheMode = HPHService.CheckConnection() ?
                     *    fullRefresh || (urldata?.Params != null && urldata.Params.ContainsKey("RefreshOnReturn")) ?
                     *        CacheModes.NoCache :
                     *        CacheModes.Normal :
                     *    CacheModes.CacheOnly;*/

                    Native.Settings.CacheMode = PGService.CheckConnection() && (fullRefresh || (urldata?.Params != null && urldata.Params.ContainsKey("RefreshOnReturn")))
                        ? CacheModes.Normal
                        : CacheModes.CacheElseNetwork;
                    var check = Native.Settings.CacheMode;
                    if (string.IsNullOrEmpty(urldata.AbsoluteUrl))
                    {
                        return;
                    }

                    if (urldata.AbsoluteUrl.StartsWith(PGService.ApiServerUrl, StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (!string.IsNullOrEmpty(Core.Settings.AuthToken))
                        {
                            var headers = new Dictionary <string, string>
                            {
                                { "Authorization", "Bearer " + Core.Settings.AuthToken }
                            };
                            Native.LoadUrl(urldata.AbsoluteUrl, headers);
                        }
                        else
                        {
                            var loc = new Localize();
                            urldata.AddParam("CountryCode", loc.GetCurrentCountry());
                            urldata.AddParam("Language", loc.GetCurrentLanguage());
                            Native.LoadUrl(urldata.AbsoluteUrl);
                        }
                    }
                    else
                    {
                        /*if (urldata.Url.Contains("id.hp.com"))
                         *  SetHpIdCookie(urldata.Url);*/
                        Native.LoadUrl(urldata.AbsoluteUrl);
                    }
                }

                else if (WebViewer.BrowserType == BrowserType.Login || WebViewer.BrowserType == BrowserType.ErrorLog)
                {
                    CanExecuteJScript = true;
                    switch (WebViewer.BrowserType)
                    {
                    case BrowserType.Login:
                        Native.LoadUrl(WebViewer.Uri);
                        break;

                    case BrowserType.ErrorLog:
                        Native.LoadUrl(ErrorLogUrl);
                        break;
                    }
                }
            }
            catch { }
        }