示例#1
0
		public void RemoveEventListener(string type, nsIDOMEventListener listener, bool useCapture)
		{
			using (var nType = new nsAString(type))
			{
				_target.Instance.RemoveEventListener(nType, listener, useCapture);
			}
		}
		/// <summary>
		/// Adds a new search engine from the file at the supplied URI, optionally
		/// asking the user for confirmation first.  If a confirmation dialog is
		/// shown, it will offer the option to begin using the newly added engine
		/// right away; if no confirmation dialog is shown, the new engine will be
		/// used right away automatically.
		///	</summary>
		/// <param name="engineUrl">The URL to the search engine's description file.</param>
		/// <param name="dataType">
		/// An integer representing the plugin file format. Must be one
		/// of the supported search engine data types defined above.
		/// </param>
		/// <param name="iconUrl">
		/// A URL string to an icon file to be used as the search engine's
		/// icon. This value may be overridden by an icon specified in the
		/// engine description file.
		///	</param>
		/// <param name="confirm">
		/// A boolean value indicating whether the user should be asked for
		/// confirmation before this engine is added to the list.  If this
		/// value is false, the engine will be added to the list upon successful
		/// load, but it will not be selected as the current engine.
		/// </param>
		/// <exception cref="COMException">
		/// @throws NS_ERROR_FAILURE if the type is invalid, or if the description
		/// file cannot be successfully loaded.
		/// </exception>
		public static void AddEngine(string engineUrl, int dataType, string iconUrl, bool confirm)
		{
			using (nsAString native1=new nsAString(engineUrl),native2=new nsAString(iconUrl))
			{
				_browserSearchService.Instance.AddEngine( native1, dataType, native2, confirm, null);
			}
		}
        internal static GeckoCanvasElement CreateCanvasOfImageElement(IGeckoWebBrowser browser, GeckoHtmlElement element, float xOffset,
                                                           float yOffset, float width, float height)
        {
            if (width == 0)
                throw new ArgumentException("width");

            if (height == 0)
                throw new ArgumentException("height");

            // Some opertations fail without a proper JSContext.
            using(var jsContext = new AutoJSContext(GlobalJSContextHolder.BackstageJSContext))
            {
                GeckoCanvasElement canvas = (GeckoCanvasElement)browser.Document.CreateElement("canvas");
                canvas.Width = (uint)width;
                canvas.Height = (uint)height;

                nsIDOMHTMLCanvasElement canvasPtr = (nsIDOMHTMLCanvasElement)canvas.DomObject;
                nsIDOMCanvasRenderingContext2D context;
                using (var str = new nsAString("2d"))
                {
                    context = (nsIDOMCanvasRenderingContext2D)canvasPtr.MozGetIPCContext(str);
                }

                context.DrawImage((nsIDOMElement)element.DomObject, xOffset, yOffset, width, height, xOffset, yOffset,
                                  width, height, 6);

                return canvas;
            }
        }
 public void AddEventListener(string type, nsIDOMEventListener listener, bool useCapture, bool wantUntrusted, int argc)
 {
     using (var nType = new nsAString(type))
     {
         _target.Instance.AddEventListener(nType, listener, useCapture, wantUntrusted, argc);
     }
 }
		public void SetData_ToTestValue_ToStringReturnsTestValue()
		{
			var objectUnderTest = new nsAString();
			objectUnderTest.SetData("hello world");

			Assert.AreEqual("hello world", objectUnderTest.ToString());
		}
		public void SetData_ToEmptyString_ToStringReturnsEmptyString()
		{
			var objectUnderTest = new nsAString();
			objectUnderTest.SetData(String.Empty);

			Assert.AreEqual(String.Empty, objectUnderTest.ToString());
		}
		public void SetData_ToNull_ToStringReturnsNull()
		{
			var objectUnderTest = new nsAString();
			objectUnderTest.SetData(null);

			Assert.AreEqual(null, objectUnderTest.ToString());
		}
		public void InitHashChangeEvent(string type,bool canBubble,bool cancelable,
		                                string oldUrl,string newUrl)
		{
			using (nsAString nType=new nsAString(type),nOld=new nsAString(oldUrl),nNew=new nsAString(newUrl))
			{
				_hashChangeEvent.InitHashChangeEvent( nType, canBubble, cancelable, nOld, nNew );
			}
		}
