Bug 1288557 - Part 1: Replace custom exceptions dialog with usage of permissions. r=MattN

MozReview-Commit-ID: 25fD9IJIVt0

--HG--
extra : rebase_source : 883976c1311db15d96bd6100e07f0ea09f576df5
This commit is contained in:
Steve Chung 2016-08-30 16:53:03 +08:00
Родитель d0d9263c81
Коммит 1ea8e5606c
11 изменённых файлов: 81 добавлений и 217 удалений

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

@ -127,7 +127,20 @@ var gSecurityPane = {
*/
showPasswordExceptions: function ()
{
gSubDialog.open("chrome://passwordmgr/content/passwordManagerExceptions.xul");
var bundlePrefs = document.getElementById("bundlePreferences");
var params = {
blockVisible: true,
sessionVisible: false,
allowVisible: false,
hideStatusColumn: true,
prefilledHost: "",
permissionType: "login-saving",
windowTitle: bundlePrefs.getString("savedLoginsExceptions_title"),
introText: bundlePrefs.getString("savedLoginsExceptions_desc")
};
gSubDialog.open("chrome://browser/content/preferences/permissions.xul",
null, params);
},
/**

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

@ -4,8 +4,8 @@
- 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/. -->
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<?xml-stylesheet href="chrome://browser/skin/preferences/preferences.css" type="text/css"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<?xml-stylesheet href="chrome://browser/skin/preferences/preferences.css" type="text/css"?>
<!DOCTYPE dialog SYSTEM "chrome://browser/locale/preferences/permissions.dtd" >
@ -34,7 +34,7 @@
<separator class="thin"/>
<label id="urlLabel" control="url" value="&address.label;" accesskey="&address.accesskey;"/>
<hbox align="start">
<textbox id="url" flex="1"
<textbox id="url" flex="1"
oninput="gPermissionManager.onHostInput(event.target);"
onkeypress="gPermissionManager.onHostKeyPress(event);"/>
</hbox>
@ -69,7 +69,7 @@
oncommand="gPermissionManager.onPermissionDeleted();"/>
<button id="removeAllPermissions"
icon="clear" label="&removeallpermissions.label;"
accesskey="&removeallpermissions.accesskey;"
accesskey="&removeallpermissions.accesskey;"
oncommand="gPermissionManager.onAllPermissionsDeleted();"/>
</hbox>
<spacer flex="1"/>

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

@ -31,6 +31,8 @@ notificationspermissionstext4=Control which websites are always or never allowed
notificationspermissionstitle=Notification Permissions
invalidURI=Please enter a valid hostname
invalidURITitle=Invalid Hostname Entered
savedLoginsExceptions_title=Exceptions - Saved Logins
savedLoginsExceptions_desc=Logins for the following sites will not be saved:
#### Block List Manager
@ -126,7 +128,7 @@ cookiesFiltered=The following cookies match your search:
# http://developer.mozilla.org/en/docs/Localization_and_Plurals
# If you need to display the number of selected elements in your language,
# you can use #1 in your localization as a placeholder for the number.
# For example this is the English string with numbers:
# For example this is the English string with numbers:
# removeSelectedCookied=Remove #1 Selected;Remove #1 Selected
removeSelectedCookies=Remove Selected;Remove Selected
defaultUserContextLabel=None

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

@ -15,12 +15,9 @@ var passwordmanager = null;
// password-manager lists
var signons = [];
var rejects = [];
var deletedSignons = [];
var deletedRejects = [];
var signonsTree;
var rejectsTree;
var showingPasswords = false;
@ -34,7 +31,6 @@ function Startup() {
kObserverService.addObserver(signonReloadDisplay, "passwordmgr-storage-changed", false);
signonsTree = document.getElementById("signonsTree");
rejectsTree = document.getElementById("rejectsTree");
}
function Shutdown() {
@ -59,17 +55,6 @@ var signonReloadDisplay = {
_filterPasswords();
}
break;
case "hostSavingEnabled":
case "hostSavingDisabled":
if (!rejectsTree) {
return;
}
rejects.length = 0;
if (lastRejectSortColumn == "hostname") {
lastRejectSortAscending = !lastRejectSortAscending; // prevents sort from being reversed
}
LoadRejects();
break;
}
kObserverService.notifyObservers(null, "passwordmgr-dialog-updated", null);
}

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

@ -1,115 +0,0 @@
/* 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/. */
/*** =================== REJECTED SIGNONS CODE =================== ***/
Components.utils.import("resource://gre/modules/AppConstants.jsm");
function RejectsStartup() {
LoadRejects();
let treecols = document.getElementsByTagName("treecols")[0];
treecols.addEventListener("click", HandleTreeColumnClick.bind(null, RejectColumnSort));
}
var rejectsTreeView = {
rowCount : 0,
setTree : function(tree) {},
getImageSrc : function(row, column) {},
getProgressMode : function(row, column) {},
getCellValue : function(row, column) {},
getCellText : function(row, column) {
var rv="";
if (column.id=="rejectCol") {
rv = rejects[row].host;
}
return rv;
},
isSeparator : function(index) { return false; },
isSorted: function() { return false; },
isContainer : function(index) { return false; },
cycleHeader : function(column) {},
getRowProperties : function(row) { return ""; },
getColumnProperties : function(column) { return ""; },
getCellProperties : function(row, column) {
if (column.element.getAttribute("id") == "rejectCol")
return "ltr";
return "";
}
};
function Reject(number, host) {
this.number = number;
this.host = host;
}
function LoadRejects() {
var hosts = passwordmanager.getAllDisabledHosts();
rejects = hosts.map(function(host, i) { return new Reject(i, host); });
rejectsTreeView.rowCount = rejects.length;
// sort and display the table
rejectsTree.view = rejectsTreeView;
RejectColumnSort(lastRejectSortColumn);
var element = document.getElementById("removeAllRejects");
if (rejects.length == 0) {
element.setAttribute("disabled", "true");
} else {
element.removeAttribute("disabled");
}
}
function RejectSelected() {
var selections = GetTreeSelections(rejectsTree);
if (selections.length) {
document.getElementById("removeReject").removeAttribute("disabled");
}
}
function DeleteReject() {
DeleteSelectedItemFromTree(rejectsTree, rejectsTreeView,
rejects, deletedRejects,
"removeReject", "removeAllRejects");
FinalizeRejectDeletions();
}
function DeleteAllRejects() {
DeleteAllFromTree(rejectsTree, rejectsTreeView,
rejects, deletedRejects,
"removeReject", "removeAllRejects");
FinalizeRejectDeletions();
}
function FinalizeRejectDeletions() {
for (var r=0; r<deletedRejects.length; r++) {
passwordmanager.setLoginSavingEnabled(deletedRejects[r].host, true);
}
deletedRejects.length = 0;
}
function HandleRejectKeyPress(e) {
if (e.keyCode == KeyEvent.DOM_VK_DELETE ||
(AppConstants.platform == "macosx" &&
e.keyCode == KeyEvent.DOM_VK_BACK_SPACE))
{
DeleteReject();
}
}
var lastRejectSortColumn = "host";
var lastRejectSortAscending = false;
function RejectColumnSort(column) {
lastRejectSortAscending =
SortTree(rejectsTree, rejectsTreeView, rejects,
column, lastRejectSortColumn, lastRejectSortAscending);
lastRejectSortColumn = column;
// set the sortDirection attribute to get the styling going
var sortedCol = document.getElementById("rejectCol");
sortedCol.setAttribute("sortDirection", lastRejectSortAscending ?
"ascending" : "descending");
}

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

@ -1,49 +0,0 @@
<?xml version="1.0"?> <!-- -*- Mode: SGML; indent-tabs-mode: nil -*- -->
<!-- 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/. -->
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<!DOCTYPE dialog SYSTEM "chrome://passwordmgr/locale/passwordManager.dtd" >
<prefwindow id="SignonViewerExceptionDialog"
windowtype="Toolkit:PasswordManagerExceptions"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
buttons="accept"
buttonlabelaccept="&closebutton.label;"
onload="Startup(); RejectsStartup();"
onunload="Shutdown();"
title="&savedLoginsExceptions.title;"
persist="width height screenX screenY">
<prefpane id="SignonViewerDialogPane" flex="1">
<script type="application/javascript" src="chrome://passwordmgr/content/passwordManagerCommon.js"/>
<script type="application/javascript" src="chrome://passwordmgr/content/passwordManagerExceptions.js"/>
<vbox id="rejectedsites" flex="1">
<description control="rejectsTree">&savedLoginsExceptions.desc;</description>
<separator class="thin"/>
<tree id="rejectsTree" flex="1" style="height: 10em;" hidecolumnpicker="true"
onkeypress="HandleRejectKeyPress(event)"
onselect="RejectSelected();">
<treecols>
<treecol id="rejectCol" label="&treehead.site.label;" flex="5"
data-field-name="host" sortDirection="ascending"/>
</treecols>
<treechildren/>
</tree>
<separator class="thin"/>
<hbox>
<button id="removeReject" disabled="true" icon="remove"
accesskey="&remove.accesskey;"
label="&remove.label;" oncommand="DeleteReject();"/>
<button id="removeAllRejects"
accesskey="&removeall.accesskey;"
icon="clear" label="&removeall.label;"
oncommand="DeleteAllRejects();"/>
</hbox>
</vbox>
</prefpane>
</prefwindow>

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

@ -7,7 +7,5 @@ toolkit.jar:
content/passwordmgr/login.xml (content/login.xml)
* content/passwordmgr/passwordManager.xul (content/passwordManager.xul)
content/passwordmgr/passwordManager.js (content/passwordManager.js)
content/passwordmgr/passwordManagerExceptions.js (content/passwordManagerExceptions.js)
content/passwordmgr/passwordManagerExceptions.xul (content/passwordManagerExceptions.xul)
content/passwordmgr/passwordManagerCommon.js (content/passwordManagerCommon.js)
content/passwordmgr/recipes.json (content/recipes.json)

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

@ -38,6 +38,7 @@ support-files =
subtst_notifications_change_p.html
[browser_DOMFormHasPassword.js]
[browser_DOMInputPasswordAdded.js]
[browser_exceptions_dialog.js]
[browser_filldoorhanger.js]
[browser_formless_submit_chrome.js]
[browser_hasInsecureLoginForms.js]

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

@ -0,0 +1,56 @@
"use strict";
const LOGIN_HOST = "http://example.com";
function openExceptionsDialog() {
return window.openDialog(
"chrome://browser/content/preferences/permissions.xul",
"Toolkit:PasswordManagerExceptions", "",
{
blockVisible: true,
sessionVisible: false,
allowVisible: false,
hideStatusColumn: true,
prefilledHost: "",
permissionType: "login-saving"
}
);
}
function countDisabledHosts(dialog) {
let doc = dialog.document;
let rejectsTree = doc.getElementById("permissionsTree");
return rejectsTree.view.rowCount;
}
function promiseStorageChanged(expectedData) {
function observer(subject, data) {
return data == expectedData && subject.QueryInterface(Ci.nsISupportsString).data == LOGIN_HOST;
}
return TestUtils.topicObserved("passwordmgr-storage-changed", observer);
}
add_task(function* test_disable() {
let dialog = openExceptionsDialog();
let promiseChanged = promiseStorageChanged("hostSavingDisabled");
yield BrowserTestUtils.waitForEvent(dialog, "load");
Services.logins.setLoginSavingEnabled(LOGIN_HOST, false);
yield promiseChanged;
is(countDisabledHosts(dialog), 1, "Verify disabled host added");
yield BrowserTestUtils.closeWindow(dialog);
});
add_task(function* test_enable() {
let dialog = openExceptionsDialog();
let promiseChanged = promiseStorageChanged("hostSavingEnabled");
yield BrowserTestUtils.waitForEvent(dialog, "load");
Services.logins.setLoginSavingEnabled(LOGIN_HOST, true);
yield promiseChanged;
is(countDisabledHosts(dialog), 0, "Verify disabled host removed");
yield BrowserTestUtils.closeWindow(dialog);
});

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

@ -12,9 +12,7 @@ function test() {
let pmDialog = window.openDialog(
"chrome://passwordmgr/content/passwordManager.xul",
"Toolkit:PasswordManager", "");
let pmexDialog = window.openDialog(
"chrome://passwordmgr/content/passwordManagerExceptions.xul",
"Toolkit:PasswordManagerExceptions", "");
let logins = [];
let loginCounter = 0;
let loginOrder = null;
@ -48,14 +46,6 @@ function test() {
is(countLogins(), 0, "Verify all logins removed");
runNextTest();
break;
case 9:
is(countDisabledHosts(), 1, "Verify disabled host added");
runNextTest();
break;
case 10:
is(countDisabledHosts(), 0, "Verify disabled host removed");
runNextTest();
break;
}
}
}
@ -75,12 +65,6 @@ function test() {
is(logins.length, LOGIN_COUNT, "Verify logins created");
}
function countDisabledHosts() {
let doc = pmexDialog.document;
let rejectsTree = doc.getElementById("rejectsTree");
return rejectsTree.view.rowCount;
}
function countLogins() {
let doc = pmDialog.document;
let signonsTree = doc.getElementById("signonsTree");
@ -134,19 +118,10 @@ function test() {
case 8: // remove all logins
Services.logins.removeAllLogins();
break;
case 9: // save a disabled host
pmDialog.close();
SimpleTest.waitForFocus(function() {
Services.logins.setLoginSavingEnabled(LOGIN_HOST, false);
}, pmexDialog);
break;
case 10: // remove a disabled host
Services.logins.setLoginSavingEnabled(LOGIN_HOST, true);
break;
case 11: // finish
case 9: // finish
Services.obs.removeObserver(
testObserver, "passwordmgr-dialog-updated", false);
pmexDialog.close();
pmDialog.close();
finish();
break;
}

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

@ -3,8 +3,6 @@
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<!ENTITY savedLogins.title "Saved Logins">
<!ENTITY savedLoginsExceptions.title "Exceptions - Saved Logins">
<!ENTITY savedLoginsExceptions.desc "Logins for the following sites will not be saved:">
<!ENTITY closebutton.label "Close">
<!ENTITY closebutton.accesskey "C">