[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] [torbutton/master 16/31] Add code to insert the button into the toolbar.
Author: Mike Perry <mikeperry-git@xxxxxxxxxx>
Date: Thu, 23 Dec 2010 01:24:02 -0600
Subject: Add code to insert the button into the toolbar.
Commit: b78bb95ab4dd641dca408fef70a166c166f80a0a
Hopefully this will help cut down on mode error. Oddly enough, found a FF4
toolbar button issue related to a TabOpen event getting registered too early.
Possibly also solves bug #1392 and #992?
---
src/chrome/content/torbutton.js | 60 ++++++++++++++++++++++++------
src/chrome/content/torbutton.xul | 7 ++--
src/defaults/preferences/preferences.js | 1 +
3 files changed, 52 insertions(+), 16 deletions(-)
diff --git a/src/chrome/content/torbutton.js b/src/chrome/content/torbutton.js
index f340d4d..558737e 100644
--- a/src/chrome/content/torbutton.js
+++ b/src/chrome/content/torbutton.js
@@ -354,7 +354,9 @@ function torbutton_set_panel_view() {
o_prefbranch = torbutton_get_prefbranch('extensions.torbutton.');
if (!o_statuspanel || !o_prefbranch) return;
- var display_panel = o_prefbranch.getBoolPref('display_panel');
+ // Firefox 4 has no toolbar panel
+ var display_panel = o_prefbranch.getBoolPref('display_panel')
+ && !m_tb_ff4;
torbutton_log(2, 'setting panel visibility');
o_statuspanel.setAttribute('collapsed', !display_panel);
}
@@ -506,8 +508,28 @@ function torbutton_init() {
var contextMenu = document.getElementById("contentAreaContextMenu");
if (contextMenu)
contextMenu.addEventListener("popupshowing", torbutton_check_contextmenu, false);
-
-
+
+ // Add toolbutton to the bar.
+ // This should maybe be in the startup function, but we want to add
+ // the button to the panel before it's state (color) is set..
+ if (!m_tb_prefs.getBoolPref("extensions.torbutton.inserted_button")) {
+ torbutton_log(3, 'Adding button');
+ try {
+ var toolbutton = torbutton_get_button_from_toolbox();
+ var navbar = document.getElementById("nav-bar");
+ // XXX: Will probably fail on fennec. Also explicitly forbidden
+ // by MDC style guides (for good reason). Fix later..
+ var urlbar = document.getElementById("urlbar-container");
+ navbar.insertBefore(toolbutton, urlbar);
+ navbar.setAttribute("currentset", navbar.currentSet);
+ document.persist("nav-bar", "currentset");
+ torbutton_log(3, 'Button added');
+ m_tb_prefs.setBoolPref("extensions.torbutton.inserted_button", true);
+ } catch(e) {
+ torbutton_log(4, 'Failed to add Torbutton to toolbar: '+e);
+ }
+ }
+
torbutton_set_panel_view();
torbutton_log(1, 'setting torbutton status from proxy prefs');
torbutton_set_status();
@@ -515,6 +537,7 @@ function torbutton_init() {
torbutton_update_toolbutton(mode);
torbutton_update_statusbar(mode);
torbutton_log(3, 'init completed');
+
}
//this function checks to see if the context menu is being clicked on a link.
@@ -653,6 +676,15 @@ function torbutton_init_prefs() {
// m_tb_prefs.setIntPref('extensions.torbutton.socks_port', m_socks_port);
}
+function torbutton_get_button_from_toolbox() {
+ var toolbox = document.getElementById("navigator-toolbox");
+ for (var child = toolbox.palette.firstChild; child; child = child.nextSibling)
+ if (child.id == "torbutton-button")
+ return child;
+ torbutton_log(3, "Could not find toolbox button, trying in window DOM");
+ return torbutton_get_toolbutton();
+}
+
function torbutton_get_toolbutton() {
var o_toolbutton = false;
@@ -3372,19 +3404,17 @@ function torbutton_get_plugin_mimetypes()
function torbutton_new_tab(event)
-{
+{
// listening for new tabs
- torbutton_log(2, "New tab");
+ torbutton_log(3, "New tab");
var tor_tag = !m_tb_prefs.getBoolPref("extensions.torbutton.tor_enabled");
var no_plugins = m_tb_prefs.getBoolPref("extensions.torbutton.no_tor_plugins");
- var browser = event.currentTarget;
+ // Changed in FF4...
+ //var browser = event.currentTarget;
+ var browser = gBrowser.getBrowserForTab(event.target);
- // Fucking garbage.. event is delivered to the current tab, not the
- // newly created one. Need to traverse the current window for it.
- for (var i = 0; i < browser.browsers.length; ++i) {
- torbutton_tag_new_browser(browser.browsers[i], tor_tag, no_plugins);
- }
+ torbutton_tag_new_browser(browser, tor_tag, no_plugins);
}
// Returns true if the window wind is neither maximized, full screen,
@@ -3464,11 +3494,15 @@ function torbutton_new_window(event)
{
torbutton_log(3, "New window");
var browser = getBrowser();
+
if(!browser) {
torbutton_log(5, "No browser for new window.");
return;
}
+ // Add tab open listener..
+ browser.tabContainer.addEventListener("TabOpen", torbutton_new_tab, false);
+
m_tb_window_height = window.outerHeight;
m_tb_window_width = window.outerWidth;
@@ -3533,7 +3567,9 @@ function torbutton_close_window(event) {
window.addEventListener('load',torbutton_new_window,false);
window.addEventListener('unload', torbutton_close_window, false);
-getBrowser().addEventListener("TabOpen", torbutton_new_tab, false);
+// getBrowser() is not available at this point for FF4..
+// XXX: This registration is possibly related to why TabMixPlus fails.
+//getBrowser().tabContainer.addEventListener("TabOpen", torbutton_new_tab, false);
// ----------- JAVASCRIPT HOOKING + EVENT HANDLERS ----------------
diff --git a/src/chrome/content/torbutton.xul b/src/chrome/content/torbutton.xul
index db0079d..278225c 100644
--- a/src/chrome/content/torbutton.xul
+++ b/src/chrome/content/torbutton.xul
@@ -19,14 +19,13 @@
<toolbarpalette id="BrowserToolbarPalette">
<toolbarbutton
- id="torbutton-button"
- class="toolbarbutton-1"
+ id="torbutton-button"
+ class="toolbarbutton-1 chromeclass-toolbar-additional"
label="Torbutton"
- tooltiptext="&torbutton.button.tooltip;"
+ tooltiptext="&torbutton.button.tooltip;"
context="torbutton-context-menu"
oncommand="torbutton_toggle(false);" />
</toolbarpalette>
-
<commandset id="mainCommandSet">
<command id="torbutton-toggle-cmd" oncommand="torbutton_toggle(false);"/>
</commandset>
diff --git a/src/defaults/preferences/preferences.js b/src/defaults/preferences/preferences.js
index 2d6e258..c97272c 100644
--- a/src/defaults/preferences/preferences.js
+++ b/src/defaults/preferences/preferences.js
@@ -108,6 +108,7 @@ pref("extensions.torbutton.asked_ca_disable",false);
pref("extensions.torbutton.warned_ff3",false);
pref("extensions.torbutton.fresh_install",true);
pref("extensions.torbutton.normal_exit",false);
+pref("extensions.torbutton.inserted_button",false);
// Security prefs:
pref("extensions.torbutton.no_tor_plugins",true);
--
1.7.1