示例#9
0
 public void OutputToString_OutputEditableBody_BodyAndContentWrittenToString()
 {
     using (nsAString formatType = new nsAString("text/html"), retval = new nsAString())
     {
         _editor.OutputToString(formatType, 8, retval);
         Assert.AreEqual("<body contenteditable=\"true\"><div>hello world</div></body>", retval.ToString());
     }
 }
 public string toDataURL(string type)
 {
     using (nsAString retval = new nsAString(), param = new nsAString(type))
     {
         DOMHTMLElement.ToDataURL(param, null, 2, retval);
         return retval.ToString();
     }
 }
示例#11
0
 public void OutputToStream_OutputEditableBody_BodyAndContentWrittenToStream()
 {
     using(nsAString formatType = new nsAString("text/html"))
     {
         var outputStream = new StubOutputStream();
         _editor.OutputToStream(outputStream, formatType, new nsACString("utf8"), 8);
         Assert.AreEqual("<body contenteditable=\"true\"><div>hello world</div></body>", outputStream._result.ToString());
     }
 }
 public string toDataURL(string type)
 {
     using (nsAString retval = new nsAString(), param = new nsAString(type))
     {
         var instance = Xpcom.CreateInstance<nsIVariant>(Contracts.Variant);
         DOMHTMLElement.ToDataURL(param, instance, 2, retval);
         Marshal.ReleaseComObject(instance);
         return retval.ToString();
     }
 }
示例#13
0
		public string ToDataURL(string type)
		{
			using (var context = new AutoJSContext(GlobalJSContextHolder.BackstageJSContext))
			using (nsAString retval = new nsAString(), param = new nsAString(type))
			{
				JsVal js = default(JsVal);
				DOMHTMLElement.ToDataURL(param, ref js, context.ContextPointer, retval);
				return retval.ToString();
			}
		}
示例#14
0
		public void InitMouseEvent(string type, bool canBubble, bool cancelable, GeckoWindow view, int detail,
								   int screenX, int screenY, int clientX, int clientY,
								   bool ctrlKey, bool altKey, bool shiftKey, bool metaKey,
			ushort button, DomEventTarget target)
		{
			using (var typeArg = new nsAString(type))
			{
				_domMouseEvent.InitMouseEvent(typeArg, canBubble, cancelable, view.DomWindow, detail, screenX, screenY,
											   clientX, clientY, ctrlKey, altKey, shiftKey, metaKey, button, target.NativeObject);
			}
		}
示例#15
0
		public static bool RememberRecentBadCert(Uri url)
		{
			if (url == null)
				throw new ArgumentNullException("url");

			ComPtr<nsISSLStatus> aSSLStatus = null;
			try
			{
				int port = url.Port;
				if (port == -1) port = 443;
				using (var hostWithPort = new nsAString(url.Host + ":" + port.ToString()))
				{
					using (var certDbSvc = Xpcom.GetService2<nsIX509CertDB>(Contracts.X509CertDb))
					{
						if (certDbSvc != null)
						{
							using (var recentBadCerts = certDbSvc.Instance.GetRecentBadCerts(false).AsComPtr())
							{
								if (recentBadCerts != null)
									aSSLStatus = recentBadCerts.Instance.GetRecentBadCert(hostWithPort).AsComPtr();
							}
						}
					}
				}
				using (var cert = aSSLStatus.Instance.GetServerCertAttribute().AsComPtr())
				{
					if (aSSLStatus == null
						|| HasMatchingOverride(url, cert))
					{
						return false;
					}

					int flags = 0;
					if (aSSLStatus.Instance.GetIsUntrustedAttribute())
						flags |= nsICertOverrideServiceConsts.ERROR_UNTRUSTED;
					if (aSSLStatus.Instance.GetIsDomainMismatchAttribute())
						flags |= nsICertOverrideServiceConsts.ERROR_MISMATCH;
					if (aSSLStatus.Instance.GetIsNotValidAtThisTimeAttribute())
						flags |= nsICertOverrideServiceConsts.ERROR_TIME;

					RememberValidityOverride(url, cert, flags);
				}
			}
			finally
			{
				if (aSSLStatus != null)
					aSSLStatus.Dispose();
			}
			return true;
		}
		/// <summary>
		/// Adds a new search engine, without asking the user for confirmation and
		/// without starting to use it right away.
		/// </summary>
		/// <param name="name">The search engine's name. Must be unique. Must not be null.</param>
		/// <param name="iconUrl">
		/// Optional: A URL string pointing to the icon to be used to represent
		/// the engine.
		/// </param>
		/// <param name="alias">
		/// Optional: A unique shortcut that can be used to retrieve the
		/// search engine.
		/// </param>
		///	<param name="description">Optional: a description of the search engine.</param>
		/// <param name="method">
		/// The HTTP request method used when submitting a search query.
		/// Must be a case insensitive value of either "get" or "post".
		/// </param>
		///	<param name="url">
		/// The URL to which search queries should be sent.
		/// Must not be null.
		/// </param>
		public static void AddEngineWithDetails(string name, string iconUrl, string alias, string description, string method, string url)
		{
			if (string.IsNullOrEmpty( name )) throw new ArgumentException("Must not be null","name");

			using (nsAString native1 = new nsAString(name),
				native2 = new nsAString(iconUrl),
				native3 = new nsAString(alias),
				native4 = new nsAString(description),
				native5 = new nsAString(method),
				native6=new nsAString(url))
			{
				_browserSearchService.Instance.AddEngineWithDetails(native1, native2, native3, native4, native5, native6);
			}
		}
