Example #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.");

			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;
		}
Example #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);
		}