Exemplo n.º 1
0
        /// <summary>
        ///  Navigates to the specified URL using the given load flags, referrer and post data
        ///  In order to find out when Navigate has finished attach a handler to NavigateFinishedNotifier.NavigateFinished.
        /// </summary>
        /// <param name="url">The url to navigate to.  If the url is empty or null, the browser does not navigate and the method returns false.</param>
        /// <param name="loadFlags">Flags which specify how the page is loaded.</param>
        /// <param name="referrer">The referring URL, or null.</param>
        /// <param name="postData">post data and headers, or null</param>
        /// <param name="headers">headers, or null</param>
        /// <returns>true if Navigate started. false otherwise.</returns>
        public bool Navigate(string url, GeckoLoadFlags loadFlags, string referrer, MimeInputStream postData, MimeInputStream headers)
        {
            if (string.IsNullOrEmpty(url))
            {
                return(false);
            }

            // added these from http://code.google.com/p/geckofx/issues/detail?id=5 so that it will work even if browser isn't currently shown
            //if (!IsHandleCreated) CreateHandle();
            //if (IsBusy) this.Stop();


            //	if (!IsHandleCreated)
            //		throw new InvalidOperationException("Cannot call Navigate() before the window handle is created.");

            // WebNav.LoadURI throws an exception if we try to open a file that doesn't exist...
            Uri created;

            if (Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out created) && created.IsAbsoluteUri && created.IsFile)
            {
                if (!File.Exists(created.LocalPath) && !Directory.Exists(created.LocalPath))
                {
                    return(false);
                }
            }

            nsIURI referrerUri = null;

            if (!string.IsNullOrEmpty(referrer))
            {
                //referrerUri = Xpcom.GetService<nsIIOService>("@mozilla.org/network/io-service;1").NewURI(new nsAUTF8String(referrer), null, null);
                referrerUri = IOService.CreateNsIUri(referrer);
            }


            _webNav.LoadURI(url, (uint)loadFlags, referrerUri, postData != null ? postData._inputStream : null, headers != null ? headers._inputStream : null);

            return(true);
        }
Exemplo n.º 2
0
 /// <summary>
 ///  Navigates to the specified URL using the given load flags, referrer and post data
 ///  In order to find out when Navigate has finished attach a handler to NavigateFinishedNotifier.NavigateFinished.
 /// </summary>
 /// <param name="url">The url to navigate to.  If the url is empty or null, the browser does not navigate and the method returns false.</param>
 /// <param name="loadFlags">Flags which specify how the page is loaded.</param>
 /// <param name="referrer">The referring URL, or null.</param>
 /// <param name="postData">post data and headers, or null</param>
 /// <returns>true if Navigate started. false otherwise.</returns>
 public bool Navigate(string url, GeckoLoadFlags loadFlags, string referrer, MimeInputStream postData)
 {
     return(Navigate(url, loadFlags, referrer, postData, null));
 }
        /// <summary>
        /// Reloads the current page using the specified flags.
        /// </summary>
        /// <param name="flags"></param>
        /// <returns></returns>
        public bool Reload(GeckoLoadFlags flags)
        {
            Uri url = this.Url;
            if (url != null && url.IsFile && !File.Exists(url.LocalPath))
            {
                // can't reload a file which no longer exists--a COM exception will be thrown
                return false;
            }

            if (WebNav != null)
                WebNav.Reload((uint)flags);

            return true;
        }
