1 //Permission is hereby granted, free of charge, to any person obtaining
2 //a copy of this software and associated documentation files (the
3 //"Software"), to deal in the Software without restriction, including
4 //without limitation the rights to use, copy, modify, merge, publish,
5 //distribute, sublicense, and/or sell copies of the Software, and to
6 //permit persons to whom the Software is furnished to do so, subject to
7 //the following conditions:
8 //
9 //The above copyright notice and this permission notice shall be
10 //included in all copies or substantial portions of the Software.
11 //
12 //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 //EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 //MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 //NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 //LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 //OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 //WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 //
20 //Copyright (c) 2008 Novell, Inc.
21 //
22 //Authors:
23 //	Andreia Gaita (shana@jitted.com)
24 //
25 
26 using System;
27 using System.ComponentModel;
28 using System.Runtime.InteropServices;
29 using Mono.WebBrowser;
30 
31 namespace Mono.Mozilla.DOM
32 {
33 	internal class ContentListener : nsIURIContentListener
34 	{
35 		WebBrowser owner;
36 
ContentListener(WebBrowser instance)37 		public ContentListener (WebBrowser instance) {
38 			owner = instance;
39 
40 		}
41 
42 		EventHandlerList events;
43 		public EventHandlerList Events {
44 			get {
45 				if (events == null)
46 					events = new EventHandlerList ();
47 				return events;
48 			}
49 		}
50 
AddHandler(NavigationRequestedEventHandler value)51 		public void AddHandler (NavigationRequestedEventHandler value) {
52 			if (Events[WebBrowser.NavigationRequestedEvent] == null) {
53 				if (owner.Navigation != null) {
54 					nsIWebBrowser browser = (nsIWebBrowser) owner.navigation.navigation;
55 					browser.setParentURIContentListener (this);
56 				}
57 			}
58 			Events.AddHandler (WebBrowser.NavigationRequestedEvent, value);
59 		}
60 
RemoveHandler(NavigationRequestedEventHandler value)61 		public void RemoveHandler (NavigationRequestedEventHandler value) {
62 			Events.RemoveHandler (WebBrowser.NavigationRequestedEvent, value);
63 		}
64 
nsIURIContentListener.onStartURIOpen(nsIURI aURI)65 		bool nsIURIContentListener.onStartURIOpen (nsIURI aURI)
66 		{
67 			NavigationRequestedEventHandler eh = (NavigationRequestedEventHandler) (Events[WebBrowser.NavigationRequestedEvent]);
68 			if (eh != null) {
69 				AsciiString uri = new Mono.Mozilla.AsciiString ("");
70 				aURI.getSpec (uri.Handle);
71 				NavigationRequestedEventArgs args = new NavigationRequestedEventArgs (uri.ToString ());
72 				eh (this, args);
73 				return args.Cancel;
74 
75 			}
76 			return true;
77 		}
78 
nsIURIContentListener.doContent(string aContentType, bool aIsContentPreferred, nsIRequest aRequest, out nsIStreamListener aContentHandler)79 		bool nsIURIContentListener.doContent (string aContentType,
80 				 bool aIsContentPreferred,
81 				 nsIRequest aRequest,
82 				out nsIStreamListener aContentHandler)
83 		{
84 			aContentHandler = null;
85 			return true;
86 		}
87 
nsIURIContentListener.isPreferred(string aContentType, ref string aDesiredContentType)88 		bool nsIURIContentListener.isPreferred (string aContentType,
89 				ref string aDesiredContentType)
90 		{
91 			return true;
92 		}
93 
nsIURIContentListener.canHandleContent(string aContentType, bool aIsContentPreferred, ref string aDesiredContentType)94 		bool nsIURIContentListener.canHandleContent (string aContentType,
95 				 bool aIsContentPreferred,
96 				ref string aDesiredContentType)
97 		{
98 			return true;
99 		}
100 
nsIURIContentListener.getLoadCookie()101 		[return: MarshalAs (UnmanagedType.Interface)] IntPtr nsIURIContentListener.getLoadCookie ()
102 		{
103 			return IntPtr.Zero;
104 		}
105 
nsIURIContentListener.setLoadCookie([MarshalAs (UnmanagedType.Interface)] IntPtr value)106 		void nsIURIContentListener.setLoadCookie ([MarshalAs (UnmanagedType.Interface)] IntPtr value)
107 		{
108 			return;
109 		}
110 
nsIURIContentListener.getParentContentListener()111 		nsIURIContentListener nsIURIContentListener.getParentContentListener ()
112 		{
113 			return null;
114 		}
115 
nsIURIContentListener.setParentContentListener(nsIURIContentListener value)116 		void nsIURIContentListener.setParentContentListener (nsIURIContentListener value)
117 		{
118 			return;
119 		}
120 	}
121 }
122