Bug 1434252 - nsICookieService may throw an error in certain circumstances, so let's make SessionCookies::restore infallible. r?dao
Please see
bug 1462402 for more details and the root cause.
SessionCookies.jsm uses nsICookieService::CookieExists and nsICookieService::Add
to restore session-cookies. These currently throw for hostnames that contain a
leading '.' and maybe other cases, so we need to wrap the calls in a try..catch
block to prevent breakage, leading to an unrestored session.
MozReview-Commit-ID: 9gZ7K6lwcQF
--- a/browser/components/sessionstore/SessionCookies.jsm
+++ b/browser/components/sessionstore/SessionCookies.jsm
@@ -52,20 +52,30 @@ var SessionCookiesInternal = {
let expiry = "expiry" in cookie ? cookie.expiry : MAX_EXPIRY;
let cookieObj = {
host: cookie.host,
path: cookie.path || "",
name: cookie.name || ""
};
let originAttributes = cookie.originAttributes || {};
- if (!Services.cookies.cookieExists(cookieObj, originAttributes)) {
- Services.cookies.add(cookie.host, cookie.path || "", cookie.name || "",
- cookie.value, !!cookie.secure, !!cookie.httponly,
- /* isSession = */ true, expiry, originAttributes);
+ let exists = false;
+ try {
+ exists = Services.cookies.cookieExists(cookieObj, originAttributes);
+ } catch (ex) {
+ Cu.reportError(`nsCookieService::CookieExists failed with error '${ex}' for '${JSON.stringify(cookie)}'.`);
+ }
+ if (!exists) {
+ try {
+ Services.cookies.add(cookie.host, cookie.path || "", cookie.name || "",
+ cookie.value, !!cookie.secure, !!cookie.httponly,
+ /* isSession = */ true, expiry, originAttributes);
+ } catch (ex) {
+ Cu.reportError(`nsCookieService::Add failed with error '${ex}' for cookie ${JSON.stringify(cookie)}.`);
+ }
}
}
},
/**
* Handles observers notifications that are sent whenever cookies are added,
* changed, or removed. Ensures that the storage is updated accordingly.
*/