Exemplo n.º 4
0
 /// <summary>
 /// Navigates to the specified URL using the given load flags.
 /// In order to find out when Navigate has finished attach a handler to NavigateFinishedNotifier.NavigateFinished.
 /// </summary>
 /// <param name="url">The url to navigate to.  If the url is empty or null, the browser does not navigate and the method returns false.</param>
 /// <param name="loadFlags">Flags which specify how the page is loaded.</param>
 public bool Navigate(string url, GeckoLoadFlags loadFlags)
 {
     return(Navigate(url, loadFlags, null, null, null));
 }
 /// <summary>
 /// Navigates to the specified URL using the given load flags.
 /// </summary>
 /// <param name="url">The url to navigate to.  If the url is empty or null, the browser does not navigate and the method returns false.</param>
 /// <param name="loadFlags">Flags which specify how the page is loaded.</param>
 public bool Navigate(string url, GeckoLoadFlags loadFlags)
 {
     return Navigate(url, loadFlags, null, null, null);
 }
        /// <summary>
        /// Navigates to the specified URL using the given load flags, referrer, post data and headers.
        /// </summary>
        /// <param name="url">The url to navigate to.  If the url is empty or null, the browser does not navigate and the method returns false.</param>
        /// <param name="loadFlags">Flags which specify how the page is loaded.</param>
        /// <param name="referrer">The referring URL, or null.</param>
        /// <param name="postData">The post data to send, or null.  If you use post data, you must explicity specify a Content-Type and Content-Length
        /// header in <paramref name="additionalHeaders"/>.</param>
        /// <param name="additionalHeaders">Any additional HTTP headers to send, or null.  Separate multiple headers with CRLF.  For example,
        /// "Content-Type: application/x-www-form-urlencoded\r\nContent-Length: 50"</param>
        public bool Navigate(string url, GeckoLoadFlags loadFlags, string referrer, byte [] postData, string additionalHeaders)
        {
            if (string.IsNullOrEmpty(url))
                return false;

            if (IsHandleCreated)
            {
                if (IsBusy)
                    this.Stop();

                // WebNav.LoadURI throws an exception if we try to open a file that doesn't exist...
                Uri created;
                if (Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out created) && created.IsAbsoluteUri && created.IsFile)
                {
                    if (!File.Exists(created.LocalPath) && !Directory.Exists(created.LocalPath))
                        return false;
                }

                nsIInputStream postDataStream = null, headersStream = null;

                if (postData != null)
                {
                    // post data must start with CRLF.  actually, you can put additional headers before this, but there's no
                    // point because this method has an "additionalHeaders" argument.  so we might as well insert it automatically
                    Array.Resize(ref postData, postData.Length + 2);
                    Array.Copy(postData, 0, postData, 2, postData.Length - 2);
                    postData[0] = (byte)'\r';
                    postData[1] = (byte)'\n';
                    postDataStream = ByteArrayInputStream.Create(postData);
                }

                if (!string.IsNullOrEmpty(additionalHeaders))
                {
                    // each header must end with a CRLF (including the last one)
                    // here we simply ensure that the last header has a CRLF.  if the header has other syntax problems,
                    // they're the caller's responsibility
                    if (!additionalHeaders.EndsWith("\r\n"))
                        additionalHeaders += "\r\n";

                    headersStream = ByteArrayInputStream.Create(System.Text.Encoding.UTF8.GetBytes(additionalHeaders));
                }

                nsIURI referrerUri = null;
                if (!string.IsNullOrEmpty(referrer))
                {
                    referrerUri = Xpcom.GetService<nsIIOService>("@mozilla.org/network/io-service;1").NewURI(new nsACString(referrer), null, null);
                }

                return (WebNav.LoadURI(url, (uint)loadFlags, referrerUri, postDataStream, headersStream) != 0);
            }
            else
            {
                throw new InvalidOperationException("Cannot call Navigate() before the window handle is created.");
            }
        }
 /// <summary>
 ///  Navigates to the specified URL using the given load flags, referrer and post data
 ///  In order to find out when Navigate has finished attach a handler to NavigateFinishedNotifier.NavigateFinished.
 /// </summary>
 /// <param name="url">The url to navigate to.  If the url is empty or null, the browser does not navigate and the method returns false.</param>
 /// <param name="loadFlags">Flags which specify how the page is loaded.</param>
 /// <param name="referrer">The referring URL, or null.</param>
 /// <param name="postData">post data and headers, or null</param>
 /// <returns>true if Navigate started. false otherwise.</returns>
 public bool Navigate(string url, GeckoLoadFlags loadFlags, string referrer, GeckoMIMEInputStream postData)
 {
     return Navigate(url, loadFlags, referrer, postData, null);
 }
        /// <summary>
        ///  Navigates to the specified URL using the given load flags, referrer and post data
        ///  In order to find out when Navigate has finished attach a handler to NavigateFinishedNotifier.NavigateFinished.
        /// </summary>
        /// <param name="url">The url to navigate to.  If the url is empty or null, the browser does not navigate and the method returns false.</param>
        /// <param name="loadFlags">Flags which specify how the page is loaded.</param>
        /// <param name="referrer">The referring URL, or null.</param>
        /// <param name="postData">post data and headers, or null</param>
        /// <param name="headers">headers, or null</param>
        /// <returns>true if Navigate started. false otherwise.</returns>
        public bool Navigate(string url, GeckoLoadFlags loadFlags, string referrer, GeckoMIMEInputStream postData, GeckoMIMEInputStream headers)
        {
            if (string.IsNullOrEmpty(url))
                return false;

            // WebNav.LoadURI throws an exception if we try to open a file that doesn't exist...
            Uri created;
            if (Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out created) && created.IsAbsoluteUri && created.IsFile)
            {
                if (!File.Exists(created.LocalPath) && !Directory.Exists(created.LocalPath))
                    return false;
            }

            nsIURI referrerUri = null;
            if (!string.IsNullOrEmpty(referrer))
            {
                //referrerUri = Xpcom.GetService<nsIIOService>("@mozilla.org/network/io-service;1").NewURI(new nsAUTF8String(referrer), null, null);
                referrerUri = IOService.CreateNsIUri(referrer);
            }

            WebNav.LoadURI(url, (uint)loadFlags, referrerUri, postData != null ? postData.InputStream : null, headers != null ? headers.InputStream : null);

            return true;
        }
