Commit 5c3fdd0b authored by Alex Catarineu's avatar Alex Catarineu Committed by Pier Angelo Vendrame
Browse files

BB 40171: Make WebRequest and GeckoWebExecutor First-Party aware

parent d7309513
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -47,6 +47,9 @@ public class WebRequest extends WebMessage {
  /** The value of the Referer header for this request. */
  public final @Nullable String referrer;

  /** The value of the origin of this request. */
  public final @Nullable String origin;

  /** Cache mode definitions for web requests. */
  @Retention(RetentionPolicy.SOURCE)
  @IntDef({
@@ -109,6 +112,7 @@ public class WebRequest extends WebMessage {
    cacheMode = builder.mCacheMode;
    referrer = builder.mReferrer;
    beConservative = builder.mBeConservative;
    origin = builder.mOrigin;

    if (builder.mBody != null) {
      body = builder.mBody.asReadOnlyBuffer();
@@ -125,6 +129,7 @@ public class WebRequest extends WebMessage {
    /* package */ int mCacheMode = CACHE_MODE_DEFAULT;
    /* package */ String mReferrer;
    /* package */ boolean mBeConservative;
    /* package */ String mOrigin;

    /**
     * Construct a Builder instance with the specified URI.
@@ -235,6 +240,17 @@ public class WebRequest extends WebMessage {
      return this;
    }

    /**
     * Set the origin URI.
     *
     * @param origin A URI String
     * @return This Builder instance.
     */
    public @NonNull Builder origin(final @Nullable String origin) {
      mOrigin = origin;
      return this;
    }

    /**
     * @return A {@link WebRequest} constructed with the values from this Builder instance.
     */
+8 −0
Original line number Diff line number Diff line
@@ -489,6 +489,14 @@ nsresult WebExecutorSupport::CreateStreamLoader(
    MOZ_ASSERT(cookieJarSettings);

    nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
    if (const auto origin = req->Origin(); origin) {
      RefPtr<nsIURI> originUri;
      rv = NS_NewURI(getter_AddRefs(originUri), origin->ToString());
      NS_ENSURE_SUCCESS(rv, NS_ERROR_MALFORMED_URI);
      OriginAttributes attrs = loadInfo->GetOriginAttributes();
      attrs.SetFirstPartyDomain(true, originUri);
      loadInfo->SetOriginAttributes(attrs);
    }
    loadInfo->SetCookieJarSettings(cookieJarSettings);
  }