示例#17
0
        /// <summary>
        /// Get byte array with png image of the current browsers Window.
        /// Wpf methods on windows platform don't use a Bitmap :-/
        /// Not captures plugin (Flash,etc...) windows
        /// </summary>
        /// <param name="xOffset"></param>
        /// <param name="yOffset"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        public static byte[] CanvasGetPngImage(IGeckoWebBrowser browser, uint xOffset, uint yOffset, uint width, uint height)
        {
            if (width == 0)
                throw new ArgumentException("width");

            if (height == 0)
                throw new ArgumentException("height");

            // Use of the canvas technique was inspired by: the abduction! firefox plugin by Rowan Lewis
            // https://addons.mozilla.org/en-US/firefox/addon/abduction/

            // Some opertations fail without a proper JSContext.
            using (AutoJSContext jsContext = new AutoJSContext(GlobalJSContextHolder.BackstageJSContext))
            {
                GeckoCanvasElement canvas = (GeckoCanvasElement)browser.Document.CreateElement("canvas");
                canvas.Width = width;
                canvas.Height = height;

                nsIDOMHTMLCanvasElement canvasPtr = (nsIDOMHTMLCanvasElement)canvas.DomObject;
                nsIDOMCanvasRenderingContext2D context;
                using (nsAString str = new nsAString("2d"))
                {
                    context = (nsIDOMCanvasRenderingContext2D)canvasPtr.MozGetIPCContext(str);
                }

                // the bitmap image needs to conform to the (Full)Zoom being applied, otherwise it will render wrongly
                var zoom = browser.GetMarkupDocumentViewer().GetFullZoomAttribute();
                context.Scale(zoom, zoom);

                using (nsAString color = new nsAString("rgb(255,255,255)"))
                {
                    context.DrawWindow((nsIDOMWindow)browser.Window.DomWindow, xOffset, yOffset, width, height, color,
                                        (uint)(nsIDOMCanvasRenderingContext2DConsts.DRAWWINDOW_DO_NOT_FLUSH |
                                                   nsIDOMCanvasRenderingContext2DConsts.DRAWWINDOW_DRAW_VIEW |
                                                   nsIDOMCanvasRenderingContext2DConsts.DRAWWINDOW_ASYNC_DECODE_IMAGES |
                                                   nsIDOMCanvasRenderingContext2DConsts.DRAWWINDOW_USE_WIDGET_LAYERS));
                    ;
                }

                string data = canvas.toDataURL("image/png");
                byte[] bytes = Convert.FromBase64String(data.Substring("data:image/png;base64,".Length));
                return bytes;
            }
        }
 /// <summary>
 ///Synthesize a mouse scroll event for a window. The event types supported
 /// are:
 /// DOMMouseScroll
 /// MozMousePixelScroll
 ///
 /// Events are sent in coordinates offset by aX and aY from the window.
 ///
 /// Cannot be accessed from unprivileged context (not content-accessible)
 /// Will throw a DOM security error if called without UniversalXPConnect
 /// privileges.
 ///
 /// @param aType event type
 /// @param aX x offset in CSS pixels
 /// @param aY y offset in CSS pixels
 /// @param aButton button to synthesize
 /// @param aScrollFlags flag bits --- see nsMouseScrollFlags in nsGUIEvent.h
 /// @param aDelta the direction and amount to scroll (in lines or pixels,
 /// depending on the event type)
 /// @param aModifiers modifiers pressed, using constants defined in nsIDOMNSEvent
 /// </summary>
 public void SendMouseScrollEvent(string aType, float aX, float aY, int aButton, int aScrollFlags, int aDelta, int aModifiers)
 {
     using (nsAString type = new nsAString(aType))
     {
         _windowUtils.SendMouseScrollEvent(type, aX, aY, aButton, aScrollFlags, aDelta, aModifiers);
     }
 }
 /// <summary>
 ///The same as sendMouseEvent but ensures that the event is dispatched to
 /// this DOM window or one of its children.
 /// </summary>		
 public void SendMouseEventToWindow(string aType, float aX, float aY, int aButton, int aClickCount, int aModifiers, bool aIgnoreRootScrollFrame)
 {
     using (nsAString type = new nsAString(aType))
     {
         _windowUtils.SendMouseEventToWindow(type, aX, aY, aButton, aClickCount, aModifiers, aIgnoreRootScrollFrame);
     }
 }
 /// <summary>
 /// Synthesize a key event to the window. The event types supported are:
 /// keydown, keyup, keypress
 ///
 /// Key events generally end up being sent to the focused node.
 ///
 /// Cannot be accessed from unprivileged context (not content-accessible)
 /// Will throw a DOM security error if called without UniversalXPConnect
 /// privileges.
 ///
 /// @param aType event type
 /// @param aKeyCode key code
 /// @param aCharCode character code
 /// @param aModifiers modifiers pressed, using constants defined in nsIDOMNSEvent
 /// @param aPreventDefault if true, preventDefault() the event before dispatch
 ///
 /// @return false if the event had preventDefault() called on it,
 /// true otherwise.  In other words, true if and only if the
 /// default action was taken.
 /// </summary>
 /// 	
 public bool SendKeyEvent(string aType, int aKeyCode, int aCharCode, int aModifiers, bool aPreventDefault)
 {
     using (nsAString type = new nsAString(aType))
     {
         return _windowUtils.SendKeyEvent(type, aKeyCode, aCharCode, aModifiers, aPreventDefault);
     }
 }
 /// <summary>
 /// Function to get metadata associated with the window's current document
 /// @param aName the name of the metadata.  This should be all lowercase.
 /// @return the value of the metadata, or the empty string if it's not set
 ///
 /// Will throw a DOM security error if called without UniversalXPConnect
 /// privileges.
 /// </summary>		
 public string GetDocumentMetadata(string name)
 {
     using (nsAString tempName = new nsAString(name), ret = new nsAString())
     {
         _windowUtils.GetDocumentMetadata(tempName, ret);
         return ret.ToString();
     }
 }
 /// <summary>
 /// See nsIWidget::ActivateNativeMenuItemAt
 ///
 /// Cannot be accessed from unprivileged context (not content-accessible)
 /// Will throw a DOM security error if called without UniversalXPConnect
 /// privileges.
 /// </summary>		
 public void ActivateNativeMenuItemAt(string indexString)
 {
     using (nsAString index = new nsAString(indexString))
     {
         _windowUtils.ActivateNativeMenuItemAt(index);
     }
 }
