public virtual ChromelyConfiguration RegisterCustomrUrlScheme(string schemeName, string domainName) { UrlScheme scheme = new UrlScheme(schemeName, domainName, false); UrlSchemeProvider.RegisterScheme(scheme); return(this); }
public virtual ChromelyConfiguration RegisterExternaleUrlScheme(string schemeName, string domainName) { UrlScheme scheme = new UrlScheme(schemeName, domainName, true); UrlSchemeProvider.RegisterScheme(scheme); return(this); }
/// <summary> /// The init. /// </summary> private void Init() { UrlSchemeProvider.RegisterScheme(new UrlScheme("http", "chromely.com", false)); UrlSchemeProvider.RegisterScheme(new UrlScheme("https", "test.com", false)); UrlSchemeProvider.RegisterScheme(new UrlScheme("https://www.google.com", true)); UrlSchemeProvider.RegisterScheme(new UrlScheme("http://www.test.com", true)); }
/// <summary> /// The init. /// </summary> private void Init() { UrlSchemeProvider.RegisterScheme(new UrlScheme("http", "chromely.com", UrlSchemeType.Custom)); UrlSchemeProvider.RegisterScheme(new UrlScheme("https", "test.com", UrlSchemeType.Custom)); UrlSchemeProvider.RegisterScheme(new UrlScheme("https://www.google.com", UrlSchemeType.External)); UrlSchemeProvider.RegisterScheme(new UrlScheme("http://www.test.com", UrlSchemeType.External)); }
/// <summary> /// The on before popup. /// </summary> /// <param name="browser"> /// The browser. /// </param> /// <param name="frame"> /// The frame. /// </param> /// <param name="targetUrl"> /// The target url. /// </param> /// <param name="targetFrameName"> /// The target frame name. /// </param> /// <param name="targetDisposition"> /// The target disposition. /// </param> /// <param name="userGesture"> /// The user gesture. /// </param> /// <param name="popupFeatures"> /// The popup features. /// </param> /// <param name="windowInfo"> /// The window info. /// </param> /// <param name="client"> /// The client. /// </param> /// <param name="settings"> /// The settings. /// </param> /// <param name="noJavascriptAccess"> /// The no javascript access. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> protected override bool OnBeforePopup(CefBrowser browser, CefFrame frame, string targetUrl, string targetFrameName, CefWindowOpenDisposition targetDisposition, bool userGesture, CefPopupFeatures popupFeatures, CefWindowInfo windowInfo, ref CefClient client, CefBrowserSettings settings, ref bool noJavascriptAccess) { var isUrlExternal = UrlSchemeProvider.IsUrlRegisteredExternal(targetUrl); if (isUrlExternal) { RegisteredExternalUrl.Launch(targetUrl); } return true; }
public virtual ChromelyConfiguration RegisterSchemeHandler(ChromelySchemeHandler chromelySchemeHandler) { if (chromelySchemeHandler != null) { UrlScheme scheme = new UrlScheme(chromelySchemeHandler.SchemeName, chromelySchemeHandler.DomainName, false); UrlSchemeProvider.RegisterScheme(scheme); IoC.RegisterInstance(typeof(ChromelySchemeHandler), chromelySchemeHandler.Key, chromelySchemeHandler); } return(this); }
/// <summary> /// Registers scheme handler. /// </summary> /// <param name="schemeHandler"> /// The chromely scheme handler. /// </param> /// <returns> /// The <see cref="ChromelyConfiguration"/> object. /// </returns> public virtual ChromelyConfiguration RegisterSchemeHandler(ChromelySchemeHandler schemeHandler) { if (schemeHandler != null) { var scheme = new UrlScheme(schemeHandler.SchemeName, schemeHandler.DomainName, UrlSchemeType.Custom); UrlSchemeProvider.RegisterScheme(scheme); IoC.RegisterInstance(typeof(ChromelySchemeHandler), schemeHandler.Key, schemeHandler); } return(this); }
/// <summary> /// Registers scheme handler. /// </summary> /// <param name="ePlugSchemeHandler"> /// The blis scheme handler. /// </param> /// <returns> /// The <see cref="CefConfiguration"/> object. /// </returns> public virtual CefConfiguration RegisterSchemeHandler(SchemeHandler ePlugSchemeHandler) { if (ePlugSchemeHandler != null) { var scheme = new UrlScheme(ePlugSchemeHandler.SchemeName, ePlugSchemeHandler.DomainName, false); UrlSchemeProvider.RegisterScheme(scheme); IoC.RegisterInstance(typeof(SchemeHandler), ePlugSchemeHandler.Key, ePlugSchemeHandler); } return(this); }
/// <summary> /// The on before browse. /// </summary> /// <param name="browserControl"> /// The browser control. /// </param> /// <param name="browser"> /// The browser. /// </param> /// <param name="frame"> /// The frame. /// </param> /// <param name="request"> /// The request. /// </param> /// <param name="isRedirect"> /// The is redirect. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> bool IRequestHandler.OnBeforeBrowse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, bool isRedirect) { bool isUrlExternal = UrlSchemeProvider.IsUrlRegisteredExternal(request.Url); if (isUrlExternal) { System.Diagnostics.Process.Start(request.Url); return(true); } return(false); }
protected override bool OnBeforeBrowse(CefBrowser browser, CefFrame frame, CefRequest request, bool isRedirect) { bool isUrlExternal = UrlSchemeProvider.IsUrlRegisteredExternal(request.Url); if (isUrlExternal) { System.Diagnostics.Process.Start(request.Url); return(true); } return(false); }
/// <summary> /// The on before browse. /// </summary> /// <param name="browser"> /// The browser. /// </param> /// <param name="frame"> /// The frame. /// </param> /// <param name="request"> /// The request. /// </param> /// <param name="userGesture"> /// The user gesture. /// </param> /// <param name="isRedirect"> /// The is redirect. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> protected override bool OnBeforeBrowse(CefBrowser browser, CefFrame frame, CefRequest request, bool userGesture, bool isRedirect) { var isUrlExternal = UrlSchemeProvider.IsUrlRegisteredExternal(request.Url); if (isUrlExternal) { // https://brockallen.com/2016/09/24/process-start-for-urls-on-net-core/ try { Process.Start(request.Url); } catch { try { // hack because of this: https://github.com/dotnet/corefx/issues/10361 if (CefRuntime.Platform == CefRuntimePlatform.Windows) { var url = request.Url.Replace("&", "^&"); Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = true }); } else if (CefRuntime.Platform == CefRuntimePlatform.Linux) { Process.Start("xdg-open", request.Url); } else if (CefRuntime.Platform == CefRuntimePlatform.MacOSX) { Process.Start("open", request.Url); } } catch (Exception exception) { Log.Error(exception); } } return(true); } var isUrlCommand = UrlSchemeProvider.IsUrlRegisteredCommand(request.Url); if (isUrlCommand) { CommandTaskRunner.RunAsync(request.Url); return(true); } return(false); }
/// <summary> /// The on before popup. /// </summary> /// <param name="browserControl"> /// The browser control. /// </param> /// <param name="browser"> /// The browser. /// </param> /// <param name="frame"> /// The frame. /// </param> /// <param name="targetUrl"> /// The target url. /// </param> /// <param name="targetFrameName"> /// The target frame name. /// </param> /// <param name="targetDisposition"> /// The target disposition. /// </param> /// <param name="userGesture"> /// The user gesture. /// </param> /// <param name="popupFeatures"> /// The popup features. /// </param> /// <param name="windowInfo"> /// The window info. /// </param> /// <param name="browserSettings"> /// The browser settings. /// </param> /// <param name="noJavascriptAccess"> /// The no javascript access. /// </param> /// <param name="newBrowser"> /// The new browser. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser) { newBrowser = null; var isUrlExternal = UrlSchemeProvider.IsUrlRegisteredExternal(targetUrl); if (isUrlExternal) { System.Diagnostics.Process.Start(targetUrl); } return(true); }
/// <summary> /// The run. /// </summary> /// <param name="request"> /// The request. /// </param> /// <returns> /// The <see cref="ChromelyResponse"/>. /// </returns> /// <exception cref="Exception"> /// Generic exception - Route path not valid. /// </exception> public static ChromelyResponse Run(IRequest request) { bool isCustomScheme = UrlSchemeProvider.IsUrlOfRegisteredCustomScheme(request.Url); if (!isCustomScheme) { throw new Exception($"Url {request.Url} is not of a registered custom scheme."); } var uri = new Uri(request.Url); string routePath = uri.LocalPath; var parameters = GetParameters(request.Url); object postData = GetPostData(request); return(Run(routePath, parameters, postData)); }
/// <summary> /// The run. /// </summary> /// <param name="request"> /// The request. /// </param> /// <returns> /// The <see cref="ChromelyResponse"/>. /// </returns> /// <exception cref="Exception"> /// Generic exception - Route path not valid. /// </exception> public static ChromelyResponse Run(IRequest request) { var isCustomScheme = UrlSchemeProvider.IsUrlOfRegisteredCustomScheme(request.Url); if (!isCustomScheme) { throw new Exception($"Url {request.Url} is not of a registered custom scheme."); } var uri = new Uri(request.Url); var path = uri.LocalPath; var parameters = request.Url.GetParameters(); var postData = GetPostData(request); var routePath = new RoutePath(request.Method, path); return(Run(string.Empty, routePath, parameters, postData)); }
/// <summary> /// The process request async. /// </summary> /// <param name="request"> /// The request. /// </param> /// <param name="callback"> /// The callback. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public override bool ProcessRequestAsync(IRequest request, ICallback callback) { bool isCustomScheme = UrlSchemeProvider.IsUrlOfRegisteredCustomScheme(request.Url); if (isCustomScheme) { Task.Run(() => { using (callback) { try { this.mChromelyResponse = RequestTaskRunner.Run(request); string jsonData = this.mChromelyResponse.Data.EnsureResponseIsJsonFormat(); var content = Encoding.UTF8.GetBytes(jsonData); this.mStream.Write(content, 0, content.Length); this.mMimeType = "application/json"; } catch (Exception exception) { Log.Error(exception); this.mChromelyResponse = new ChromelyResponse { Status = (int)HttpStatusCode.BadRequest, Data = "An error occured." }; } finally { callback.Continue(); } } }); return(true); } Log.Error($"Url {request.Url} is not of a registered custom scheme."); callback.Dispose(); return(false); }
/// <summary> /// The on before browse. /// </summary> /// <param name="browserControl"> /// The browser control. /// </param> /// <param name="browser"> /// The browser. /// </param> /// <param name="frame"> /// The frame. /// </param> /// <param name="request"> /// The request. /// </param> /// <param name="userGesture"> /// The user Gesture. /// </param> /// <param name="isRedirect"> /// The is redirect. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> bool IRequestHandler.OnBeforeBrowse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, bool userGesture, bool isRedirect) { bool isUrlExternal = UrlSchemeProvider.IsUrlRegisteredExternal(request.Url); if (isUrlExternal) { System.Diagnostics.Process.Start(request.Url); return(true); } var isUrlCommand = UrlSchemeProvider.IsUrlRegisteredCommand(request.Url); if (isUrlCommand) { CommandTaskRunner.RunAsync(request.Url); return(true); } return(false); }
/// <summary> /// The process request. /// </summary> /// <param name="request"> /// The request. /// </param> /// <param name="callback"> /// The callback. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> protected override bool ProcessRequest(CefRequest request, CefCallback callback) { bool isCustomScheme = UrlSchemeProvider.IsUrlOfRegisteredCustomScheme(request.Url); if (isCustomScheme) { Task.Run(() => { using (callback) { try { mChromelyResponse = RequestTaskRunner.Run(request); string jsonData = mChromelyResponse.Data.EnsureResponseIsJsonFormat(); mResponseBytes = Encoding.UTF8.GetBytes(jsonData); } catch (Exception exception) { Log.Error(exception); mChromelyResponse = new ChromelyResponse { Status = (int)HttpStatusCode.BadRequest, Data = "An error occured." }; } finally { callback.Continue(); } } }); return(true); } Log.Error($"Url {request.Url} is not of a registered custom scheme."); callback.Dispose(); return(false); }
protected override bool ProcessRequest(CefRequest request, CefCallback callback) { bool isCustomScheme = UrlSchemeProvider.IsUrlOfRegisteredCustomScheme(request.Url); if (isCustomScheme) { Task.Factory.StartNew(() => { using (callback) { try { m_chromelyResponse = CefGlueRequestTaskRunner.Run(request); } catch (Exception exception) { Log.Error(exception); m_chromelyResponse = new ChromelyResponse(); m_chromelyResponse.Status = (int)HttpStatusCode.BadRequest; m_chromelyResponse.Data = "An error occured."; } finally { callback.Continue(); } } }); return(true); } Log.Error(string.Format("Url {0} is not of a registered custom scheme.", request.Url)); callback.Dispose(); return(false); }
/// <summary> /// The register url scheme. /// </summary> /// <param name="scheme"> /// The scheme. /// </param> public void RegisterUrlScheme(UrlScheme scheme) { UrlSchemeProvider.RegisterScheme(scheme); }
public void RegisterExternalUrlScheme(UrlScheme scheme) { scheme.IsExternal = true; UrlSchemeProvider.RegisterScheme(scheme); }
public void IsCustomUrlTest() { Assert.True(UrlSchemeProvider.IsUrlOfRegisteredCustomScheme("http://chromely.com/getvaluefromme")); Assert.True(UrlSchemeProvider.IsUrlOfRegisteredCustomScheme("https://test.com/savevaluetome")); }
public void IsExternalUrlTest() { Assert.True(UrlSchemeProvider.IsUrlRegisteredExternal("https://www.google.com/getvaluefromme")); Assert.True(UrlSchemeProvider.IsUrlRegisteredExternal("http://www.test.com/savevaluetome")); }
/// <summary> /// Registers customr url scheme. /// </summary> /// <param name="urlScheme"> /// The url scheme object. /// </param> /// <returns> /// The <see cref="ChromelyConfiguration"/> object. /// </returns> public virtual ChromelyConfiguration RegisterCustomrUrlScheme(UrlScheme urlScheme) { UrlSchemeProvider.RegisterScheme(urlScheme); return(this); }