home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / 01_02.iso / software / netscape62win / browser.xpi / bin / chrome / comm.jar / content / cookie / cookieContextOverlay.xul < prev    next >
Encoding:
Extensible Markup Language  |  2001-08-13  |  5.0 KB  |  129 lines

  1. <?xml version="1.0"?>
  2.  
  3. <!--
  4.    The contents of this file are subject to the Netscape 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/NPL/
  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 Mozilla Communicator client code, released
  15.    March 31, 1998.
  16.    
  17.    The Initial Developer of the Original Code is Netscape
  18.    Communications Corporation. Portions created by Netscape are
  19.    Copyright (C) 1998-1999 Netscape Communications Corporation. All
  20.    Rights Reserved.
  21.    
  22.    Contributor(s): 
  23.   -->
  24.  
  25. <!DOCTYPE window SYSTEM "chrome://cookie/locale/cookieContextOverlay.dtd">
  26.  
  27. <overlay id="cookieContextOverlay"
  28.          xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  29.  
  30.   <script type="application/x-javascript" src="chrome://cookie/content/cookieOverlay.js"/>
  31.  
  32.   <script type="application/x-javascript">
  33.   <![CDATA[
  34.  
  35.     // Code from nsContextMenu.js. Note that we extend the prototype here, rather 
  36.     // than making these methods on a new object, as some methods require access
  37.     // to data maintained by nsContextMenu.  
  38.  
  39.     var cookieContextMenu = {
  40.  
  41.       // Determine if "Block Image" is to appear in the menu.
  42.       // Return true if "imageBlocker.enabled" pref is set and image is not already blocked.
  43.       isBlockingImages : function () {
  44.         /* determine if "imageBlocker.enabled" pref is set */
  45.         var pref = gContextMenu.getService('@mozilla.org/preferences;1', 'nsIPref');
  46.         var result = false;
  47.         try {
  48.           result = pref.GetBoolPref( "imageblocker.enabled" );
  49.         } catch(e) {
  50.         }
  51.         if (!result) {
  52.           /* pref is not set so return false */
  53.           return false;
  54.         }
  55.   
  56.         /* determine if image is already being blocked */
  57.         var permissionmanager =
  58.           Components.classes["@mozilla.org/permissionmanager;1"]
  59.             .getService().QueryInterface(Components.interfaces.nsIPermissionManager);
  60.  
  61.  
  62.         var enumerator = permissionmanager.enumerator;
  63.         while (enumerator.hasMoreElements()) {
  64.           var nextPermission = enumerator.getNext();
  65.           nextPermission = nextPermission.QueryInterface(Components.interfaces.nsIPermission);
  66.           var imageType = 1;
  67.           if (nextPermission.type == imageType &&
  68.               !nextPermission.capability) {
  69.             /* some image host is being blocked, need to find out if it's our image's host */
  70.             var host = nextPermission.host;
  71.             if(host.charAt(0) == ".") {  // get rid of the ugly dot on the start of some domains
  72.               host = host.substring(1,host.length);
  73.             }
  74.             if (host && gContextMenu.imageURL.search(host) != -1) {
  75.               /* it's our image's host that's being blocked */
  76.               return false;
  77.             }
  78.           }
  79.         }
  80.         /* image is not already being blocked, so "Block Image" can appear on the menu */
  81.         return true;
  82.       },
  83.  
  84.       // Block image from loading in the future.
  85.       blockImage : function () {
  86.         var imgmanager =
  87.           Components.classes["@mozilla.org/imgmanager;1"]
  88.             .getService().QueryInterface(Components.interfaces.nsIImgManager);
  89.         imgmanager.block(gContextMenu.imageURL);
  90.       },
  91.  
  92.       initImageBlocking : function () {
  93.         try {
  94.         // Block image depends on whether an image was clicked on, and,
  95.         // whether the user pref is enabled.
  96.         gContextMenu.showItem
  97.           ("context-blockimage",
  98.            gContextMenu.onImage && cookieContextMenu.isBlockingImages());
  99.         } catch (e) {}
  100.       },
  101.  
  102.       addContextMenuItemListeners : function (aEvent) {
  103.         var contextPopup = document.getElementById("contentAreaContextSet");
  104.         contextPopup.addEventListener("popupshowing", cookieContextMenu.initImageBlocking, false);
  105.       }
  106.     }
  107.  
  108.     window.addEventListener("load", cookieContextMenu.addContextMenuItemListeners, false);
  109.  
  110.     // For some unexplainable reason, this overlay is loaded twice as can be demonstrated
  111.     // by uncommenting the following "dump" statement which will get displayed twice
  112.     //    dump("$$$$$$$$$$ HERE WE ARE IN cookieContextOverlay.xul $$$$$$$$$$\n");
  113.     // As a consequence, the block-image item appears twice in the context menu.  To
  114.     // prevent that from happening, the "display:none" was added to the menuitem below
  115.  
  116.    ]]>
  117.   </script>         
  118.  
  119.   <!-- context menu -->
  120.   <popup id="contentAreaContextMenu">
  121.     <menuitem id="context-blockimage"
  122.               label="&blockImageCmd.label;"
  123.               accesskey=""
  124.               oncommand="cookieContextMenu.blockImage();"
  125.               style="display:none;"
  126.               insertafter="context-viewimage"/>
  127.   </popup>
  128. </overlay>
  129.