adding popup window checkbox. bug 166442 r=jag,jst,timeless

This commit is contained in:
danm%netscape.com 2002-09-11 02:31:13 +00:00
Родитель 757e769851
Коммит 3f4f479c52
3 изменённых файлов: 95 добавлений и 0 удалений

Просмотреть файл

@ -29,6 +29,10 @@
:: window rules are in xul.css
::::: */
window[chromehidden~="popupcontrol"] #popup-control {
display: none;
}
window[chromehidden~="toolbar"] #nav-bar-buttons,
window[chromehidden~="toolbar"] #print-button {
display: none;

Просмотреть файл

@ -63,11 +63,28 @@ var appCore = null;
//cached elements
var gBrowser = null;
var gOpenerOrgURI = null; // opener's URI at time of opening
// focused frame URL
var gFocusedURL = null;
var gFocusedDocument = null;
const gPopupPermListener = {
observe: function(subject, topic, data) {
if (topic != "popup perm change")
return;
if (!gOpenerOrgURI)
return;
var pm = Components.classes["@mozilla.org/PopupWindowManager;1"]
.getService(Components.interfaces.nsIPopupWindowManager);
var checkbox = document.getElementById("popup-checkbox");
checkbox.checked = pm.testPermission(gOpenerOrgURI) != Components.interfaces.nsIPopupWindowManager.eDisallow;
}
};
// Pref listener constants
const gButtonPrefListener =
{
@ -155,6 +172,26 @@ function removePrefListener(observer)
}
}
function addPopupPermListener(observer)
{
try {
var pm = Components.classes["@mozilla.org/PopupWindowManager;1"]
.getService(Components.interfaces.nsIPopupWindowManager);
pm.addObserver(observer);
} catch(e) {
}
}
function removePopupPermListener(observer)
{
try {
var pm = Components.classes["@mozilla.org/PopupWindowManager;1"]
.getService(Components.interfaces.nsIPopupWindowManager);
pm.removeObserver(observer);
} catch(e) {
}
}
/**
* We can avoid adding multiple load event listeners and save some time by adding
* one listener that calls all real handlers.
@ -378,6 +415,7 @@ function Startup()
addPrefListener(gButtonPrefListener);
addPrefListener(gTabStripPrefListener);
addPrefListener(gHomepagePrefListener);
addPopupPermListener(gPopupPermListener);
window.browserContentListener =
new nsBrowserContentListener(window, getBrowser());
@ -502,6 +540,9 @@ function Startup()
// now load bookmarks after a delay
setTimeout(LoadBookmarksCallback, 0);
// initialize this checkbox after the rest of the onload sequence has completed
setTimeout(initPopupCheckbox, 0);
}
function LoadBookmarksCallback()
@ -576,6 +617,7 @@ function Shutdown()
removePrefListener(gButtonPrefListener);
removePrefListener(gTabStripPrefListener);
removePrefListener(gHomepagePrefListener);
removePopupPermListener(gPopupPermListener);
window.browserContentListener.close();
// Close the app core.
@ -1953,3 +1995,47 @@ function checkTheme()
}
}
}
function popupCheckboxClick(aCheckbox)
{
if (!gOpenerOrgURI)
return;
try {
var pm = Components.classes["@mozilla.org/PopupWindowManager;1"]
.getService(Components.interfaces.nsIPopupWindowManager);
pm.add(gOpenerOrgURI, aCheckbox.checked);
} catch(e) {
}
}
function initPopupCheckbox()
{
if (!window.content || !window.content.opener)
return;
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var spec = Components.lookupMethod(window.content.opener, "location").call(location);
gOpenerOrgURI = ioService.newURI(spec, null, null);
var valid = false;
var hostname = window.content.opener.location.hostname;
if (hostname) {
try {
var pm = Components.classes["@mozilla.org/PopupWindowManager;1"]
.getService(Components.interfaces.nsIPopupWindowManager);
valid = pm.testSuitability(gOpenerOrgURI);
} catch(e) {
}
}
var checkbox = document.getElementById("popup-checkbox");
if (valid)
checkbox.setAttribute("tooltiptext", hostname);
else {
checkbox.setAttribute("tooltiptext", gNavigatorBundle.getString("noPopupControl"));
checkbox.setAttribute("disabled", true);
}
}

Просмотреть файл

@ -412,4 +412,9 @@ Contributor(s):
<statusbarpanel class="statusbarpanel-iconic" id="security-button"/>
</statusbar>
<hbox id="popup-control">
<separator class="thin"/>
<checkbox id="popup-checkbox" label="&popup-control.label;" checked="true"
oncommand="popupCheckboxClick(this)"/>
</hbox>
</window>