示例#23
0
 public void PostMessage(IntPtr message, nsAString targetOrigin)
 {
     throw new NotImplementedException();
 }
        void nsIContextMenuListener2.OnShowContextMenu(uint aContextFlags, nsIContextMenuInfo info)
        {
            // if we don't have a target node, we can't do anything by default.  this happens in XUL forms (i.e. about:config)
            if (info.GetTargetNodeAttribute() == null)
                return;

            ContextMenu menu = new ContextMenu();

            // no default items are added when the context menu is disabled
            if (!this.NoDefaultContextMenu)
            {
                List<MenuItem> optionals = new List<MenuItem>();

                if (this.CanUndo || this.CanRedo)
                {
                    optionals.Add(new MenuItem("Undo", delegate { Undo(); }));
                    optionals.Add(new MenuItem("Redo", delegate { Redo(); }));

                    optionals[0].Enabled = this.CanUndo;
                    optionals[1].Enabled = this.CanRedo;
                }
                else
                {
                    optionals.Add(new MenuItem("Back", delegate { GoBack(); }));
                    optionals.Add(new MenuItem("Forward", delegate { GoForward(); }));

                    optionals[0].Enabled = this.CanGoBack;
                    optionals[1].Enabled = this.CanGoForward;
                }

                optionals.Add(new MenuItem("-"));

                if (this.CanCopyImageContents)
                    optionals.Add(new MenuItem("Copy Image Contents", delegate { CopyImageContents(); }));

                if (this.CanCopyImageLocation)
                    optionals.Add(new MenuItem("Copy Image Location", delegate { CopyImageLocation(); }));

                if (this.CanCopyLinkLocation)
                    optionals.Add(new MenuItem("Copy Link Location", delegate { CopyLinkLocation(); }));

                if (this.CanCopySelection)
                    optionals.Add(new MenuItem("Copy Selection", delegate { CopySelection(); }));

                MenuItem mnuSelectAll = new MenuItem("Select All");
                mnuSelectAll.Click += delegate { SelectAll(); };

                GeckoDomDocument doc = GeckoDomDocument.CreateDomDocumentWraper(info.GetTargetNodeAttribute().GetOwnerDocumentAttribute());

                string viewSourceUrl = (doc == null) ? null : Convert.ToString(doc.Uri);

                MenuItem mnuViewSource = new MenuItem("View Source");
                mnuViewSource.Enabled = !string.IsNullOrEmpty(viewSourceUrl);
                mnuViewSource.Click += delegate { ViewSource(viewSourceUrl); };

                MenuItem mnuOpenInSystemBrowser = new MenuItem("View In System Browser");//nice for debugging with firefox/firebug
                mnuOpenInSystemBrowser.Enabled = !string.IsNullOrEmpty(viewSourceUrl);
                mnuOpenInSystemBrowser.Click += delegate { ViewInSystemBrowser(viewSourceUrl); };

                string properties = (doc != null && doc.Uri == Document.Uri) ? "Page Properties" : "IFRAME Properties";

                MenuItem mnuProperties = new MenuItem(properties);
                mnuProperties.Enabled = doc != null;
                mnuProperties.Click += delegate { ShowPageProperties(doc); };

                menu.MenuItems.AddRange(optionals.ToArray());
                menu.MenuItems.Add(mnuSelectAll);
                menu.MenuItems.Add("-");
                menu.MenuItems.Add(mnuViewSource);
                menu.MenuItems.Add(mnuOpenInSystemBrowser);
                menu.MenuItems.Add(mnuProperties);
            }

            // get image urls
            Uri backgroundImageSrc = null, imageSrc = null;
            nsIURI src;
            try
            {
                src = info.GetBackgroundImageSrcAttribute();
                backgroundImageSrc = new Uri(new nsURI(src).Spec);
            }
            catch (COMException comException)
            {
                if ((comException.ErrorCode & 0xFFFFFFFF) != 0x80004005)
                    throw comException;
            }

            try
            {
                src = info.GetImageSrcAttribute();
                if (src != null)
                    imageSrc = new Uri(new nsURI(src).Spec);
            }
            catch (COMException comException)
            {
                if ((comException.ErrorCode & 0xFFFFFFFF) != 0x80004005)
                    throw comException;
            }

            // get associated link.  note that this needs to be done manually because GetAssociatedLink returns a non-zero
            // result when no associated link is available, so an exception would be thrown by nsString.Get()
            string associatedLink = null;
            try
            {
                using (nsAString str = new nsAString())
                {
                    info.GetAssociatedLinkAttribute(str);
                    associatedLink = str.ToString();
                }
            }
            catch (COMException comException) { }

            //GeckoContextMenuEventArgs e = new GeckoContextMenuEventArgs(
            //    PointToClient(MousePosition), menu, associatedLink, backgroundImageSrc, imageSrc,
            //    GeckoNode.Create(Xpcom.QueryInterface<nsIDOMNode>(info.GetTargetNodeAttribute()))
            //    );

            //OnShowContextMenu(e);

            //if (e.ContextMenu != null && e.ContextMenu.MenuItems.Count > 0)
            //{
            //    e.ContextMenu.Show(this, e.Location);
            //}
        }
        /// <summary>
        /// Gets the value of an attribute on this element with the specified name and namespace.
        /// </summary>
        /// <param name="attributeName"></param>
        /// <returns></returns>
        public string GetAttributeNS(string namespaceUri, string attributeName)
        {
            if (string.IsNullOrEmpty(namespaceUri))
                return GetAttribute(attributeName);

            if (string.IsNullOrEmpty(attributeName))
                throw new ArgumentException("attributeName");
            nsAString retval = new nsAString();
            _domElement.GetAttributeNS(new nsAString(namespaceUri), new nsAString(attributeName), retval);
            return retval.ToString();
        }
