home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 May / PCWorld_2003-05_cd.bin / Komunik / phoenix / chrome / toolkit.jar / content / global / bindings / browser.xml next >
Extensible Markup Language  |  2002-09-10  |  13KB  |  382 lines

  1. <?xml version="1.0"?>
  2.  
  3. <!--
  4.    - The contents of this file are subject to the Mozilla Public
  5.    - License Version 1.1 (the "License"); you may not use this file
  6.    - except in compliance with the License. You may obtain a copy of
  7.    - the License at http://www.mozilla.org/MPL/
  8.    -
  9.    - Software distributed under the License is distributed on an "AS
  10.    - IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  11.    - implied. See the License for the specific language governing
  12.    - rights and limitations under the License.
  13.    -
  14.    - The Original Code is this file as it was released on
  15.    - March 28, 2001.
  16.    -
  17.    - The Initial Developer of the Original Code is Peter Annema.
  18.    - Portions created by Peter Annema are Copyright (C) 2001
  19.    - Peter Annema.  All Rights Reserved.
  20.    -
  21.    - Contributor(s):
  22.    -   Peter Annema <disttsc@bart.nl> (Original Author of <browser>)
  23.    -
  24.    - Alternatively, the contents of this file may be used under the
  25.    - terms of the GNU General Public License Version 2 or later (the
  26.    - "GPL"), in which case the provisions of the GPL are applicable
  27.    - instead of those above.  If you wish to allow use of your
  28.    - version of this file only under the terms of the GPL and not to
  29.    - allow others to use your version of this file under the MPL,
  30.    - indicate your decision by deleting the provisions above and
  31.    - replace them with the notice and other provisions required by
  32.    - the GPL.  If you do not delete the provisions above, a recipient
  33.    - may use your version of this file under either the MPL or the
  34.    - GPL.
  35.   -->
  36.  
  37. <bindings id="browserBindings"
  38.           xmlns="http://www.mozilla.org/xbl"
  39.           xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  40.  
  41.   <binding id="browser" extends="xul:browser">
  42.     <implementation type="application/x-javascript" implements="nsIAccessibleProvider">
  43.       <property name="accessible">
  44.         <getter>
  45.           <![CDATA[
  46.             var accService = Components.classes["@mozilla.org/accessibilityService;1"].getService(Components.interfaces.nsIAccessibilityService);
  47.             return accService.createIFrameAccessible(this);
  48.           ]]>
  49.         </getter>
  50.       </property>
  51.  
  52.       <property name="canGoBack"
  53.                 onget="return this.webNavigation.canGoBack;"
  54.                 readonly="true"/>
  55.  
  56.       <property name="canGoForward"
  57.                 onget="return this.webNavigation.canGoForward;"
  58.                 readonly="true"/>
  59.  
  60.       <method name="goBack">
  61.         <body>
  62.           <![CDATA[
  63.             var webNavigation = this.webNavigation;
  64.             if (webNavigation.canGoBack)
  65.               webNavigation.goBack();
  66.           ]]>
  67.         </body>
  68.       </method>
  69.  
  70.       <method name="goForward">
  71.         <body>
  72.           <![CDATA[
  73.             var webNavigation = this.webNavigation;
  74.             if (webNavigation.canGoForward)
  75.               webNavigation.goForward();
  76.           ]]>
  77.         </body>
  78.       </method>
  79.  
  80.       <method name="reload">
  81.         <body>
  82.           <![CDATA[
  83.             const nsIWebNavigation = Components.interfaces.nsIWebNavigation;
  84.             const flags = nsIWebNavigation.LOAD_FLAGS_NONE;
  85.             this.reloadWithFlags(flags);
  86.           ]]>
  87.         </body>
  88.       </method>
  89.  
  90.       <method name="reloadWithFlags">
  91.         <parameter name="aFlags"/>
  92.         <body>
  93.           <![CDATA[
  94.             this.webNavigation.reload(aFlags);
  95.           ]]>
  96.         </body>
  97.       </method>
  98.  
  99.       <method name="stop">
  100.         <body>
  101.           <![CDATA[
  102.             const nsIWebNavigation = Components.interfaces.nsIWebNavigation;
  103.             const flags = nsIWebNavigation.STOP_ALL;
  104.             this.webNavigation.stop(flags);
  105.           ]]>
  106.         </body>
  107.       </method>
  108.  
  109.       <!-- throws exception for unknown schemes -->
  110.       <method name="loadURI">
  111.         <parameter name="aURI"/>
  112.         <parameter name="aReferrerURI"/>
  113.         <body>
  114.           <![CDATA[
  115.             const nsIWebNavigation = Components.interfaces.nsIWebNavigation;
  116.             const flags = nsIWebNavigation.LOAD_FLAGS_NONE;
  117.             this.loadURIWithFlags(aURI, flags, aReferrerURI);
  118.           ]]>
  119.         </body>
  120.       </method>
  121.  
  122.       <!-- throws exception for unknown schemes -->
  123.       <method name="loadURIWithFlags">
  124.         <parameter name="aURI"/>
  125.         <parameter name="aFlags"/>
  126.         <parameter name="aReferrerURI"/>
  127.         <body>
  128.           <![CDATA[
  129.             if (!aURI)
  130.               aURI = "about:blank";
  131.  
  132.             this.webNavigation.loadURI(aURI, aFlags, aReferrerURI, null, null);
  133.           ]]>
  134.         </body>
  135.       </method>
  136.  
  137.       <method name="goHome">
  138.         <body>
  139.           <![CDATA[
  140.             try {
  141.               this.loadURI(this.homePage);
  142.             }
  143.             catch (e) {
  144.             }
  145.           ]]>
  146.         </body>
  147.       </method>
  148.  
  149.       <property name="homePage">
  150.         <getter>
  151.           <![CDATA[
  152.             var uri;
  153.  
  154.             if (this.hasAttribute("homepage"))
  155.               uri = this.getAttribute("homepage");
  156.             else
  157.               uri = "http://www.mozilla.org/"; // widget pride
  158.  
  159.             return uri;
  160.           ]]>
  161.         </getter>
  162.         <setter>
  163.           <![CDATA[
  164.             this.setAttribute("homepage", val);
  165.             return val;
  166.           ]]>
  167.         </setter>
  168.       </property>
  169.  
  170.       <method name="gotoIndex">
  171.         <parameter name="aIndex"/>
  172.         <body>
  173.           <![CDATA[
  174.             this.webNavigation.gotoIndex(aIndex);
  175.           ]]>
  176.         </body>
  177.       </method>
  178.  
  179.       <property name="currentURI"
  180.                 onget="return this.webNavigation.currentURI;"
  181.                 readonly="true"/>
  182.  
  183.       <property name="preferences"
  184.                 onget="return Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefService);"
  185.                 readonly="true"/>
  186.  
  187.       <property name="docShell"
  188.                 onget="return this.boxObject.QueryInterface(Components.interfaces.nsIBrowserBoxObject).docShell;"
  189.                 readonly="true"/>
  190.  
  191.       <property name="webNavigation"
  192.                 onget="return this.docShell.QueryInterface(Components.interfaces.nsIWebNavigation);"
  193.                 readonly="true"/>
  194.  
  195.       <property name="webBrowserFind"
  196.                 readonly="true"
  197.                 onget="return this.docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIWebBrowserFind);"/>
  198.  
  199.       <property name="webProgress"
  200.                 readonly="true"
  201.                 onget="return this.docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIWebProgress);"/>
  202.  
  203.       <property name="contentWindow"
  204.                 readonly="true"
  205.                 onget="return this.docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindow);"/>
  206.  
  207.       <property name="sessionHistory"
  208.                 onget="return this.webNavigation.sessionHistory;"
  209.                 readonly="true"/>
  210.  
  211.       <property name="markupDocumentViewer"
  212.                 onget="return this.docShell.contentViewer.QueryInterface(Components.interfaces.nsIMarkupDocumentViewer);"
  213.                 readonly="true"/>
  214.  
  215.       <property name="contentViewerEdit"
  216.                 onget="return this.docShell.contentViewer.QueryInterface(Components.interfaces.nsIContentViewerEdit);"
  217.                 readonly="true"/>
  218.  
  219.       <property name="contentViewerFile"
  220.                 onget="return this.docShell.contentViewer.QueryInterface(Components.interfaces.nsIContentViewerFile);"
  221.                 readonly="true"/>
  222.  
  223.       <property name="documentCharsetInfo"
  224.                 onget="return this.docShell.documentCharsetInfo;"
  225.                 readonly="true"/>
  226.  
  227.       <property name="contentDocument"
  228.                 onget="return this.webNavigation.document;"
  229.                 readonly="true"/>
  230.  
  231.       <property name="contentTitle"
  232.                 onget="return Components.lookupMethod(this.contentDocument, 'title').call(this.contentDocument);"
  233.                 readonly="true"/>
  234.  
  235.       <field name="mPrefs" readonly="true">
  236.         Components.classes['@mozilla.org/preferences-service;1']
  237.                   .getService(Components.interfaces.nsIPrefService)
  238.                   .getBranch(null);
  239.       </field>
  240.  
  241.       <field name="_mStrBundle">null</field>
  242.  
  243.       <property name="mStrBundle">
  244.         <getter>
  245.         <![CDATA[
  246.           if (!this._mStrBundle) {
  247.             // need to create string bundle manually instead of using <xul:stringbundle/>
  248.             // see bug 63370 for details
  249.             var localeService = Components.classes["@mozilla.org/intl/nslocaleservice;1"]
  250.                                   .getService(Components.interfaces.nsILocaleService);
  251.             var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"]
  252.                                   .getService(Components.interfaces.nsIStringBundleService);
  253.             var bundleURL = "chrome://global/locale/tabbrowser.properties";
  254.             this._mStrBundle = stringBundleService.createBundle(bundleURL, localeService.GetApplicationLocale());
  255.           }
  256.           return this._mStrBundle;
  257.         ]]></getter>
  258.       </property>
  259.  
  260.       <method name="addProgressListener">
  261.         <parameter name="aListener"/>
  262.         <body>
  263.           <![CDATA[
  264.             this.webProgress.addProgressListener(aListener, Components.interfaces.nsIWebProgress.NOTIFY_ALL);
  265.           ]]>
  266.         </body>
  267.       </method>
  268.  
  269.       <method name="removeProgressListener">
  270.         <parameter name="aListener"/>
  271.         <body>
  272.           <![CDATA[
  273.             this.webProgress.removeProgressListener(aListener);
  274.          ]]>
  275.         </body>
  276.       </method>
  277.  
  278.       <field name="mDragDropHandler">
  279.         null
  280.       </field>
  281.  
  282.       <field name="securityUI">
  283.         null
  284.       </field>
  285.  
  286.       <constructor>
  287.         <![CDATA[
  288.           try {
  289.             if (!this.hasAttribute("disablehistory")) {
  290.               // wire up session history
  291.               this.webNavigation.sessionHistory = Components.classes["@mozilla.org/browser/shistory;1"].createInstance(Components.interfaces.nsISHistory);
  292.  
  293.               // wire up global history
  294.               var globalHistory = Components.classes["@mozilla.org/browser/global-history;1"].getService(Components.interfaces.nsIGlobalHistory);
  295.  
  296.               this.docShell.QueryInterface(Components.interfaces.nsIDocShellHistory).globalHistory = globalHistory;      
  297.             }
  298.           }
  299.           catch (e) {
  300.           }
  301.           try {
  302.             this.mDragDropHandler = Components.classes["@mozilla.org:/content/content-area-dragdrop;1"].createInstance(Components.interfaces.nsIDragDropHandler);
  303.             this.mDragDropHandler.hookupTo(this, null, null, null);
  304.           }
  305.           catch (e) {
  306.           }
  307.           try {
  308.             const SECUREBROWSERUI_CONTRACTID = "@mozilla.org/secure_browser_ui;1";
  309.             if (!this.hasAttribute("disablesecurity") &&
  310.                 SECUREBROWSERUI_CONTRACTID in Components.classes) {
  311.               this.securityUI = Components.classes[SECUREBROWSERUI_CONTRACTID].createInstance(Components.interfaces.nsISecureBrowserUI);
  312.               this.securityUI.init(this.contentWindow);
  313.             }
  314.           }
  315.           catch (e) {
  316.           }
  317.         ]]>
  318.       </constructor>
  319.       
  320.       <destructor>
  321.         <![CDATA[
  322.           if (this.mDragDropHandler)
  323.             this.mDragDropHandler.detach();
  324.  
  325.           this.securityUI = null;
  326.         ]]>
  327.       </destructor>
  328.     </implementation>
  329.  
  330.     <handlers>
  331.       <handler event="keypress" keycode="VK_F7">
  332.         <![CDATA[
  333.           // Toggle browse with caret mode
  334.           var browseWithCaretOn = false;
  335.           var warn = true;
  336.  
  337.           try {
  338.             warn = this.mPrefs.getBoolPref("accessibility.warn_on_browsewithcaret");
  339.           } catch (ex) {
  340.           }
  341.  
  342.           try {
  343.             browseWithCaretOn = this.mPrefs.getBoolPref("accessibility.browsewithcaret");
  344.           } catch (ex) {
  345.           }
  346.           if (warn && !browseWithCaretOn) {
  347.             var checkValue = {value:false};
  348.             promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
  349.  
  350.             var buttonPressed = promptService.confirmEx(window, 
  351.               this.mStrBundle.GetStringFromName('browsewithcaret.checkWindowTitle'), 
  352.               this.mStrBundle.GetStringFromName('browsewithcaret.checkLabel'),
  353.               (promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0) +
  354.               (promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_1),
  355.               this.mStrBundle.GetStringFromName('browsewithcaret.checkButtonLabel'),
  356.               null, null,
  357.               this.mStrBundle.GetStringFromName('browsewithcaret.checkMsg'), 
  358.               checkValue);
  359.             if (buttonPressed != 0)
  360.               return;
  361.             if (checkValue.value) {
  362.               try {
  363.                 this.mPrefs.setBoolPref("accessibility.warn_on_browsewithcaret", false);
  364.               }
  365.               catch (ex) {
  366.               }
  367.             }
  368.           }
  369.  
  370.           // Toggle the pref
  371.           try {
  372.             this.mPrefs.setBoolPref("accessibility.browsewithcaret",!browseWithCaretOn);
  373.           } catch (ex) {
  374.           }
  375.         ]]>
  376.       </handler>
  377.     </handlers>
  378.  
  379.   </binding>
  380.  
  381. </bindings>
  382.