Bug 619355 Replace contentAreaDNDObserver with droppedLinkHandler r=jag
authorNeil Rashbrook <neil@parkwaycc.co.uk>
Thu, 16 Dec 2010 23:37:42 +0000
changeset 6851 85faf50deb16ec623f6f97ce3bfb31d700d59fb2
parent 6850 c671983f52d8ec575445dd629d4b37564ea2a567
child 6852 2df02366747d0dcbaa8672a011482349fff81d51
push idunknown
push userunknown
push dateunknown
reviewersjag
bugs619355
Bug 619355 Replace contentAreaDNDObserver with droppedLinkHandler r=jag
suite/browser/navigator.js
suite/browser/navigator.xul
suite/browser/tabbrowser.xml
suite/common/contentAreaDD.js
suite/common/jar.mn
suite/common/sidebar/sidebarOverlay.xul
suite/debugQA/content/debugQATextEditorShell.xul
suite/mailnews/compose/messengercompose.xul
--- a/suite/browser/navigator.js
+++ b/suite/browser/navigator.js
@@ -585,16 +585,18 @@ function Startup()
     document.documentElement.setAttribute("height", defaultHeight);
     // Make sure we're safe at the left/top edge of screen
     document.documentElement.setAttribute("screenX", screen.availLeft);
     document.documentElement.setAttribute("screenY", screen.availTop);
   }
 
   // hook up UI through progress listener
   getBrowser().addProgressListener(window.XULBrowserWindow, Components.interfaces.nsIWebProgress.NOTIFY_ALL);
+  // hook up drag'n'drop
+  getBrowser().droppedLinkHandler = handleDroppedLink;
 
   var uriToLoad = "";
 
   // Check window.arguments[0]. If not null then use it for uriArray
   // otherwise the new window is being called when another browser
   // window already exists so use the New Window pref for uriArray
   if ("arguments" in window && window.arguments.length >= 1) {
     var uriArray;
@@ -1685,16 +1687,28 @@ function getShortcutOrURI(aURL, aPostDat
     aPostDataRef.value = null;
 
     return aURL;
   }
 
   return shortcutURL;
 }
 
