suite/browser/mailNavigatorOverlay.xul
author timeless@mozdev.org
Mon, 19 Jul 2010 00:23:03 +0300
changeset 6065 bbc1f808ff9d3183ea4205ac4e109a28e6e15b36
parent 5839 04473c202657e3b012fd0e4bd13616a3fadedd41
child 7392 8dad96e3d0da57d28811f18675a1a8d201a4e4f6
permissions -rw-r--r--
Bug 579781 yyerror should be const in nsVCard.cpp warning: deprecated conversion from string constant to 'char*' r=bienvenu

<?xml version="1.0"?>

<?xul-overlay href="chrome://navigator/content/platformMailOverlay.xul"?>

<!DOCTYPE overlay SYSTEM "chrome://navigator/locale/mailNavigatorOverlay.dtd" >

<overlay id="mailNavigatorOverlay"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <script type="application/javascript">
  <![CDATA[
    var gUseExternalMailto =
        Components.classes["@mozilla.org/network/io-service;1"]
                  .getService(Components.interfaces.nsIIOService)
                  .getProtocolHandler("mailto")
                   instanceof Components.interfaces.nsIExternalProtocolHandler;

    // attachment: 0 - link
    //             1 - page
    //             2 - image
    function openComposeWindow(url, title, attachment, charset)
    {
      if (gUseExternalMailto) {
        openExternalMailer(url, title);
      }
      else {
        var params = Components.classes["@mozilla.org/messengercompose/composeparams;1"]
                               .createInstance(Components.interfaces.nsIMsgComposeParams);
        if (params)
        {
          params.composeFields = Components.classes["@mozilla.org/messengercompose/composefields;1"]
                                           .createInstance(Components.interfaces.nsIMsgCompFields);
          if (params.composeFields)
          {
            if (attachment == 0 || attachment == 1)
            {
              params.composeFields.body = url;
              params.composeFields.subject = title;
              params.bodyIsLink = true;
            }
            if (attachment == 1 || attachment == 2)
            {
              var attachmentData = Components.classes["@mozilla.org/messengercompose/attachment;1"]
                                             .createInstance(Components.interfaces.nsIMsgAttachment);
              if (attachmentData)
              {
                attachmentData.url = url;
                attachmentData.urlCharset = charset;
                params.composeFields.addAttachment(attachmentData);
              }
            }
            var composeService = Components.classes["@mozilla.org/messengercompose;1"]
                                           .getService(Components.interfaces.nsIMsgComposeService);
            if (composeService) {
              // it is possible you won't have a default identity
              // like if you've never launched mail before on a new profile.
              // see bug #196073
              try {
                params.identity = composeService.defaultIdentity;
              }
              catch (ex) {
                params.identity = null;
              }
              composeService.OpenComposeWindowWithParams(null, params);
            }
          }                                                                         
        }                                                                         
      }
    }

    function openExternalMailer(url, title) {
      var extProtocolSvc = Components.classes["@mozilla.org/uriloader/external-protocol-service;1"]
                                     .getService(Components.interfaces.nsIExternalProtocolService);
      var ioService = Components.classes["@mozilla.org/network/io-service;1"]
                                .getService(Components.interfaces.nsIIOService);
      var mailto = url ? "mailto:?body="+encodeURIComponent(url)+"&subject="+encodeURIComponent(title) : "mailto:";
      var uri = ioService.newURI(mailto, null, null);

      extProtocolSvc.loadUrl(uri);
    }

    function openNewCardDialog()
    {
      window.openDialog("chrome://messenger/content/addressbook/abNewCardDialog.xul",
                        "", "chrome,modal,resizable=no,centerscreen");
    }

    function goOpenNewMessage()
    {
      if (gUseExternalMailto) {
        openExternalMailer();
      }
      else {
        if ("MsgNewMessage" in window)
        {
          MsgNewMessage(null);
          return;
        }
        
        var msgComposeService = Components.classes["@mozilla.org/messengercompose;1"].getService();
        msgComposeService = msgComposeService.QueryInterface(Components.interfaces.nsIMsgComposeService);
        msgComposeService.OpenComposeWindow(null, null, null,
                                           Components.interfaces.nsIMsgCompType.New,
                                           Components.interfaces.nsIMsgCompFormat.Default,
                                           null, null);
      }
    }

    function sendLink(aURL)
    {
      var title = "";
      if (!aURL) {
        aURL = window.content.document.URL;
        title = window.content.document.title;
      }
      try {
        openComposeWindow(aURL, title, 0, null);
      } catch(ex) { dump("Cannot Send Link: " + ex + "\n"); }
    }

    function sendMedia(mediaURL)
    {
      try {
        var charset =  getCharsetforSave(null);
        openComposeWindow(mediaURL, null, 2, charset);
      } catch(ex) { dump("Cannot Send Media: " + ex + "\n"); }
    }

    function sendPage(aDocument)
    {
      if (!aDocument)
        aDocument = window.content.document;
        
      try {
        var charset = getCharsetforSave(aDocument);
        openComposeWindow(aDocument.URL, aDocument.title, 1, charset);
      } catch(ex) { dump("Cannot Send Page: " + ex + "\n"); }
    }

    function initMailContextMenuItems(aEvent)
    {
      var shouldShowSendPage = !(gContextMenu.onTextInput || gContextMenu.isContentSelected ||
                               gContextMenu.onVideo || gContextMenu.onAudio) &&
                               !(gContextMenu.onLink && gContextMenu.onImage) &&
                               !gUseExternalMailto;
      gContextMenu.showItem("context-sendpage", shouldShowSendPage);
   
      gContextMenu.showItem("context-sep-apps", gContextMenu.shouldShowSeparator("context-sep-apps"));
    }
      
    function initMailContextMenuPopupListener(aEvent)
    {
      var popup = document.getElementById("contentAreaContextMenu");
      if (popup)
        popup.addEventListener("popupshowing", initMailContextMenuItems, false);
    }

    function hideMenuitems() {
      document.getElementById("menu_newCard").hidden = gUseExternalMailto;
      var menu_sendPage = document.getElementById("menu_sendPage");
      if (menu_sendPage)
        menu_sendPage.hidden = gUseExternalMailto;
    }

    function initOverlay(aEvent) {
      initMailContextMenuPopupListener(aEvent);
      hideMenuitems();
    }

    addEventListener("load", initOverlay, false);
  ]]>
  </script>         

  <!-- navigator specific commands -->
  <commandset id="tasksCommands">
    <command id="cmd_newMessage" oncommand="goOpenNewMessage();"/>
    <command id="cmd_newCard" oncommand="openNewCardDialog()"/>
    <command id="cmd_sendPage" oncommand="sendPage();"/>
    <command id="Browser:SendLink" oncommand="sendLink();"/>
  </commandset>
  <keyset id="tasksKeys">
    <key id="key_newMessage" key="&newMessageCmd.key;" command="cmd_newMessage" modifiers="accel"/>
  </keyset>
         
  <!-- navigator specific UI items -->
  <menupopup id="menu_NewPopup">
    <menuitem id="menu_newCard"
              label="&newContactCmd.label;"
              accesskey="&newContactCmd.accesskey;"
              command="cmd_newCard"
              insertafter="navBeginGlobalNewItems"/>
    <menuitem id="menu_newMessage"
              label="&newMessageCmd.label;"
              accesskey="&newMessageCmd.accesskey;"
              command="cmd_newMessage"
              key="key_newMessage"           
              insertafter="navBeginGlobalNewItems"/>
  </menupopup>

  <menupopup id="menu_FilePopup">
    <menuitem id="menu_sendPage"
              label="&sendPage.label;"
              accesskey="&sendPage.accesskey;"
              command="cmd_sendPage"
              position="9"/>
    <menuitem id="menu_sendLink"
              label="&sendLinkCmd.label;"
              accesskey="&sendLinkCmd.accesskey;"
              command="Browser:SendLink"
              position="10"/>
  </menupopup>

  <menupopup id="contentAreaContextMenu">
    <menuitem id="context-sendpage"
              label="&contextSendThisPage.label;"
              accesskey="&contextSendThisPage.accesskey;"
              oncommand="sendPage();"
              insertafter="context-savepage"/>
    <menuitem id="context-sendimage"
              label="&contextSendImage.label;"
              accesskey="&contextSendImage.accesskey;"
              oncommand="sendMedia(gContextMenu.mediaURL);"
              insertafter="context-saveimage"/>
    <menuitem id="context-sendvideo"
              label="&contextSendVideo.label;"
              accesskey="&contextSendVideo.accesskey;"
              oncommand="sendMedia(gContextMenu.mediaURL);"
              insertafter="context-savevideo"/>
    <menuitem id="context-sendaudio"
              label="&contextSendAudio.label;"
              accesskey="&contextSendAudio.accesskey;"
              oncommand="sendMedia(gContextMenu.mediaURL);"
              insertafter="context-saveaudio"/>
    <menuitem id="context-sendlink"
              label="&contextSendThisLink.label;"
              accesskey="&contextSendThisLink.accesskey;"
              oncommand="sendLink(gContextMenu.linkURL);"
              insertafter="context-savelink"/>
    <menu id="frame">
    <menupopup id="frame_popup">
      <menuitem id="context-sendframe"
                insertafter="context-saveframe"
                label="&contextSendFrame.label;"
                accesskey="&contextSendFrame.accesskey;"
                oncommand="sendPage(gContextMenu.target.ownerDocument);"/>
    </menupopup>
    </menu>
  </menupopup>
  
</overlay>