Exemplo n.º 9
0
		/// <summary>
		/// Reloads the current page using the specified flags.
		/// </summary>
		/// <param name="flags"></param>
		/// <returns></returns>
		public bool Reload(GeckoLoadFlags flags)
		{
			if (WebNav != null)
				WebNav.Reload((uint)flags); 
			return true;
		}
Exemplo n.º 10
0
        /// <summary>
        ///  Navigates to the specified URL using the given load flags, referrer and post data
        ///  In order to find out when Navigate has finished attach a handler to NavigateFinishedNotifier.NavigateFinished.
        /// </summary>
        /// <param name="url">The url to navigate to.  If the url is empty or null, the browser does not navigate and the method returns false.</param>
        /// <param name="loadFlags">Flags which specify how the page is loaded.</param>
        /// <param name="referrer">The referring URL, or null.</param>
        /// <param name="postData">post data and headers, or null</param>
        /// <returns></returns>
        public bool Navigate(string url, GeckoLoadFlags loadFlags, string referrer, GeckoMIMEInputStream postData)
        {
            if (string.IsNullOrEmpty(url))
                return false;

            if (!IsHandleCreated)
                throw new InvalidOperationException("Cannot call Navigate() before the window handle is created.");

            // WebNav.LoadURI throws an exception if we try to open a file that doesn't exist...
            Uri created;
            if (Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out created) && created.IsAbsoluteUri && created.IsFile)
            {
                if (!File.Exists(created.LocalPath) && !Directory.Exists(created.LocalPath))
                    return false;
            }

            nsIURI referrerUri = null;
            if (!string.IsNullOrEmpty(referrer))
            {
                referrerUri = Xpcom.GetService<nsIIOService>("@mozilla.org/network/io-service;1").NewURI(new nsAUTF8String(referrer), null, null);
            }

            WebNav.LoadURI(url, (uint)loadFlags, referrerUri, postData.InputStream, null);

            return true;
        }
Exemplo n.º 11
0
		/// <summary>
		/// Reloads the current page using the specified flags.
		/// </summary>
		/// <param name="flags"></param>
		/// <returns></returns>
		public bool Reload(GeckoLoadFlags flags)
		{
			// We want Reload() to return immediately and to fire events asynchronously.
			BeginInvoke(new Action(() =>
			{
				try
				{
					WebNav.Reload((uint)flags);
				}
				catch (COMException e)
				{
					OnNavigationError(new GeckoNavigationErrorEventArgs(Url.ToString(), Window, e.ErrorCode));
				}
			}));
			
			return true;
		}
