Changeset 1027
- Timestamp:
- 08/02/08 16:13:35 (1 month ago)
- Files:
-
- trunk/chrome/content/common/bindings.xml (modified) (1 diff)
- trunk/chrome/content/common/internalFunctions.js (modified) (1 diff)
- trunk/chrome/content/common/overlayFunctions.js (modified) (9 diffs)
- trunk/chrome/content/dta/addurl.js (modified) (4 diffs)
- trunk/chrome/content/dta/manager.js (modified) (8 diffs)
- trunk/chrome/content/dta/manager/imex.js (modified) (1 diff)
- trunk/chrome/content/dta/manager/metalinker.js (modified) (5 diffs)
- trunk/chrome/content/dta/manager/metaselect.xul (modified) (2 diffs)
- trunk/chrome/content/dta/manager/sessionmanager.js (modified) (1 diff)
- trunk/chrome/content/dta/manager/tree.js (modified) (1 diff)
- trunk/chrome/content/integration/elements.js (modified) (6 diffs)
- trunk/chrome/content/integration/saveas.js (modified) (1 diff)
- trunk/chrome/skin/icons/metalink48.png (added)
- trunk/chrome/skin/icons/metalink_big.png (deleted)
- trunk/chrome/skin/manager/metalinker.css (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/chrome/content/common/bindings.xml
r993 r1027 202 202 <xul:hbox flex="1"> 203 203 <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"/> 205 207 </xul:vbox> 206 208 <xul:vbox flex="1"> trunk/chrome/content/common/internalFunctions.js
r1022 r1027 359 359 var url; 360 360 if (link instanceof DTA_URL) { 361 url = link.url ;361 url = link.url.spec; 362 362 } 363 363 else if (link instanceof Components.interfaces.nsIURI) { trunk/chrome/content/common/overlayFunctions.js
r1000 r1027 116 116 }; 117 117 118 function DTA_URL(url, charset, usable, preference) { 119 this.charset = this.str(charset); 118 function DTA_URL(url, preference) { 120 119 this.url = url; 121 if (usable) {122 this.usable = this.str(usable);123 }124 120 this.preference = preference ? preference : 100; 125 126 this.decode();127 121 }; 128 122 DTA_URL.prototype = { 129 str: function(value) {130 return value ? String(value) : '';131 },132 // only a getter here. :p133 123 get url() { 134 124 return this._url; … … 136 126 set url(nv) { 137 127 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 = ''; 140 140 if (hash) { 141 141 this.hash = hash; 142 142 } 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 } 157 154 } 158 155 }; … … 177 174 throw new Components.Exception("Link cannot be opened!"); 178 175 } 176 url = this.ios.newURI(url, null, null); 179 177 } 180 178 catch (ex) { … … 184 182 var doc = document.commandDispatcher.focusedWindow.document; 185 183 186 varml = 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); 188 186 189 varref = DTA_AddingFunctions.getRef(doc);187 let ref = DTA_AddingFunctions.getRef(doc); 190 188 this.func(url, ref); 191 189 } … … 201 199 isLinkOpenable : function(url) { 202 200 if (url instanceof DTA_URL) { 203 url = url.url ;201 url = url.url.spec; 204 202 } 205 203 try { … … 449 447 ref = ref.url; 450 448 } 449 if (!url instanceof Components.interfaces.nsIURI) { 450 throw new Error("Cannot open non nsIURI"); 451 } 451 452 if (ref && !(ref instanceof Components.interfaces.nsIURI)) { 452 453 try { 453 454 ref = DTA_AddingFunctions.ios.newURI(ref, null, null); 454 } catch (ex) { 455 } 456 catch (ex) { 455 457 DTA_debug.log(ref, ex); 456 458 ref = null; … … 469 471 var ps = Components.classes['@mozilla.org/uriloader/external-protocol-service;1'] 470 472 .getService(Components.interfaces.nsIExternalProtocolService); 471 ps.loadUrl( this._ios.newURI(url, null, null));473 ps.loadUrl(url); 472 474 } 473 475 catch (ex) { … … 549 551 */ 550 552 function 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)) { 555 554 return null; 556 555 } 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); 559 557 if (lp) { 560 558 try { … … 574 572 * @return Valid hash string or null 575 573 */ 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)) { 574 function DTA_getLinkPrintMetalink(url) { 575 if (!(url instanceof Components.interfaces.nsIURL)) { 584 576 return null; 585 577 } 586 587 var lp = url.match(/#!metalink3!((?:https?|ftp):.+)$/); 578 let lp = url.ref.match(/^!metalink3!(.+)$/); 588 579 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 } 592 586 } 593 587 catch (ex) { 588 alert(ex); 594 589 // not a valid link, ignore it. 595 590 } trunk/chrome/content/dta/addurl.js
r1022 r1027 117 117 function BatchGenerator(link) { 118 118 this.url = link.url; 119 var url = this.url;119 let url = this.url.spec; 120 120 this._length = 1; 121 121 this._pats = []; … … 394 394 url = url.replace(/#.*$/, ''); 395 395 address.value = url; 396 url = new DTA_URL( url);396 url = new DTA_URL(IOService.newURI(url, null, null)); 397 397 } 398 398 … … 434 434 } 435 435 catch (ex) { 436 Debug. dump("Cannot create batch", ex);436 Debug.log("Cannot create batch", ex); 437 437 return; 438 438 } … … 458 458 batch = function() { 459 459 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); 461 461 } 462 462 }(); trunk/chrome/content/dta/manager.js
r1022 r1027 575 575 initByArray: function um_initByArray(urls) { 576 576 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 } 585 592 } 586 593 this._urls.sort(this._sort); … … 591 598 throw (url + " is not an DTA_URL"); 592 599 } 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)) { 594 601 this._urls.push(url); 595 602 } … … 611 618 return this._urls[0].usable; 612 619 }, 613 get charset() {614 return this._urls[0].charset;615 },616 620 get length() { 617 621 return this._urls.length; … … 633 637 toSource: function um_toSource() { 634 638 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 } 645 642 return rv; 646 643 }, 647 644 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"); 655 646 } 656 647 }; … … 1544 1535 delete this._autoRetryTime; 1545 1536 this.save(); 1546 } catch(ex) { 1537 } 1538 catch(ex) { 1547 1539 Debug.log("cancel():", ex); 1548 1540 } … … 1950 1942 Debug.logString("starting: " + this.url.url); 1951 1943 1952 this._chan = IOService.newChannelFromURI(this.url.url .toURL());1944 this._chan = IOService.newChannelFromURI(this.url.url); 1953 1945 var r = Ci.nsIRequest; 1954 1946 this._chan.loadFlags = r.LOAD_NORMAL | r.LOAD_BYPASS_CACHE; … … 2585 2577 let lnk = e.url; 2586 2578 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))]); 2588 2580 } 2589 2581 else if (lnk instanceof UrlManager) { … … 2627 2619 } 2628 2620 2629 let postData = ContentHandling.getPostDataFor(qi.urlManager.url .toURI());2621 let postData = ContentHandling.getPostDataFor(qi.urlManager.url); 2630 2622 if (e.url.postData) { 2631 2623 postData = e.url.postData; trunk/chrome/content/dta/manager/imex.js
r985 r1027 228 228 } 229 229 links.push({ 230 'url': new DTA_URL(url .spec),230 'url': new DTA_URL(url), 231 231 'referrer': '', 232 232 'description': 'imported from ' + file.leafName trunk/chrome/content/dta/manager/metalinker.js
r1024 r1027 34 34 * 35 35 * ***** END LICENSE BLOCK ***** */ 36 37 const METALINK_LOGO = 'chrome://dta/skin/icons/metalink48.png'; 36 38 37 39 function NSResolver(prefix) { … … 196 198 url = this._checkURL(url.textContent.trim()); 197 199 if (url) { 198 urls.push(new DTA_URL( url, charset, usable, preference));200 urls.push(new DTA_URL(IOService.newURI(url, charset, null), preference)); 199 201 } 200 202 } … … 268 270 ); 269 271 downloads = downloads.filter(function(d) { return d.selected; }); 270 if ( downloads.length) {272 if (info.start && downloads.length) { 271 273 startDownloads(info.start, downloads); 272 274 } … … 306 308 'identity': _('mlidentity'), 307 309 'description': _('mldescription'), 308 'logo': 'chrome://dta/skin/icons/metalink_big.png',310 'logo': null, 309 311 'publisher': null, 310 312 'license': null … … 323 325 $('identity').value = info.identity; 324 326 $('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; 326 353 if (info.publisher) { 327 354 var e = $('publisher'); trunk/chrome/content/dta/manager/metaselect.xul
r959 r1027 80 80 <hbox id="header"> 81 81 <vbox> 82 <spacer flex="1"/>83 <imageid="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> 86 86 <vbox flex="1"> 87 87 <grid flex="1"> … … 101 101 </rows> 102 102 </grid> 103 <description id="desc"/> 103 <description id="desc"/> 104 <spacer flex="1"/> 104 105 </vbox> 105 106 </hbox> trunk/chrome/content/dta/manager/sessionmanager.js
r1015 r1027 172 172 let count = stmt.getInt64(0); 173 173 stmt.finalize(); 174 if (!count) { 175 Dialog.start(); 176 return; 177 } 174 178 let loading = $('loading'); 175 179 trunk/chrome/content/dta/manager/tree.js
r1022 r1027 514 514 } 515 515 $("infoIcon").src = d.largeIcon; 516 $("infoURL").value = d.urlManager.url ;516 $("infoURL").value = d.urlManager.url.spec; 517 517 $("infoDest").value = d.destinationFile; 518 518 trunk/chrome/content/integration/elements.js
r993 r1027 81 81 udesc = this.trim(link.getAttribute('title')); 82 82 } 83 let url = DTA_AddingFunctions.ios.newURI(link.href, doc.characterSet, null); 83 84 urls.push({ 84 'url': new DTA_URL( link.href, doc.characterSet),85 'url': new DTA_URL(url), 85 86 'referrer': ref, 86 87 'description': this.extractDescription(link), … … 88 89 }); 89 90 90 var ml = DTA_getLinkPrintMetalink( link.hash);91 var ml = DTA_getLinkPrintMetalink(url.ref); 91 92 if (ml) { 92 93 urls.push({ 93 'url': new DTA_URL(ml , doc.characterSet),94 'url': new DTA_URL(ml), 94 95 'referrer': ref, 95 96 'description': '[metalink] http://www.metalinker.org/', … … 132 133 } 133 134 images.push({ 134 'url': new DTA_URL( src, doc.characterSet),135 'url': new DTA_URL(DTA_AddingFunctions.ios.newURI(src, doc.characterSet)), 135 136 'referrer': ref, 136 137 'description': desc … … 333 334 334 335 if (!DTA_AddingFunctions.isLinkOpenable(url)) { 335 DTA_Prompts.alert(window, this.getString('error'), this.get Error('errornodownload'));336 DTA_Prompts.alert(window, this.getString('error'), this.getString('errornodownload')); 336 337 return; 337 338 } 338 339 340 url = DTA_AddingFunctions.ios.newURI(url, win.document.characterSet, null); 339 341 var ml = DTA_getLinkPrintMetalink(url); 340 url = new DTA_URL(ml ? ml : url , win.document.characterSet);342 url = new DTA_URL(ml ? ml : url); 341 343 342 344 var ref = DTA_AddingFunctions.getRef(document.commandDispatcher.focusedWindow.document); … … 420 422 ss.close(); 421 423 422 action = new DTA_URL( action.spec, form.ownerDocument.characterSet);424 action = new DTA_URL(DTA_AddingFunctions.ios.newURI(action.spec, form.ownerDocument.characterSet)); 423 425 action.postData = postData; 424 426 } … … 426 428 action.query = values; 427 429 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)); 429 431 } 430 432 trunk/chrome/content/integration/saveas.js
r993 r1027 71 71 72 72 this.dialog = dialog; 73 this.url = dialog.mLauncher.source .spec;73 this.url = dialog.mLauncher.source; 74 74 try { 75 75 this.referrer = dialog.mContext.QueryInterface(Components.interfaces.nsIWebNavigation).currentURI.spec; 76 76 } 77 77 catch(ex) { 78 this.referrer = this.url; 79 } 78 this.referrer = this.url.spec; 79 } 80 80 81 var ml = DTA_getLinkPrintMetalink(this.url); 81 82 this.url = new DTA_URL(ml ? ml : this.url); trunk/chrome/skin/manager/metalinker.css
r551 r1027 1 1 @import 'chrome://dta/skin/common/style.css'; 2 2 @namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); 3 3 @namespace html url("http://www.w3.org/1999/xhtml"); 4 4 5 #metaselect { 5 6 width: 600px; … … 7 8 } 8 9 #header { 10 margin: 1ex; 9 11 margin-bottom: 1em; 10 12 } … … 12 14 font-weight: bold; 13 15 } 14 .icon { 15 height: 32px !important; 16 width: 32px !important; 16 .icon, html|*.icon { 17 17 margin: 1ex; 18 margin-top: 0 ;18 margin-top: 0.5ex; 19 19 } 20 20 .additional {
