зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1437057 - Expose the origin of a cookie to JS, r=mayhemer
Differential Revision: https://phabricator.services.mozilla.com/D67589 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
1de24ce2ba
Коммит
bd961ae216
|
@ -5734,7 +5734,7 @@ void Document::GetCookie(nsAString& aCookie, ErrorResult& rv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Document::SetCookie(const nsAString& aCookie, ErrorResult& rv) {
|
void Document::SetCookie(const nsAString& aCookie, ErrorResult& aRv) {
|
||||||
if (mDisableCookieAccess) {
|
if (mDisableCookieAccess) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -5742,7 +5742,7 @@ void Document::SetCookie(const nsAString& aCookie, ErrorResult& rv) {
|
||||||
// If the document's sandboxed origin flag is set, access to write cookies
|
// If the document's sandboxed origin flag is set, access to write cookies
|
||||||
// is prohibited.
|
// is prohibited.
|
||||||
if (mSandboxFlags & SANDBOXED_ORIGIN) {
|
if (mSandboxFlags & SANDBOXED_ORIGIN) {
|
||||||
rv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5761,31 +5761,49 @@ void Document::SetCookie(const nsAString& aCookie, ErrorResult& rv) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!mDocumentURI) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The code for getting the URI matches Navigator::CookieEnabled
|
||||||
|
nsCOMPtr<nsIURI> principalURI;
|
||||||
|
NodePrincipal()->GetURI(getter_AddRefs(principalURI));
|
||||||
|
|
||||||
|
if (!principalURI) {
|
||||||
|
// Document's principal is not a content or null (may be system), so
|
||||||
|
// can't set cookies
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsIChannel> channel(mChannel);
|
||||||
|
if (!channel) {
|
||||||
|
channel = CreateDummyChannelForCookies(principalURI);
|
||||||
|
if (!channel) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// not having a cookie service isn't an error
|
// not having a cookie service isn't an error
|
||||||
nsCOMPtr<nsICookieService> service =
|
nsCOMPtr<nsICookieService> service =
|
||||||
do_GetService(NS_COOKIESERVICE_CONTRACTID);
|
do_GetService(NS_COOKIESERVICE_CONTRACTID);
|
||||||
if (service && mDocumentURI) {
|
if (!service) {
|
||||||
// The code for getting the URI matches Navigator::CookieEnabled
|
return;
|
||||||
nsCOMPtr<nsIURI> principalURI;
|
}
|
||||||
NodePrincipal()->GetURI(getter_AddRefs(principalURI));
|
|
||||||
|
|
||||||
if (!principalURI) {
|
NS_ConvertUTF16toUTF8 cookie(aCookie);
|
||||||
// Document's principal is not a content or null (may be system), so
|
nsresult rv = service->SetCookieString(principalURI, cookie, channel);
|
||||||
// can't set cookies
|
|
||||||
|
|
||||||
return;
|
// No warning messages here.
|
||||||
}
|
if (NS_FAILED(rv)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIChannel> channel(mChannel);
|
nsCOMPtr<nsIObserverService> observerService =
|
||||||
if (!channel) {
|
mozilla::services::GetObserverService();
|
||||||
channel = CreateDummyChannelForCookies(principalURI);
|
if (observerService) {
|
||||||
if (!channel) {
|
observerService->NotifyObservers(ToSupports(this), "document-set-cookie",
|
||||||
return;
|
nsString(aCookie).get());
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_ConvertUTF16toUTF8 cookie(aCookie);
|
|
||||||
service->SetCookieString(principalURI, cookie, channel);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2125,7 +2125,6 @@ HttpBaseChannel::GetResponseVersion(uint32_t* major, uint32_t* minor) {
|
||||||
void HttpBaseChannel::NotifySetCookie(const nsACString& aCookie) {
|
void HttpBaseChannel::NotifySetCookie(const nsACString& aCookie) {
|
||||||
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
||||||
if (obs) {
|
if (obs) {
|
||||||
nsAutoString cookie;
|
|
||||||
obs->NotifyObservers(static_cast<nsIChannel*>(this),
|
obs->NotifyObservers(static_cast<nsIChannel*>(this),
|
||||||
"http-on-response-set-cookie",
|
"http-on-response-set-cookie",
|
||||||
NS_ConvertASCIItoUTF16(aCookie).get());
|
NS_ConvertASCIItoUTF16(aCookie).get());
|
||||||
|
|
Загрузка…
Ссылка в новой задаче