зеркало из https://github.com/mozilla/gecko-dev.git
Rework cookie dialogs to allow setting session-only cookies. Bug 230624, patch
by Mike Connor <mconnor@myrealbox.com>, r=mvl, sr=darin
This commit is contained in:
Родитель
91f18d4734
Коммит
16e457b12e
|
@ -386,11 +386,24 @@ nsCookiePermission::CanSetCookie(nsIURI *aURI,
|
|||
countFromHost, foundCookie,
|
||||
&rememberDecision, aResult);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (*aResult == nsICookiePromptService::ACCEPT_SESSION_COOKIE)
|
||||
*aIsSession = PR_TRUE;
|
||||
|
||||
if (rememberDecision) {
|
||||
mPermMgr->Add(aURI, kPermissionType,
|
||||
*aResult ? (PRUint32) nsIPermissionManager::ALLOW_ACTION
|
||||
: (PRUint32) nsIPermissionManager::DENY_ACTION);
|
||||
switch (*aResult) {
|
||||
case nsICookiePromptService::DENY_COOKIE:
|
||||
mPermMgr->Add(aURI, kPermissionType, (PRUint32) nsIPermissionManager::DENY_ACTION);
|
||||
break;
|
||||
case nsICookiePromptService::ACCEPT_COOKIE:
|
||||
mPermMgr->Add(aURI, kPermissionType, (PRUint32) nsIPermissionManager::ALLOW_ACTION);
|
||||
break;
|
||||
case nsICookiePromptService::ACCEPT_SESSION_COOKIE:
|
||||
mPermMgr->Add(aURI, kPermissionType, ACCESS_SESSION);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ nsCookiePromptService::CookieDialog(nsIDOMWindow *aParent,
|
|||
PRInt32 aCookiesFromHost,
|
||||
PRBool aChangingCookie,
|
||||
PRBool *aRememberDecision,
|
||||
PRBool *aAccept)
|
||||
PRInt32 *aAccept)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
|
@ -104,11 +104,11 @@ nsCookiePromptService::CookieDialog(nsIDOMWindow *aParent,
|
|||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// get back output parameters
|
||||
// GetInt returns a PRInt32; we need to sanitize it into PRBool
|
||||
PRBool tempValue;
|
||||
block->GetInt(nsICookieAcceptDialog::ACCEPT_COOKIE, &tempValue);
|
||||
*aAccept = (tempValue == 1);
|
||||
|
||||
*aAccept = tempValue;
|
||||
|
||||
// GetInt returns a PRInt32; we need to sanitize it into PRBool
|
||||
block->GetInt(nsICookieAcceptDialog::REMEMBER_DECISION, &tempValue);
|
||||
*aRememberDecision = (tempValue == 1);
|
||||
|
||||
|
|
|
@ -46,26 +46,30 @@ interface nsICookie;
|
|||
[scriptable, uuid(CE002B28-92B7-4701-8621-CC925866FB87)]
|
||||
interface nsICookiePromptService : nsISupports
|
||||
{
|
||||
const PRUint32 DENY_COOKIE = 0;
|
||||
const PRUint32 ACCEPT_COOKIE = 1;
|
||||
const PRUint32 ACCEPT_SESSION_COOKIE = 2;
|
||||
|
||||
/* Open a dialog that asks for permission to accept a cookie
|
||||
* Returns true when the permission is given.
|
||||
* return values are not modified when something fails.
|
||||
*
|
||||
* @param parent
|
||||
* @param cookie
|
||||
* @param hostname the host that wants to set the cookie,
|
||||
* not the domain: part of the cookie
|
||||
* @param cookiesFromHost the number of cookies there are already for this host
|
||||
* @param aChangingCookie are we changing this cookie?
|
||||
* @param checkValue is the decision remembered?
|
||||
* @param changingCookie are we changing this cookie?
|
||||
* @param rememberDecision should we set the matching permission for this host?
|
||||
* @returns 0 == deny cookie
|
||||
* 1 == accept cookie
|
||||
* 2 == accept cookie for current session
|
||||
*/
|
||||
|
||||
boolean cookieDialog(in nsIDOMWindow parent,
|
||||
in nsICookie cookie,
|
||||
in ACString hostname,
|
||||
in long cookiesFromHost,
|
||||
in boolean changingCookie,
|
||||
out boolean rememberDecision);
|
||||
long cookieDialog(in nsIDOMWindow parent,
|
||||
in nsICookie cookie,
|
||||
in ACString hostname,
|
||||
in long cookiesFromHost,
|
||||
in boolean changingCookie,
|
||||
out boolean rememberDecision);
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
const nsICookieAcceptDialog = Components.interfaces.nsICookieAcceptDialog;
|
||||
const nsIDialogParamBlock = Components.interfaces.nsIDialogParamBlock;
|
||||
const nsICookie = Components.interfaces.nsICookie;
|
||||
const nsICookiePromptService = Components.interfaces.nsICookiePromptService;
|
||||
|
||||
var params;
|
||||
var cookieBundle;
|
||||
|
@ -165,8 +166,11 @@ function showhideinfo()
|
|||
|
||||
function cookieAccept()
|
||||
{
|
||||
// say that the cookie was accepted
|
||||
params.SetInt(nsICookieAcceptDialog.ACCEPT_COOKIE, 1);
|
||||
// the cookie was accepted, now check whether it should be session-only and return accordingly
|
||||
if (document.getElementById('acceptSession').checked)
|
||||
params.SetInt(nsICookieAcceptDialog.ACCEPT_COOKIE, nsICookiePromptService.ACCEPT_SESSION_COOKIE);
|
||||
else
|
||||
params.SetInt(nsICookieAcceptDialog.ACCEPT_COOKIE, nsICookiePromptService.ACCEPT_COOKIE);
|
||||
// And remember that when needed
|
||||
params.SetInt(nsICookieAcceptDialog.REMEMBER_DECISION, document.getElementById('persistDomainAcceptance').checked);
|
||||
window.close();
|
||||
|
@ -175,7 +179,7 @@ function cookieAccept()
|
|||
function cookieDeny()
|
||||
{
|
||||
// say that the cookie was rejected
|
||||
params.SetInt(nsICookieAcceptDialog.ACCEPT_COOKIE, 0);
|
||||
params.SetInt(nsICookieAcceptDialog.ACCEPT_COOKIE, nsICookiePromptService.DENY_COOKIE);
|
||||
// And remember that when needed
|
||||
params.SetInt(nsICookieAcceptDialog.REMEMBER_DECISION, document.getElementById('persistDomainAcceptance').checked);
|
||||
window.close();
|
||||
|
|
|
@ -71,9 +71,17 @@
|
|||
<description id="dialog-header" class="header"/>
|
||||
</vbox>
|
||||
|
||||
<hbox id="acceptSessionContainer">
|
||||
<checkbox id="acceptSession"
|
||||
label="&dialog.acceptSession.label;"
|
||||
accesskey="&dialog.acceptSession.accesskey;"
|
||||
persist="checked"/>
|
||||
</hbox>
|
||||
|
||||
<hbox id="checkboxContainer">
|
||||
<checkbox id="persistDomainAcceptance"
|
||||
label="&dialog.remember.label;" accesskey="&dialog.remember.accesskey;"
|
||||
label="&dialog.remember.label;"
|
||||
accesskey="&dialog.remember.accesskey;"
|
||||
persist="checked"/>
|
||||
</hbox>
|
||||
</vbox>
|
||||
|
|
|
@ -15,3 +15,5 @@
|
|||
<!ENTITY dialog.title "Confirm">
|
||||
<!ENTITY dialog.remember.label "Use my choice for all cookies from this site">
|
||||
<!ENTITY dialog.remember.accesskey "U">
|
||||
<!ENTITY dialog.acceptSession.label "Accept for the current session only">
|
||||
<!ENTITY dialog.acceptSession.accesskey "S">
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
const nsICookieAcceptDialog = Components.interfaces.nsICookieAcceptDialog;
|
||||
const nsIDialogParamBlock = Components.interfaces.nsIDialogParamBlock;
|
||||
const nsICookie = Components.interfaces.nsICookie;
|
||||
const nsICookiePromptService = Components.interfaces.nsICookiePromptService;
|
||||
|
||||
var params;
|
||||
var cookieBundle;
|
||||
|
@ -165,8 +166,11 @@ function showhideinfo()
|
|||
|
||||
function cookieAccept()
|
||||
{
|
||||
// say that the cookie was accepted
|
||||
params.SetInt(nsICookieAcceptDialog.ACCEPT_COOKIE, 1);
|
||||
// the cookie was accepted, now check whether it should be session-only and return accordingly
|
||||
if (document.getElementById('acceptSession').checked)
|
||||
params.SetInt(nsICookieAcceptDialog.ACCEPT_COOKIE, nsICookiePromptService.ACCEPT_SESSION_COOKIE);
|
||||
else
|
||||
params.SetInt(nsICookieAcceptDialog.ACCEPT_COOKIE, nsICookiePromptService.ACCEPT_COOKIE);
|
||||
// And remember that when needed
|
||||
params.SetInt(nsICookieAcceptDialog.REMEMBER_DECISION, document.getElementById('persistDomainAcceptance').checked);
|
||||
window.close();
|
||||
|
@ -175,7 +179,7 @@ function cookieAccept()
|
|||
function cookieDeny()
|
||||
{
|
||||
// say that the cookie was rejected
|
||||
params.SetInt(nsICookieAcceptDialog.ACCEPT_COOKIE, 0);
|
||||
params.SetInt(nsICookieAcceptDialog.ACCEPT_COOKIE, nsICookiePromptService.DENY_COOKIE);
|
||||
// And remember that when needed
|
||||
params.SetInt(nsICookieAcceptDialog.REMEMBER_DECISION, document.getElementById('persistDomainAcceptance').checked);
|
||||
window.close();
|
||||
|
|
|
@ -71,9 +71,17 @@
|
|||
<description id="dialog-header" class="header"/>
|
||||
</vbox>
|
||||
|
||||
<hbox id="acceptSessionContainer">
|
||||
<checkbox id="acceptSession"
|
||||
label="&dialog.acceptSession.label;"
|
||||
accesskey="&dialog.acceptSession.accesskey;"
|
||||
persist="checked"/>
|
||||
</hbox>
|
||||
|
||||
<hbox id="checkboxContainer">
|
||||
<checkbox id="persistDomainAcceptance"
|
||||
label="&dialog.remember.label;" accesskey="&dialog.remember.accesskey;"
|
||||
label="&dialog.remember.label;"
|
||||
accesskey="&dialog.remember.accesskey;"
|
||||
persist="checked"/>
|
||||
</hbox>
|
||||
</vbox>
|
||||
|
|
|
@ -15,3 +15,5 @@
|
|||
<!ENTITY dialog.title "Confirm">
|
||||
<!ENTITY dialog.remember.label "Use my choice for all cookies from this site">
|
||||
<!ENTITY dialog.remember.accesskey "U">
|
||||
<!ENTITY dialog.acceptSession.label "Accept for the current session only">
|
||||
<!ENTITY dialog.acceptSession.accesskey "S">
|
||||
|
|
Загрузка…
Ссылка в новой задаче