195924, 195921, 195928 - popup blocking changes to use whitelisting only and provide info dlg when popup first encountered. r=danm, sr=jag.

This commit is contained in:
shliang%netscape.com 2003-03-26 02:03:13 +00:00
Родитель 088d5783b7
Коммит 459e7e4277
36 изменённых файлов: 753 добавлений и 501 удалений

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

@ -2829,6 +2829,22 @@ void FirePopupBlockedEvent(nsIDOMDocument* aDoc)
}
}
void FirePopupWindowEvent(nsIDOMDocument* aDoc)
{
if (aDoc) {
// Fire a "PopupWindow" event
nsCOMPtr<nsIDOMDocumentEvent> docEvent(do_QueryInterface(aDoc));
nsCOMPtr<nsIDOMEvent> event;
docEvent->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event));
if (event) {
event->InitEvent(NS_LITERAL_STRING("PopupWindow"), PR_TRUE, PR_TRUE);
PRBool noDefault;
nsCOMPtr<nsIDOMEventTarget> targ(do_QueryInterface(aDoc));
targ->DispatchEvent(event, &noDefault);
}
}
}
// static
PRBool
GlobalWindowImpl::CanSetProperty(const char *aPrefName)
@ -2870,7 +2886,7 @@ GlobalWindowImpl::CheckForAbusePoint ()
}
if (!mIsDocumentLoaded || mRunningTimeout) {
return IsPopupBlocked(mDocument);
return PR_TRUE;
}
PRInt32 clickDelay = 0;
@ -2883,7 +2899,7 @@ GlobalWindowImpl::CheckForAbusePoint ()
LL_L2I(delta, ll_delta);
delta /= 1000;
if (delta > clickDelay) {
return IsPopupBlocked(mDocument);
return PR_TRUE;
}
}
@ -2945,31 +2961,40 @@ GlobalWindowImpl::Open(nsIDOMWindow **_retval)
* If we're in a commonly abused state (top level script, running a timeout,
* or onload/onunload), and the preference is enabled, prevent window.open().
*/
if (CheckForAbusePoint()) {
if (name.IsEmpty()) {
FirePopupBlockedEvent(mDocument);
return NS_OK;
}
PRBool abusedWindow = CheckForAbusePoint();
nsCOMPtr<nsIDOMWindow> topWindow;
GetTop(getter_AddRefs(topWindow));
nsCOMPtr<nsIDOMDocument> topDoc;
topWindow->GetDocument(getter_AddRefs(topDoc));
// Special case items that don't actually open new windows.
if (!name.EqualsIgnoreCase("_top") &&
!name.EqualsIgnoreCase("_self") &&
!name.EqualsIgnoreCase("_content")) {
nsCOMPtr<nsIWindowWatcher> wwatch =
do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv);
// If getting a window watcher fails, we'd fail downstream anyway
// when trying to open a new window so just bail here.
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMWindow> namedWindow;
wwatch->GetWindowByName(name.get(), this,
getter_AddRefs(namedWindow));
if (!namedWindow) {
FirePopupBlockedEvent(mDocument);
if (abusedWindow) {
if (IsPopupBlocked(mDocument)) {
if (name.IsEmpty()) {
FirePopupBlockedEvent(topDoc);
return NS_OK;
}
// Special case items that don't actually open new windows.
if (!name.EqualsIgnoreCase("_top") &&
!name.EqualsIgnoreCase("_self") &&
!name.EqualsIgnoreCase("_content")) {
nsCOMPtr<nsIWindowWatcher> wwatch =
do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv);
// If getting a window watcher fails, we'd fail downstream anyway
// when trying to open a new window so just bail here.
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMWindow> namedWindow;
wwatch->GetWindowByName(name.get(), this,
getter_AddRefs(namedWindow));
if (!namedWindow) {
FirePopupBlockedEvent(topDoc);
return NS_OK;
}
}
}
}
@ -2977,7 +3002,8 @@ GlobalWindowImpl::Open(nsIDOMWindow **_retval)
nsCOMPtr<nsIDOMChromeWindow> chrome_win(do_QueryInterface(*_retval));
if (NS_SUCCEEDED(rv) && !chrome_win) {
if (NS_SUCCEEDED(rv)) {
if (!chrome_win) {
// A new non-chrome window was created from a call to
// window.open() from JavaScript, make sure there's a document in
// the new window. We do this by simply asking the new window for
@ -2995,8 +3021,12 @@ GlobalWindowImpl::Open(nsIDOMWindow **_retval)
}
#endif
nsCOMPtr<nsIDOMDocument> doc;
(*_retval)->GetDocument(getter_AddRefs(doc));
nsCOMPtr<nsIDOMDocument> doc;
(*_retval)->GetDocument(getter_AddRefs(doc));
}
if (abusedWindow)
FirePopupWindowEvent(topDoc);
}
return rv;

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

@ -110,10 +110,16 @@
var policy = pref.getBoolPref("dom.disable_open_during_load");
blocked = permissionmanager.testPermission(getBrowser().currentURI, nsIPermissionManager.POPUP_TYPE);
document.getElementById("AboutPopups").hidden = policy;
document.getElementById("ManagePopups").hidden = !policy;
enableElement("BlockPopups", blocked != nsIPermissionManager.DENY_ACTION);
enableElement("AllowPopups", blocked != nsIPermissionManager.ALLOW_ACTION);
enableElement("ManagePopups", true);
if (policy) {
enableElement("AllowPopups", blocked != nsIPermissionManager.ALLOW_ACTION);
return;
}
enableElement("AllowPopups", false);
}
function enableElement(elementID, enable) {
@ -158,32 +164,23 @@
}
}
function PopupAction(action) {
var policy = pref.getBoolPref("dom.disable_open_during_load");
var uri = getBrowser().currentURI;
switch (action) {
case "block":
permissionmanager.add(uri, nsIPermissionManager.POPUP_TYPE, nsIPermissionManager.DENY_ACTION);
break;
case "allow":
var browsers = getBrowser().browsers;
var popupIcon = document.getElementById("popupIcon");
permissionmanager.add(uri, nsIPermissionManager.POPUP_TYPE, nsIPermissionManager.ALLOW_ACTION);
for (var i = 0; i < browsers.length; i++) {
if (browsers[i].popupDomain == uri.host) {
browsers[i].popupDomain = null;
popupIcon.hidden = true;
}
}
break;
}
function PopupAction() {
var hostPort = getBrowser().currentURI.hostPort;
window.openDialog("chrome://communicator/content/popupManager.xul", "",
"chrome,resizable=yes,modal=yes",
hostPort,
false);
}
function ViewPopupManager() {
function OpenAboutPopups() {
window.openDialog("chrome://communicator/content/aboutPopups.xul", "",
"chrome,centerscreen,resizable=yes",
false);
}
function OpenManagePopups() {
window.openDialog("chrome://communicator/content/popupManager.xul", "",
"chrome,resizable=yes,modal=yes",
pref.getBoolPref("dom.disable_open_during_load"),
"chrome,resizable=yes",
"",
false);
}
@ -235,18 +232,17 @@
id="popup"
insertbefore="navBeginGlobalItems">
<menupopup>
<menuitem id="BlockPopups" label="&cookieBlockPopupsCmd.label;"
accesskey="&cookieBlockPopupsCmd.accesskey;"
msg="&cookieBlockPopupsMsg.label;"
oncommand="PopupAction('block');"/>
<menuitem id="AllowPopups" label="&cookieAllowPopupsCmd.label;"
accesskey="&cookieAllowPopupsCmd.accesskey;"
msg="&cookieAllowPopupsMsg.label;"
oncommand="PopupAction('allow');"/>
<menuseparator/>
<menuitem id="ManagePopups" label="&cookieDisplayPopupsCmd.label;"
accesskey="&cookieDisplayPopupsCmd.accesskey;"
oncommand="ViewPopupManager();"/>
oncommand="PopupAction();"/>
<menuitem id="AboutPopups" label="&cookieAboutPopupBlocking.label;"
accesskey="&cookieAboutPopupBlocking.accesskey;"
oncommand="OpenAboutPopups();"
hidden="true"/>
<menuitem id="ManagePopups" label="&cookieManagePopups.label;"
accesskey="&cookieManagePopups.accesskey;"
oncommand="OpenManagePopups();"
hidden="true"/>
</menupopup>
</menu>
</menupopup>

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

@ -20,18 +20,12 @@
var COOKIEPERMISSION = 0;
var IMAGEPERMISSION = 1;
var WINDOWPERMISSION = 2;
function viewImages() {
window.openDialog("chrome://communicator/content/wallet/CookieViewer.xul","_blank",
"chrome,resizable=yes", "imageManager" );
}
function viewPopups() {
window.openDialog("chrome://communicator/content/wallet/CookieViewer.xul","_blank",
"chrome,resizable=yes", "popupManager" );
}
function viewCookies() {
window.openDialog("chrome://communicator/content/wallet/CookieViewer.xul","_blank",
"chrome,resizable=yes", "cookieManager");

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

@ -40,7 +40,7 @@
label="&images.label;"/>
</treerow>
</treeitem>
<treeitem position="3">
<treeitem id="popupspref" position="3">
<treerow>
<treecell url="chrome://cookie/content/pref-popups.xul"
label="&popups.label;"/>

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

@ -48,37 +48,75 @@
onload="init()"
headertitle="&title;">
<script type="application/x-javascript" src="chrome://cookie-/content/cookieOverlay.js"/>
<script type="application/x-javascript">
<![CDATA[
var _elementIDs = ["popupPolicy","playSound","playSoundUrl","displayIcon","prefillWhitelist"];
var _elementIDs = ["popupPolicy","playSound","playSoundUrl","displayIcon","removeBlacklist","prefillWhitelist"];
var gPolicyButton;
const nsIPermissionManager = Components.interfaces.nsIPermissionManager
const popupType = nsIPermissionManager.POPUP_TYPE;
var gPolicyCheckbox;
var gSoundCheckbox;
var gSoundUrlBox;
var gSoundUrlButton;
var gPreviewSoundButton;
var gIconCheckbox;
const POPUP_TYPE = 2;
var permissionManager;
var ioService;
function init() {
parent.initPanel("chrome://cookie/content/pref-popups.xul");
gPolicyButton = document.getElementById("popupPolicy");
permissionManager = Components.classes["@mozilla.org/permissionmanager;1"]
.getService(Components.interfaces.nsIPermissionManager);
ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
gPolicyCheckbox = document.getElementById("popupPolicy");
gSoundCheckbox = document.getElementById("playSound");
gSoundUrlBox = document.getElementById("playSoundUrl");
gSoundUrlButton = document.getElementById("selectSound");
gPreviewSoundButton = document.getElementById("previewSound");
gIconCheckbox = document.getElementById("displayIcon");
setButtons();
var removeBlacklist = (document.getElementById("removeBlacklist").getAttribute("value") == "true");
if (removeBlacklist) {
clearBlacklist();
document.getElementById("removeBlacklist").setAttribute("value", false);
}
var prefillWhitelist = (document.getElementById("prefillWhitelist").getAttribute("value") == "true");
if (prefillWhitelist) {
loadWhitelist();
document.getElementById("prefillWhitelist").setAttribute("value", false);
}
if (!parent.window.opener.location) // opened from About Popups menuitem
gPolicyCheckbox.checked = true;
setButtons();
}
function clearBlacklist() {
var enumerator = permissionManager.enumerator;
var hosts = [];
while (enumerator.hasMoreElements()) {
var permission = enumerator.getNext();
if (permission) {
permission = permission.QueryInterface(Components.interfaces.nsIPermission);
if ((permission.type == popupType) && (permission.capability == nsIPermissionManager.DENY_ACTION))
hosts[hosts.length] = permission.host;
}
}
for (var i = 0; i < hosts.length; i++) {
permissionManager.remove(hosts[i], popupType);
}
}
function loadWhitelist() {
@ -92,56 +130,32 @@
Components.interfaces.nsIPrefLocalizedString).data;
hosts = whitelist.split(",");
var popupmanager = Components.classes["@mozilla.org/PopupWindowManager;1"]
.getService(Components.interfaces.nsIPopupWindowManager);
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
for (var i = 0; i < hosts.length; i++) {
var host = hosts[i];
host = "http://" + host;
var uri = ioService.newURI(host, null, null);
popupmanager.add(uri, true);
permissionManager.add(uri, popupType, true);
}
}
catch (ex) { }
}
function blacklistEmpty() {
var permissionmanager = Components.classes["@mozilla.org/permissionmanager;1"]
.getService(Components.interfaces.nsIPermissionManager);
var popupManager = Components.classes["@mozilla.org/PopupWindowManager;1"]
.getService(Components.interfaces.nsIPopupWindowManager);
var enumerator = popupManager.getEnumerator();
while (enumerator.hasMoreElements()) {
var permission = enumerator.getNext()
.QueryInterface(Components.interfaces.nsIPermission);
if (!permission.capability)
return false;
}
return true;
}
function setButtons() {
var exceptionsAllow = document.getElementById("exceptionsAllow");
var exceptionsBlock = document.getElementById("exceptionsBlock");
var exceptionsButton = document.getElementById("exceptionsButton");
exceptionsButton.disabled = !gPolicyCheckbox.checked;
exceptionsAllow.disabled = (gPolicyButton.value == "true");
exceptionsBlock.disabled = (!exceptionsAllow.disabled);
if (blacklistEmpty() && (gPolicyButton.value == "false")) {
if (!gPolicyCheckbox.checked) {
gSoundCheckbox.disabled = true;
gSoundUrlBox.disabled = true;
gSoundUrlButton.disabled = true;
gPreviewSoundButton.disabled = true;
gIconCheckbox.disabled = true;
}
else {
gSoundCheckbox.disabled = false;
gSoundUrlBox.disabled = false;
gSoundUrlButton.disabled = false;
gPreviewSoundButton.disabled = false;
gIconCheckbox.disabled = false;
enableSoundUrl(gSoundCheckbox.checked);
@ -159,17 +173,42 @@
var ret = filepicker.show();
if (ret == nsIFilePicker.returnOK)
gSoundUrlBox.value = filepicker.file.path;
onSoundInput();
}
function previewSound() {
var soundUrl = gSoundUrlBox.value;
var sound = Components.classes["@mozilla.org/sound;1"]
.createInstance(Components.interfaces.nsISound);
if (soundUrl.indexOf("file://") == -1) {
sound.playSystemSound(soundUrl);
}
else {
var url = Components.classes["@mozilla.org/network/standard-url;1"]
.createInstance(Components.interfaces.nsIURL);
url.spec = soundUrl;
sound.play(url)
}
}
function enableSoundUrl(soundChecked) {
gSoundUrlBox.disabled = !soundChecked;
gSoundUrlButton.disabled = !soundChecked;
if (soundChecked && gSoundUrlBox.value) {
gPreviewSoundButton.disabled = false;
}
else
gPreviewSoundButton.disabled = true;
}
function onSoundInput() {
gPreviewSoundButton.disabled = gSoundUrlBox.value == "";
}
function viewPopups() {
window.openDialog("chrome://communicator/content/popupManager.xul", "",
"chrome,resizable=yes,modal=yes",
(gPolicyButton.value == "true"),
"",
true);
}
@ -179,29 +218,17 @@
<groupbox id="popupsArea">
<caption label="&popupBlocking.label;"/>
<description>&popupDetails;</description>
<hbox align="center">
<radiogroup id="popupPolicy" preftype="bool" prefstring="dom.disable_open_during_load">
<vbox flex="1">
<hbox>
<radio value="false" label="&popupAllow.label;"
oncommand="setButtons()"/>
<checkbox id="popupPolicy" label="&popupBlock.label;" accesskey="&popupBlock.accesskey;"
oncommand="setButtons()"
preftype="bool" prefstring="dom.disable_open_during_load"
prefattribute="checked"/>
<spacer flex="1"/>
<button id="exceptionsAllow" label="&popupViewAllow.label;"
accesskey="&popupViewAllow.accesskey;"
oncommand="viewPopups();"/>
</hbox>
<hbox>
<radio value="true" label="&popupBlock.label;"
oncommand="setButtons()"/>
<spacer flex="1"/>
<button id="exceptionsBlock" label="&popupViewBlock.label;"
accesskey="&popupViewBlock.accesskey;"
<button id="exceptionsButton" label="&popupExceptions.label;"
accesskey="&popupExceptions.accesskey;"
oncommand="viewPopups();"/>
</hbox>
</vbox>
</radiogroup>
</hbox>
<separator class="thin"/>
<description id="whenBlock">&whenBlock.description;</description>
<hbox align="center">
@ -209,9 +236,14 @@
oncommand="enableSoundUrl(this.checked);"
preftype="bool" prefstring="privacy.popups.sound_enabled"
prefattribute="checked"/>
<textbox flex="1" id="playSoundUrl" prefstring="privacy.popups.sound_url"/>
</hbox>
<hbox align="center">
<textbox flex="1" id="playSoundUrl"
prefstring="privacy.popups.sound_url" oninput="onSoundInput()"/>
<button id="selectSound" label="&selectSound.label;" accesskey="&selectSound.accesskey;"
filepickertitle="&selectSound.title;" oncommand="selectSound();"/>
<button id="previewSound" label="&previewSound.label;" accesskey="&previewSound.accesskey;"
oncommand="previewSound();"/>
</hbox>
<hbox align="center">
<checkbox id="displayIcon" label="&displayIcon.label;"
@ -221,6 +253,7 @@
<separator class="thin"/>
<description>&popupNote.description;</description>
<data id="prefillWhitelist" preftype="bool" prefattribute="value" prefstring="privacy.popups.prefill_whitelist"/>
<data id="removeBlacklist" preftype="bool" prefattribute="value" prefstring="privacy.popups.remove_blacklist"/>
</groupbox>
</page>

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

@ -18,14 +18,12 @@
<!ENTITY cookieBlockImagesCmd.accesskey "b">
<!ENTITY cookieBlockImagesMsg.label "Images from this site will never be downloaded">
<!ENTITY cookieDisplayPopupsCmd.label "Manage Popup Permissions">
<!ENTITY cookieDisplayPopupsCmd.accesskey "M">
<!ENTITY cookieAllowPopupsCmd.label "Allow Popups from this Site">
<!ENTITY cookieAllowPopupsCmd.label "Allow Popups From This Site">
<!ENTITY cookieAllowPopupsCmd.accesskey "A">
<!ENTITY cookieAllowPopupsMsg.label "Popup windows from this site will always be allowed">
<!ENTITY cookieBlockPopupsCmd.label "Suppress Popups from this Site">
<!ENTITY cookieBlockPopupsCmd.accesskey "S">
<!ENTITY cookieBlockPopupsMsg.label "Popup windows from this site will always be blocked">
<!ENTITY cookieAboutPopupBlocking.label "About Popup Blocking">
<!ENTITY cookieAboutPopupBlocking.accesskey "b">
<!ENTITY cookieManagePopups.label "Manage Popups">
<!ENTITY cookieManagePopups.accesskey "M">
<!ENTITY cookieTutorialCmd.label "Understanding Privacy">
<!ENTITY cookieTutorialCmd.accesskey "u">

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

@ -2,26 +2,24 @@
<!ENTITY popupBlocking.label "Popup Windows">
<!ENTITY popupDetails "Specify how to handle popup windows that appear on top of or under the current Navigator window:">
<!ENTITY popupDesc.label "Specify how to handle popup windows that appear on top of or under the current Navigator window:">
<!ENTITY popupAllow.label "Allow popups">
<!ENTITY popupAllow.accesskey "A">
<!ENTITY popupBlock.label "Suppress popups">
<!ENTITY popupBlock.accesskey "S">
<!ENTITY popupBlock.label "Block unrequested popup windows">
<!ENTITY popupBlock.accesskey "B">
<!ENTITY popupViewAllow.label "Exceptions...">
<!ENTITY popupViewAllow.accesskey "x">
<!ENTITY popupViewBlock.label "Exceptions...">
<!ENTITY popupViewBlock.accesskey "c">
<!ENTITY popupExceptions.label "Allowed Sites...">
<!ENTITY popupExceptions.accesskey "A">
<!ENTITY whenBlock.description "When a popup window has been suppressed:">
<!ENTITY whenBlock.description "When a popup window has been blocked:">
<!ENTITY playSound.label "Play a sound:">
<!ENTITY selectSound.label "Select...">
<!ENTITY selectSound.accesskey "e">
<!ENTITY selectSound.title "Select Popup Suppress Sound">
<!ENTITY previewSound.label "Preview">
<!ENTITY previewSound.accesskey "r">
<!ENTITY selectSound.title "Select Popup Block Sound">
<!ENTITY displayIcon.label "Display an icon in the Navigator status bar">
<!ENTITY popupNote.description "Note: Suppressing all popups may prevent important features of some web sites from working, such as login windows for banks and shopping sites. For details of how to allow specific sites to use popups while suppressing all others, click Help. Even if suppressed, sites may use other methods to show popups.">
<!ENTITY popupNote.description "Note: Blocking all popups may prevent important features of some web sites from working, such as login windows for banks and shopping sites. For details of how to allow specific sites to use popups while blocking all others, click Help. Even if blocked, sites may use other methods to show popups.">

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

@ -452,7 +452,6 @@ pref("browser.block.target_new_window", false);
pref("dom.disable_cookie_get", false);
pref("dom.disable_cookie_set", false);
pref("dom.disable_image_src_set", false);
pref("dom.disable_open_during_load", false);
pref("dom.disable_window_flip", false);
pref("dom.disable_window_move_resize", false);
pref("dom.disable_window_status_change", false);
@ -858,7 +857,10 @@ pref("browser.popups.showPopupBlocker", true);
// See http://bugzilla.mozilla.org/show_bug.cgi?id=169483 for further details...
pref("viewmanager.do_doublebuffering", true);
pref("dom.disable_open_during_load", false);
pref("privacy.popups.first_popup", true);
pref("privacy.popups.sound_enabled", false);
pref("privacy.popups.sound_url", "");
pref("privacy.popups.statusbar_icon_enabled", true);
pref("privacy.popups.prefill_whitelist", false);
pref("privacy.popups.remove_blacklist", true);

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

@ -338,3 +338,4 @@ classic.jar:
skin/classic/navigator/icons/restore.gif (navigator/icons/restore.gif)
skin/classic/navigator/icons/close.gif (navigator/icons/close.gif)
skin/classic/navigator/icons/popup-blocked.png (navigator/icons/popup-blocked.png)
skin/classic/navigator/icons/about-popups.gif (navigator/icons/about-popups.gif)

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

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

@ -342,6 +342,11 @@
list-style-image: url("chrome://navigator/skin/icons/popup-blocked.png");
}
#popupImage {
list-style-image: url("chrome://navigator/skin/icons/about-popups.gif");
margin: 6px 0px;
}
/* ::::: personal toolbar ::::: */
#home-button {

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

@ -442,3 +442,4 @@ modern.jar:
skin/modern/navigator/icons/btn1.gif (navigator/icons/btn1.gif)
skin/modern/navigator/icons/btn1-small.gif (navigator/icons/btn1-small.gif)
skin/modern/navigator/icons/popup-blocked.png (navigator/icons/popup-blocked.png)
skin/modern/navigator/icons/about-popups.gif (navigator/icons/about-popups.gif)

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

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

@ -534,3 +534,8 @@ toolbox {
#popupIcon {
list-style-image: url("chrome://navigator/skin/icons/popup-blocked.png");
}
#popupImage {
list-style-image: url("chrome://navigator/skin/icons/about-popups.gif");
margin: 6px 0px;
}

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

@ -160,6 +160,9 @@ const gPopupPrefListener =
var browsers = getBrowser().browsers;
var policy = pref.getBoolPref(prefName);
if (policy && pref.getBoolPref("privacy.popups.first_popup"))
pref.setBoolPref("privacy.popups.first_popup", false);
var hosts = [];
var popupManager = Components.classes["@mozilla.org/PopupWindowManager;1"]
@ -176,14 +179,14 @@ const gPopupPrefListener =
var popupIcon = document.getElementById("popupIcon");
if (!policy) { // blacklist
if (!policy) {
for (var i = 0; i < browsers.length; i++) {
if (browsers[i].popupDomain in hosts)
break;
browsers[i].popupDomain = null;
popupIcon.hidden = true;
}
} else { // whitelist
} else {
for (i = 0; i < browsers.length; i++) {
if (browsers[i].popupDomain in hosts) {
browsers[i].popupDomain = null;
@ -475,7 +478,7 @@ function Startup()
addPrefListener(gTabStripPrefListener);
addPrefListener(gHomepagePrefListener);
addPopupPermListener(gPopupPermListener);
addPrefListener(gPopupPrefListener);
addPrefListener(gPopupPrefListener);
window.browserContentListener =
new nsBrowserContentListener(window, getBrowser());
@ -603,6 +606,7 @@ function Startup()
// initiated by a web page script
addEventListener("fullscreen", onFullScreen, false);
addEventListener("PopupWindow", onPopupWindow, false);
addEventListener("DOMPopupBlocked", onPopupBlocked, false);
// does clicking on the urlbar select its contents?
@ -1952,6 +1956,43 @@ function onFullScreen()
FullScreen.toggle();
}
function onPopupWindow(aEvent) {
var firstPopup = pref.getBoolPref("privacy.popups.first_popup");
var blockingEnabled = pref.getBoolPref("dom.disable_open_during_load");
if (blockingEnabled) {
pref.setBoolPref("privacy.popups.first_popup", false);
return;
}
if (firstPopup) {
var showDialog = true;
var specialList = "";
try {
specialList = pref.getComplexValue("privacy.popups.default_whitelist",
Components.interfaces.nsIPrefLocalizedString).data;
}
catch(ex) { }
if (specialList) {
hosts = specialList.split(",");
var browser = getBrowserForDocument(aEvent.target);
if (!browser)
return;
var currentHost = browser.currentURI.hostPort;
for (var i = 0; i < hosts.length; i++) {
var nextHost = hosts[i];
if (nextHost == currentHost ||
"."+nextHost == currentHost.substr(currentHost.length - (nextHost.length+1))) {
showDialog = false;
break;
}
}
}
if (showDialog) {
window.openDialog("chrome://communicator/content/aboutPopups.xul", "",
"chrome,centerscreen,resizable=yes", true);
pref.setBoolPref("privacy.popups.first_popup", false);
}
}
}
function onPopupBlocked(aEvent) {
var playSound = pref.getBoolPref("privacy.popups.sound_enabled");
@ -1962,7 +2003,6 @@ function onPopupBlocked(aEvent) {
var soundUrlSpec = pref.getCharPref("privacy.popups.sound_url");
//beep if no sound file specified
if (!soundUrlSpec)
sound.beep();
@ -1981,33 +2021,37 @@ function onPopupBlocked(aEvent) {
var showIcon = pref.getBoolPref("privacy.popups.statusbar_icon_enabled");
if (showIcon) {
var doc = aEvent.target;
var browsers = getBrowser().browsers;
for (var i = 0; i < browsers.length; i++) {
if (browsers[i].contentDocument == doc) {
var hostPort = browsers[i].currentURI.hostPort;
browsers[i].popupDomain = hostPort;
if (browsers[i] == getBrowser().selectedBrowser) {
var popupIcon = document.getElementById("popupIcon");
popupIcon.hidden = false;
}
}
var browser = getBrowserForDocument(aEvent.target);
if (browser) {
var hostPort = browser.currentURI.hostPort;
browser.popupDomain = hostPort;
if (browser == getBrowser().selectedBrowser) {
var popupIcon = document.getElementById("popupIcon");
popupIcon.hidden = false;
}
}
}
}
function getBrowserForDocument(doc) {
var browsers = getBrowser().browsers;
for (var i = 0; i < browsers.length; i++) {
if (browsers[i].contentDocument == doc)
return browsers[i];
}
return null;
}
function StatusbarViewPopupManager() {
var policy = pref.getBoolPref("dom.disable_open_during_load");
var hostPort = "";
try {
hostPort = getBrowser().selectedBrowser.currentURI.hostPort;
}
catch(ex) { }
//open blacklist or whitelist with web site prefilled to unblock
// open whitelist with site prefilled to unblock
window.openDialog("chrome://communicator/content/popupManager.xul", "",
"chrome,resizable=yes", policy, hostPort, false);
"chrome,resizable=yes", hostPort, false);
}
// Set up a lame hack to avoid opening two bookmarks.

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

@ -32,6 +32,7 @@ comm.jar:
content/communicator/plugins.html (resources/content/plugins.html)
content/communicator/popupManager.js (resources/content/popupManager.js)
content/communicator/popupManager.xul (resources/content/popupManager.xul)
content/communicator/aboutPopups.xul (resources/content/aboutPopups.xul)
en-US.jar:
locale/en-US/communicator/contents.rdf (resources/locale/en-US/contents.rdf)
@ -50,6 +51,7 @@ en-US.jar:
locale/en-US/communicator/printPageSetup.properties (resources/locale/en-US/printPageSetup.properties)
locale/en-US/communicator/popupManager.dtd (resources/locale/en-US/popupManager.dtd)
locale/en-US/communicator/popupManager.properties (resources/locale/en-US/popupManager.properties)
locale/en-US/communicator/aboutPopups.dtd (resources/locale/en-US/aboutPopups.dtd)
locale/en-US/communicator/plugins.properties (resources/locale/en-US/plugins.properties)
US.jar:

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

@ -0,0 +1,108 @@
<?xml version="1.0"?>
<!-- ***** 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) 2002
- the Initial Developer. All Rights Reserved.
-
- Alternatively, the contents of this file may be used under the terms of
- either 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 LGPL or the GPL. 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 ***** -->
<?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?>
<?xml-stylesheet href="chrome://navigator/skin/navigator.css" type="text/css"?>
<!DOCTYPE window [
<!ENTITY % brandDTD SYSTEM "chrome://global/locale/brand.dtd" >
%brandDTD;
<!ENTITY % aboutPopupsDTD SYSTEM "chrome://communicator/locale/aboutPopups.dtd" >
%aboutPopupsDTD;
]>
<dialog id="aboutPopups"
buttons="accept,cancel,help"
title="&windowtitle.label;"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
width="380" height="260"
onload="init();"
ondialogaccept="return onAccept();"
ondialoghelp="return doHelpButton();">
<script type="application/x-javascript" src="chrome://help/content/contextHelp.js"/>
<script type="application/x-javascript" src="chrome://communicator/content/utilityOverlay.js"/>
<script type="application/x-javascript">
<![CDATA[
var enableBlock = true;
function init() {
if (!window.arguments[0])
document.getElementById("popupDesc").hidden = true;
else
document.getElementById("popupDescAlt").hidden = true;
}
function onAccept() {
var pref;
try {
var prefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService);
pref = prefService.getBranch(null);
}
catch(ex) { }
goPreferences("securityItem", "chrome://communicator/content/cookie/pref-popups.xul", "popupspref");
}
function doHelpButton() {
openHelp("pop_up_blocking");
return true;
}
]]>
</script>
<keyset id="dialogKeys"/>
<description id="popupDesc">&popupDesc.label;</description>
<description id="popupDescAlt">&popupDescAlt.label;</description>
<vbox align="center">
<image id="popupImage"/>
</vbox>
<description>&popupNote1.label;</description>
<separator class="thin"/>
<description>&popupNote2.label;</description>
<spacer flex="1"/>
<hbox class="dialog-button-box" pack="center">
<button dlgtype="accept" label="&acceptButton.label;"/>
<button dlgtype="cancel" label="&cancelButton.label;"/>
<button dlgtype="help"/>
</hbox>
</dialog>

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

@ -24,24 +24,15 @@
const nsIPermissionManager = Components.interfaces.nsIPermissionManager;
const popupType = nsIPermissionManager.POPUP_TYPE;
var popupManager = null;
var permissionManager = null;
var permissions = [];
var listCapability; // the capability of sites on the currently viewed list
// TRUE: current popup policy is BLOCK ALL WITH EXCEPTIONS - sites on
// the whitelist are allowed and have permission.capability = true
// FALSE: current popup policy is ALLOW ALL WITH EXCEPTIONS - sites on
// the blacklist are blocked and have permission.capability = false
var additions = [];
var removals = [];
const SIMPLEURI_CONTRACTID = "@mozilla.org/network/simple-uri;1";
var sortColumn = "host";
var lastSort = false;
var sortAscending = false;
var permissionsTreeView = {
rowCount: 0,
@ -66,76 +57,27 @@ var permissionsTree;
var popupStringBundle;
function Startup() {
popupManager = Components.classes["@mozilla.org/PopupWindowManager;1"]
.getService(Components.interfaces.nsIPopupWindowManager);
permissionManager = Components.classes["@mozilla.org/permissionmanager;1"]
.getService(Components.interfaces.nsIPermissionManager);
.getService(Components.interfaces.nsIPermissionManager);
permissionsTree = document.getElementById("permissionsTree");
popupStringBundle = document.getElementById("popupStringBundle");
var title;
if (window.arguments[0]) {
document.getElementById("blockExcept").hidden = false;
lastSort = (permissionsTree.getAttribute("lastSortWhitelist") == "true");
title = popupStringBundle.getString("whitelistTitle");
}
else {
document.getElementById("allowExcept").hidden = false;
lastSort = (permissionsTree.getAttribute("lastSortBlacklist") == "true");
title = popupStringBundle.getString("blacklistTitle");
}
// window.args[0]: host to prefill
// window.args[1]: true = opened from pref panel, false = opened from tools menu or statusbar icon
document.getElementById("popupManager").setAttribute("title", title);
listCapability = window.arguments[0];
sortAscending = (permissionsTree.getAttribute("sortAscending") == "true");
loadPermissions(permissions);
loadTree();
if (window.arguments[1]) { // dialog opened from statusbar icon
if (listCapability) {
document.getElementById("addSiteBox").value = window.arguments[1];
}
else {
// pre-pend '.' so we always match on host boundaries. Otherwise
// we might think notfoo.com matches foo.com
var currentLoc = '.'+window.arguments[1];
var nextHost;
var inList;
var matchIndex;
var matchLength = 0;
for (var i = 0; i < permissionsTreeView.rowCount; i++) {
nextHost = '.'+permissions[i].host;
if (currentLoc.length < nextHost.length)
continue; // can't be a match, list host is more specific
// look for an early out exact match -- check length first for speed
if (currentLoc.length == nextHost.length && nextHost == currentLoc) {
inList = true;
matchIndex = i;
break;
}
if (nextHost == currentLoc.substr(currentLoc.length - nextHost.length)) {
inList = true;
if (listCapability) // host is already on whitelist, don't prefill
break;
if (nextHost.length > matchLength) {
matchIndex = i;
matchLength = nextHost.length;
}
}
}
if (inList) // host is in blacklist, select for removal
permissionsTree.treeBoxObject.view.selection.select(matchIndex);
}
if (window.arguments[0] != "") {
// fill textbox to unblock/add to whitelist
var prefill = window.arguments[0];
if (prefill.indexOf("www.") == 0)
prefill = prefill.slice(4);
document.getElementById("addSiteBox").value = prefill;
}
document.documentElement.addEventListener("keypress", onReturnHit, true);
@ -143,19 +85,47 @@ function Startup() {
window.sizeToContent();
}
function getMatch(host) {
// pre-pend '.' so we always match on host boundaries. Otherwise
// we might think notfoo.com matches foo.com
var currentLoc = '.'+host;
var nextHost;
var inList;
var matchIndex = null;
var matchLength = 0;
for (var i = 0; i < permissionsTreeView.rowCount; i++) {
nextHost = '.'+permissions[i].host;
if (currentLoc.length < nextHost.length)
continue; // can't be a match, list host is more specific
// look for an early out exact match -- check length first for speed
if (currentLoc.length == nextHost.length && nextHost == currentLoc) {
inList = true;
matchIndex = i;
break;
}
if (nextHost == currentLoc.substr(currentLoc.length - nextHost.length)) {
inList = true;
if (nextHost.length > matchLength) {
matchIndex = i;
matchLength = nextHost.length;
}
}
}
return matchIndex;
}
function onAccept() {
finalizeChanges();
var unblocked;
var unblocked = additions;
if (listCapability) {
unblocked = additions;
permissionsTree.setAttribute("lastSortWhitelist", !lastSort);
}
else {
unblocked = removals;
permissionsTree.setAttribute("lastSortBlacklist", !lastSort);
}
permissionsTree.setAttribute("sortAscending", !sortAscending);
var nextLocation;
var nextUnblocked;
@ -195,10 +165,9 @@ function onAccept() {
}
}
if (window.arguments[2])
if (window.arguments[1])
window.opener.setButtons();
return true;
}
@ -215,8 +184,7 @@ function loadPermissions(table) {
var permission = enumerator.getNext();
if (permission) {
permission = permission.QueryInterface(Components.interfaces.nsIPermission);
if ((permission.type == popupType) &&
(permission.capability == listCapability)) {
if ((permission.type == popupType) && (permission.capability == nsIPermissionManager.ALLOW_ACTION)) {
var host = permission.host;
table[count] = new Permission(host,count++);
}
@ -237,9 +205,9 @@ function loadTree() {
}
function permissionColumnSort() {
lastSort =
sortAscending =
SortTree(permissionsTree, permissionsTreeView, permissions,
sortColumn, sortColumn, lastSort);
sortColumn, sortColumn, sortAscending);
}
function permissionSelected() {
@ -327,8 +295,7 @@ function finalizeChanges() {
var uri;
var host;
var i;
var perm = (listCapability == true) ? nsIPermissionManager.ALLOW_ACTION : nsIPermissionManager.DENY_ACTION
//note: the scheme will be taken off later, it is being added now only to
//create the uri for add/remove
for (i in additions) {
@ -336,7 +303,7 @@ function finalizeChanges() {
if (host != null) {
host = "http://" + host;
uri = ioService.newURI(host, null, null);
permissionManager.add(uri, popupType, listCapability);
permissionManager.add(uri, popupType, true);
}
}
@ -402,7 +369,7 @@ function addPermission() {
var newPermission = new Permission(host, length);
permissions.push(newPermission);
lastSort = !lastSort; //keep same sort direction
sortAscending = !sortAscending; //keep same sort direction
loadTree();
if (removals[host] != null)
@ -434,7 +401,7 @@ function onReturnHit(event) {
}
function doHelpButton() {
openHelp("pop_up_blocking_prefs");
openHelp("pop_up_blocking");
return true;
}

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

@ -58,8 +58,7 @@
<vbox id="servers" flex="1">
<description id="allowExcept" value="&allowExcept.label;" hidden="true"/>
<description id="blockExcept" value="&blockExcept.label;" hidden="true"/>
<description id="allowPopups" value="&allowPopups.label;"/>
<separator class="thin"/>
@ -78,8 +77,8 @@
hidecolumnpicker="true"
onkeypress="handlePermissionKeyPress(event)"
onselect="permissionSelected();"
lastSortBlacklist="false" lastSortWhitelist="false"
persist="lastSortBlacklist lastSortWhitelist">
sortAscending="false"
persist="sortAscending">
<treecols>
<treecol id="siteCol" label="&treehead.sitename.label;" flex="1"
onclick="permissionColumnSort();"/>

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

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

@ -1,16 +0,0 @@
<!ENTITY windowtitle.label "Popup Exceptions">
<!ENTITY allowExcept.label "Suppress popups from the following web sites:">
<!ENTITY blockExcept.label "Allow popups from the following web sites:">
<!ENTITY addSite.label "Add">
<!ENTITY addSite.accesskey "A">
<!ENTITY treehead.sitename.label "Site">
<!ENTITY remove.label "Remove">
<!ENTITY remove.accesskey "R">
<!ENTITY removeAll.label "Remove All">
<!ENTITY removeAll.accesskey "e">

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

@ -1,4 +0,0 @@
blacklistTitle=Popup Exceptions - Suppressed Web Sites
whitelistTitle=Popup Exceptions - Allowed Web Sites
alertDuplicate=The web site %S already exists in this list.
alertInvalid=The web site %S is invalid.

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

@ -0,0 +1,108 @@
<?xml version="1.0"?>
<!-- ***** 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) 2002
- the Initial Developer. All Rights Reserved.
-
- Alternatively, the contents of this file may be used under the terms of
- either 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 LGPL or the GPL. 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 ***** -->
<?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?>
<?xml-stylesheet href="chrome://navigator/skin/navigator.css" type="text/css"?>
<!DOCTYPE window [
<!ENTITY % brandDTD SYSTEM "chrome://global/locale/brand.dtd" >
%brandDTD;
<!ENTITY % aboutPopupsDTD SYSTEM "chrome://communicator/locale/aboutPopups.dtd" >
%aboutPopupsDTD;
]>
<dialog id="aboutPopups"
buttons="accept,cancel,help"
title="&windowtitle.label;"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
width="380" height="260"
onload="init();"
ondialogaccept="return onAccept();"
ondialoghelp="return doHelpButton();">
<script type="application/x-javascript" src="chrome://help/content/contextHelp.js"/>
<script type="application/x-javascript" src="chrome://communicator/content/utilityOverlay.js"/>
<script type="application/x-javascript">
<![CDATA[
var enableBlock = true;
function init() {
if (!window.arguments[0])
document.getElementById("popupDesc").hidden = true;
else
document.getElementById("popupDescAlt").hidden = true;
}
function onAccept() {
var pref;
try {
var prefService = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService);
pref = prefService.getBranch(null);
}
catch(ex) { }
goPreferences("securityItem", "chrome://communicator/content/cookie/pref-popups.xul", "popupspref");
}
function doHelpButton() {
openHelp("pop_up_blocking");
return true;
}
]]>
</script>
<keyset id="dialogKeys"/>
<description id="popupDesc">&popupDesc.label;</description>
<description id="popupDescAlt">&popupDescAlt.label;</description>
<vbox align="center">
<image id="popupImage"/>
</vbox>
<description>&popupNote1.label;</description>
<separator class="thin"/>
<description>&popupNote2.label;</description>
<spacer flex="1"/>
<hbox class="dialog-button-box" pack="center">
<button dlgtype="accept" label="&acceptButton.label;"/>
<button dlgtype="cancel" label="&cancelButton.label;"/>
<button dlgtype="help"/>
</hbox>
</dialog>

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

@ -24,24 +24,15 @@
const nsIPermissionManager = Components.interfaces.nsIPermissionManager;
const popupType = nsIPermissionManager.POPUP_TYPE;
var popupManager = null;
var permissionManager = null;
var permissions = [];
var listCapability; // the capability of sites on the currently viewed list
// TRUE: current popup policy is BLOCK ALL WITH EXCEPTIONS - sites on
// the whitelist are allowed and have permission.capability = true
// FALSE: current popup policy is ALLOW ALL WITH EXCEPTIONS - sites on
// the blacklist are blocked and have permission.capability = false
var additions = [];
var removals = [];
const SIMPLEURI_CONTRACTID = "@mozilla.org/network/simple-uri;1";
var sortColumn = "host";
var lastSort = false;
var sortAscending = false;
var permissionsTreeView = {
rowCount: 0,
@ -66,76 +57,27 @@ var permissionsTree;
var popupStringBundle;
function Startup() {
popupManager = Components.classes["@mozilla.org/PopupWindowManager;1"]
.getService(Components.interfaces.nsIPopupWindowManager);
permissionManager = Components.classes["@mozilla.org/permissionmanager;1"]
.getService(Components.interfaces.nsIPermissionManager);
.getService(Components.interfaces.nsIPermissionManager);
permissionsTree = document.getElementById("permissionsTree");
popupStringBundle = document.getElementById("popupStringBundle");
var title;
if (window.arguments[0]) {
document.getElementById("blockExcept").hidden = false;
lastSort = (permissionsTree.getAttribute("lastSortWhitelist") == "true");
title = popupStringBundle.getString("whitelistTitle");
}
else {
document.getElementById("allowExcept").hidden = false;
lastSort = (permissionsTree.getAttribute("lastSortBlacklist") == "true");
title = popupStringBundle.getString("blacklistTitle");
}
// window.args[0]: host to prefill
// window.args[1]: true = opened from pref panel, false = opened from tools menu or statusbar icon
document.getElementById("popupManager").setAttribute("title", title);
listCapability = window.arguments[0];
sortAscending = (permissionsTree.getAttribute("sortAscending") == "true");
loadPermissions(permissions);
loadTree();
if (window.arguments[1]) { // dialog opened from statusbar icon
if (listCapability) {
document.getElementById("addSiteBox").value = window.arguments[1];
}
else {
// pre-pend '.' so we always match on host boundaries. Otherwise
// we might think notfoo.com matches foo.com
var currentLoc = '.'+window.arguments[1];
var nextHost;
var inList;
var matchIndex;
var matchLength = 0;
for (var i = 0; i < permissionsTreeView.rowCount; i++) {
nextHost = '.'+permissions[i].host;
if (currentLoc.length < nextHost.length)
continue; // can't be a match, list host is more specific
// look for an early out exact match -- check length first for speed
if (currentLoc.length == nextHost.length && nextHost == currentLoc) {
inList = true;
matchIndex = i;
break;
}
if (nextHost == currentLoc.substr(currentLoc.length - nextHost.length)) {
inList = true;
if (listCapability) // host is already on whitelist, don't prefill
break;
if (nextHost.length > matchLength) {
matchIndex = i;
matchLength = nextHost.length;
}
}
}
if (inList) // host is in blacklist, select for removal
permissionsTree.treeBoxObject.view.selection.select(matchIndex);
}
if (window.arguments[0] != "") {
// fill textbox to unblock/add to whitelist
var prefill = window.arguments[0];
if (prefill.indexOf("www.") == 0)
prefill = prefill.slice(4);
document.getElementById("addSiteBox").value = prefill;
}
document.documentElement.addEventListener("keypress", onReturnHit, true);
@ -143,19 +85,47 @@ function Startup() {
window.sizeToContent();
}
function getMatch(host) {
// pre-pend '.' so we always match on host boundaries. Otherwise
// we might think notfoo.com matches foo.com
var currentLoc = '.'+host;
var nextHost;
var inList;
var matchIndex = null;
var matchLength = 0;
for (var i = 0; i < permissionsTreeView.rowCount; i++) {
nextHost = '.'+permissions[i].host;
if (currentLoc.length < nextHost.length)
continue; // can't be a match, list host is more specific
// look for an early out exact match -- check length first for speed
if (currentLoc.length == nextHost.length && nextHost == currentLoc) {
inList = true;
matchIndex = i;
break;
}
if (nextHost == currentLoc.substr(currentLoc.length - nextHost.length)) {
inList = true;
if (nextHost.length > matchLength) {
matchIndex = i;
matchLength = nextHost.length;
}
}
}
return matchIndex;
}
function onAccept() {
finalizeChanges();
var unblocked;
var unblocked = additions;
if (listCapability) {
unblocked = additions;
permissionsTree.setAttribute("lastSortWhitelist", !lastSort);
}
else {
unblocked = removals;
permissionsTree.setAttribute("lastSortBlacklist", !lastSort);
}
permissionsTree.setAttribute("sortAscending", !sortAscending);
var nextLocation;
var nextUnblocked;
@ -195,10 +165,9 @@ function onAccept() {
}
}
if (window.arguments[2])
if (window.arguments[1])
window.opener.setButtons();
return true;
}
@ -215,8 +184,7 @@ function loadPermissions(table) {
var permission = enumerator.getNext();
if (permission) {
permission = permission.QueryInterface(Components.interfaces.nsIPermission);
if ((permission.type == popupType) &&
(permission.capability == listCapability)) {
if ((permission.type == popupType) && (permission.capability == nsIPermissionManager.ALLOW_ACTION)) {
var host = permission.host;
table[count] = new Permission(host,count++);
}
@ -237,9 +205,9 @@ function loadTree() {
}
function permissionColumnSort() {
lastSort =
sortAscending =
SortTree(permissionsTree, permissionsTreeView, permissions,
sortColumn, sortColumn, lastSort);
sortColumn, sortColumn, sortAscending);
}
function permissionSelected() {
@ -327,8 +295,7 @@ function finalizeChanges() {
var uri;
var host;
var i;
var perm = (listCapability == true) ? nsIPermissionManager.ALLOW_ACTION : nsIPermissionManager.DENY_ACTION
//note: the scheme will be taken off later, it is being added now only to
//create the uri for add/remove
for (i in additions) {
@ -336,7 +303,7 @@ function finalizeChanges() {
if (host != null) {
host = "http://" + host;
uri = ioService.newURI(host, null, null);
permissionManager.add(uri, popupType, listCapability);
permissionManager.add(uri, popupType, true);
}
}
@ -402,7 +369,7 @@ function addPermission() {
var newPermission = new Permission(host, length);
permissions.push(newPermission);
lastSort = !lastSort; //keep same sort direction
sortAscending = !sortAscending; //keep same sort direction
loadTree();
if (removals[host] != null)
@ -434,7 +401,7 @@ function onReturnHit(event) {
}
function doHelpButton() {
openHelp("pop_up_blocking_prefs");
openHelp("pop_up_blocking");
return true;
}

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

@ -58,8 +58,7 @@
<vbox id="servers" flex="1">
<description id="allowExcept" value="&allowExcept.label;" hidden="true"/>
<description id="blockExcept" value="&blockExcept.label;" hidden="true"/>
<description id="allowPopups" value="&allowPopups.label;"/>
<separator class="thin"/>
@ -78,8 +77,8 @@
hidecolumnpicker="true"
onkeypress="handlePermissionKeyPress(event)"
onselect="permissionSelected();"
lastSortBlacklist="false" lastSortWhitelist="false"
persist="lastSortBlacklist lastSortWhitelist">
sortAscending="false"
persist="sortAscending">
<treecols>
<treecol id="siteCol" label="&treehead.sitename.label;" flex="1"
onclick="permissionColumnSort();"/>

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

@ -110,10 +110,16 @@
var policy = pref.getBoolPref("dom.disable_open_during_load");
blocked = permissionmanager.testPermission(getBrowser().currentURI, nsIPermissionManager.POPUP_TYPE);
document.getElementById("AboutPopups").hidden = policy;
document.getElementById("ManagePopups").hidden = !policy;
enableElement("BlockPopups", blocked != nsIPermissionManager.DENY_ACTION);
enableElement("AllowPopups", blocked != nsIPermissionManager.ALLOW_ACTION);
enableElement("ManagePopups", true);
if (policy) {
enableElement("AllowPopups", blocked != nsIPermissionManager.ALLOW_ACTION);
return;
}
enableElement("AllowPopups", false);
}
function enableElement(elementID, enable) {
@ -158,32 +164,23 @@
}
}
function PopupAction(action) {
var policy = pref.getBoolPref("dom.disable_open_during_load");
var uri = getBrowser().currentURI;
switch (action) {
case "block":
permissionmanager.add(uri, nsIPermissionManager.POPUP_TYPE, nsIPermissionManager.DENY_ACTION);
break;
case "allow":
var browsers = getBrowser().browsers;
var popupIcon = document.getElementById("popupIcon");
permissionmanager.add(uri, nsIPermissionManager.POPUP_TYPE, nsIPermissionManager.ALLOW_ACTION);
for (var i = 0; i < browsers.length; i++) {
if (browsers[i].popupDomain == uri.host) {
browsers[i].popupDomain = null;
popupIcon.hidden = true;
}
}
break;
}
function PopupAction() {
var hostPort = getBrowser().currentURI.hostPort;
window.openDialog("chrome://communicator/content/popupManager.xul", "",
"chrome,resizable=yes,modal=yes",
hostPort,
false);
}
function ViewPopupManager() {
function OpenAboutPopups() {
window.openDialog("chrome://communicator/content/aboutPopups.xul", "",
"chrome,centerscreen,resizable=yes",
false);
}
function OpenManagePopups() {
window.openDialog("chrome://communicator/content/popupManager.xul", "",
"chrome,resizable=yes,modal=yes",
pref.getBoolPref("dom.disable_open_during_load"),
"chrome,resizable=yes",
"",
false);
}
@ -235,18 +232,17 @@
id="popup"
insertbefore="navBeginGlobalItems">
<menupopup>
<menuitem id="BlockPopups" label="&cookieBlockPopupsCmd.label;"
accesskey="&cookieBlockPopupsCmd.accesskey;"
msg="&cookieBlockPopupsMsg.label;"
oncommand="PopupAction('block');"/>
<menuitem id="AllowPopups" label="&cookieAllowPopupsCmd.label;"
accesskey="&cookieAllowPopupsCmd.accesskey;"
msg="&cookieAllowPopupsMsg.label;"
oncommand="PopupAction('allow');"/>
<menuseparator/>
<menuitem id="ManagePopups" label="&cookieDisplayPopupsCmd.label;"
accesskey="&cookieDisplayPopupsCmd.accesskey;"
oncommand="ViewPopupManager();"/>
oncommand="PopupAction();"/>
<menuitem id="AboutPopups" label="&cookieAboutPopupBlocking.label;"
accesskey="&cookieAboutPopupBlocking.accesskey;"
oncommand="OpenAboutPopups();"
hidden="true"/>
<menuitem id="ManagePopups" label="&cookieManagePopups.label;"
accesskey="&cookieManagePopups.accesskey;"
oncommand="OpenManagePopups();"
hidden="true"/>
</menupopup>
</menu>
</menupopup>

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

@ -20,18 +20,12 @@
var COOKIEPERMISSION = 0;
var IMAGEPERMISSION = 1;
var WINDOWPERMISSION = 2;
function viewImages() {
window.openDialog("chrome://communicator/content/wallet/CookieViewer.xul","_blank",
"chrome,resizable=yes", "imageManager" );
}
function viewPopups() {
window.openDialog("chrome://communicator/content/wallet/CookieViewer.xul","_blank",
"chrome,resizable=yes", "popupManager" );
}
function viewCookies() {
window.openDialog("chrome://communicator/content/wallet/CookieViewer.xul","_blank",
"chrome,resizable=yes", "cookieManager");

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

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

@ -1,8 +1,6 @@
<!ENTITY windowtitle.label "Popup Exceptions">
<!ENTITY windowtitle.label "Allowed Web Sites">
<!ENTITY allowExcept.label "Suppress popups from the following web sites:">
<!ENTITY blockExcept.label "Allow popups from the following web sites:">
<!ENTITY allowPopups.label "Allow popups from the following web sites:">
<!ENTITY addSite.label "Add">
<!ENTITY addSite.accesskey "A">

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

@ -1,4 +1,2 @@
blacklistTitle=Popup Exceptions - Suppressed Web Sites
whitelistTitle=Popup Exceptions - Allowed Web Sites
alertDuplicate=The web site %S already exists in this list.
alertInvalid=The web site %S is invalid.

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

@ -18,14 +18,12 @@
<!ENTITY cookieBlockImagesCmd.accesskey "b">
<!ENTITY cookieBlockImagesMsg.label "Images from this site will never be downloaded">
<!ENTITY cookieDisplayPopupsCmd.label "Manage Popup Permissions">
<!ENTITY cookieDisplayPopupsCmd.accesskey "M">
<!ENTITY cookieAllowPopupsCmd.label "Allow Popups from this Site">
<!ENTITY cookieAllowPopupsCmd.label "Allow Popups From This Site">
<!ENTITY cookieAllowPopupsCmd.accesskey "A">
<!ENTITY cookieAllowPopupsMsg.label "Popup windows from this site will always be allowed">
<!ENTITY cookieBlockPopupsCmd.label "Suppress Popups from this Site">
<!ENTITY cookieBlockPopupsCmd.accesskey "S">
<!ENTITY cookieBlockPopupsMsg.label "Popup windows from this site will always be blocked">
<!ENTITY cookieAboutPopupBlocking.label "About Popup Blocking">
<!ENTITY cookieAboutPopupBlocking.accesskey "b">
<!ENTITY cookieManagePopups.label "Manage Popups">
<!ENTITY cookieManagePopups.accesskey "M">
<!ENTITY cookieTutorialCmd.label "Understanding Privacy">
<!ENTITY cookieTutorialCmd.accesskey "u">

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

@ -40,7 +40,7 @@
label="&images.label;"/>
</treerow>
</treeitem>
<treeitem position="3">
<treeitem id="popupspref" position="3">
<treerow>
<treecell url="chrome://cookie/content/pref-popups.xul"
label="&popups.label;"/>

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

@ -40,7 +40,7 @@
label="&images.label;"/>
</treerow>
</treeitem>
<treeitem position="3">
<treeitem id="popupspref" position="3">
<treerow>
<treecell url="chrome://cookie/content/pref-popups.xul"
label="&popups.label;"/>

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

@ -45,7 +45,7 @@ var fm = {
"chrome://communicator/content/pref/pref-security.xul": "sec_gen",
"chrome://cookie/content/pref-cookies.xul": "cookies_prefs",
"chrome://cookie/content/pref-images.xul": "images_prefs",
"chrome://cookie/content/pref-popups.xul": "pop_up_blocking_prefs",
"chrome://cookie/content/pref-popups.xul": "pop_up_blocking",
"chrome://wallet/content/pref-wallet.xul": "forms_prefs",
"chrome://pippki/content/pref-masterpass.xul": "passwords_master",
"chrome://wallet/content/pref-passwords.xul": "passwords_prefs",

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

@ -48,37 +48,75 @@
onload="init()"
headertitle="&title;">
<script type="application/x-javascript" src="chrome://cookie-/content/cookieOverlay.js"/>
<script type="application/x-javascript">
<![CDATA[
var _elementIDs = ["popupPolicy","playSound","playSoundUrl","displayIcon","prefillWhitelist"];
var _elementIDs = ["popupPolicy","playSound","playSoundUrl","displayIcon","removeBlacklist","prefillWhitelist"];
var gPolicyButton;
const nsIPermissionManager = Components.interfaces.nsIPermissionManager
const popupType = nsIPermissionManager.POPUP_TYPE;
var gPolicyCheckbox;
var gSoundCheckbox;
var gSoundUrlBox;
var gSoundUrlButton;
var gPreviewSoundButton;
var gIconCheckbox;
const POPUP_TYPE = 2;
var permissionManager;
var ioService;
function init() {
parent.initPanel("chrome://cookie/content/pref-popups.xul");
gPolicyButton = document.getElementById("popupPolicy");
permissionManager = Components.classes["@mozilla.org/permissionmanager;1"]
.getService(Components.interfaces.nsIPermissionManager);
ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
gPolicyCheckbox = document.getElementById("popupPolicy");
gSoundCheckbox = document.getElementById("playSound");
gSoundUrlBox = document.getElementById("playSoundUrl");
gSoundUrlButton = document.getElementById("selectSound");
gPreviewSoundButton = document.getElementById("previewSound");
gIconCheckbox = document.getElementById("displayIcon");
setButtons();
var removeBlacklist = (document.getElementById("removeBlacklist").getAttribute("value") == "true");
if (removeBlacklist) {
clearBlacklist();
document.getElementById("removeBlacklist").setAttribute("value", false);
}
var prefillWhitelist = (document.getElementById("prefillWhitelist").getAttribute("value") == "true");
if (prefillWhitelist) {
loadWhitelist();
document.getElementById("prefillWhitelist").setAttribute("value", false);
}
if (!parent.window.opener.location) // opened from About Popups menuitem
gPolicyCheckbox.checked = true;
setButtons();
}
function clearBlacklist() {
var enumerator = permissionManager.enumerator;
var hosts = [];
while (enumerator.hasMoreElements()) {
var permission = enumerator.getNext();
if (permission) {
permission = permission.QueryInterface(Components.interfaces.nsIPermission);
if ((permission.type == popupType) && (permission.capability == nsIPermissionManager.DENY_ACTION))
hosts[hosts.length] = permission.host;
}
}
for (var i = 0; i < hosts.length; i++) {
permissionManager.remove(hosts[i], popupType);
}
}
function loadWhitelist() {
@ -92,56 +130,32 @@
Components.interfaces.nsIPrefLocalizedString).data;
hosts = whitelist.split(",");
var popupmanager = Components.classes["@mozilla.org/PopupWindowManager;1"]
.getService(Components.interfaces.nsIPopupWindowManager);
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
for (var i = 0; i < hosts.length; i++) {
var host = hosts[i];
host = "http://" + host;
var uri = ioService.newURI(host, null, null);
popupmanager.add(uri, true);
permissionManager.add(uri, popupType, true);
}
}
catch (ex) { }
}
function blacklistEmpty() {
var permissionmanager = Components.classes["@mozilla.org/permissionmanager;1"]
.getService(Components.interfaces.nsIPermissionManager);
var popupManager = Components.classes["@mozilla.org/PopupWindowManager;1"]
.getService(Components.interfaces.nsIPopupWindowManager);
var enumerator = popupManager.getEnumerator();
while (enumerator.hasMoreElements()) {
var permission = enumerator.getNext()
.QueryInterface(Components.interfaces.nsIPermission);
if (!permission.capability)
return false;
}
return true;
}
function setButtons() {
var exceptionsAllow = document.getElementById("exceptionsAllow");
var exceptionsBlock = document.getElementById("exceptionsBlock");
var exceptionsButton = document.getElementById("exceptionsButton");
exceptionsButton.disabled = !gPolicyCheckbox.checked;
exceptionsAllow.disabled = (gPolicyButton.value == "true");
exceptionsBlock.disabled = (!exceptionsAllow.disabled);
if (blacklistEmpty() && (gPolicyButton.value == "false")) {
if (!gPolicyCheckbox.checked) {
gSoundCheckbox.disabled = true;
gSoundUrlBox.disabled = true;
gSoundUrlButton.disabled = true;
gPreviewSoundButton.disabled = true;
gIconCheckbox.disabled = true;
}
else {
gSoundCheckbox.disabled = false;
gSoundUrlBox.disabled = false;
gSoundUrlButton.disabled = false;
gPreviewSoundButton.disabled = false;
gIconCheckbox.disabled = false;
enableSoundUrl(gSoundCheckbox.checked);
@ -159,17 +173,42 @@
var ret = filepicker.show();
if (ret == nsIFilePicker.returnOK)
gSoundUrlBox.value = filepicker.file.path;
onSoundInput();
}
function previewSound() {
var soundUrl = gSoundUrlBox.value;
var sound = Components.classes["@mozilla.org/sound;1"]
.createInstance(Components.interfaces.nsISound);
if (soundUrl.indexOf("file://") == -1) {
sound.playSystemSound(soundUrl);
}
else {
var url = Components.classes["@mozilla.org/network/standard-url;1"]
.createInstance(Components.interfaces.nsIURL);
url.spec = soundUrl;
sound.play(url)
}
}
function enableSoundUrl(soundChecked) {
gSoundUrlBox.disabled = !soundChecked;
gSoundUrlButton.disabled = !soundChecked;
if (soundChecked && gSoundUrlBox.value) {
gPreviewSoundButton.disabled = false;
}
else
gPreviewSoundButton.disabled = true;
}
function onSoundInput() {
gPreviewSoundButton.disabled = gSoundUrlBox.value == "";
}
function viewPopups() {
window.openDialog("chrome://communicator/content/popupManager.xul", "",
"chrome,resizable=yes,modal=yes",
(gPolicyButton.value == "true"),
"",
true);
}
@ -179,29 +218,17 @@
<groupbox id="popupsArea">
<caption label="&popupBlocking.label;"/>
<description>&popupDetails;</description>
<hbox align="center">
<radiogroup id="popupPolicy" preftype="bool" prefstring="dom.disable_open_during_load">
<vbox flex="1">
<hbox>
<radio value="false" label="&popupAllow.label;"
oncommand="setButtons()"/>
<checkbox id="popupPolicy" label="&popupBlock.label;" accesskey="&popupBlock.accesskey;"
oncommand="setButtons()"
preftype="bool" prefstring="dom.disable_open_during_load"
prefattribute="checked"/>
<spacer flex="1"/>
<button id="exceptionsAllow" label="&popupViewAllow.label;"
accesskey="&popupViewAllow.accesskey;"
oncommand="viewPopups();"/>
</hbox>
<hbox>
<radio value="true" label="&popupBlock.label;"
oncommand="setButtons()"/>
<spacer flex="1"/>
<button id="exceptionsBlock" label="&popupViewBlock.label;"
accesskey="&popupViewBlock.accesskey;"
<button id="exceptionsButton" label="&popupExceptions.label;"
accesskey="&popupExceptions.accesskey;"
oncommand="viewPopups();"/>
</hbox>
</vbox>
</radiogroup>
</hbox>
<separator class="thin"/>
<description id="whenBlock">&whenBlock.description;</description>
<hbox align="center">
@ -209,9 +236,14 @@
oncommand="enableSoundUrl(this.checked);"
preftype="bool" prefstring="privacy.popups.sound_enabled"
prefattribute="checked"/>
<textbox flex="1" id="playSoundUrl" prefstring="privacy.popups.sound_url"/>
</hbox>
<hbox align="center">
<textbox flex="1" id="playSoundUrl"
prefstring="privacy.popups.sound_url" oninput="onSoundInput()"/>
<button id="selectSound" label="&selectSound.label;" accesskey="&selectSound.accesskey;"
filepickertitle="&selectSound.title;" oncommand="selectSound();"/>
<button id="previewSound" label="&previewSound.label;" accesskey="&previewSound.accesskey;"
oncommand="previewSound();"/>
</hbox>
<hbox align="center">
<checkbox id="displayIcon" label="&displayIcon.label;"
@ -221,6 +253,7 @@
<separator class="thin"/>
<description>&popupNote.description;</description>
<data id="prefillWhitelist" preftype="bool" prefattribute="value" prefstring="privacy.popups.prefill_whitelist"/>
<data id="removeBlacklist" preftype="bool" prefattribute="value" prefstring="privacy.popups.remove_blacklist"/>
</groupbox>
</page>

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

@ -2,26 +2,24 @@
<!ENTITY popupBlocking.label "Popup Windows">
<!ENTITY popupDetails "Specify how to handle popup windows that appear on top of or under the current Navigator window:">
<!ENTITY popupDesc.label "Specify how to handle popup windows that appear on top of or under the current Navigator window:">
<!ENTITY popupAllow.label "Allow popups">
<!ENTITY popupAllow.accesskey "A">
<!ENTITY popupBlock.label "Suppress popups">
<!ENTITY popupBlock.accesskey "S">
<!ENTITY popupBlock.label "Block unrequested popup windows">
<!ENTITY popupBlock.accesskey "B">
<!ENTITY popupViewAllow.label "Exceptions...">
<!ENTITY popupViewAllow.accesskey "x">
<!ENTITY popupViewBlock.label "Exceptions...">
<!ENTITY popupViewBlock.accesskey "c">
<!ENTITY popupExceptions.label "Allowed Sites...">
<!ENTITY popupExceptions.accesskey "A">
<!ENTITY whenBlock.description "When a popup window has been suppressed:">
<!ENTITY whenBlock.description "When a popup window has been blocked:">
<!ENTITY playSound.label "Play a sound:">
<!ENTITY selectSound.label "Select...">
<!ENTITY selectSound.accesskey "e">
<!ENTITY selectSound.title "Select Popup Suppress Sound">
<!ENTITY previewSound.label "Preview">
<!ENTITY previewSound.accesskey "r">
<!ENTITY selectSound.title "Select Popup Block Sound">
<!ENTITY displayIcon.label "Display an icon in the Navigator status bar">
<!ENTITY popupNote.description "Note: Suppressing all popups may prevent important features of some web sites from working, such as login windows for banks and shopping sites. For details of how to allow specific sites to use popups while suppressing all others, click Help. Even if suppressed, sites may use other methods to show popups.">
<!ENTITY popupNote.description "Note: Blocking all popups may prevent important features of some web sites from working, such as login windows for banks and shopping sites. For details of how to allow specific sites to use popups while blocking all others, click Help. Even if blocked, sites may use other methods to show popups.">