text-link.xml (5297B)
1 <?xml version="1.0"?> 2 <!-- ***** BEGIN LICENSE BLOCK ***** 3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 4 * 5 * The contents of this file are subject to the Mozilla Public License Version 6 * 1.1 (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * http://www.mozilla.org/MPL/ 9 * 10 * Software distributed under the License is distributed on an "AS IS" basis, 11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 12 * for the specific language governing rights and limitations under the 13 * License. 14 * 15 * The Original Code is Mozilla Toolkit. 16 * 17 * The Initial Developer of the Original Code is 18 * the Mozilla Foundation. 19 * Portions created by the Initial Developer are Copyright (C) 2010 20 * the Initial Developer. All Rights Reserved. 21 * 22 * Alternatively, the contents of this file may be used under the terms of 23 * either the GNU General Public License Version 2 or later (the "GPL"), or 24 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 25 * in which case the provisions of the GPL or the LGPL are applicable instead 26 * of those above. If you wish to allow use of your version of this file only 27 * under the terms of either the GPL or the LGPL, and not to allow others to 28 * use your version of this file under the terms of the MPL, indicate your 29 * decision by deleting the provisions above and replace them with the notice 30 * and other provisions required by the GPL or the LGPL. If you do not delete 31 * the provisions above, a recipient may use your version of this file under 32 * the terms of any one of the MPL, the GPL or the LGPL. 33 * 34 * ***** END LICENSE BLOCK ***** --> 35 <bindings id="textBindings" 36 xmlns="http://www.mozilla.org/xbl" 37 xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 38 xmlns:html="http://www.w3.org/1999/xhtml"> 39 40 <binding id="text-link" extends="chrome://global/content/bindings/text.xml#text-label"> 41 <implementation implements="nsIAccessibleProvider"> 42 <property name="accessibleType" readonly="true"> 43 <getter> 44 <![CDATA[ 45 return Components.interfaces.nsIAccessibleProvider.XULLink; 46 ]]> 47 </getter> 48 </property> 49 <property name="href" onget="return this.getAttribute('href');" 50 onset="this.setAttribute('href', val); return val;" /> 51 <method name="open"> 52 <parameter name="aEvent"/> 53 <body> 54 <![CDATA[ 55 var href = this.href; 56 if (!href || this.disabled || aEvent.getPreventDefault()) 57 return; 58 59 var uri = null; 60 try { 61 const nsISSM = Components.interfaces.nsIScriptSecurityManager; 62 const secMan = 63 Components.classes["@mozilla.org/scriptsecuritymanager;1"] 64 .getService(nsISSM); 65 66 const ioService = 67 Components.classes["@mozilla.org/network/io-service;1"] 68 .getService(Components.interfaces.nsIIOService); 69 70 uri = ioService.newURI(href, null, null); 71 72 var nullPrincipal = 73 Components.classes["@mozilla.org/nullprincipal;1"] 74 .createInstance(Components.interfaces.nsIPrincipal); 75 try { 76 secMan.checkLoadURIWithPrincipal(nullPrincipal, uri, 77 nsISSM.DISALLOW_INHERIT_PRINCIPAL) 78 } 79 catch (ex) { 80 var msg = "Error: Cannot open a " + uri.scheme + ": link using \ 81 the text-link binding."; 82 Components.utils.reportError(msg); 83 return; 84 } 85 86 const cID = "@mozilla.org/uriloader/external-protocol-service;1"; 87 const nsIEPS = Components.interfaces.nsIExternalProtocolService; 88 var protocolSvc = Components.classes[cID].getService(nsIEPS); 89 90 // if the scheme is not an exposed protocol, then opening this link 91 // should be deferred to the system's external protocol handler 92 if (!protocolSvc.isExposedProtocol(uri.scheme) 93 || (window.Zotero && window.Zotero.isStandalone && ["http", "https"].indexOf(uri.scheme) !== -1)) { 94 protocolSvc.loadUrl(uri); 95 aEvent.preventDefault() 96 return; 97 } 98 99 } 100 catch (ex) { 101 Components.utils.reportError(ex); 102 } 103 104 // otherwise, fall back to opening the anchor directly 105 var win = window; 106 if (window instanceof Components.interfaces.nsIDOMChromeWindow) { 107 while (win.opener && !win.opener.closed) 108 win = win.opener; 109 } 110 111 if (uri) 112 win.open(uri.spec); 113 else 114 win.open(href); 115 116 aEvent.preventDefault(); 117 ]]> 118 </body> 119 </method> 120 </implementation> 121 122 <handlers> 123 <handler event="click" phase="capturing" button="0" action="this.open(event)"/> 124 <handler event="keypress" preventdefault="true" keycode="VK_ENTER" action="this.click()" /> 125 <handler event="keypress" preventdefault="true" keycode="VK_RETURN" action="this.click()" /> 126 </handlers> 127 </binding> 128 129 </bindings>