Changeset 1027

Show
Ignore:
Timestamp:
08/02/08 16:13:35 (1 month ago)
Author:
MaierMan
Message:
  • #830: use nsIURL for DTA_URL
  • proportionally scale metalink main logo
  • Fallback to default metalink logo on load errors
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/chrome/content/common/bindings.xml

    r993 r1027  
    202202                        <xul:hbox flex="1"> 
    203203                                <xul:vbox> 
    204                                         <xul:image class="icon" xbl:inherits="src=iconURL"/> 
     204                                        <spacer flex="1"/> 
     205                                        <xul:image style="width: 32px; height: 32px;" class="icon" xbl:inherits="src=iconURL"/> 
     206                                        <spacer flex="1"/> 
    205207                                </xul:vbox> 
    206208                                <xul:vbox flex="1"> 
  • trunk/chrome/content/common/internalFunctions.js

    r1022 r1027  
    359359                var url; 
    360360                if (link instanceof DTA_URL) { 
    361                         url = link.url
     361                        url = link.url.spec
    362362                } 
    363363                else if (link instanceof Components.interfaces.nsIURI) { 
  • trunk/chrome/content/common/overlayFunctions.js

    r1000 r1027  
    116116}; 
    117117 
    118 function DTA_URL(url, charset, usable, preference) { 
    119         this.charset = this.str(charset); 
     118function DTA_URL(url, preference) { 
    120119        this.url = url; 
    121         if (usable) { 
    122                 this.usable = this.str(usable); 
    123         } 
    124120        this.preference = preference ? preference : 100; 
    125  
    126         this.decode(); 
    127121}; 
    128122DTA_URL.prototype = { 
    129         str: function(value) { 
    130                 return value ? String(value) : ''; 
    131         }, 
    132         // only a getter here. :p 
    133123        get url() { 
    134124                return this._url; 
     
    136126        set url(nv) { 
    137127                delete this.hash; 
    138                 this._url = this.str(nv); 
    139                 var hash = DTA_getLinkPrintHash(this._url); 
     128                 
     129                if (nv instanceof Components.interfaces.nsIURI) { 
     130                        nv = nv.QueryInterface(Components.interfaces.nsIURL); 
     131                } 
     132                if (!(nv instanceof Components.interfaces.nsIURL)) { 
     133                        throw new Components.Exception("you must pass an nsIURL"); 
     134                } 
     135 
     136                this._url = nv.clone(); 
     137                 
     138                let hash = DTA_getLinkPrintHash(this._url); 
     139                this._url.ref = '';              
    140140                if (hash) { 
    141141                        this.hash = hash; 
    142142                } 
    143                 this._url = this._url.replace(/#.*$/, ''); 
    144                 this.usable = ''; 
    145                 this.decode(); 
    146         }, 
    147         decode: function DU_decode() { 
    148                 if (!this.usable) 
    149                 { 
    150                         this.usable = DTA_URLhelpers.decodeCharset(this._url, this.charset); 
    151                 } 
    152         }, 
    153         save: function DU_save(element) { 
    154                 element.setAttribute("url", this._url); 
    155                 element.setAttribute("charset", this.charset); 
    156                 element.setAttribute("usableURL", this.usable); 
     143                this._usable = DTA_URLhelpers.decodeCharset(this._url.spec, this._url.originCharset); 
     144        }, 
     145        get usable() { 
     146                return this._usable; 
     147        }, 
     148        toSource: function DU_toSource() { 
     149                return { 
     150                        url: this._url.spec, 
     151                        charset: this._url.originCharset, 
     152                        preference: this.preference 
     153                } 
    157154        } 
    158155}; 
     
    177174                                throw new Components.Exception("Link cannot be opened!"); 
    178175                        } 
     176                        url = this.ios.newURI(url, null, null); 
    179177                } 
    180178                catch (ex) { 
     
    184182                var doc = document.commandDispatcher.focusedWindow.document; 
    185183                 
    186                 var ml = DTA_getLinkPrintMetalink(url); 
    187                 url = new DTA_URL(ml ? ml : url, doc.characterSet); 
     184                let ml = DTA_getLinkPrintMetalink(url); 
     185                url = new DTA_URL(ml ? ml : url); 
    188186                 
    189                 var ref = DTA_AddingFunctions.getRef(doc); 
     187                let ref = DTA_AddingFunctions.getRef(doc); 
    190188                this.func(url, ref); 
    191189        } 
     
    201199        isLinkOpenable : function(url) { 
    202200                if (url instanceof DTA_URL) { 
    203                         url = url.url
     201                        url = url.url.spec
    204202                } 
    205203                try { 
     
    449447                        ref = ref.url; 
    450448                } 
     449                if (!url instanceof Components.interfaces.nsIURI) { 
     450                        throw new Error("Cannot open non nsIURI"); 
     451                } 
    451452                if (ref && !(ref instanceof Components.interfaces.nsIURI)) { 
    452453                        try { 
    453454                                ref = DTA_AddingFunctions.ios.newURI(ref, null, null); 
    454                         } catch (ex) { 
     455                        } 
     456                        catch (ex) { 
    455457                                DTA_debug.log(ref, ex); 
    456458                                ref = null; 
     
    469471                                var ps = Components.classes['@mozilla.org/uriloader/external-protocol-service;1'] 
    470472                                        .getService(Components.interfaces.nsIExternalProtocolService); 
    471                                 ps.loadUrl(this._ios.newURI(url, null, null)); 
     473                                ps.loadUrl(url); 
    472474                        } 
    473475                        catch (ex) { 
     
    549551 */ 
    550552function DTA_getLinkPrintHash(url) { 
    551         if (url instanceof Components.interfaces.nsIURI) { 
    552                 url = url.spec; 
    553         } 
    554         else if (typeof(url) != 'string' && !(url instanceof String)) { 
     553        if (!(url instanceof Components.interfaces.nsIURL)) { 
    555554                return null; 
    556555        } 
    557          
    558         var lp = url.match(/#hash\((md5|sha(?:1|256|384|512)):([\da-f]+)\)$/i);  
     556        var lp = url.ref.match(/^hash\((md5|sha(?:1|256|384|512)):([\da-f]+)\)$/i);  
    559557        if (lp) { 
    560558                try { 
     
    574572 * @return Valid hash string or null 
    575573 */ 
    576 function DTA_getLinkPrintMetalink(url, charset) { 
    577         if (url instanceof Components.interfaces.nsIURL) { 
    578                 url = url.ref; 
    579         } 
    580         else if (url instanceof Components.interfaces.nsIURI) { 
    581                 url = url.spec; 
    582         } 
    583         else if (typeof(url) != 'string' && !(url instanceof String)) { 
     574function DTA_getLinkPrintMetalink(url) { 
     575        if (!(url instanceof Components.interfaces.nsIURL)) { 
    584576                return null; 
    585577        } 
    586          
    587         var lp = url.match(/#!metalink3!((?:https?|ftp):.+)$/); 
     578        let lp = url.ref.match(/^!metalink3!(.+)$/); 
    588579        if (lp) { 
    589                 var rv = lp[1]; 
    590                 try { 
    591                         return DTA_AddingFunctions.ios.newURI(rv, charset, null).spec; 
     580                let rv = lp[1]; 
     581                try { 
     582                        rv = DTA_AddingFunctions.ios.newURI(rv, url.originCharset, url); 
     583                        if (DTA_AddingFunctions.isLinkOpenable(rv.spec)) { 
     584                                return rv; 
     585                        } 
    592586                } 
    593587                catch (ex) { 
     588                        alert(ex); 
    594589                        // not a valid link, ignore it. 
    595590                } 
  • trunk/chrome/content/dta/addurl.js

    r1022 r1027  
    117117function BatchGenerator(link) { 
    118118        this.url = link.url; 
    119         var url = this.url
     119        let url = this.url.spec
    120120        this._length = 1; 
    121121        this._pats = []; 
     
    394394                        url = url.replace(/#.*$/, ''); 
    395395                        address.value = url; 
    396                         url = new DTA_URL(url); 
     396                        url = new DTA_URL(IOService.newURI(url, null, null)); 
    397397                } 
    398398                 
     
    434434                } 
    435435                catch (ex) { 
    436                         Debug.dump("Cannot create batch", ex); 
     436                        Debug.log("Cannot create batch", ex); 
    437437                        return; 
    438438                } 
     
    458458                        batch = function() { 
    459459                                for (let i in g) { 
    460                                         yield new QueueItem(new DTA_URL(i), num, desc); 
     460                                        yield new QueueItem(new DTA_URL(IOService.newURI(i, null, null)), num, desc); 
    461461                                } 
    462462                        }(); 
  • trunk/chrome/content/dta/manager.js

    r1022 r1027  
    575575        initByArray: function um_initByArray(urls) { 
    576576                for each (let u in urls) { 
    577                         this.add( 
    578                                 new DTA_URL( 
    579                                         u.url, 
    580                                         u.charset, 
    581                                         u.usable, 
    582                                         u.preference 
    583                                 ) 
    584                         ); 
     577                        Debug.logString(u.toSource()); 
     578                        if (u instanceof DTA_URL || (u.url && u.url instanceof Ci.nsIURI)) { 
     579                                this.add(u); 
     580                        } 
     581                        else if (u instanceof Ci.nsIURI) { 
     582                                this.add(new DTA_URL(u)); 
     583                        } 
     584                        else { 
     585                                this.add( 
     586                                        new DTA_URL( 
     587                                                IOService.newURI(u.url, u.charset, null), 
     588                                                u.preference 
     589                                        ) 
     590                                ); 
     591                        } 
    585592                } 
    586593                this._urls.sort(this._sort); 
     
    591598                        throw (url + " is not an DTA_URL"); 
    592599                } 
    593                 if (!this._urls.some(function(ref) { return ref.url == url.url; })) { 
     600                if (!this._urls.some(function(ref) ref.url.spec == url.url.spec)) { 
    594601                        this._urls.push(url); 
    595602                } 
     
    611618                return this._urls[0].usable; 
    612619        }, 
    613         get charset() { 
    614                 return this._urls[0].charset; 
    615         }, 
    616620        get length() { 
    617621                return this._urls.length; 
     
    633637        toSource: function um_toSource() { 
    634638                let rv = []; 
    635                 this._urls.forEach( 
    636                         function(url) { 
    637                                 rv.push({ 
    638                                         'url': url.url, 
    639                                         'charset': url.charset, 
    640                                         'usable': url.usable, 
    641                                         'preference': url.preference 
    642                                 }); 
    643                         } 
    644                 ); 
     639                for each (let url in this._urls) { 
     640                        rv.push(url.toSource()); 
     641                } 
    645642                return rv; 
    646643        }, 
    647644        toString: function() { 
    648                 let rv = ''; 
    649                 this._urls.forEach( 
    650                         function(u) { 
    651                                 rv += u.preference + " " + u.url + "\n"; 
    652                         } 
    653                 ); 
    654                 return rv; 
     645                return this._urls.reduce(function(v, u) v + u.preference + " " + u.url + "\n"); 
    655646        } 
    656647}; 
     
    15441535                        delete this._autoRetryTime; 
    15451536                        this.save(); 
    1546                 } catch(ex) { 
     1537                } 
     1538                catch(ex) { 
    15471539                        Debug.log("cancel():", ex); 
    15481540                } 
     
    19501942        Debug.logString("starting: " + this.url.url); 
    19511943 
    1952         this._chan = IOService.newChannelFromURI(this.url.url.toURL()); 
     1944        this._chan = IOService.newChannelFromURI(this.url.url); 
    19531945        var r = Ci.nsIRequest; 
    19541946        this._chan.loadFlags = r.LOAD_NORMAL | r.LOAD_BYPASS_CACHE; 
     
    25852577                let lnk = e.url; 
    25862578                if (typeof lnk == 'string') { 
    2587                         qi.urlManager = new UrlManager([new DTA_URL(lnk)]); 
     2579                        qi.urlManager = new UrlManager([new DTA_URL(IOService.newURI(lnk, null, null))]); 
    25882580                } 
    25892581                else if (lnk instanceof UrlManager) { 
     
    26272619                } 
    26282620 
    2629                 let postData = ContentHandling.getPostDataFor(qi.urlManager.url.toURI()); 
     2621                let postData = ContentHandling.getPostDataFor(qi.urlManager.url); 
    26302622                if (e.url.postData) { 
    26312623                        postData = e.url.postData; 
  • trunk/chrome/content/dta/manager/imex.js

    r985 r1027  
    228228                                } 
    229229                                links.push({ 
    230                                         'url': new DTA_URL(url.spec), 
     230                                        'url': new DTA_URL(url), 
    231231                                        'referrer': '', 
    232232                                        'description': 'imported from ' + file.leafName  
  • trunk/chrome/content/dta/manager/metalinker.js

    r1024 r1027  
    3434 * 
    3535 * ***** END LICENSE BLOCK ***** */ 
     36 
     37const METALINK_LOGO = 'chrome://dta/skin/icons/metalink48.png'; 
    3638  
    3739function NSResolver(prefix) { 
     
    196198                                                url = this._checkURL(url.textContent.trim()); 
    197199                                                if (url) { 
    198                                                         urls.push(new DTA_URL(url, charset, usable, preference)); 
     200                                                        urls.push(new DTA_URL(IOService.newURI(url, charset, null), preference)); 
    199201                                                } 
    200202                                        } 
     
    268270                                ); 
    269271                                downloads = downloads.filter(function(d) { return d.selected; }); 
    270                                 if (downloads.length) { 
     272                                if (info.start && downloads.length) { 
    271273                                        startDownloads(info.start, downloads); 
    272274                                } 
     
    306308                        'identity': _('mlidentity'), 
    307309                        'description': _('mldescription'), 
    308                         'logo': 'chrome://dta/skin/icons/metalink_big.png'
     310                        'logo': null
    309311                        'publisher': null, 
    310312                        'license': null 
     
    323325                $('identity').value = info.identity; 
    324326                $('desc').appendChild(document.createTextNode(info.description)); 
    325                 $('icon').src = info.logo; 
     327                let logo = new Image(); 
     328                logo.onload = function() { 
     329                        let canvas = $('icon'); 
     330                        try { 
     331                                canvas.width = canvas.clientWidth; 
     332                                canvas.height = canvas.clientHeight; 
     333                                let ctx = canvas.getContext('2d'); 
     334                                 
     335                                let w = logo.naturalWidth; 
     336                                let h = logo.naturalHeight; 
     337                                d = Math.max(w, h); 
     338                                 
     339                                ctx.scale(canvas.width / d, canvas.height / d); 
     340                                 
     341                                ctx.drawImage(logo, (d - w) /2, (d - h) / 2);                                                            
     342                        } 
     343                        catch (ex) { 
     344                                alert(ex); 
     345                                Debug.log("Cannot load logo", ex); 
     346                                logo.src = METALINK_LOGO; 
     347                        } 
     348                }; 
     349                logo.onerror = function() { 
     350                        logo.src = METALINK_LOGO; 
     351                }; 
     352                logo.src = info.logo ? info.logo : METALINK_LOGO; 
    326353                if (info.publisher) { 
    327354                        var e = $('publisher'); 
  • trunk/chrome/content/dta/manager/metaselect.xul

    r959 r1027  
    8080        <hbox id="header"> 
    8181                <vbox> 
    82                                <spacer flex="1"/> 
    83                                <image id="icon" class="icon"/> 
    84                                <spacer flex="1"/> 
    85                 </vbox> 
     82                        <spacer flex="1"/> 
     83                        <html:canvas width="48" height="48" id="icon" class="icon"/> 
     84                        <spacer flex="1"/> 
     85                </vbox>         
    8686                <vbox flex="1"> 
    8787                        <grid flex="1"> 
     
    101101                                </rows>                                  
    102102                        </grid> 
    103                         <description id="desc"/>                 
     103                        <description id="desc"/>         
     104                        <spacer flex="1"/>       
    104105                </vbox> 
    105106        </hbox> 
  • trunk/chrome/content/dta/manager/sessionmanager.js

    r1015 r1027  
    172172                let count = stmt.getInt64(0); 
    173173                stmt.finalize(); 
     174                if (!count) { 
     175                        Dialog.start(); 
     176                        return;                  
     177                } 
    174178                let loading = $('loading'); 
    175179 
  • trunk/chrome/content/dta/manager/tree.js

    r1022 r1027  
    514514                } 
    515515                $("infoIcon").src = d.largeIcon; 
    516                 $("infoURL").value = d.urlManager.url
     516                $("infoURL").value = d.urlManager.url.spec
    517517                $("infoDest").value = d.destinationFile; 
    518518         
  • trunk/chrome/content/integration/elements.js

    r993 r1027  
    8181                                udesc = this.trim(link.getAttribute('title')); 
    8282                        } 
     83                        let url = DTA_AddingFunctions.ios.newURI(link.href, doc.characterSet, null); 
    8384                        urls.push({ 
    84                                 'url': new DTA_URL(link.href, doc.characterSet), 
     85                                'url': new DTA_URL(url), 
    8586                                'referrer': ref, 
    8687                                'description': this.extractDescription(link), 
     
    8889                        }); 
    8990                         
    90                         var ml = DTA_getLinkPrintMetalink(link.hash); 
     91                        var ml = DTA_getLinkPrintMetalink(url.ref); 
    9192                        if (ml) { 
    9293                                urls.push({ 
    93                                         'url': new DTA_URL(ml, doc.characterSet), 
     94                                        'url': new DTA_URL(ml), 
    9495                                        'referrer': ref, 
    9596                                        'description': '[metalink] http://www.metalinker.org/', 
     
    132133                        } 
    133134                        images.push({ 
    134                                 'url': new DTA_URL(src, doc.characterSet), 
     135                                'url': new DTA_URL(DTA_AddingFunctions.ios.newURI(src, doc.characterSet)), 
    135136                                'referrer': ref, 
    136137                                'description': desc 
     
    333334                         
    334335                        if (!DTA_AddingFunctions.isLinkOpenable(url)) { 
    335                                 DTA_Prompts.alert(window, this.getString('error'), this.getError('errornodownload')); 
     336                                DTA_Prompts.alert(window, this.getString('error'), this.getString('errornodownload')); 
    336337                                return; 
    337338                        } 
    338339                         
     340                        url = DTA_AddingFunctions.ios.newURI(url, win.document.characterSet, null); 
    339341                        var ml = DTA_getLinkPrintMetalink(url); 
    340                         url = new DTA_URL(ml ? ml : url, win.document.characterSet); 
     342                        url = new DTA_URL(ml ? ml : url); 
    341343                         
    342344                        var ref = DTA_AddingFunctions.getRef(document.commandDispatcher.focusedWindow.document); 
     
    420422                                ss.close(); 
    421423                                 
    422                                 action = new DTA_URL(action.spec, form.ownerDocument.characterSet); 
     424                                action = new DTA_URL(DTA_AddingFunctions.ios.newURI(action.spec, form.ownerDocument.characterSet)); 
    423425                                action.postData = postData; 
    424426                        } 
     
    426428                                action.query = values; 
    427429                                action.ref = ''; 
    428                                 action = new DTA_URL(action.spec, form.ownerDocument.characterSet); 
     430                                action = new DTA_URL(DTA_AddingFunctions.ios.newURI(action.spec, form.ownerDocument.characterSet)); 
    429431                        }                        
    430432 
  • trunk/chrome/content/integration/saveas.js

    r993 r1027  
    7171                 
    7272                this.dialog = dialog; 
    73                 this.url = dialog.mLauncher.source.spec
     73                this.url = dialog.mLauncher.source
    7474                try { 
    7575                        this.referrer = dialog.mContext.QueryInterface(Components.interfaces.nsIWebNavigation).currentURI.spec; 
    7676        } 
    7777                catch(ex) { 
    78                         this.referrer = this.url; 
    79                 } 
     78                        this.referrer = this.url.spec; 
     79                } 
     80                 
    8081                var ml = DTA_getLinkPrintMetalink(this.url); 
    8182                this.url = new DTA_URL(ml ? ml : this.url); 
  • trunk/chrome/skin/manager/metalinker.css

    r551 r1027  
    11@import 'chrome://dta/skin/common/style.css'; 
    22@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); 
    3  
     3@namespace html url("http://www.w3.org/1999/xhtml"); 
     4         
    45#metaselect { 
    56        width: 600px; 
     
    78} 
    89#header { 
     10        margin: 1ex; 
    911        margin-bottom: 1em; 
    1012} 
     
    1214        font-weight: bold; 
    1315} 
    14 .icon { 
    15         height: 32px !important; 
    16         width: 32px !important; 
     16.icon, html|*.icon { 
    1717        margin: 1ex; 
    18         margin-top: 0
     18        margin-top: 0.5ex
    1919} 
    2020.additional {