Ejemplo n.º 1
0
 private void WebBrowserOnNavigating(object sender, GeckoNavigatingEventArgs geckoNavigatingEventArgs)
 {
     if (!_messageEventHasBeenSetup)
     {
         _webBrowser.AddMessageEventListener("FreezerFire", WebBrowserOnFreezerFireDispach);
         _messageEventHasBeenSetup = true;
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Only the first call per browser per event name takes effect.
 /// </summary>
 /// <param name="eventName"></param>
 /// <param name="action"></param>
 public void AddMessageEventListener(string eventName, Action <string> action)
 {
     Debug.Assert(!InvokeRequired);
     if (_knownEvents.Contains(eventName))
     {
         return;                 // This browser already knows what to do about this; hopefully we don't have a conflict.
     }
     _browser.AddMessageEventListener(eventName, action);
     _knownEvents.Add(eventName);
 }
        async void init()
        {
            if (!InitFireFoxed)
            {
                InitFireFoxed = true;
                await Task.Run(() =>
                {
                    Thread.Sleep(1000);
                });

                Gecko.Xpcom.Initialize("Firefox");
            }
            this.Title     = "Loading...";
            this.AllowDrop = true;
            _gecko         = new GeckoWebBrowser();
            _gecko.CreateControl();
            _gecko.Enabled   = false;
            _gecko.AllowDrop = true;


            var uri = new Uri(Helper.Config.ServerUrl);
            //often cookies are stored on domain level, so ".google.com", not "www.google.com" (leading dot is important)
            string host = uri.Host.Replace("www", "");

            CookieManager.Add(host, "/", "WayScriptRemoting", RemotingClient.SessionID, false, false, false, Helper.ConvertDateTimeInt(DateTime.Now.AddYears(3)));

            //WayScriptRemoting
            //_gecko.NoDefaultContextMenu = true; //禁用右键菜单
            //_gecko.AddMessageEventListener("copyToClipboard", copyToClipboard);
            //_gecko.AddMessageEventListener("save", save);
            _gecko.AddMessageEventListener("loadFinish", loadFinish);
            //_gecko.AddMessageEventListener("watchPointValues", watchPointValues);
            //_gecko.AddMessageEventListener("openRunMode", openRunMode);
            //_gecko.AddMessageEventListener("writePointValue", writePointValue);
            //_gecko.AddMessageEventListener("go", go);
            //_gecko.AddMessageEventListener("goBack", goBack);
            //_gecko.AddMessageEventListener("open", open);
            //_gecko.AddMessageEventListener("openCode", openCode);
            //_gecko.AddMessageEventListener("fullScreen", fullScreen);
            //_gecko.AddMessageEventListener("exitFullScreen", exitFullScreen);
            //_gecko.AddMessageEventListener("showHistoryWindow", showHistoryWindow);

            winHost.Child             = _gecko;
            _gecko.ProgressChanged   += Gecko_ProgressChanged;
            _gecko.CreateWindow      += Gecko_CreateWindow;
            _gecko.DocumentCompleted += Gecko_DocumentCompleted;
            if (_dataModel.id != null)
            {
                _gecko.Navigate($"{Helper.Config.ServerUrl}/Home/GetWindowContent?windowid={_dataModel.id}");
            }
            else
            {
                _gecko.Navigate($"{Helper.Config.ServerUrl}/editor");
            }
        }
        /// <summary>
        /// create browser
        /// </summary>
        /// <returns></returns>
        private static GeckoWebBrowser CreateBrowserInternal()
        {
            GeckoWebBrowser browser = new GeckoWebBrowser();

            browser.CreateControl();
            browser.AddMessageEventListener("__post", ((string data) =>
            {
                data = System.Web.HttpUtility.UrlDecode(data);
            }));
            //////browser.NavigateFinishedNotifier.BlockUntilNavigationFinished();
            ////browser.JavascriptError += (sender, error) =>
            ////{
            ////    // do something
            ////};
            return(browser);
        }
Ejemplo n.º 5
0
        public Form1()
        {
            InitializeComponent();

            Gecko.Xpcom.Initialize("Firefox");

            gecko = new GeckoWebBrowser();
            gecko.CreateControl();
            gecko.NoDefaultContextMenu = true; //禁用右键菜单
            gecko.AddMessageEventListener("copyToClipboard", copyToClipboard);

            gecko.Dock = DockStyle.Fill;
            panel1.Controls.Add(gecko);
            gecko.ProgressChanged   += Gecko_ProgressChanged;
            gecko.CreateWindow      += Gecko_CreateWindow;
            gecko.DocumentCompleted += Gecko_DocumentCompleted;
            gecko.Navigate("http://localhost:8988/editor");
        }
Ejemplo n.º 6
0
        public void AddEventListener_JScriptFiresEvent_ListenerIsCalledWithMessage()
        {
            string payload = null;

            browser.AddMessageEventListener("callMe", ((string p) => payload = p));

            browser.LoadHtml(
                @"<!DOCTYPE html>
			                 <html><head>
			                 <script type='text/javascript'>
								window.onload= function() {
									var event = new MessageEvent('callMe',  { 'view' : window, 'bubbles' : true, 'cancelable' : false, 'data' : 'some data'}); document.dispatchEvent (event);
									document.dispatchEvent (event);
								}
							</script>
							</head><body></body></html>"                            );

            browser.NavigateFinishedNotifier.BlockUntilNavigationFinished();
            Assert.AreEqual("some data", payload);
        }
Ejemplo n.º 7
0
        public void AddEventListener_JScriptFiresEvent_ListenerIsCalledWithMessage()
        {
            string payload = null;

            browser.AddMessageEventListener("callMe", ((string p) => payload = p));

            browser.LoadHtml(
                @"<!DOCTYPE html>
			                 <html><head>
			                 <script type='text/javascript'>
								window.onload= function() {
									event = document.createEvent('MessageEvent');
									var origin = window.location.protocol + '//' + window.location.host;
									event.initMessageEvent ('callMe', true, true, 'some data', origin, 1234, window, null);
									document.dispatchEvent (event);
								}
							</script>
							</head><body></body></html>"                            );

            browser.NavigateFinishedNotifier.BlockUntilNavigationFinished();
            Assert.AreEqual("some data", payload);
        }
        private async Task DoStressTest(GeckoWebBrowser browser)
        {
            await Task.Delay(1000);

            var pageLinks = Enumerable.Range(1, 100).Select(page => string.Format(@"https://bitbucket.org/repo/all/{0}?name=c%23", page)).ToList();
            var callbacks = new List <string>();

            browser.AddMessageEventListener("callback", value => callbacks.Add(value));


            var repoLinks = new List <string>();

            foreach (var link in pageLinks)
            {
                repoLinks.AddRange(await RetrieveBitbucketRepositoryLinks(browser, link));

                DoCallbacks(browser);
            }
            Debug.WriteLine("Found {0} repo links", repoLinks.Count);

            //await browser.NavigateAndWait("http://www.google.de");
        }
Ejemplo n.º 9
0
 static void InstallCustomEventListener(object sender, GeckoNavigatingEventArgs e)
 {
     _browser.Navigating -= InstallCustomEventListener;
     _browser.AddMessageEventListener("callMe", ((string p) =>
                                                 MessageBox.Show(String.Format("C# : Got Message '{0}' from javascript", p))));
 }