1 | <?xml version="1.0"?> |
---|
2 | <!-- ***** BEGIN LICENSE BLOCK ***** |
---|
3 | - This program is free software; you can redistribute it and/or modify |
---|
4 | - it under the terms of the GNU General Public License as published by |
---|
5 | - the Free Software Foundation; either version 2 of the License, or |
---|
6 | - (at your option) any later version. |
---|
7 | |
---|
8 | - This program is distributed in the hope that it will be useful, |
---|
9 | - but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
10 | - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
11 | - GNU General Public License for more details. |
---|
12 | |
---|
13 | - You should have received a copy of the GNU General Public License |
---|
14 | - along with this program; if not, write to the Free Software |
---|
15 | - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
16 | |
---|
17 | - The Original Code is the Virtual Identity Extension. |
---|
18 | |
---|
19 | - The Initial Developer of the Original Code is Rene Ejury. |
---|
20 | - code of remoteBrowserBox was copied and adapted from mozapps/update/updates.xml |
---|
21 | - Portions created by the Initial Developer are Copyright (C) 2007 |
---|
22 | - the Initial Developer. All Rights Reserved. |
---|
23 | |
---|
24 | - Contributor(s): |
---|
25 | - ***** END LICENSE BLOCK ***** --> |
---|
26 | |
---|
27 | <!DOCTYPE overlay [ |
---|
28 | <!ENTITY % vIdentDTD SYSTEM "chrome://v_identity/locale/vI_prefDialog.dtd"> |
---|
29 | %vIdentDTD; |
---|
30 | ]> |
---|
31 | |
---|
32 | <bindings id="vI_htmlTextBoxBindings" |
---|
33 | xmlns="http://www.mozilla.org/xbl" |
---|
34 | xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
---|
35 | xmlns:xbl="http://www.mozilla.org/xbl"> |
---|
36 | |
---|
37 | <binding id="vI_remoteBrowserBox"> |
---|
38 | <content> |
---|
39 | <xul:vbox flex="1" > |
---|
40 | <xul:vbox class="vI_remoteBrowserBoxProgressmeter" flex="1" > |
---|
41 | <xul:progressmeter mode="undetermined" /> |
---|
42 | <xul:spacer flex="1" /> |
---|
43 | </xul:vbox> |
---|
44 | <xul:browser xbl:inherits="src=url" type="content" class="vI_htmlTextBox" hidden="true" flex="1" disablehistory="true" /> |
---|
45 | <xul:button xbl:inherits="tooltiptext=url" label="&vI_prefDialog.openHelpInBrowserButton.label;" |
---|
46 | oncommand="virtualIdentityExtension.prefDialog.openURL(this.tooltipText); virtualIdentityExtension.prefDialog.toggleHelp();" /> |
---|
47 | </xul:vbox> |
---|
48 | </content> |
---|
49 | <resources> |
---|
50 | <stylesheet src="chrome://v_identity/skin/v_identity.css"/> |
---|
51 | </resources> |
---|
52 | <implementation> |
---|
53 | <destructor><![CDATA[ |
---|
54 | // clean up the listener but you may not have one if you never showed |
---|
55 | // the page with a <remotecontent> element |
---|
56 | if (this._remoteProgressListener) this._content.webProgress.removeProgressListener(this._remoteProgressListener); |
---|
57 | ]]></destructor> |
---|
58 | <field name="_init">null</field> |
---|
59 | <method name="init"> |
---|
60 | <body><![CDATA[ |
---|
61 | if (this._init) return; |
---|
62 | |
---|
63 | // just to be safe, turn off js, auth, plugins, and subframes |
---|
64 | var docShell = this._content.docShell; |
---|
65 | docShell.allowJavascript = false; |
---|
66 | docShell.allowAuth = false; |
---|
67 | docShell.allowPlugins = false; |
---|
68 | //allow redirects |
---|
69 | //docShell.allowMetaRedirects = false; |
---|
70 | docShell.allowSubframes = false; |
---|
71 | //allow images |
---|
72 | //docShell.allowImages = false; |
---|
73 | |
---|
74 | this._init = true; |
---|
75 | ]]></body> |
---|
76 | </method> |
---|
77 | <field name="_remoteProgressListener">null</field> |
---|
78 | <property name="url"> |
---|
79 | <getter><![CDATA[ |
---|
80 | return this.getAttribute("url"); |
---|
81 | ]]></getter> |
---|
82 | <setter><![CDATA[ |
---|
83 | this.init(); |
---|
84 | if (this._remoteProgressListener) |
---|
85 | this._content.webProgress.removeProgressListener(this._remoteProgressListener); |
---|
86 | var self = this; |
---|
87 | |
---|
88 | this._remoteProgressListener = { |
---|
89 | QueryInterface: function(aIID) { |
---|
90 | if (aIID.equals(Components.interfaces.nsIWebProgressListener) || |
---|
91 | aIID.equals(Components.interfaces.nsISupportsWeakReference) || |
---|
92 | aIID.equals(Components.interfaces.nsISupports)) |
---|
93 | return this; |
---|
94 | throw Components.results.NS_NOINTERFACE; |
---|
95 | }, |
---|
96 | onLocationChange: function() {}, |
---|
97 | onProgressChange: function() {}, |
---|
98 | onStatusChange: function() {}, |
---|
99 | onSecurityChange: function() {}, |
---|
100 | onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus) { |
---|
101 | if (!aRequest) |
---|
102 | return; |
---|
103 | |
---|
104 | const nsIWebProgressListener = |
---|
105 | Components.interfaces.nsIWebProgressListener; |
---|
106 | |
---|
107 | if (aStateFlags & nsIWebProgressListener.STATE_IS_NETWORK) |
---|
108 | { |
---|
109 | if (aStateFlags & nsIWebProgressListener.STATE_START) self.onStart(); |
---|
110 | else if (aStateFlags & nsIWebProgressListener.STATE_STOP) { |
---|
111 | const nsIHttpChannel = Components.interfaces.nsIHttpChannel; |
---|
112 | try { |
---|
113 | var channel = aRequest.QueryInterface(nsIHttpChannel); |
---|
114 | if (channel.requestSucceeded) { |
---|
115 | // if we get here, the load was OK, report success |
---|
116 | self.onLoad(); |
---|
117 | return; |
---|
118 | } |
---|
119 | } catch (ex) { |
---|
120 | // the channel.requestSucceeded can throw |
---|
121 | // NS_ERROR_NOT_AVAILABLE if you can't reach the server |
---|
122 | // so we treat that as an error |
---|
123 | } |
---|
124 | // everything else (like a 404) is an error |
---|
125 | self.onError(); |
---|
126 | } |
---|
127 | } |
---|
128 | } |
---|
129 | } |
---|
130 | this._content.webProgress.addProgressListener(this._remoteProgressListener,Components.interfaces.nsIWebProgress.NOTIFY_ALL); |
---|
131 | // load the url now that the listener is registered |
---|
132 | this.setAttribute("url", val); |
---|
133 | ]]></setter> |
---|
134 | </property> |
---|
135 | <field name="_content"> |
---|
136 | document.getAnonymousElementByAttribute(this, "class", "vI_htmlTextBox"); |
---|
137 | </field> |
---|
138 | <field name="_progress"> |
---|
139 | document.getAnonymousElementByAttribute(this, "class", "vI_remoteBrowserBoxProgressmeter"); |
---|
140 | </field> |
---|
141 | <property name="localCss" onget="return this.getAttribute('localCss');" onset="this.setAttribute('localCss', val); return val;" /> |
---|
142 | <method name="onError"> |
---|
143 | <body><![CDATA[ |
---|
144 | // alert("error"); |
---|
145 | ]]></body> |
---|
146 | </method> |
---|
147 | <method name="onLoad"> |
---|
148 | <body><![CDATA[ |
---|
149 | this._content.cssSource = this.localCss; |
---|
150 | this._progress.setAttribute("hidden", "true"); |
---|
151 | this._content.removeAttribute("hidden"); |
---|
152 | ]]></body> |
---|
153 | </method> |
---|
154 | <method name="onStart"> |
---|
155 | <body><![CDATA[ |
---|
156 | this._content.setAttribute("hidden", "true"); |
---|
157 | this._progress.removeAttribute("hidden"); |
---|
158 | ]]></body> |
---|
159 | </method> |
---|
160 | </implementation> |
---|
161 | </binding> |
---|
162 | |
---|
163 | |
---|
164 | <binding id="vI_htmlTextBox" extends="chrome://global/content/bindings/browser.xml#browser"> |
---|
165 | <implementation> |
---|
166 | <constructor> |
---|
167 | <![CDATA[ |
---|
168 | dump('******* vI_htmlTextBox.xml constructor\n'); |
---|
169 | ]]> |
---|
170 | </constructor> |
---|
171 | <field name="_cssRead">false</field> |
---|
172 | <property name="cssSource" > |
---|
173 | <setter><![CDATA[ |
---|
174 | if (!val) return; |
---|
175 | dump("cssSource set to " + val + "\n"); |
---|
176 | var head = this.contentDocument.getElementsByTagName("HEAD").item(0); |
---|
177 | var range = document.createRange(); |
---|
178 | range.selectNode(head); |
---|
179 | var css_text = this._getContents("chrome://v_identity/skin/" + val); |
---|
180 | dump("cssSource set to " + val + " cont.\n"); |
---|
181 | var documentFragment = range.createContextualFragment("<style type='text/css'>" + css_text + "</style>"); |
---|
182 | head.appendChild(documentFragment); |
---|
183 | dump("cssSource set to " + val + " done\n"); |
---|
184 | this._cssRead = true; |
---|
185 | ]]></setter> |
---|
186 | </property> |
---|
187 | <method name="_getContents"> |
---|
188 | <parameter name="aURL" /> |
---|
189 | <body><![CDATA[ |
---|
190 | // read the chrome file (copied from http://forums.mozillazine.org/viewtopic.php?p=921150) |
---|
191 | var ioService=Components.classes["@mozilla.org/network/io-service;1"] |
---|
192 | .getService(Components.interfaces.nsIIOService); |
---|
193 | var scriptableStream=Components |
---|
194 | .classes["@mozilla.org/scriptableinputstream;1"] |
---|
195 | .getService(Components.interfaces.nsIScriptableInputStream); |
---|
196 | |
---|
197 | var channel=ioService.newChannel(aURL,null,null); |
---|
198 | var input=channel.open(); |
---|
199 | scriptableStream.init(input); |
---|
200 | var str=scriptableStream.read(input.available()); |
---|
201 | scriptableStream.close(); |
---|
202 | input.close(); |
---|
203 | return str; |
---|
204 | ]]></body> |
---|
205 | </method> |
---|
206 | <property name="outputString" > |
---|
207 | <setter><![CDATA[ |
---|
208 | if (!this._cssRead) this.cssSource = this.getAttribute('cssSource'); // read initial Attributes |
---|
209 | this.contentDocument.lastChild.setAttribute("style", this.getAttribute('documentStyle')); |
---|
210 | |
---|
211 | var oldChilds = this.contentDocument.body.childNodes; |
---|
212 | while (oldChilds.length > 0) this.contentDocument.body.removeChild(oldChilds[0]) |
---|
213 | |
---|
214 | var text_list = val.split(/\n/) |
---|
215 | for (var i = 0; i < text_list.length; i++) { |
---|
216 | if (this._isHR(text_list[i])) continue; |
---|
217 | var text_item = this._checkList(text_list[i]); |
---|
218 | this._add(text_item); |
---|
219 | if (!this._currentList && (i + 1) < text_list.length) { |
---|
220 | var new_br = this.contentDocument |
---|
221 | .createElementNS("http://www.w3.org/1999/xhtml", 'html:br'); |
---|
222 | this.contentDocument.body.appendChild(new_br); |
---|
223 | } |
---|
224 | } |
---|
225 | ]]></setter> |
---|
226 | </property> |
---|
227 | <field name="_currentList">null</field> |
---|
228 | <field name="_currentBaseNode">null</field> |
---|
229 | <method name="_isHR"> |
---|
230 | <parameter name="text" /> |
---|
231 | <body><![CDATA[ |
---|
232 | if (text == "---") { |
---|
233 | var new_hr = this.contentDocument |
---|
234 | .createElementNS("http://www.w3.org/1999/xhtml", 'html:hr'); |
---|
235 | this.contentDocument.body.appendChild(new_hr); |
---|
236 | return true; |
---|
237 | } |
---|
238 | return false; |
---|
239 | ]]></body> |
---|
240 | </method> |
---|
241 | <method name="_checkList"> |
---|
242 | <parameter name="text" /> |
---|
243 | <body><![CDATA[ |
---|
244 | if (text.match(/^\*\s/)) { |
---|
245 | if (!this._currentList) { |
---|
246 | this._currentList = this.contentDocument |
---|
247 | .createElementNS("http://www.w3.org/1999/xhtml", 'html:ul'); |
---|
248 | this.contentDocument.body.appendChild(this._currentList); |
---|
249 | } |
---|
250 | this._currentBaseNode = this.contentDocument |
---|
251 | .createElementNS("http://www.w3.org/1999/xhtml", 'html:li'); |
---|
252 | this._currentList.appendChild(this._currentBaseNode); |
---|
253 | } |
---|
254 | else { |
---|
255 | this._currentList = null; |
---|
256 | this._currentBaseNode = this.contentDocument.body; |
---|
257 | } |
---|
258 | return text.replace(/^\*\s/,"") |
---|
259 | ]]></body> |
---|
260 | </method> |
---|
261 | <method name="_add"> |
---|
262 | <parameter name="text" /> |
---|
263 | <body><![CDATA[ |
---|
264 | if (text.match(/http[s]?:\/\/\S+/)) { |
---|
265 | if (RegExp.leftContext) this._addText(RegExp.leftContext) |
---|
266 | if (RegExp.lastMatch) this._addLink(RegExp.lastMatch) |
---|
267 | if (RegExp.rightContext) this._add(RegExp.rightContext) |
---|
268 | } |
---|
269 | else this._addText(text); |
---|
270 | ]]></body> |
---|
271 | </method> |
---|
272 | <method name="_addText"> |
---|
273 | <parameter name="text" /> |
---|
274 | <body><![CDATA[ |
---|
275 | var range = document.createRange(); |
---|
276 | range.selectNode(this._currentBaseNode); |
---|
277 | var documentFragment = range.createContextualFragment(text); |
---|
278 | this._currentBaseNode.appendChild(documentFragment); |
---|
279 | ]]></body> |
---|
280 | </method> |
---|
281 | <method name="_addLink"> |
---|
282 | <parameter name="text" /> |
---|
283 | <body><![CDATA[ |
---|
284 | var new_a = this.contentDocument |
---|
285 | .createElementNS("http://www.w3.org/1999/xhtml", 'html:a'); |
---|
286 | new_a.setAttribute("href", text) |
---|
287 | new_a.setAttribute("style", "text-decoration: underline") |
---|
288 | this._currentBaseNode.appendChild(new_a); |
---|
289 | var new_text = this.contentDocument.createTextNode(text); |
---|
290 | new_a.appendChild(new_text); |
---|
291 | ]]></body> |
---|
292 | </method> |
---|
293 | </implementation> |
---|
294 | </binding> |
---|
295 | |
---|
296 | </bindings> |
---|