+function handleDroppedLink(event, url, name)
+{
+  var postData = { };
+  var uri = getShortcutOrURI(url, postData);
+  if (uri)
+    loadURI(uri, null, postData.value, false);
+
+  // Keep the event from being handled by the dragDrop listeners
+  // built-in to gecko if they happen to be above us.
+  event.preventDefault();
+};
+
 function readFromClipboard()
 {
   var url;
 
   try {
     // Get clipboard.
     var clipboard = Components.classes["@mozilla.org/widget/clipboard;1"]
                               .getService(Components.interfaces.nsIClipboard);
--- a/suite/browser/navigator.xul
+++ b/suite/browser/navigator.xul
@@ -77,17 +77,16 @@
   <script type="application/javascript" src="chrome://global/content/nsClipboard.js"/>
   <script type="application/javascript" src="chrome://global/content/nsDragAndDrop.js"/>
   <script type="application/javascript" src="chrome://global/content/viewSourceUtils.js"/>
 
   <!-- Content Area -->
   <script type="application/javascript" src="chrome://navigator/content/nsBrowserStatusHandler.js"/>
   <script type="application/javascript" src="chrome://navigator/content/nsBrowserContentListener.js"/>
   <script type="application/javascript" src="chrome://communicator/content/contentAreaClick.js"/>
-  <script type="application/javascript" src="chrome://communicator/content/contentAreaDD.js"/>
   <script type="application/javascript" src="chrome://communicator/content/findUtils.js"/>
   <script type="application/javascript" src="chrome://global/content/printUtils.js"/>
 
   <!-- Navigator -->
   <script type="application/javascript" src="chrome://navigator/content/fullScreen.js"/>
   <script type="application/javascript" src="chrome://navigator/content/browser.js"/>
   <script type="application/javascript" src="chrome://navigator/content/navigator.js"/>
   <script type="application/javascript" src="chrome://navigator/content/navigatorDD.js"/>
@@ -487,20 +486,17 @@
     </toolbarpalette>
 
   </toolbox>
 
   <hbox flex="1">
     <vbox id="sidebar-box" class="chromeclass-extrachrome"/>
     <splitter id="sidebar-splitter" class="chromeclass-extrachrome" />
 
-    <!-- we only need to handle |ondragdrop| because everything else is
-          taken care of by the builtin behavior inside the tabbrowser -->
-    <vbox id="appcontent" flex="1"
-         ondragdrop="nsDragAndDrop.drop(event, contentAreaDNDObserver);">
+    <vbox id="appcontent" flex="1">
       <findbar id="FindToolbar" browserid="content"/>
 
       <!-- this box is temporary, pending XBLified <browser> -->
       <hbox id="browser" flex="1">
         <tabbrowser id="content"
                     flex="1" contenttooltip="aHTMLTooltip"
                     contentcontextmenu="contentAreaContextMenu"
                     onnewtab="BrowserOpenTab();"
@@ -513,18 +509,17 @@
              require error page UI to do privileged things, without letting
              error pages have any privilege themselves. -->
       </hbox>
     </vbox>  
   </hbox>
 
   <panel id="customizeToolbarSheetPopup"/>
 
-  <statusbar id="status-bar" class="chromeclass-status"
-             ondragdrop="nsDragAndDrop.drop(event, contentAreaDNDObserver);">
+  <statusbar id="status-bar" class="chromeclass-status">
     <statusbarpanel id="component-bar"/>
     <statusbarpanel id="statusbar-display" label="&statusText.label;" flex="1"/>
     <statusbarpanel class="statusbarpanel-progress" id="statusbar-progresspanel" collapsed="true">
       <progressmeter class="progressmeter-statusbar" id="statusbar-icon" mode="normal" value="0"/>
     </statusbarpanel>
     <statusbarpanel id="popupIcon" class="statusbarpanel-iconic" hidden="true"
                     oncommand="StatusbarViewPopupManager()"
                     tooltiptext="&popupIcon.tooltiptext;"
--- a/suite/browser/tabbrowser.xml
+++ b/suite/browser/tabbrowser.xml
@@ -951,17 +951,22 @@
         <body>
           <![CDATA[
             // we only want to return to the parent tab if no other
             // tabs have been opened and the user hasn't switched tabs
             this.mPreviousTab = null;
             this.mLastRelatedIndex = 0;
 
             var newBrowser = this.mPanelContainer.selectedPanel.firstChild;
+            // Transfer the dropped link handler to the new browser.
+            // Note: closing the current tab sets mCurrentBrowser to null
+            //       so we use mCurrentTab.linkedBrowser instead.
+            newBrowser.droppedLinkHandler = this.mCurrentTab.linkedBrowser.droppedLinkHandler;
             if (this.mCurrentBrowser) {
+              this.mCurrentBrowser.droppedLinkHandler = null;
               // Only save the focused element if it is in our content window
               // or in an ancestor window.
               var focusedWindow = document.commandDispatcher.focusedWindow;
               var saveFocus = false;
 
               if (focusedWindow && focusedWindow.top == window.content) {
                 saveFocus = true;
               } else {
@@ -2587,16 +2592,20 @@
       <property name="userTypedClear"
                 onget="return this.mCurrentBrowser.userTypedClear;"
                 onset="return this.mCurrentBrowser.userTypedClear = val;"/>
 
       <property name="userTypedValue"
                 onget="return this.mCurrentBrowser.userTypedValue;"
                 onset="return this.mCurrentBrowser.userTypedValue = val;"/>
 
+      <property name="droppedLinkHandler"
+                onget="return this.mCurrentBrowser.droppedLinkHandler;"
+                onset="return this.mCurrentBrowser.droppedLinkHandler = val;"/>
+
       <method name="observe">
         <parameter name="aSubject"/>
         <parameter name="aTopic"/>
         <parameter name="aState"/>
         <body>
           <![CDATA[
             if (aTopic != "browser:purge-session-history")
               return;
deleted file mode 100644
--- a/suite/common/contentAreaDD.js
+++ /dev/null
@@ -1,89 +0,0 @@
-/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Alec Flett      <alecf@netscape.com>
- *   Ben Goodger     <ben@netscape.com>
- *   Mike Pinkerton  <pinkerton@netscape.com>
- *   Blake Ross      <blakeross@telocity.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/*
- * Note that most of this routine has been moved into C++ in order to
- * be available for all <browser> tags as well as gecko embedding. See
- * mozilla/content/base/src/nsContentAreaDragDrop.cpp.
- *
- * Do not add any new fuctionality here other than what is needed for
- * a standalone product.
- */
-
-var contentAreaDNDObserver = {
-  onDrop: function (aEvent, aXferData, aDragSession)
-    {
-      var url = transferUtils.retrieveURLFromData(aXferData.data, aXferData.flavour.contentType);
-
-      // valid urls don't contain spaces ' '; if we have a space it
-      // isn't a valid url, or if it's a javascript: or data: url,
-      // bail out
-      if (!url || !url.length || url.indexOf(" ", 0) != -1 ||
-          /^\s*(javascript|data):/.test(url))
-        return;
-
-      switch (document.documentElement.getAttribute('windowtype')) {
-        case "navigator:browser":
-          // Perform a security check before loading the URI
-          nsDragAndDrop.dragDropSecurityCheck(aEvent, aDragSession, url);
-
-          loadURI(getShortcutOrURI(url));
-          break;
-        case "navigator:view-source":
-          viewSource(url);
-          break;
-      }
-      
-      // keep the event from being handled by the dragDrop listeners
-      // built-in to gecko if they happen to be above us.    
-      aEvent.preventDefault();
-    },
-
-  getSupportedFlavours: function ()
-    {
-      var flavourSet = new FlavourSet();
-      flavourSet.appendFlavour("text/x-moz-url");
-      flavourSet.appendFlavour("text/unicode");
-      flavourSet.appendFlavour("application/x-moz-file", "nsIFile");
-      return flavourSet;
-    }
-  
-};
--- a/suite/common/jar.mn
+++ b/suite/common/jar.mn
@@ -54,17 +54,16 @@ comm.jar:
    content/communicator/askViewZoom.xul
    content/communicator/askViewZoom.js
    content/communicator/browserBindings.xul
    content/communicator/certError.css
    content/communicator/certError.xhtml
    content/communicator/certError.xml
    content/communicator/communicator.css
    content/communicator/consoleOverlay.xul
-   content/communicator/contentAreaDD.js
    content/communicator/contentAreaClick.js
    content/communicator/contentAreaContextOverlay.xul
    content/communicator/defaultClientDialog.js
    content/communicator/defaultClientDialog.xul
    content/communicator/editorBindings.xul
    content/communicator/findUtils.js
    content/communicator/fullscreen-video.xhtml
    content/communicator/helpEditorOverlay.xul
--- a/suite/common/sidebar/sidebarOverlay.xul
+++ b/suite/common/sidebar/sidebarOverlay.xul
@@ -160,18 +160,17 @@
         <toolbarbutton id="sidebar-close-button" oncommand="SidebarShowHide();"
                        tooltiptext="&sidebar.close.tooltip;"/>
       </sidebarheader>
   
       <vbox id="sidebar-panels"
         datasources="rdf:null"
         ref="urn:sidebar:current-panel-list"
         persist="last-selected-panel height collapsed" flex="1"
-        onclick="return contentAreaClick(event);"
-        ondraggesture="nsDragAndDrop.startDrag(event, contentAreaDNDObserver);">
+        onclick="return contentAreaClick(event);">
         <template id="sidebar-template">
           <rule>
             <conditions>
               <content uri="?uri"/>
               <triple subject="?uri" object="?panel-list"
                 predicate="http://home.netscape.com/NC-rdf#panel-list" />
               <member container="?panel-list" child="?panel"/>
               <triple subject="?panel" object="?title"
--- a/suite/debugQA/content/debugQATextEditorShell.xul
+++ b/suite/debugQA/content/debugQATextEditorShell.xul
@@ -70,17 +70,16 @@
         windowtype="composer:text"
         width="640" height="480"
         screenX="10" screenY="10"
         persist="screenX screenY width height sizemode">
 
   <script type="application/javascript" src="chrome://editor/content/editor.js"/>
   <script type="application/javascript" src="chrome://editor/content/ComposerCommands.js"/>
   <script type="application/javascript" src="chrome://global/content/nsDragAndDrop.js"/>
-  <script type="application/javascript" src="chrome://communicator/content/contentAreaDD.js"/>
 
   <commands id="commands">
     <commandset id="globalEditMenuItems"/>
     <commandset id="selectEditMenuItems"/>
     <commandset id="undoEditMenuItems"/>
     <commandset id="clipboardEditMenuItems"/>
     <commandset id="commonEditorMenuItems"/>
     <commandset id="composerEditMenuItems"/>
--- a/suite/mailnews/compose/messengercompose.xul
+++ b/suite/mailnews/compose/messengercompose.xul
@@ -86,17 +86,16 @@
 <stringbundleset id="stringbundleset">
   <stringbundle id="bundle_composeMsgs" src="chrome://messenger/locale/messengercompose/composeMsgs.properties"/>
   <stringbundle id="bundle_messenger" src="chrome://messenger/locale/messenger.properties"/>
   <stringbundle id="bundle_offlinePrompts" src="chrome://messenger/locale/offline.properties"/>
   <stringbundle id="languageBundle" src="chrome://global/locale/languageNames.properties"/>
   <stringbundle id="brandBundle" src="chrome://branding/locale/brand.properties"/>
 </stringbundleset>
 
-<script type="application/javascript" src="chrome://communicator/content/contentAreaDD.js"/>
 <script type="application/javascript" src="chrome://communicator/content/contentAreaClick.js"/>
 <script type="application/javascript" src="chrome://global/content/printUtils.js"/>
 <script type="application/javascript" src="chrome://messenger/content/accountUtils.js"/>
 <script type="application/javascript" src="chrome://messenger/content/widgetglue.js"/>
 <script type="application/javascript" src="chrome://messenger/content/mail-offline.js"/>
 <script type="application/javascript" src="chrome://editor/content/editor.js"/>
 <script type="application/javascript" src="chrome://messenger/content/messengercompose/MsgComposeCommands.js"/>