Exemplo n.º 1
0
    private void WebCoreInit()
    {
        int attemptCount = 0;
        int maxAttempts  = 10;

        while (!WebCore.IsRunning && attemptCount < maxAttempts)
        {
            WebCoreConfig wcConfig = new WebCoreConfig()
            {
                SaveCacheAndCookies = true
            };
            if (attemptCount > 0)
            {
                wcConfig.UserDataPath = "CSIDL_APPDATA/Awesomium/Default" + customCacheStr + attemptCount;
            }
            WebCore.Initialize(wcConfig);

            try
            {
                WebView wv = WebCore.CreateWebView(1, 1);
                wv.Close();
            }
            catch (Exception e)
            {
                Debug.LogError("Caught webcore init exception, trying new path for cache...");
                attemptCount++;
            }
        }
        error = attemptCount >= maxAttempts;
    }
Exemplo n.º 2
0
        public TitleScreen(DangerZone pParent)
            : base(pParent)
        {
            #if WINDOWS
            WebCoreConfig pConfig = new WebCoreConfig();
            pConfig.EnableJavascript = true;
            //WebCore.Initialize(pConfig, true);

            this.Parent.IsMouseVisible = true;

            m_pWebView = WebCore.CreateWebView(800, 600);
            {
                m_pWebView.LoadURL("http://www.google.com"); //Content\\Editor\\index.html
                while (m_pWebView.IsLoadingPage)
                    WebCore.Update();

                m_pWebView.Render().SaveToPNG("result.png", true);

                /*
                 * Här kan vi då kanske ladda in filen?
                 */

            }
            //WebCore.Shutdown();
            #endif
        }
        public void InitializeWebCore()
        {
            if (IsWebCoreInitialized)
            {
                throw new InvalidOperationException("Cannot initialize WebBrowserPool more than once.");
            }

            _webViews = new Stack <WebView>();
            Console.WriteLine("-- Initializing WebBrowserPool thread: " + Thread.CurrentThread.ManagedThreadId + " : " +
                              Thread.CurrentThread.Name);
            Console.WriteLine("-- Initializing WebBrowserPool At " + DateTime.Now);

            dispatcher = Dispatcher.CurrentDispatcher;
            //Init Awesomium Webview correctly.
            //Note: Do we need special settings for WebCoreConfig?
            //var webCoreConfig = new WebCoreConfig();
            WebCoreConfig config = new WebCoreConfig
            {
                // !THERE CAN ONLY BE A SINGLE WebCore RUNNING PER PROCESS!
                // We have ensured that our application is single instance,
                // with the use of the WPFSingleInstance utility.
                // We can now safely enable cache and cookies.
                SaveCacheAndCookies = true,
                // In case our application is installed in ProgramFiles,
                // we wouldn't want the WebCore to attempt to create folders
                // and files in there. We do not have the required privileges.
                // Furthermore, it is important to allow each user account
                // have its own cache and cookies. So, there's no better place
                // than the Application User Data Path.
                EnablePlugins      = true,
                EnableVisualStyles = false,
                // ...See comments for UserDataPath.
                // Let's gather some extra info for this sample.
                LogLevel = LogLevel.Verbose
            };

            WebCore.Initialize(config);

            for (int i = NUM_WEB_VIEWS - 1; i >= 0; i--)
            {
                WebView view = WebCore.CreateWebView(1024, 768);
                _webViews.Push(view);
            }
            Console.WriteLine("-- Done -- Initializing the WebBrowserPool At " + DateTime.Now);
            Console.WriteLine("Entering Update Loop");

            DispatcherTimer updateTimer = new DispatcherTimer(DispatcherPriority.Send, Dispatcher.CurrentDispatcher)
            {
                Interval = TimeSpan.FromMilliseconds(20)
            };

            updateTimer.Tick += (sender, args) => WebCore.Update();
            updateTimer.Start();

            IsWebCoreInitialized = true;
            Dispatcher.Run();
        }
Exemplo n.º 4
0
        public D3DBrowser()
        {
            IsActive = true;

            var wConfig = new WebCoreConfig();
            wConfig.LogLevel = LogLevel.Verbose;
            wConfig.LogPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\web.log";
            wConfig.EnableVisualStyles = false;
            WebCore.Initialize(wConfig);

            InitializeComponent();
        }
