]> git.saurik.com Git - apple/mdnsresponder.git/blob - Clients/FirefoxExtension/extension/content/bonjour4firefox.xul
mDNSResponder-878.270.2.tar.gz
[apple/mdnsresponder.git] / Clients / FirefoxExtension / extension / content / bonjour4firefox.xul
1 <?xml version="1.0"?>
2 <?xml-stylesheet href="chrome://browser/content/places/places.css"?>
3 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
4 <?xml-stylesheet href="chrome://browser/skin/places/places.css"?>
5 <?xml-stylesheet href="browseList.css"?>
6 <!DOCTYPE page SYSTEM "chrome://bonjour4firefox/locale/bonjour4firefox.dtd">
7 <page
8 orient="vertical"
9 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
10 style="background-color: transparent !important; -moz-appearance: none !important;"
11 onload="BonjourBrowser.init()"
12 onunload="BonjourBrowser.cleanup()">
13
14
15 <menupopup id="targetmenu">
16 <menuitem label="&bonjour4firefoxSidebarOpenDefault.label;" value="current"/>
17 <menuitem label="&bonjour4firefoxSidebarOpenTab.label;" value="tab"/>
18 <menuitem label="&bonjour4firefoxSidebarOpenWindow.label;" value="window"/>
19 </menupopup>
20
21 <tree id="treeBrowseList" flex="1" class="sidebar-placesTree" hidecolumnpicker="true">
22 <treecols hide="true">
23 <treecol id="title" flex="1" primary="true" hideheader="true"/>
24 </treecols>
25
26 <treechildren class="sidebar-placesTreechildren" context="targetmenu" flex="1" id="treeChildrenBrowseList">
27 <treeitem>
28 <treerow>
29 <treecell src="chrome://bonjour4firefox/content/_internal_bonjour4firefox.png" label="About Bonjour"/>
30 </treerow>
31 </treeitem>
32 </treechildren>
33 </tree>
34
35 <script><![CDATA[
36
37 var BonjourBrowser =
38 {
39 Service: null,
40 Browse: null,
41 BrowseListener: null,
42 Resolve: null,
43 ResolveListener: null,
44
45 init: function()
46 {
47 document.getElementById("treeChildrenBrowseList").addEventListener( "click", this.listListener, false );
48
49 try
50 {
51 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
52 const cid = "@apple.com/DNSSDService;1";
53 Service = Components.classes[cid].createInstance();
54 Service = Service.QueryInterface(Components.interfaces.IDNSSDService);
55 }
56 catch (err)
57 {
58 alert(err);
59 return;
60 }
61
62 BrowseListener = this.browseListener;
63 ResolveListener = this.resolveListener;
64
65 try
66 {
67 Browse = Service.browse(0, "_http._tcp", "", BrowseListener );
68 }
69 catch ( err )
70 {
71 alert( err );
72 return;
73 }
74 },
75
76 cleanup: function()
77 {
78 if ( Browse != null )
79 {
80 Browse.stop();
81 Browse = null;
82 }
83 },
84
85
86 browseListener: function( service, add, interfaceIndex, error, serviceName, regtype, domain )
87 {
88 if ( error == 0 )
89 {
90 // First see if we can look this guy up
91
92 var treeView = document.getElementById( 'treeChildrenBrowseList' );
93 var treeItem = null;
94
95 for ( i = 1; i < treeView.childNodes.length; i++ )
96 {
97 var ti = treeView.childNodes[ i ];
98 var tr = ti.childNodes[ 0 ];
99 var tc = tr.childNodes[ 0 ];
100
101 if ( tc.getAttribute( 'label' ) == serviceName )
102 {
103 treeItem = ti;
104 break;
105 }
106 }
107
108 if ( add )
109 {
110 // If we've already seen this guy, then bump up his reference count
111
112 if ( treeItem )
113 {
114 var refcnt = treeItem.getUserData( 'refcnt' );
115 refcnt++;
116 }
117 else
118 {
119 var newTreeItem = document.createElement('treeitem');
120 var newTreeRow = document.createElement('treerow');
121 newTreeRow.setAttribute( 'properties', 'bonjourRow' );
122 var newTreeCell = document.createElement('treecell');
123 newTreeCell.setAttribute( 'label', serviceName );
124 newTreeCell.setAttribute( 'src', 'chrome://bonjour4firefox/content/_internal_bonjour4firefox.png' );
125
126 newTreeItem.appendChild( newTreeRow );
127 newTreeRow.appendChild( newTreeCell );
128 newTreeItem.setUserData( 'interfaceIndex', interfaceIndex, null );
129 newTreeItem.setUserData( 'serviceName', serviceName, null );
130 newTreeItem.setUserData( 'regtype', regtype, null );
131 newTreeItem.setUserData( 'domain', domain, null );
132 newTreeItem.setUserData( 'refcnt', 1, null );
133
134 // Insert in alphabetical order
135
136 var insertBefore = null;
137
138 for ( i = 1; i < treeView.childNodes.length; i++ )
139 {
140 var ti = treeView.childNodes[ i ];
141 var tr = ti.childNodes[ 0 ];
142 var tc = tr.childNodes[ 0 ];
143
144 if ( serviceName.toLowerCase() < tc.getAttribute( 'label' ).toLowerCase() )
145 {
146 insertBefore = ti;
147 break;
148 }
149 }
150
151 if ( insertBefore != null )
152 {
153 treeView.insertBefore( newTreeItem, insertBefore );
154 }
155 else
156 {
157 treeView.appendChild( newTreeItem );
158 }
159 }
160 }
161 else if ( treeItem )
162 {
163 var refcnt = treeItem.getUserData( 'refcnt' );
164
165 if ( --refcnt == 0 )
166 {
167 treeView.removeChild( treeItem );
168 }
169 }
170 }
171 else
172 {
173 alert( 'There was an error browsing for websites: ' + error );
174 }
175 },
176
177 listListener: function( event )
178 {
179 var treeBrowseList = document.getElementById( 'treeBrowseList' );
180
181 if ( treeBrowseList.currentIndex == 0 )
182 {
183 window._content.location="http://www.apple.com/macosx/features/bonjour";
184 }
185 else
186 {
187 var item = treeBrowseList.view.getItemAtIndex(treeBrowseList.currentIndex);
188
189 var interfaceIndex = item.getUserData("interfaceIndex");
190 var serviceName = item.getUserData("serviceName");
191 var regtype = item.getUserData("regtype");
192 var domain = item.getUserData("domain");
193
194 try
195 {
196 Resolve = Service.resolve( interfaceIndex, serviceName, regtype, domain, ResolveListener );
197 }
198 catch ( err )
199 {
200 alert( err );
201 return;
202 }
203 }
204 },
205
206 resolveListener: function( service, interfaceIndex, error, fullname, host, port, path )
207 {
208 if ( error == 0 )
209 {
210 window._content.location='http://' + host + ':' + port + path;
211 }
212 else
213 {
214 alert( 'There was an error resolving ' + fullname );
215 }
216
217 Resolve.stop();
218 },
219 };
220
221 ]]></script>
222 </page>