Bug 1570846 - Switch permissionsManager and cookieViewer to use Services.jsm. r=frg
This commit is contained in:
Родитель
7230d001ed
Коммит
0f09bcdb9c
|
@ -7,14 +7,6 @@
|
|||
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const {AppConstants} = ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
|
||||
|
||||
var kObserverService;
|
||||
|
||||
// interface variables
|
||||
var cookiemanager = null; // cookiemanager interface
|
||||
var permissionmanager = null; // permissionmanager interface
|
||||
var promptservice = null; // promptservice interface
|
||||
var gDateService = null;
|
||||
|
||||
// cookies and permissions list
|
||||
var cookies = [];
|
||||
var permissions = [];
|
||||
|
@ -22,9 +14,6 @@ var allCookies = [];
|
|||
var deletedCookies = [];
|
||||
var deletedPermissions = [];
|
||||
|
||||
const nsIPermissionManager = Ci.nsIPermissionManager;
|
||||
const nsICookiePermission = Ci.nsICookiePermission;
|
||||
|
||||
var cookieBundle;
|
||||
var gUpdatingBatch = "";
|
||||
|
||||
|
@ -33,14 +22,6 @@ function Startup() {
|
|||
// arguments passed to this routine:
|
||||
// cookieManager
|
||||
|
||||
// xpconnect to cookiemanager/permissionmanager/promptservice interfaces
|
||||
cookiemanager = Cc["@mozilla.org/cookiemanager;1"]
|
||||
.getService(Ci.nsICookieManager);
|
||||
permissionmanager = Cc["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Ci.nsIPermissionManager);
|
||||
promptservice = Cc["@mozilla.org/embedcomp/prompt-service;1"]
|
||||
.getService(Ci.nsIPromptService);
|
||||
|
||||
// intialize string bundle
|
||||
cookieBundle = document.getElementById("cookieBundle");
|
||||
|
||||
|
@ -51,9 +32,8 @@ function Startup() {
|
|||
loadPermissions();
|
||||
|
||||
// be prepared to reload the display if anything changes
|
||||
kObserverService = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
|
||||
kObserverService.addObserver(cookieReloadDisplay, "cookie-changed");
|
||||
kObserverService.addObserver(cookieReloadDisplay, "perm-changed");
|
||||
Services.obs.addObserver(cookieReloadDisplay, "cookie-changed", false);
|
||||
Services.obs.addObserver(cookieReloadDisplay, "perm-changed", false);
|
||||
|
||||
// filter the table if requested by caller
|
||||
if (window.arguments &&
|
||||
|
@ -65,8 +45,21 @@ function Startup() {
|
|||
}
|
||||
|
||||
function Shutdown() {
|
||||
kObserverService.removeObserver(cookieReloadDisplay, "cookie-changed");
|
||||
kObserverService.removeObserver(cookieReloadDisplay, "perm-changed");
|
||||
Services.obs.removeObserver(cookieReloadDisplay, "cookie-changed");
|
||||
Services.obs.removeObserver(cookieReloadDisplay, "perm-changed");
|
||||
}
|
||||
|
||||
function PromptConfirm(title, msg, yes) {
|
||||
var flags =
|
||||
((Services.prompt.BUTTON_TITLE_IS_STRING * Services.prompt.BUTTON_POS_0) +
|
||||
(Services.prompt.BUTTON_TITLE_CANCEL * Services.prompt.BUTTON_POS_1) +
|
||||
Services.prompt.BUTTON_POS_1_DEFAULT)
|
||||
return Services.prompt.confirmEx(window,
|
||||
cookieBundle.getString(title),
|
||||
cookieBundle.getString(msg),
|
||||
flags,
|
||||
cookieBundle.getString(yes),
|
||||
null, null, null, {value:0});
|
||||
}
|
||||
|
||||
var cookieReloadDisplay = {
|
||||
|
@ -91,8 +84,6 @@ function doSelectAll() {
|
|||
|
||||
/*** =================== COOKIES CODE =================== ***/
|
||||
|
||||
const nsICookie = Ci.nsICookie;
|
||||
|
||||
var cookiesTreeView = {
|
||||
rowCount : 0,
|
||||
setTree : function(tree){},
|
||||
|
@ -141,7 +132,7 @@ function Cookie(id, host, name, path, originAttributes, value,
|
|||
|
||||
function loadCookies() {
|
||||
// load cookies into a table
|
||||
var enumerator = cookiemanager.enumerator;
|
||||
var enumerator = Services.cookies.enumerator;
|
||||
var count = 0;
|
||||
while (enumerator.hasMoreElements()) {
|
||||
var nextCookie = enumerator.getNext();
|
||||
|
@ -239,15 +230,11 @@ function ClearCookieProperties() {
|
|||
}
|
||||
|
||||
function DeleteCookie() {
|
||||
if (cookiesTreeView.selection.count > 1) {
|
||||
var title = cookieBundle.getString("deleteSelectedCookiesTitle");
|
||||
var msg = cookieBundle.getString("deleteSelectedCookies");
|
||||
var flags = ((promptservice.BUTTON_TITLE_IS_STRING * promptservice.BUTTON_POS_0) +
|
||||
(promptservice.BUTTON_TITLE_CANCEL * promptservice.BUTTON_POS_1) +
|
||||
promptservice.BUTTON_POS_1_DEFAULT)
|
||||
var yes = cookieBundle.getString("deleteSelectedCookiesYes");
|
||||
if (promptservice.confirmEx(window, title, msg, flags, yes, null, null, null, {value:0}) == 1)
|
||||
return;
|
||||
if (cookiesTreeView.selection.count > 1 &&
|
||||
PromptConfirm("deleteSelectedCookiesTitle",
|
||||
"deleteSelectedCookies",
|
||||
"deleteSelectedCookiesYes") == 1) {
|
||||
return;
|
||||
}
|
||||
DeleteSelectedItemFromTree(cookiesTree, cookiesTreeView,
|
||||
cookies, deletedCookies,
|
||||
|
@ -265,14 +252,11 @@ function DeleteCookie() {
|
|||
}
|
||||
|
||||
function DeleteAllCookies() {
|
||||
var title = cookieBundle.getString("deleteAllCookiesTitle");
|
||||
var msg = cookieBundle.getString("deleteAllCookies");
|
||||
var flags = ((promptservice.BUTTON_TITLE_IS_STRING * promptservice.BUTTON_POS_0) +
|
||||
(promptservice.BUTTON_TITLE_CANCEL * promptservice.BUTTON_POS_1) +
|
||||
promptservice.BUTTON_POS_1_DEFAULT)
|
||||
var yes = cookieBundle.getString("deleteAllCookiesYes");
|
||||
if (promptservice.confirmEx(window, title, msg, flags, yes, null, null, null, {value:0}) == 1)
|
||||
if (PromptConfirm("deleteAllCookiesTitle",
|
||||
"deleteAllCookies",
|
||||
"deleteAllCookiesYes") == 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
ClearCookieProperties();
|
||||
DeleteAllFromTree(cookiesTree, cookiesTreeView,
|
||||
|
@ -285,11 +269,11 @@ function DeleteAllCookies() {
|
|||
function FinalizeCookieDeletions() {
|
||||
gUpdatingBatch = "cookie-changed";
|
||||
for (let delCookie of deletedCookies) {
|
||||
cookiemanager.remove(delCookie.host,
|
||||
delCookie.name,
|
||||
delCookie.path,
|
||||
document.getElementById("checkbox").checked,
|
||||
delCookie.originAttributes);
|
||||
Services.cookies.remove(delCookie.host,
|
||||
delCookie.name,
|
||||
delCookie.path,
|
||||
document.getElementById("checkbox").checked,
|
||||
delCookie.originAttributes);
|
||||
}
|
||||
deletedCookies.length = 0;
|
||||
gUpdatingBatch = "";
|
||||
|
@ -384,7 +368,7 @@ function Permission(id, principal, type, capability) {
|
|||
|
||||
function loadPermissions() {
|
||||
// load permissions into a table
|
||||
var enumerator = permissionmanager.enumerator;
|
||||
var enumerator = Services.perms.enumerator;
|
||||
var canStr = cookieBundle.getString("can");
|
||||
var canSessionStr = cookieBundle.getString("canSession");
|
||||
var cannotStr = cookieBundle.getString("cannot");
|
||||
|
@ -408,13 +392,13 @@ function loadPermissions() {
|
|||
|
||||
var capability;
|
||||
switch (nextPermission.capability) {
|
||||
case nsIPermissionManager.ALLOW_ACTION:
|
||||
case Ci.nsIPermissionManager.ALLOW_ACTION:
|
||||
capability = canStr;
|
||||
break;
|
||||
case nsIPermissionManager.DENY_ACTION:
|
||||
case Ci.nsIPermissionManager.DENY_ACTION:
|
||||
capability = cannotStr;
|
||||
break;
|
||||
case nsICookiePermission.ACCESS_SESSION:
|
||||
case Ci.nsICookiePermission.ACCESS_SESSION:
|
||||
capability = canSessionStr;
|
||||
break;
|
||||
default:
|
||||
|
@ -453,15 +437,11 @@ function PermissionSelected() {
|
|||
}
|
||||
|
||||
function DeletePermission() {
|
||||
if (permissionsTreeView.selection.count > 1) {
|
||||
var title = cookieBundle.getString("deleteSelectedSitesTitle");
|
||||
var msg = cookieBundle.getString("deleteSelectedCookiesSites");
|
||||
var flags = ((promptservice.BUTTON_TITLE_IS_STRING * promptservice.BUTTON_POS_0) +
|
||||
(promptservice.BUTTON_TITLE_CANCEL * promptservice.BUTTON_POS_1) +
|
||||
promptservice.BUTTON_POS_1_DEFAULT)
|
||||
var yes = cookieBundle.getString("deleteSelectedSitesYes");
|
||||
if (promptservice.confirmEx(window, title, msg, flags, yes, null, null, null, {value:0}) == 1)
|
||||
return;
|
||||
if (permissionsTreeView.selection.count > 1 &&
|
||||
PromptConfirm("deleteSelectedSitesTitle",
|
||||
"deleteSelectedCookiesSites",
|
||||
"deleteSelectedSitesYes") == 1) {
|
||||
return;
|
||||
}
|
||||
DeleteSelectedItemFromTree(permissionsTree, permissionsTreeView,
|
||||
permissions, deletedPermissions,
|
||||
|
@ -481,11 +461,8 @@ function setCookiePermissions(action) {
|
|||
return;
|
||||
}
|
||||
|
||||
var ioService = Cc["@mozilla.org/network/io-service;1"]
|
||||
.getService(Ci.nsIIOService);
|
||||
|
||||
try {
|
||||
var uri = ioService.newURI(url);
|
||||
var uri = Services.io.newURI(url);
|
||||
} catch (e) {
|
||||
// show an error if URI can not be constructed or adding it failed
|
||||
window.alert(cookieBundle.getString("errorAddPermission"));
|
||||
|
@ -500,8 +477,8 @@ function setCookiePermissions(action) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (permissionmanager.testPermission(uri, "cookie") != action)
|
||||
permissionmanager.add(uri, "cookie", action);
|
||||
if (Services.perms.testPermission(uri, "cookie") != action)
|
||||
Services.perms.add(uri, "cookie", action);
|
||||
|
||||
site.focus();
|
||||
site.value = "";
|
||||
|
@ -519,14 +496,11 @@ function buttonEnabling(textfield) {
|
|||
}
|
||||
|
||||
function DeleteAllPermissions() {
|
||||
var title = cookieBundle.getString("deleteAllSitesTitle");
|
||||
var msg = cookieBundle.getString("deleteAllCookiesSites");
|
||||
var flags = ((promptservice.BUTTON_TITLE_IS_STRING * promptservice.BUTTON_POS_0) +
|
||||
(promptservice.BUTTON_TITLE_CANCEL * promptservice.BUTTON_POS_1) +
|
||||
promptservice.BUTTON_POS_1_DEFAULT)
|
||||
var yes = cookieBundle.getString("deleteAllSitesYes");
|
||||
if (promptservice.confirmEx(window, title, msg, flags, yes, null, null, null, {value:0}) == 1)
|
||||
if (PromptConfirm("deleteAllSitesTitle",
|
||||
"deleteAllCookiesSites",
|
||||
"deleteAllSitesYes") == 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
DeleteAllFromTree(permissionsTree, permissionsTreeView,
|
||||
permissions, deletedPermissions,
|
||||
|
@ -540,7 +514,7 @@ function FinalizePermissionDeletions() {
|
|||
|
||||
gUpdatingBatch = "perm-changed";
|
||||
for (let permission of deletedPermissions)
|
||||
permissionmanager.removeFromPrincipal(permission.principal, permission.type);
|
||||
Services.perms.removeFromPrincipal(permission.principal, permission.type);
|
||||
deletedPermissions.length = 0;
|
||||
gUpdatingBatch = "";
|
||||
}
|
||||
|
|
|
@ -154,13 +154,13 @@
|
|||
<textbox id="cookie-site" flex="1" oninput="buttonEnabling(this);"/>
|
||||
<button id="btnBlock" label="&blockSite.label;" disabled="true"
|
||||
accesskey="&blockSite.accesskey;"
|
||||
oncommand="setCookiePermissions(nsIPermissionManager.DENY_ACTION);"/>
|
||||
oncommand="setCookiePermissions(Ci.nsIPermissionManager.DENY_ACTION);"/>
|
||||
<button id="btnSession" label="&allowSiteSession.label;" disabled="true"
|
||||
accesskey="&allowSiteSession.accesskey;"
|
||||
oncommand="setCookiePermissions(nsICookiePermission.ACCESS_SESSION);"/>
|
||||
oncommand="setCookiePermissions(Ci.nsICookiePermission.ACCESS_SESSION);"/>
|
||||
<button id="btnAllow" label="&allowSite.label;" disabled="true"
|
||||
accesskey="&allowSite.accesskey;"
|
||||
oncommand="setCookiePermissions(nsIPermissionManager.ALLOW_ACTION);"/>
|
||||
oncommand="setCookiePermissions(Ci.nsIPermissionManager.ALLOW_ACTION);"/>
|
||||
</hbox>
|
||||
<separator class="thin"/>
|
||||
<tree id="permissionsTree"
|
||||
|
|
|
@ -2,10 +2,7 @@
|
|||
* 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/. */
|
||||
|
||||
const nsIPermissionManager = Ci.nsIPermissionManager;
|
||||
const nsICookiePermission = Ci.nsICookiePermission;
|
||||
|
||||
var permissionManager;
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
var additions = [];
|
||||
var removals = [];
|
||||
|
@ -44,9 +41,6 @@ var permissionsBundle;
|
|||
function Startup() {
|
||||
var introText, windowTitle;
|
||||
|
||||
permissionManager = Cc["@mozilla.org/permissionmanager;1"]
|
||||
.getService(nsIPermissionManager);
|
||||
|
||||
permissionsTree = document.getElementById("permissionsTree");
|
||||
|
||||
permissionsBundle = document.getElementById("permissionsBundle");
|
||||
|
@ -127,7 +121,7 @@ function btnDisable(aDisabled) {
|
|||
}
|
||||
|
||||
function loadPermissions() {
|
||||
var enumerator = permissionManager.enumerator;
|
||||
var enumerator = Services.perms.enumerator;
|
||||
var count = 0;
|
||||
var permission;
|
||||
|
||||
|
@ -155,14 +149,14 @@ function loadPermissions() {
|
|||
function capabilityString(aCapability) {
|
||||
var capability = null;
|
||||
switch (aCapability) {
|
||||
case nsIPermissionManager.ALLOW_ACTION:
|
||||
case Ci.nsIPermissionManager.ALLOW_ACTION:
|
||||
capability = "can";
|
||||
break;
|
||||
case nsIPermissionManager.DENY_ACTION:
|
||||
case Ci.nsIPermissionManager.DENY_ACTION:
|
||||
capability = "cannot";
|
||||
break;
|
||||
// we should only ever hit this for cookies
|
||||
case nsICookiePermission.ACCESS_SESSION:
|
||||
case Ci.nsICookiePermission.ACCESS_SESSION:
|
||||
capability = "canSession";
|
||||
break;
|
||||
default:
|
||||
|
@ -185,7 +179,7 @@ function permissionColumnSort(aColumn, aUpdateSelection) {
|
|||
}
|
||||
|
||||
function permissionSelected() {
|
||||
if (permissionManager) {
|
||||
if (Services.perms) {
|
||||
var selections = GetTreeSelections(permissionsTree);
|
||||
document.getElementById("removePermission").disabled = (selections.length < 1);
|
||||
}
|
||||
|
@ -202,14 +196,12 @@ function deleteAllPermissions() {
|
|||
}
|
||||
|
||||
function finalizeChanges() {
|
||||
var ioService = Cc["@mozilla.org/network/io-service;1"]
|
||||
.getService(Ci.nsIIOService);
|
||||
var i, p;
|
||||
|
||||
for (i in removals) {
|
||||
p = removals[i];
|
||||
try {
|
||||
permissionManager.remove(p.host, p.type);
|
||||
Services.perms.remove(p.host, p.type);
|
||||
} catch(ex) {
|
||||
}
|
||||
}
|
||||
|
@ -217,8 +209,8 @@ function finalizeChanges() {
|
|||
for (i in additions) {
|
||||
p = additions[i];
|
||||
try {
|
||||
var uri = ioService.newURI("http://" + p.host);
|
||||
permissionManager.add(uri, p.type, p.perm);
|
||||
var uri = Services.io.newURI("http://" + p.host);
|
||||
Services.perms.add(uri, p.type, p.perm);
|
||||
} catch(ex) {
|
||||
}
|
||||
}
|
||||
|
@ -235,16 +227,12 @@ function addPermission(aPermission) {
|
|||
// trim any leading and trailing spaces and scheme
|
||||
var host = trimSpacesAndScheme(textbox.value);
|
||||
try {
|
||||
var ioService = Cc["@mozilla.org/network/io-service;1"]
|
||||
.getService(Ci.nsIIOService);
|
||||
var uri = ioService.newURI("http://" + host);
|
||||
var uri = Services.io.newURI("http://" + host);
|
||||
host = uri.host;
|
||||
} catch(ex) {
|
||||
var promptService = Cc["@mozilla.org/embedcomp/prompt-service;1"]
|
||||
.getService(Ci.nsIPromptService);
|
||||
var message = permissionsBundle.getFormattedString("alertInvalid", [host]);
|
||||
var title = permissionsBundle.getString("alertInvalidTitle");
|
||||
promptService.alert(window, title, message);
|
||||
Services.prompt.alert(window, title, message);
|
||||
textbox.value = "";
|
||||
textbox.focus();
|
||||
handleHostInput(textbox);
|
||||
|
|
|
@ -37,11 +37,11 @@
|
|||
</hbox>
|
||||
<hbox pack="end">
|
||||
<button id="btnBlock" disabled="true" accesskey="&block.accesskey;"
|
||||
label="&block.label;" oncommand="addPermission(nsIPermissionManager.DENY_ACTION);"/>
|
||||
label="&block.label;" oncommand="addPermission(Ci.nsIPermissionManager.DENY_ACTION);"/>
|
||||
<button id="btnSession" disabled="true" accesskey="&session.accesskey;"
|
||||
label="&session.label;" oncommand="addPermission(nsICookiePermission.ACCESS_SESSION);"/>
|
||||
label="&session.label;" oncommand="addPermission(Ci.nsICookiePermission.ACCESS_SESSION);"/>
|
||||
<button id="btnAllow" disabled="true" accesskey="&allow.accesskey;"
|
||||
label="&allow.label;" oncommand="addPermission(nsIPermissionManager.ALLOW_ACTION);"/>
|
||||
label="&allow.label;" oncommand="addPermission(Ci.nsIPermissionManager.ALLOW_ACTION);"/>
|
||||
</hbox>
|
||||
<separator class="thin"/>
|
||||
<tree id="permissionsTree" flex="1" style="height: 18em;"
|
||||
|
|
Загрузка…
Ссылка в новой задаче