Exemplo n.º 5
0
 private static void SetupBrowser()
 {
     // We may be a new window in the same process.
     if (!WebCore.IsRunning)
     {
         // Setup WebCore with plugins enabled.
         WebCoreConfig config = new WebCoreConfig
         {
             ProxyServer         = "http://127.0.0.1:" + FiddlerApplication.oProxy.ListenPort.ToString(),
             EnablePlugins       = true,
             SaveCacheAndCookies = true
         };
         WebCore.Initialize(config);
     }
     else
     {
         throw new InvalidOperationException("WebCore should be already running");
     }
 }
Exemplo n.º 6
0
        public MainForm()
        {
            InitializeComponent();

            WebCoreConfig webConfig = new WebCoreConfig()
            {
                SaveCacheAndCookies = true,
                HomeURL = "http://www.google.com",
                LogLevel = LogLevel.Verbose
            };
            WebCore.Initialize(webConfig);

            DocumentWindow MainTab = new DocumentWindow();
            MainTab.Text = "Home";
            Browser MainBr = new Browser();
            MainBr.Dock = DockStyle.Fill;
            MainTab.Controls.Add(MainBr);
            radDock1.AddDocument(MainTab, DockPosition.Fill);
        }
Exemplo n.º 7
0
Arquivo: Program.cs Projeto: hiiru/lab
        private static void Main(string[] args)
        {
            PrintMessage("Starting spider test.", true);
            var config = new WebCoreConfig { CustomCSS = "::-webkit-scrollbar { visibility: hidden; }" };
            WebCore.Initialize(config);

            using (WebView webView = WebCore.CreateWebView(1800, 3600))
            {
                webView.LoadCompleted += OnFinishLoading;
                webView.BeginLoading += OnBeginLoading;
                webView.ResourceRequest += OnRessourceRequest;

                webView.LoadURL("http://www.autoscout24.ch/default.aspx?lng=de");
                WebCore.SetCookie("http://www.autoscout24.ch", ".listPageSize=50; domain=autoscout24.ch; path=/Search/", false, false);

                WaitForRequest();
                string idModelDDL = "DdlMakes";
                string idSearchButton = "BtnSearch";
                JSValue value = webView.ExecuteJavascriptWithResult(String.Format("document.getElementById('{0}').value='{1}'", idModelDDL, 12894));  //If you want simulate KeyStrokes instead you should use KeyEvent

                webView.Render().SaveToPNG("pre-submitsearch.png", true);
                Process.Start("pre-submitsearch.png");
                JSValue valueSelectText = webView.ExecuteJavascriptWithResult(String.Format("document.getElementById('{0}').click()", idSearchButton)); //With This you take focus of textbox

                WaitForRequest();
                webView.ExecuteJavascriptWithResult("document.getElementsByTagName('html')[0].outerHTML;");
                JSValue innerHtml = webView.ExecuteJavascriptWithResult("document.getElementById('aspnetForm').getElementsByTagName('fieldset')[0].innerHTML");
                var list = parseList(innerHtml);
                if (list != null && list.Count > 0)
                {
                    printList(list);
                }

                webView.Render().SaveToPNG("result.png", true);
                Process.Start("result.png");
            }

            Console.ReadKey(true);

            // Shut down Awesomium before exiting.
            WebCore.Shutdown();
        }
Exemplo n.º 8
0
        public WebForm()
        {
            // Notice that Control.DoubleBuffered has been set to true
            // in the designer, to prevent flickering.

            InitializeComponent();

            WebCoreConfig config = new WebCoreConfig {
                EnablePlugins = true
            };

            WebCore.Initialize(config);

            webView = WebCore.CreateWebView(this.ClientSize.Width, this.ClientSize.Height);
            webView.IsDirtyChanged   += OnIsDirtyChanged;
            webView.SelectLocalFiles += OnSelectLocalFiles;
            webView.CursorChanged    += OnCursorChanged;
            webView.LoadURL("http://www.google.com");
            webView.Focus();
        }
