public override void CreateControl() { base.CreateControl(); if (!_controlCreated && !DesignMode) { if (!ParagonRuntime.IsInitialized) { ParagonRuntime.Initialize(); } _client = new CefWebClient(this); if (!IsPopup && _browser == null) { var settings = new CefBrowserSettings { Java = CefState.Disabled }; using (AutoStopwatch.TimeIt("Creating browser")) { var info = CefWindowInfo.Create(); var ea = new BrowserCreateEventArgs(); using (AutoStopwatch.TimeIt("Raising BeforeBrowserCreate event")) { BeforeBrowserCreate.Raise(this, ea); } _router = ea.Router; _currentUrl = _sourceUrl; if (IntPtr.Zero != ParentHandle) { RECT rect = new RECT(); Win32Api.GetClientRect(ParentHandle, ref rect); info.SetAsChild(ParentHandle, new CefRectangle(rect.Left, rect.Top, rect.Width, rect.Height)); } Logger.Info(string.Format("OnHandleCreated - Creating a browser with url {0}", _currentUrl)); CefBrowserHost.CreateBrowser(info, _client, settings, _currentUrl); } } _controlCreated = true; } }
private void LoadEventPage() { if (_eventPageBrowser != null) { return; } _eventPageBrowser = _createNewBrowser(); _eventPageBrowser.BeforeBrowserCreate += OnBeforeEventPageBrowserCreate; _eventPageBrowser.LoadEnd += OnEventPageBrowserLoad; _eventPageBrowser.RenderProcessTerminated += OnRenderProcessTerminated; using (AutoStopwatch.TimeIt("Creating browser control")) { _eventPageBrowser.CreateControl(); } }
public CreateWindowRequest( string startUrl, CreateWindowOptions options, JavaScriptPluginCallback windowCreatedCallback, string id = null) { _stopwatch = AutoStopwatch.TimeIt("Creating app window"); RequestId = id; if (string.IsNullOrEmpty(id)) { RequestId = Guid.NewGuid().ToString(); } StartUrl = startUrl; Options = options; if (windowCreatedCallback != null) { _callbackReference = new WeakReference(windowCreatedCallback, true); _windowCreatedCallback = windowCreatedCallback; } }
public static bool ResolveMetadataAndPackage(ParagonCommandLineParser cmdLine, out ApplicationMetadata appMetadata, out IApplicationPackage appPackage) { appMetadata = null; appPackage = null; try { using (AutoStopwatch.TimeIt("Parsing application metadata")) { appMetadata = cmdLine.ParseApplicationMetadata(); Logger.Info("The current environment is {0}", appMetadata != null ? appMetadata.Environment : ApplicationEnvironment.Production); } } catch (Exception ex) { MessageBox.Show(string.Format("Error parsing command line : {0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } try { using (AutoStopwatch.TimeIt("Gettting application package")) { appPackage = appMetadata.GetApplicationPackage(); Logger.Info("The current application package is {0}", appPackage == null || appPackage.Signature == null ? "unsigned" : string.Format("digitally signed by {0} on {1}", appPackage.Signature.Signer.Subject, appPackage.Signature.SigningTime)); return(appPackage != null); } } catch (SecurityException ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } catch (Exception ex) { MessageBox.Show(string.Format("Error parsing manifest file : {0}", ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } return(false); }
protected virtual void RunApplicationInternal(ParagonCommandLineParser cmdLine, IApplicationPackage package, ApplicationMetadata metadata) { IParagonSplashScreen splash = null; IApplication application = null; Window splashWindow = null; var manifest = package.Manifest; #if ENFORCE_PACKAGE_SECURITY var isSigned = package.Signature != null; #endif try { ParagonLogManager.AddApplicationTraceListener(manifest.Id); // Load custom WPF theme for the application var stylePart = !string.IsNullOrEmpty(manifest.CustomTheme) ? package.GetPart(manifest.CustomTheme) : null; var styleStream = stylePart != null?stylePart.GetStream() : null; if (styleStream != null) { var theme = XamlReader.Load(styleStream) as ResourceDictionary; if (theme != null) { #if ENFORCE_PACKAGE_SECURITY if (isSigned) #endif Application.Current.Resources.MergedDictionaries.Add(theme); } } // Create and show the splash screen if needed if (cmdLine != null && !cmdLine.HasFlag("no-splash") && _createSplashScreen != null) { #if ENFORCE_PACKAGE_SECURITY splash = _createSplashScreen(isSigned ? manifest.Name : manifest.Name + " (Unsigned)", manifest.Version, package.GetIcon()); #else splash = _createSplashScreen(manifest.Name, manifest.Version, package.GetIcon()); #endif splashWindow = (Window)splash; metadata.UpdateLaunchStatus = s => { if (splash != null && splashWindow != null && splashWindow.IsVisible) { splash.ShowText(s); } }; #if ENFORCE_PACKAGE_SECURITY if (!isSigned) { splashWindow.Style = Application.Current.Resources["AlarmSplashScreenStyle"] as Style; } #endif splashWindow.Show(); } // Extract the application arguments from the command line Dictionary <string, object> args = null; if (cmdLine != null && _appArgumentParser != null) { string appArgs, appUrl; if (cmdLine.GetValue("args", out appArgs)) { args = _appArgumentParser(appArgs); } else if (cmdLine.GetValue("url", out appUrl)) { Uri uri; if (Uri.TryCreate(appUrl, UriKind.Absolute, out uri)) { if (!string.IsNullOrEmpty(uri.Query)) { args = _appArgumentParser(uri.Query.Substring(1)); } } } } //Create and register application application = _createApplication(package, metadata, args); Register(application); // Launch the application var stopWatch = AutoStopwatch.TimeIt("Launching"); application.Launched += delegate { if (splashWindow != null) { splashWindow.Dispatcher.BeginInvoke(new Action(() => { if (splashWindow != null) { splashWindow.Close(); } })); } this.RemoveSingleInstanceLaunchMarker(metadata.Id); stopWatch.Dispose(); }; application.Launch(); string protocolUri = null; if (cmdLine != null) { cmdLine.GetValue("url", out protocolUri); if (!string.IsNullOrEmpty(protocolUri)) { application.OnProtocolInvoke(protocolUri); } } } catch (Exception ex) { Logger.Info("Error starting paragon application : {0}", ex); MessageBox.Show("Unable to start:\n\n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); if (splashWindow != null) { splashWindow.Close(); } if (application != null) { RemoveSingleInstanceLaunchMarker(metadata.Id); application.Close(); application = null; } } }
/// <summary> /// Launch the first application in the host process /// </summary> /// <param name="package"></param> /// <param name="metadata"></param> public void RunApplication(ParagonCommandLineParser cmdLine, IApplicationPackage package, ApplicationMetadata metadata) { if (IsInitialized) { throw new Exception("Application manger is already initialized"); } var manifest = package.Manifest; // Initialize the following from the first application manifest ProcessGroup = manifest.ProcessGroup ?? string.Empty; CacheFolder = Path.Combine(_paragonFolder, string.IsNullOrEmpty(manifest.ProcessGroup) ? manifest.Id : manifest.ProcessGroup); Environment = metadata.Environment; DisableSpellChecking = manifest.DisableSpellChecking; // set browser language from manifest - default is en-US // "automatic" will set browser language to os culture info if (!string.IsNullOrEmpty(manifest.BrowserLanguage)) { if (string.Equals(manifest.BrowserLanguage, "Automatic", StringComparison.InvariantCultureIgnoreCase)) { BrowserLanguage = CultureInfo.CurrentCulture.Name; } else { //verify specified culture CultureInfo cultureInfo = null; try { cultureInfo = new CultureInfo(manifest.BrowserLanguage); } catch (Exception) { Logger.Error("Manifest browser language is not valid. Using default browser language en-US"); } BrowserLanguage = (cultureInfo != null) ? (cultureInfo.Name) : (BrowserLanguage); } Logger.Info(string.Format("Browser language being used is {0}", BrowserLanguage)); } string auth_server_whitelist = null; string auth_delegate_whitelist = null; if (cmdLine != null) { cmdLine.GetValue("auth-server-whitelist", out auth_server_whitelist); Logger.Info(string.Format("auth-server-whitelist [{0}]", auth_server_whitelist)); cmdLine.GetValue("auth-delegate-whitelist", out auth_delegate_whitelist); Logger.Info(string.Format("auth-delegate-whitelist [{0}]", auth_delegate_whitelist)); } // Initialize CEF using (AutoStopwatch.TimeIt("CEF initialization")) { ParagonRuntime.Initialize( CacheFolder, null, BrowserLanguage, auth_server_whitelist, auth_delegate_whitelist, DisableSpellChecking, Environment == ApplicationEnvironment.Development); } RunApplicationInternal(cmdLine, package, metadata); }
public static void Main() { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; // Create command line args parser. var cmdLine = new ParagonCommandLineParser(Environment.GetCommandLineArgs()); /* * Following statement is due to the Chromium bug: https://code.google.com/p/chromium/issues/detail?id=125614 * This statement can be removed once we know for sure that the issue has been fixed by Chrome. * For now, we are disabling any system setting/command line setting for the TZ variable. */ Environment.SetEnvironmentVariable("TZ", null); // Launch a debugger if a --debug flag was passed. if (cmdLine.HasFlag("debug")) { Debugger.Launch(); } // Extract app package. ApplicationMetadata appMetadata; IApplicationPackage appPackage; if (!ApplicationManager.ResolveMetadataAndPackage(cmdLine, out appMetadata, out appPackage)) { Environment.ExitCode = 1; return; } try { _appManager = ApplicationManager.GetInstance(); //initialize logger earlier in the start up sequence _appManager.InitializeLogger(Environment.ExpandEnvironmentVariables(Settings.Default.CacheDirectory), appPackage); // Bail if the app is a singleton and an instance is already running. Cmd line args from // this instance will be sent to the singleton isntance by the SingleInstance utility. if (_appManager.RedirectApplicationLaunchIfNeeded(appPackage, appMetadata.Environment)) { return; } // Initialize the app. App app; using (AutoStopwatch.TimeIt("Initializing Paragon.App")) { app = new App(); app.InitializeComponent(); app.Startup += delegate { _appManager.Initialize( (name, version, iconStream) => new ParagonSplashScreen(name, version, iconStream), (package, metadata, args) => { var bootstrapper = new Bootstrapper(); var appFactory = bootstrapper.Resolve <ApplicationFactory>(); return(appFactory.CreateApplication(metadata, package, args)); }, (args) => { var query = HttpUtility.ParseQueryString(args); return(query.Keys.Cast <string>().ToDictionary <string, string, object>(key => key, key => query[key])); }, Environment.ExpandEnvironmentVariables(Settings.Default.CacheDirectory), true, appPackage.Manifest.DisableSpellChecking ); _appManager.AllApplicationsClosed += delegate { _appManager.Shutdown("All applications closed"); _appManager.ShutdownLogger(); app.Shutdown(); }; _appManager.RunApplication(cmdLine, appPackage, appMetadata); }; } // Run the app (this is a blocking call). app.Run(); } catch (Exception ex) { MessageBox.Show(string.Format("Error launching application : {0}", ex.InnerException != null ? ex.InnerException.Message : ex.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error); Environment.ExitCode = 1; throw; } }