Exemplo n.º 12
0
		/// <summary>
		///  Navigates to the specified URL using the given load flags, referrer and post data
		///  In order to find out when Navigate has finished attach a handler to NavigateFinishedNotifier.NavigateFinished.
		/// </summary>
		/// <param name="url">The url to navigate to.  If the url is empty or null, the browser does not navigate and the method returns false.</param>
		/// <param name="loadFlags">Flags which specify how the page is loaded.</param>
		/// <param name="referrer">The referring URL, or null.</param>
		/// <param name="postData">post data and headers, or null</param>
		/// <param name="headers">headers, or null</param>
		/// <returns>true if Navigate started. false otherwise.</returns>
		public bool Navigate(string url, GeckoLoadFlags loadFlags, string referrer, MimeInputStream postData, MimeInputStream headers)
		{
			if (string.IsNullOrEmpty(url))
				return false;

			// added these from http://code.google.com/p/geckofx/issues/detail?id=5 so that it will work even if browser isn't currently shown
			if (!IsHandleCreated) CreateHandle(); 
			if (IsBusy) this.Stop();

			if (!IsHandleCreated)
				throw new InvalidOperationException("Cannot call Navigate() before the window handle is created.");

			nsIURI referrerUri = null;
			if (!string.IsNullOrEmpty(referrer))
			{
				referrerUri = IOService.CreateNsIUri( referrer );
			}

			// We want Navigate() to return immediately and to fire events asynchronously. Howerver,
			// WebNav.LoadURI() may fire 'Navigating' event synchronously, so we call it asynchronously.
			// WebNav.LoadURI may throw exceptions for some inaccessable urls
			// (see https://bugzilla.mozilla.org/show_bug.cgi?id=995298), 
			// so we convert them into NavigationError events.
			BeginInvoke(new Action(() =>
			{
				if (IsDisposed)
					return;

				try
				{
					WebNav.LoadURI(
						url, (uint) loadFlags, referrerUri, postData != null ? postData._inputStream : null,
						headers != null ? headers._inputStream : null );
				}
				catch (COMException ce)
				{
					OnNavigationError(new GeckoNavigationErrorEventArgs(url, Window, ce.ErrorCode));
				}
				catch (Exception e)
				{
					OnNavigationError(new GeckoNavigationErrorEventArgs(url, Window, GeckoError.NS_ERROR_UNEXPECTED));
				}
			}));

			return true;
		}
Exemplo n.º 13
0
        /// <summary>
        ///  Navigates to the specified URL using the given load flags, referrer and post data
        ///  In order to find out when Navigate has finished attach a handler to NavigateFinishedNotifier.NavigateFinished.
        /// </summary>
        /// <param name="url">The url to navigate to.  If the url is empty or null, the browser does not navigate and the method returns false.</param>
        /// <param name="loadFlags">Flags which specify how the page is loaded.</param>
        /// <param name="referrer">The referring URL, or null.</param>
        /// <param name="postData">post data and headers, or null</param>
        /// <param name="headers">headers, or null</param>
        /// <returns>true if Navigate started. false otherwise.</returns>
        public bool Navigate(string url, GeckoLoadFlags loadFlags, string referrer, GeckoMIMEInputStream postData, GeckoMIMEInputStream headers)
        {
            if (string.IsNullOrEmpty(url))
                return false;

            // added these from http://code.google.com/p/geckofx/issues/detail?id=5 so that it will work even if browser isn't currently shown
            if (!IsHandleCreated) CreateHandle();
            if (IsBusy) this.Stop();


            if (!IsHandleCreated)
                throw new InvalidOperationException("Cannot call Navigate() before the window handle is created.");

            // WebNav.LoadURI throws an exception if we try to open a file that doesn't exist...
            Uri created;
            if (Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out created) && created.IsAbsoluteUri && created.IsFile)
            {
                if (!File.Exists(created.LocalPath) && !Directory.Exists(created.LocalPath))
                    return false;
            }

            nsIURI referrerUri = null;
            if (!string.IsNullOrEmpty(referrer))
            {
                //TODO - check for memory leaks
                referrerUri = IOService.CreateNsIUri(referrer);
            }

            ClearCachedCOMPtrs();

            WebNav.LoadURI(url, (uint)loadFlags, referrerUri, postData != null ? postData.InputStream : null, headers != null ? headers.InputStream : null);

            return true;
        }