This is just some static backup of the original site, don't expect every link to work!

source: content/bindings/vI_htmlTextBox.xml

ng_0.9 0.10.3
Last change on this file was c69e30, checked in by rene <rene@…>, 4 years ago

https://bugzilla.mozilla.org/show_bug.cgi?id=1329186

  • Property mode set to 100644
File size: 10.7 KB
Line 
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="virtualIdentityExtension_remoteBrowserBox">
38    <content>
39        <xul:vbox flex="1" >
40            <xul:vbox class="virtualIdentityExtension_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", "virtualIdentityExtension_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        virtualIdentityExtension.MyLog.debug('******* vI_htmlTextBox.xml constructor');
169        ]]>
170    </constructor>
171    <field name="_cssRead">false</field>
172    <property name="cssSource" >
173        <setter><![CDATA[
174        if (!val) return;
175        var head = this.contentDocument.getElementsByTagName("HEAD").item(0);
176        var range = document.createRange();
177        range.selectNode(head);
178        var css_text = this._getContents("chrome://v_identity/skin/" + val);
179        var documentFragment = range.createContextualFragment("<style type='text/css'>" + css_text + "</style>");
180        head.appendChild(documentFragment);
181        virtualIdentityExtension.MyLog.debug("cssSource set to " + val + " done");
182        this._cssRead = true;
183        ]]></setter>
184    </property>
185    <method name="_getContents">
186        <parameter name="aURL" />
187        <body><![CDATA[     
188                var {classes: Cc, interfaces: Ci, utils: Cu} = Components;
189                // read the chrome file (copied from http://forums.mozillazine.org/viewtopic.php?p=921150)
190        var ioService=Cc["@mozilla.org/network/io-service;1"]
191            .getService(Components.interfaces.nsIIOService);
192        var scriptableStream=Cc["@mozilla.org/scriptableinputstream;1"]
193            .getService(Components.interfaces.nsIScriptableInputStream);
194                Cu.import("resource:///modules/imServices.jsm");
195        var channel=ioService.newChannel2(aURL, null, null, null,
196                                          Services.scriptSecurityManager.getSystemPrincipal(),
197                                          null,
198                                          Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
199                                          Ci.nsIContentPolicy.TYPE_OTHER);
200        var input=channel.open();
201        scriptableStream.init(input);
202        var str=scriptableStream.read(input.available());
203        scriptableStream.close();
204        input.close();
205        return str;
206        ]]></body>
207    </method>
208    <property name="outputString" >
209        <setter><![CDATA[
210        if (!this._cssRead) this.cssSource = this.getAttribute('cssSource');    // read initial Attributes
211        this.contentDocument.lastChild.setAttribute("style", this.getAttribute('documentStyle'));
212       
213        var oldChilds = this.contentDocument.body.childNodes;
214        while (oldChilds.length > 0) this.contentDocument.body.removeChild(oldChilds[0])
215
216        var text_list = val.split(/\n/)
217        for (var i = 0; i < text_list.length; i++) {
218            if (this._isHR(text_list[i])) continue;
219            var text_item = this._checkList(text_list[i]);
220            this._add(text_item);
221            if (!this._currentList && (i + 1) < text_list.length) {
222                var new_br = this.contentDocument
223                    .createElementNS("http://www.w3.org/1999/xhtml", 'html:br');
224                this.contentDocument.body.appendChild(new_br);
225            }
226        }
227        ]]></setter>
228    </property>
229    <field name="_currentList">null</field>
230    <field name="_currentBaseNode">null</field>
231    <method name="_isHR">
232        <parameter name="text" />
233        <body><![CDATA[     
234        if (text == "---") {
235            var new_hr = this.contentDocument
236                .createElementNS("http://www.w3.org/1999/xhtml", 'html:hr');
237            this.contentDocument.body.appendChild(new_hr);
238            return true;
239        }
240        return false;
241        ]]></body>
242    </method>
243    <method name="_checkList">
244        <parameter name="text" />
245        <body><![CDATA[
246        if (text.match(/^\*\s/)) {
247            if (!this._currentList) {
248                this._currentList = this.contentDocument
249                    .createElementNS("http://www.w3.org/1999/xhtml", 'html:ul');
250                this.contentDocument.body.appendChild(this._currentList);
251            }
252            this._currentBaseNode = this.contentDocument
253                                .createElementNS("http://www.w3.org/1999/xhtml", 'html:li');
254            this._currentList.appendChild(this._currentBaseNode);
255        }
256        else {
257            this._currentList = null;
258            this._currentBaseNode = this.contentDocument.body;
259        }
260        return text.replace(/^\*\s/,"")
261        ]]></body>
262    </method>
263    <method name="_add">
264        <parameter name="text" />
265        <body><![CDATA[
266        if (text.match(/http[s]?:\/\/\S+/)) {
267            if (RegExp.leftContext) this._addText(RegExp.leftContext)
268            if (RegExp.lastMatch) this._addLink(RegExp.lastMatch)
269            if (RegExp.rightContext) this._add(RegExp.rightContext)
270        }
271        else this._addText(text);
272        ]]></body>
273    </method>
274    <method name="_addText">
275        <parameter name="text" />
276        <body><![CDATA[     
277        var range = document.createRange();
278        range.selectNode(this._currentBaseNode);
279        var documentFragment = range.createContextualFragment(text);
280        this._currentBaseNode.appendChild(documentFragment);
281        ]]></body>
282    </method>
283    <method name="_addLink">
284        <parameter name="text" />
285        <body><![CDATA[     
286        var new_a = this.contentDocument
287            .createElementNS("http://www.w3.org/1999/xhtml", 'html:a');
288        new_a.setAttribute("href", text)
289        new_a.setAttribute("style", "text-decoration: underline")
290        this._currentBaseNode.appendChild(new_a);
291        var new_text = this.contentDocument.createTextNode(text);
292        new_a.appendChild(new_text);
293        ]]></body>
294    </method>
295    </implementation>
296    </binding>
297
298</bindings>
Note: See TracBrowser for help on using the repository browser.