示例#26
0
		private void SetValue(string name, nsISupports value)
		{
			if (name == null)
				throw new ArgumentNullException("name");

			using (var data = Xpcom.CreateInstance2<nsIWritableVariant>("@mozilla.org/variant;1"))
			{
				data.Instance.SetAsISupports(value);
				using (var key = new nsAString(name))
				{
					object comObj = command.Instance.SetUserData(key, data.Instance, null);
					Xpcom.FreeComObject(ref comObj);
				}
			}
		}
示例#27
0
		private void ClearValue(string name)
		{
			if (name == null)
				throw new ArgumentNullException("name");

			using (var key = new nsAString(name))
			{
				object comObj = command.Instance.SetUserData(key, null, null);
				Xpcom.FreeComObject(ref comObj);
			}
		}
示例#28
0
 public void PostMessage(IntPtr message, nsAString targetOrigin)
 {
     throw new NotImplementedException();
 }
示例#29
0
		//public void ObserveActivity(nsISupports aHttpChannel, uint aActivityType, uint aActivitySubtype, uint aTimestamp, ulong aExtraSizeData, nsACString aExtraStringData)
		public void ObserveActivity(nsISupports aHttpChannel,
												 UInt32 aActivityType,
												 UInt32 aActivitySubtype,
												 Int64 aTimestamp,
												 UInt64 aExtraSizeData,
					 nsACStringBase aExtraStringData) {
			nsIHttpChannel httpChannel = Xpcom.QueryInterface<nsIHttpChannel>(aHttpChannel);

			if (httpChannel != null) {
				switch (aActivityType) {
					case nsIHttpActivityObserverConstants.ACTIVITY_TYPE_SOCKET_TRANSPORT:
						switch (aActivitySubtype) {
							case nsISocketTransportConstants.STATUS_RESOLVING:
								break;
							case nsISocketTransportConstants.STATUS_RESOLVED:
								break;
							case nsISocketTransportConstants.STATUS_CONNECTING_TO:
								break;
							case nsISocketTransportConstants.STATUS_CONNECTED_TO:
								break;
							case nsISocketTransportConstants.STATUS_SENDING_TO:
								break;
							case nsISocketTransportConstants.STATUS_WAITING_FOR:
								break;
							case nsISocketTransportConstants.STATUS_RECEIVING_FROM:
								break;
						}
						break;
					case nsIHttpActivityObserverConstants.ACTIVITY_TYPE_HTTP_TRANSACTION:
						switch (aActivitySubtype) {
							case nsIHttpActivityObserverConstants.ACTIVITY_SUBTYPE_REQUEST_HEADER: {
									activeNetworkChannels++;
									ActiveNetworkChannelUrls.Add(nsString.Get(httpChannel.GetURIAttribute().GetSpecAttribute));

									var callbacks = httpChannel.GetNotificationCallbacksAttribute();

                                    if (callbacks != null)
                                    {
                                        var httpChannelXHR = Xpcom.QueryInterface<nsIXMLHttpRequest>(callbacks);

                                        if (httpChannelXHR != null)
                                        {
                                            nsIXMLHttpRequestEventTarget mXMLRequestEvent = Xpcom.QueryInterface<nsIXMLHttpRequestEventTarget>(httpChannelXHR);

                                            if (mXMLRequestEvent != null)
                                            {
                                                GeckoJavaScriptHttpChannelWrapper mEventListener = new GeckoJavaScriptHttpChannelWrapper(this, httpChannel);
                                                origJavaScriptHttpChannels.Add(httpChannel, mEventListener);
                       
                                                using (nsAString mLoads = new nsAString("load"))
                                                {
                                                    mXMLRequestEvent.AddEventListener(mLoads, mEventListener, true, false, 0);
                                                }

                                                using (nsAString mLoads = new nsAString("abort"))
                                                {
                                                    mXMLRequestEvent.AddEventListener(mLoads, mEventListener, true, false, 0);
                                                }

                                                using (nsAString mLoads = new nsAString("error"))
                                                {
                                                    mXMLRequestEvent.AddEventListener(mLoads, mEventListener, true, false, 0);
                                                }

                                                Marshal.ReleaseComObject(mXMLRequestEvent);
                                            }

                                            Marshal.ReleaseComObject(httpChannelXHR);
                                        }

                                        Marshal.ReleaseComObject(callbacks);
                                    }

								}
								break;
							case nsIHttpActivityObserverConstants.ACTIVITY_SUBTYPE_REQUEST_BODY_SENT:
								break;
							case nsIHttpActivityObserverConstants.ACTIVITY_SUBTYPE_RESPONSE_START:
								break;
							case nsIHttpActivityObserverConstants.ACTIVITY_SUBTYPE_RESPONSE_COMPLETE:
								break;
							case nsIHttpActivityObserverConstants.ACTIVITY_SUBTYPE_TRANSACTION_CLOSE:
								activeNetworkChannels--;
								ActiveNetworkChannelUrls.Remove(nsString.Get(httpChannel.GetURIAttribute().GetSpecAttribute));
								break;
						}
						break;
				}
			}
		}
 /// <summary>
 /// See nsIWidget::SynthesizeNativeKeyEvent
 ///
 /// Cannot be accessed from unprivileged context (not content-accessible)
 /// Will throw a DOM security error if called without UniversalXPConnect
 /// privileges.
 /// </summary>		
 public void SendNativeKeyEvent(int aNativeKeyboardLayout, int aNativeKeyCode, int aModifierFlags, string aCharacters, string aUnmodifiedCharacters)
 {
     using (nsAString characters = new nsAString(aCharacters), unmodifiedCharaters = new nsAString(aUnmodifiedCharacters))
     {
         _windowUtils.SendNativeKeyEvent(aNativeKeyboardLayout, aNativeKeyCode, aModifierFlags, characters, unmodifiedCharaters);
     }
 }
