| Index: chrome/android/java/src/org/chromium/chrome/browser/cookies/CanonicalCookie.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/cookies/CanonicalCookie.java b/chrome/android/java/src/org/chromium/chrome/browser/cookies/CanonicalCookie.java
|
| index eead2a8143cd2a0b0c936f61b537e87c74846f5f..c8d67b5dc21bdc64b43c738a4ef8e25b6da2e3e9 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/cookies/CanonicalCookie.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/cookies/CanonicalCookie.java
|
| @@ -7,9 +7,13 @@ package org.chromium.chrome.browser.cookies;
|
| import java.io.DataInputStream;
|
| import java.io.DataOutputStream;
|
| import java.io.IOException;
|
| +import java.util.ArrayList;
|
| +import java.util.List;
|
|
|
| /**
|
| * Java representation of net/cookies/canonical_cookie.h.
|
| + *
|
| + * Also has static methods serialize Cookies.
|
| */
|
| class CanonicalCookie {
|
| private final String mUrl;
|
| @@ -22,13 +26,13 @@ class CanonicalCookie {
|
| private final long mLastAccess;
|
| private final boolean mSecure;
|
| private final boolean mHttpOnly;
|
| - private final boolean mSameSite;
|
| + private final int mSameSite;
|
| private final int mPriority;
|
|
|
| /** Constructs a CanonicalCookie */
|
| CanonicalCookie(String url, String name, String value, String domain, String path,
|
| long creation, long expiration, long lastAccess, boolean secure, boolean httpOnly,
|
| - boolean sameSite, int priority) {
|
| + int sameSite, int priority) {
|
| mUrl = url;
|
| mName = name;
|
| mValue = value;
|
| @@ -53,8 +57,8 @@ class CanonicalCookie {
|
| return mHttpOnly;
|
| }
|
|
|
| - /** @return True if the cookie is Same-Site. */
|
| - boolean isSameSite() {
|
| + /** @return SameSite enum */
|
| + int getSameSite() {
|
| return mSameSite;
|
| }
|
|
|
| @@ -103,13 +107,63 @@ class CanonicalCookie {
|
| return mValue;
|
| }
|
|
|
| - /**
|
| - * Serializes for saving to disk. Does not close the stream.
|
| - * It is up to the caller to do so.
|
| - *
|
| - * @param out Stream to write the cookie to.
|
| - */
|
| - void saveToStream(DataOutputStream out) throws IOException {
|
| + // Note incognito state cannot persist across app installs since the encryption key is stored
|
| + // in the activity state bundle. So the version here is more of a guard than a real version
|
| + // used for format migrations.
|
| + private static final int SERIALIZATION_VERSION = 20160426;
|
| +
|
| + static void saveListToStream(DataOutputStream out, CanonicalCookie[] cookies)
|
| + throws IOException {
|
| + if (out == null) {
|
| + throw new IllegalArgumentException("out arg is null");
|
| + }
|
| + if (cookies == null) {
|
| + throw new IllegalArgumentException("cookies arg is null");
|
| + }
|
| + for (CanonicalCookie cookie : cookies) {
|
| + if (cookie == null) {
|
| + throw new IllegalArgumentException("cookies arg contains null value");
|
| + }
|
| + }
|
| +
|
| + int length = cookies.length;
|
| + out.writeInt(SERIALIZATION_VERSION);
|
| + out.writeInt(length);
|
| + for (int i = 0; i < length; ++i) {
|
| + cookies[i].saveToStream(out);
|
| + }
|
| + }
|
| +
|
| + // Not private for tests.
|
| + static class UnexpectedFormatException extends Exception {
|
| + public UnexpectedFormatException(String message) {
|
| + super(message);
|
| + }
|
| + }
|
| +
|
| + static List<CanonicalCookie> readListFromStream(DataInputStream in)
|
| + throws IOException, UnexpectedFormatException {
|
| + if (in == null) {
|
| + throw new IllegalArgumentException("in arg is null");
|
| + }
|
| +
|
| + final int version = in.readInt();
|
| + if (version != SERIALIZATION_VERSION) {
|
| + throw new UnexpectedFormatException("Unexpected version");
|
| + }
|
| + final int length = in.readInt();
|
| + if (length < 0) {
|
| + throw new UnexpectedFormatException("Negative length: " + length);
|
| + }
|
| +
|
| + ArrayList<CanonicalCookie> cookies = new ArrayList<>(length);
|
| + for (int i = 0; i < length; ++i) {
|
| + cookies.add(createFromStream(in));
|
| + }
|
| + return cookies;
|
| + }
|
| +
|
| + private void saveToStream(DataOutputStream out) throws IOException {
|
| out.writeUTF(mUrl);
|
| out.writeUTF(mName);
|
| out.writeUTF(mValue);
|
| @@ -120,20 +174,13 @@ class CanonicalCookie {
|
| out.writeLong(mLastAccess);
|
| out.writeBoolean(mSecure);
|
| out.writeBoolean(mHttpOnly);
|
| - out.writeBoolean(mSameSite);
|
| + out.writeInt(mSameSite);
|
| out.writeInt(mPriority);
|
| }
|
|
|
| - /**
|
| - * Constructs a cookie by deserializing a single entry from the
|
| - * input stream.
|
| - *
|
| - * @param in Stream to read a cookie entry from.
|
| - */
|
| - static CanonicalCookie createFromStream(DataInputStream in)
|
| - throws IOException {
|
| + private static CanonicalCookie createFromStream(DataInputStream in) throws IOException {
|
| return new CanonicalCookie(in.readUTF(), in.readUTF(), in.readUTF(), in.readUTF(),
|
| in.readUTF(), in.readLong(), in.readLong(), in.readLong(), in.readBoolean(),
|
| - in.readBoolean(), in.readBoolean(), in.readInt());
|
| + in.readBoolean(), in.readInt(), in.readInt());
|
| }
|
| }
|
|
|