Exemplo n.º 9
0
        private static void InitializeCore()
        {
            // We may be a new window in the same process.
            if (!WebCore.IsRunning)
            {
                // Setup WebCore with plugins enabled.
                WebCoreConfig config = new WebCoreConfig
                {
                    // !THERE CAN ONLY BE A SINGLE WebCore RUNNING PER PROCESS!
                    // We have ensured that our application is single instance,
                    // with the use of the WPFSingleInstance utility.
                    // We can now safely enable cache and cookies.
                    SaveCacheAndCookies = true,
                    // In case our application is installed in ProgramFiles,
                    // we wouldn't want the WebCore to attempt to create folders
                    // and files in there. We do not have the required privileges.
                    // Furthermore, it is important to allow each user account
                    // have its own cache and cookies. So, there's no better place
                    // than the Application User Data Path.
                    UserDataPath  = My.Application.UserAppDataPath,
                    EnablePlugins = true,
                    HomeURL       = Settings.Default.HomeURL,
                    // ...Se comments for UserDataPath.
                    LogPath = My.Application.UserAppDataPath,
                    // Let's gather some extra info for this sample.
                    LogLevel = LogLevel.Verbose
                };

                // Caution! Do not start the WebCore in window's constructor.
                // This may be a startup window and a synchronization context
                // (necessary for auto-update), may not be available during
                // construction; the Dispatcher may not be running yet
                // (see App.xaml.cs).
                //
                // Setting the start parameter to false, let's us define
                // configuration settings early enough to be secure, but
                // actually delay the starting of the WebCore until
                // the first WebControl or WebView is created.
                WebCore.Initialize(config, false);
            }
        }
 private static void SetupBrowser()
 {
     // We may be a new window in the same process.
     if (!WebCore.IsRunning)
     {
         // Setup WebCore with plugins enabled.
         WebCoreConfig config = new WebCoreConfig
         {
             // Here we plug the internal proxy to the awesomium engine
             ProxyServer = "http://127.0.0.1:" + FiddlerApplication.oProxy.ListenPort.ToString(),
             // Adapt others options related to your needs
             EnablePlugins       = true,
             SaveCacheAndCookies = true,
             UserDataPath        = Environment.ExpandEnvironmentVariables(@"%APPDATA%\MyApp"),
         };
         WebCore.Initialize(config);
     }
     else
     {
         throw new InvalidOperationException("WebCore should be already running");
     }
 }
Exemplo n.º 11
0
    public void Start()
    {
        // Initialize the WebCore if it's not active
        if (!WebCore.IsRunning)
        {
            WebCoreConfig conf = new WebCoreConfig();
            conf.EnablePlugins = true;
            WebCore.Initialize(conf);

            webCoreHelper = new GameObject("WebCoreHelperInstance");
            webCoreHelper.AddComponent <WebCoreHelper>();
        }

        webView = WebCore.CreateWebView(width, height);

        webViewList.Add(webView);
        LoadURL(initialURL);
        texture = new Texture2D(width, height, TextureFormat.RGBA32, false);

        Pixels       = texture.GetPixels32(0);
        PixelsHandle = GCHandle.Alloc(Pixels, GCHandleType.Pinned);

        if (renderer)
        {
            renderer.material.mainTexture = texture;
        }
        else if (GetComponent(typeof(GUITexture)))
        {
            GUITexture gui = GetComponent(typeof(GUITexture)) as GUITexture;
            gui.texture = texture;
        }
        else
        {
            Debug.Log("Game Object has no Material or GUI Texture, we cannot render a web-page to this object!");
        }
    }
Exemplo n.º 12
0
 /// <summary>
 /// Ctor
 /// </summary>
 /// <param name="config">Config</param>
 /// <param name="webHelper">Web helper</param>
 /// <param name="httpContext">HTTP context</param>
 public UserAgentHelper(WebCoreConfig config, IWebHelper webHelper, HttpContextBase httpContext)
 {
     this._config      = config;
     this._webHelper   = webHelper;
     this._httpContext = httpContext;
 }
Exemplo n.º 13
0
 static WebCoreConfig()
 {
     Default = new WebCoreConfig();
 }
Exemplo n.º 14
0
    public void Start()
    {
        // Initialize the WebCore if it's not active
        if (!WebCore.IsRunning)
        {
            WebCoreConfig conf = new WebCoreConfig();
            conf.EnablePlugins = true;
            WebCore.Initialize(conf);

            webCoreHelper = new GameObject("WebCoreHelperInstance");
            webCoreHelper.AddComponent<WebCoreHelper>();
        }

        webView = WebCore.CreateWebView(width, height);

        webViewList.Add(webView);
        LoadURL(initialURL);
        texture = new Texture2D(width, height, TextureFormat.RGBA32, false);

        Pixels = texture.GetPixels32(0);
        PixelsHandle = GCHandle.Alloc(Pixels, GCHandleType.Pinned);

        if (GetComponent<Renderer>())
        {
            GetComponent<Renderer>().material.mainTexture = texture;
        }
        else if (GetComponent(typeof(GUITexture)))
        {
            GUITexture gui = GetComponent(typeof(GUITexture)) as GUITexture;
            gui.texture = texture;
        }
        else
        {
            Debug.Log("Game Object has no Material or GUI Texture, we cannot render a web-page to this object!");
        }
    }