示例#31
0
		void nsIContextMenuListener2.OnShowContextMenu(uint aContextFlags, nsIContextMenuInfo info)
		{
			// if we don't have a target node, we can't do anything by default.  this happens in XUL forms (i.e. about:config)
			if (info.GetTargetNodeAttribute() == null)
				return;
			
			ContextMenu menu = new ContextMenu();
			
			// no default items are added when the context menu is disabled
			if (!this.NoDefaultContextMenu)
			{
				List<MenuItem> optionals = new List<MenuItem>();
				
				if (this.CanUndo || this.CanRedo)
				{
					optionals.Add(new MenuItem("Undo", delegate { Undo(); }));
					optionals.Add(new MenuItem("Redo", delegate { Redo(); }));
					
					optionals[0].Enabled = this.CanUndo;
					optionals[1].Enabled = this.CanRedo;
				}
				else
				{
					optionals.Add(new MenuItem("Back", delegate { GoBack(); }));
					optionals.Add(new MenuItem("Forward", delegate { GoForward(); }));
					
					optionals[0].Enabled = this.CanGoBack;
					optionals[1].Enabled = this.CanGoForward;
				}
				
				optionals.Add(new MenuItem("-"));
				
				if (this.CanCopyImageContents)
					optionals.Add(new MenuItem("Copy Image Contents", delegate { CopyImageContents(); }));
				
				if (this.CanCopyImageLocation)
					optionals.Add(new MenuItem("Copy Image Location", delegate { CopyImageLocation(); }));
				
				if (this.CanCopyLinkLocation)
					optionals.Add(new MenuItem("Copy Link Location", delegate { CopyLinkLocation(); }));
				
				if (this.CanCopySelection)
					optionals.Add(new MenuItem("Copy Selection", delegate { CopySelection(); }));
				
				MenuItem mnuSelectAll = new MenuItem("Select All");
				mnuSelectAll.Click += delegate { SelectAll(); };

				GeckoDomDocument doc = GeckoDomDocument.CreateDomDocumentWraper(info.GetTargetNodeAttribute().GetOwnerDocumentAttribute());

				string viewSourceUrl = (doc == null) ? null : Convert.ToString(doc.Uri);
				
				MenuItem mnuViewSource = new MenuItem("View Source");
				mnuViewSource.Enabled = !string.IsNullOrEmpty(viewSourceUrl);
				mnuViewSource.Click += delegate { ViewSource(viewSourceUrl); };

				MenuItem mnuOpenInSystemBrowser = new MenuItem("View In System Browser");//nice for debugging with firefox/firebug
				mnuOpenInSystemBrowser.Enabled = !string.IsNullOrEmpty(viewSourceUrl);
				mnuOpenInSystemBrowser.Click += delegate { ViewInSystemBrowser(viewSourceUrl); };


				string properties = (doc != null && doc.Uri == Document.Uri) ? "Page Properties" : "IFRAME Properties";
				
				MenuItem mnuProperties = new MenuItem(properties);
				mnuProperties.Enabled = doc != null;
				mnuProperties.Click += delegate { ShowPageProperties(doc); };
				
				menu.MenuItems.AddRange(optionals.ToArray());
				menu.MenuItems.Add(mnuSelectAll);
				menu.MenuItems.Add("-");
				menu.MenuItems.Add(mnuViewSource);
				menu.MenuItems.Add(mnuOpenInSystemBrowser);
				menu.MenuItems.Add(mnuProperties);
			}

			// get image urls
			Uri backgroundImageSrc = null, imageSrc = null;
			nsIURI src;
			try
			{
				src = info.GetBackgroundImageSrcAttribute();
				backgroundImageSrc = src.ToUri();
				Marshal.ReleaseComObject( src );
			}
			catch (COMException comException)
			{
				if ((comException.ErrorCode & 0xFFFFFFFF) != 0x80004005)
					throw comException;
			}

			try
			{
				src = info.GetImageSrcAttribute();
				if ( src != null )
				{
					imageSrc = src.ToUri();
					Marshal.ReleaseComObject( src );
				}
			}
			catch (COMException comException)
			{
				if ((comException.ErrorCode & 0xFFFFFFFF) != 0x80004005)
					throw comException;
			}
			
			// get associated link.  note that this needs to be done manually because GetAssociatedLink returns a non-zero
			// result when no associated link is available, so an exception would be thrown by nsString.Get()
			string associatedLink = null;
			try
			{
				using (nsAString str = new nsAString())
				{
					info.GetAssociatedLinkAttribute(str);
					associatedLink = str.ToString();
				}
			}
			catch (COMException comException) { }			
			
			GeckoContextMenuEventArgs e = new GeckoContextMenuEventArgs(
				PointToClient(MousePosition), menu, associatedLink, backgroundImageSrc, imageSrc,
				GeckoNode.Create(Xpcom.QueryInterface<nsIDOMNode>(info.GetTargetNodeAttribute()))
				);
			
			OnShowContextMenu(e);
			
			if (e.ContextMenu != null && e.ContextMenu.MenuItems.Count > 0)
			{
#if GTK
				// When using GTK we can't use SWF to display the context menu: SWF displays
				// the context menu and then tries to track the mouse so that it knows when to
				// close the context menu. However, GTK intercepts the mouse click before SWF gets
				// it, so the menu never closes. Instead we display a GTK menu and translate
				// the SWF menu items into Gtk.MenuItems.
				// TODO: currently this code only handles text menu items. Would be nice to also
				// translate images etc.
				var popupMenu = new Gtk.Menu();

				foreach (MenuItem swfMenuItem in e.ContextMenu.MenuItems)
				{
					var gtkMenuItem = new Gtk.MenuItem(swfMenuItem.Text);
					gtkMenuItem.Sensitive = swfMenuItem.Enabled;
					MenuItem origMenuItem = swfMenuItem;
					gtkMenuItem.Activated += (sender, ev) => origMenuItem.PerformClick();
					popupMenu.Append(gtkMenuItem);
				}
				popupMenu.ShowAll();
				popupMenu.Popup();
#else
				e.ContextMenu.Show(this, e.Location);
#endif
			}
		}
        public void ConstructorWithString_ToTestValue_ToStringReturnsTestValue()
        {
            var objectUnderTest = new nsAString("Hello world");

            Assert.AreEqual("Hello world", objectUnderTest.ToString());
        }