1
/* ***** BEGIN LICENSE BLOCK *****
2
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
4
* The contents of this file are subject to the Mozilla Public License Version
5
* 1.1 (the "License"); you may not use this file except in compliance with
6
* the License. You may obtain a copy of the License at
7
* http://www.mozilla.org/MPL/
9
* Software distributed under the License is distributed on an "AS IS" basis,
10
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
* for the specific language governing rights and limitations under the
14
* The Original Code is Eric Hodel's <drbrain@segment7.net> code.
16
* The Initial Developer of the Original Code is
18
* Portions created by the Initial Developer are Copyright (C) 2001
19
* the Initial Developer. All Rights Reserved.
22
* Christopher Hoess <choess@force.stwing.upenn.edu>
23
* Tim Taylor <tim@tool-man.org>
24
* Henri Sivonen <henris@clinet.fi>
25
* Stuart Ballard <sballard@netreach.net>
27
* Alternatively, the contents of this file may be used under the terms of
28
* either the GNU General Public License Version 2 or later (the "GPL"), or
29
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30
* in which case the provisions of the GPL or the LGPL are applicable instead
31
* of those above. If you wish to allow use of your version of this file only
32
* under the terms of either the GPL or the LGPL, and not to allow others to
33
* use your version of this file under the terms of the MPL, indicate your
34
* decision by deleting the provisions above and replace them with the notice
35
* and other provisions required by the GPL or the LGPL. If you do not delete
36
* the provisions above, a recipient may use your version of this file under
37
* the terms of any one of the MPL, the GPL or the LGPL.
39
* ***** END LICENSE BLOCK ***** */
41
var LinkToolbarUI = function()
45
LinkToolbarUI.prototype.linkAdded =
48
var element = event.originalTarget;
50
if (element.ownerDocument != getBrowser().contentDocument ||
51
!linkToolbarUI.isLinkToolbarEnabled() ||
52
!element instanceof Components.interfaces.nsIDOMHTMLLinkElement ||
53
!element.href || (!element.rel && !element.rev))
56
linkToolbarHandler.handle(element);
59
LinkToolbarUI.prototype.isLinkToolbarEnabled =
62
if (document.getElementById("linktoolbar").getAttribute("hidden") == "true")
68
LinkToolbarUI.prototype.clear =
71
if (event.originalTarget != getBrowser().contentDocument ||
72
!linkToolbarUI.isLinkToolbarEnabled() ||
73
!linkToolbarHandler.hasItems)
76
linkToolbarHandler.clearAllItems();
79
LinkToolbarUI.prototype.tabSelected =
82
if (event.originalTarget.localName != "tabs" ||
83
!linkToolbarUI.isLinkToolbarEnabled())
86
linkToolbarHandler.clearAllItems();
87
linkToolbarUI.deactivate();
88
linkToolbarUI.fullSlowRefresh();
91
LinkToolbarUI.prototype.fullSlowRefresh =
94
var currentNode = getBrowser().contentDocument.documentElement;
95
if (!(currentNode instanceof Components.interfaces.nsIDOMHTMLHtmlElement))
97
currentNode = currentNode.firstChild;
101
if (currentNode instanceof Components.interfaces.nsIDOMHTMLHeadElement) {
102
currentNode = currentNode.firstChild;
106
if (currentNode instanceof Components.interfaces.nsIDOMHTMLLinkElement)
107
linkToolbarUI.linkAdded({originalTarget: currentNode});
108
currentNode = currentNode.nextSibling;
111
else if (currentNode instanceof Components.interfaces.nsIDOMElement)
113
// head is supposed to be the first element inside html.
114
// Got something else instead. returning
119
// Got a comment node or something like that. Moving on.
120
currentNode = currentNode.nextSibling;
125
LinkToolbarUI.prototype.toolbarActive = false;
127
LinkToolbarUI.prototype.activate =
130
if (!linkToolbarUI.toolbarActive) {
131
linkToolbarUI.toolbarActive = true;
132
document.getElementById("linktoolbar").setAttribute("hasitems", "true");
133
var contentArea = document.getElementById("appcontent");
134
contentArea.addEventListener("unload", linkToolbarUI.clear, true);
135
contentArea.addEventListener("load", linkToolbarUI.deactivate, true);
136
contentArea.addEventListener("DOMHeadLoaded", linkToolbarUI.deactivate,
141
LinkToolbarUI.prototype.deactivate =
144
// This function can never be called unless the toolbar is active, because
145
// it's a handler that's only activated in that situation, so there's no need
146
// to check toolbarActive. On the other hand, by the time this method is
147
// called the toolbar might have been populated again already, in which case
148
// we don't want to deactivate.
149
if (!linkToolbarHandler.hasItems) {
150
linkToolbarUI.toolbarActive = false;
151
document.getElementById("linktoolbar").setAttribute("hasitems", "false");
152
var contentArea = document.getElementById("appcontent");
153
contentArea.removeEventListener("unload", linkToolbarUI.clear, true);
154
contentArea.removeEventListener("load", linkToolbarUI.deactivate, true);
155
contentArea.removeEventListener("DOMHeadLoaded", linkToolbarUI.deactivate,
160
/* called whenever something on the toolbar gets an oncommand event */
161
LinkToolbarUI.prototype.commanded =
164
// Return if this is one of the menubuttons.
165
if (event.target.getAttribute("type") == "menu") return;
167
if (!event.target.getAttribute("href")) return;
169
var destURL = event.target.getAttribute("href");
171
// We have to do a security check here, because we are loading URIs given
172
// to us by a web page from chrome, which is privileged.
174
var ssm = Components.classes["@mozilla.org/scriptsecuritymanager;1"].getService().
175
QueryInterface(Components.interfaces.nsIScriptSecurityManager);
176
ssm.checkLoadURIStr(window.content.location.href, destURL, 0);
178
Components.classes["@mozilla.org/network/standard-url;1"].
179
createInstance(Components.interfaces.nsIURI);
180
referrer.spec = window.content.location.href;
181
loadURI(destURL, referrer);
183
dump("Error: it is not permitted to load this URI from a <link> element: " + e);
187
// functions for twiddling XUL elements in the toolbar
189
LinkToolbarUI.prototype.toggleLinkToolbar =
190
function(checkedItem)
192
this.goToggleTristateToolbar("linktoolbar", checkedItem);
194
if (this.isLinkToolbarEnabled())
195
this.fullSlowRefresh();
197
linkToolbarHandler.clearAllItems();
200
LinkToolbarUI.prototype.initLinkbarVisibilityMenu =
203
var state = document.getElementById("linktoolbar").getAttribute("hidden");
206
var checkedItem = document.getElementById("cmd_viewlinktoolbar_" + state);
207
checkedItem.setAttribute("checked", true);
208
checkedItem.checked = true;
211
LinkToolbarUI.prototype.goToggleTristateToolbar =
212
function(id, checkedItem)
214
var toolbar = document.getElementById(id);
217
toolbar.setAttribute("hidden", checkedItem.value);
218
document.persist(id, "hidden");
222
LinkToolbarUI.prototype.addHandlerActive = false;
224
LinkToolbarUI.prototype.initialized = false;
226
LinkToolbarUI.prototype.initHandlers =
229
var contentArea = document.getElementById("appcontent");
230
if (linkToolbarUI.isLinkToolbarEnabled())
232
if (!linkToolbarUI.addHandlerActive) {
233
contentArea.addEventListener("select", linkToolbarUI.tabSelected,
235
contentArea.addEventListener("DOMLinkAdded", linkToolbarUI.linkAdded,
237
linkToolbarUI.addHandlerActive = true;
241
if (linkToolbarUI.addHandlerActive) {
242
contentArea.removeEventListener("select", linkToolbarUI.tabSelected,
244
contentArea.removeEventListener("DOMLinkAdded", linkToolbarUI.linkAdded,
246
linkToolbarUI.addHandlerActive = false;
249
if (!linkToolbarUI.initialized)
251
linkToolbarUI.initialized = true;
252
document.removeEventListener("load", linkToolbarUI.initHandlers, true);
256
const linkToolbarUI = new LinkToolbarUI;