summaryrefslogtreecommitdiffstats
path: root/comm/suite/browser/navigatorDD.js
blob: 19c4b8f228d122d4156bb8ad47a4988a9688d564 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

function htmlEscape(aString)
{
  return aString.replace(/&/g, "&")
                .replace(/>/g, ">")
                .replace(/</g, "&lt;")
                .replace(/"/g, "&quot;")
                .replace(/'/g, "&apos;");
}

function BeginDragLink(aEvent, aHref, aTitle)
{
  var dt = aEvent.dataTransfer;
  dt.setData("text/x-moz-url", aHref + "\n" + aTitle);
  dt.setData("text/uri-list", aHref);
  dt.setData("text/html", "<a href=\"" + htmlEscape(aHref) +
                          "\">" + htmlEscape(aTitle) + "</a>");
  dt.setData("text/plain", aHref);
}

function DragLinkOver(aEvent)
{
  if (Services.droppedLinkHandler.canDropLink(aEvent, true))
    aEvent.preventDefault();
}

var proxyIconDNDObserver = {
  onDragStart: function (aEvent)
  {
    if (gProxyButton.getAttribute("pageproxystate") != "valid")
      return;

    BeginDragLink(aEvent, window.content.location.href,
                  window.content.document.title);
  }
};

var homeButtonObserver = {
  onDragStart: function (aEvent)
  {
    var homepage = GetLocalizedStringPref("browser.startup.homepage",
                                          "about:blank");

    if (homepage)
    {
      // XXX find a readable title string for homepage,
      // perhaps do a history lookup.
      BeginDragLink(aEvent, homepage, homepage);
    }
  },

  onDrop: function (aEvent)
  {
    aEvent.stopPropagation();
    // disallow setting home pages that inherit the principal
    var url = Services.droppedLinkHandler.dropLink(aEvent, {}, true);
    setTimeout(openHomeDialog, 0, url);
  },

  onDragOver: function (aEvent)
  {
    if (aEvent.target == aEvent.dataTransfer.mozSourceNode)
      return;

    DragLinkOver(aEvent);
    aEvent.dropEffect = "link";
    var statusTextFld = document.getElementById("statusbar-display");
    statusTextFld.label = gNavigatorBundle.getString("droponhomebutton");
  },

  onDragExit: function (aEvent)
  {
    aEvent.stopPropagation();
    document.getElementById("statusbar-display").label = "";
  }
};

function openHomeDialog(aURL)
{
  var promptTitle = gNavigatorBundle.getString("droponhometitle");
  var promptMsg   = gNavigatorBundle.getString("droponhomemsg");
  var okButton    = gNavigatorBundle.getString("droponhomeokbutton");
  if (Services.prompt.confirmEx(window, promptTitle, promptMsg,
                                (Services.prompt.BUTTON_TITLE_IS_STRING *
                                 Services.prompt.BUTTON_POS_0) +
                                (Services.prompt.BUTTON_TITLE_CANCEL *
                                 Services.prompt.BUTTON_POS_1),
                                okButton, null, null, null,
                                {value: false}) == 0)
    SetStringPref("browser.startup.homepage", aURL);
}

var goButtonObserver = {
  onDragOver: DragLinkOver,

  onDrop: function (aEvent)
  {
    var url = Services.droppedLinkHandler.dropLink(aEvent, {});

    getShortcutOrURIAndPostData(url).then(data => {
      if (data.url)
        loadURI(data.url, null, data.postData, false);
    });
  }
};

var searchButtonObserver = {
  onDragOver: DragLinkOver,

  onDrop: function (aEvent)
  {
    var name = {};
    var url = Services.droppedLinkHandler.dropLink(aEvent, name);
    if (url)
      BrowserSearch.loadSearch(name.value || url);
  }
};