Exemplo n.º 15
0
        public void InitializeWebCore()
        {
            if (IsWebCoreInitialized)
            {
                throw new InvalidOperationException("Cannot initialize WebBrowserPool more than once.");
            }

            _webViews = new Stack<WebView>();
            Console.WriteLine("-- Initializing WebBrowserPool thread: " + Thread.CurrentThread.ManagedThreadId + " : " +
                              Thread.CurrentThread.Name);
            Console.WriteLine("-- Initializing WebBrowserPool At " + DateTime.Now);

            dispatcher = Dispatcher.CurrentDispatcher;
            //Init Awesomium Webview correctly.
            //Note: Do we need special settings for WebCoreConfig?
            //var webCoreConfig = new WebCoreConfig();
            WebCoreConfig config = new WebCoreConfig
                                       {
                                           // !THERE CAN ONLY BE A SINGLE WebCore RUNNING PER PROCESS!
                                           // We have ensured that our application is single instance,
                                           // with the use of the WPFSingleInstance utility.
                                           // We can now safely enable cache and cookies.
                                           SaveCacheAndCookies = true,
                                           // In case our application is installed in ProgramFiles,
                                           // we wouldn't want the WebCore to attempt to create folders
                                           // and files in there. We do not have the required privileges.
                                           // Furthermore, it is important to allow each user account
                                           // have its own cache and cookies. So, there's no better place
                                           // than the Application User Data Path.
                                           EnablePlugins = true,
                                           EnableVisualStyles = false,
                                           // ...See comments for UserDataPath.
                                           // Let's gather some extra info for this sample.
                                           LogLevel = LogLevel.Verbose
                                       };
            WebCore.Initialize(config);

            for (int i = NUM_WEB_VIEWS - 1; i >= 0; i--)
            {
                WebView view = WebCore.CreateWebView(1024, 768);
                _webViews.Push(view);
            }
            Console.WriteLine("-- Done -- Initializing the WebBrowserPool At " + DateTime.Now);
            Console.WriteLine("Entering Update Loop");

            DispatcherTimer updateTimer = new DispatcherTimer(DispatcherPriority.Send, Dispatcher.CurrentDispatcher)
                                              {Interval = TimeSpan.FromMilliseconds(20)};
            updateTimer.Tick += (sender, args) => WebCore.Update();
            updateTimer.Start();

            IsWebCoreInitialized = true;
            Dispatcher.Run();
        }
Exemplo n.º 16
0
 static WebCoreConfig()
 {
     Default = new WebCoreConfig();
 }
Exemplo n.º 17
0
        /// <summary>
        /// Initializes the <see cref="WebCore"/> singleton with certain configuration settings.
        /// </summary>
        /// <param name="config">
        /// An instance of <see cref="WebCoreConfig"/> specifying configuration settings.
        /// </param>
        /// <param name="start">
        /// True if the <see cref="WebCore"/> should immediately start. False to perform lazy instantiation.
        /// The <see cref="WebCore"/> will start when the first view (<see cref="WebView"/> or <see cref="Windows.Controls.WebControl"/>)
        /// is created. The default is true.
        /// </param>
        /// <remarks>
        /// <para>
        /// If you do not call this method, the <see cref="WebCore"/> will start automatically,
        /// using default configuration settings, when you first create a view through <see cref="CreateWebView"/>
        /// or by instantiating a <see cref="Windows.Controls.WebControl"/>.
        /// </para>
        /// <note>
        /// If you are not sure if <see cref="WebCore"/> is running, check <see cref="IsRunning"/>
        /// before calling this method. If <see cref="WebCore"/> is running, you will have
        /// to shut it down (see <see cref="Shutdown"/>) and <b>restart the hosting application</b> before 
        /// initializing <see cref="WebCore"/> again. Only a single initialization/instantiation of the 
        /// <see cref="WebCore"/> is possible per application session (process).
        /// </note>
        /// <para>
        /// If you set <see cref="WebCoreConfig.SaveCacheAndCookies"/> to true, 
        /// please make sure that your hosting application is a single instance application, 
        /// unless you are sure that you provide a unique <see cref="WebCoreConfig.UserDataPath"/>
        /// for each of your application's instances.
        /// </para>
        /// </remarks>
        /// <exception cref="InvalidOperationException">
        /// The member is called while <see cref="WebCore"/> is running.
        /// </exception>
        /// <seealso cref="IsRunning"/>
        public static void Initialize( WebCoreConfig config, bool start = true )
        {
            if ( isRunning )
                throw new InvalidOperationException( "The WebCore is already initialized. Call Shutdown() before initializing it again." );

            isShuttingDown = false;
            configuration = config;

            if ( start )
                Start();
        }