Attachment #8932304: Bug 1222008 - P6a: Implement the quirk response for bug #1222008

View | Details | Raw Unified | Return to bug 1222008
Collapse All | Expand All

(-)a/dom/fetch/InternalResponse.cpp (-3 / +18 lines)
Line     Link Here 
 Lines 143-170   InternalResponse::ToIPC(IPCInternalRespo Link Here 
143
  } else {
143
  } else {
144
    aIPCResponse->body() = void_t();
144
    aIPCResponse->body() = void_t();
145
  }
145
  }
146
146
147
  aIPCResponse->bodySize() = bodySize;
147
  aIPCResponse->bodySize() = bodySize;
148
}
148
}
149
149
150
already_AddRefed<InternalResponse>
150
already_AddRefed<InternalResponse>
151
InternalResponse::Clone(CloneType aCloneType)
151
InternalResponse::Clone(CloneType aCloneType, const bool aQuirkResponse)
152
{
152
{
153
  RefPtr<InternalResponse> clone = CreateIncompleteCopy();
153
  RefPtr<InternalResponse> clone;
154
  if (aQuirkResponse) {
155
      auto createQuirkResponse = [&]() -> already_AddRefed<InternalResponse> {
156
      RefPtr<InternalResponse> copy =
157
        new InternalResponse(mStatus, mStatusText);
158
      // XXXtt: not sure about this.
159
      copy->mType = mType;
160
161
      return copy.forget();
162
    };
163
164
    clone = createQuirkResponse();
165
  } else {
166
    clone =  CreateIncompleteCopy();
167
  }
154
168
155
  clone->mHeaders = new InternalHeaders(*mHeaders);
169
  clone->mHeaders = new InternalHeaders(*mHeaders);
156
170
157
  // Make sure the clone response will have the same padding size.
171
  // Make sure the clone response will have the same padding size.
158
  clone->mPaddingInfo = mPaddingInfo;
172
  clone->mPaddingInfo = mPaddingInfo;
159
  clone->mPaddingSize = mPaddingSize;
173
  clone->mPaddingSize = mPaddingSize;
160
174
161
  if (mWrappedResponse) {
175
  if (mWrappedResponse) {
162
    clone->mWrappedResponse = mWrappedResponse->Clone(aCloneType);
176
    clone->mWrappedResponse = mWrappedResponse->Clone(aCloneType,
177
                                                      aQuirkResponse);
163
    MOZ_ASSERT(!mBody);
178
    MOZ_ASSERT(!mBody);
164
    return clone.forget();
179
    return clone.forget();
165
  }
180
  }
166
181
167
  if (!mBody || aCloneType == eDontCloneInputStream) {
182
  if (!mBody || aCloneType == eDontCloneInputStream) {
168
    return clone.forget();
183
    return clone.forget();
169
  }
184
  }
170
185
(-)a/dom/fetch/InternalResponse.h (-1 / +2 lines)
Line     Link Here 
 Lines 45-61   public: Link Here 
45
        UniquePtr<mozilla::ipc::AutoIPCStream>& aAutoStream);
45
        UniquePtr<mozilla::ipc::AutoIPCStream>& aAutoStream);
46
46
47
  enum CloneType
47
  enum CloneType
48
  {
48
  {
49
    eCloneInputStream,
49
    eCloneInputStream,
50
    eDontCloneInputStream,
50
    eDontCloneInputStream,
51
  };
51
  };
52
52
53
  already_AddRefed<InternalResponse> Clone(CloneType eCloneType);
53
  already_AddRefed<InternalResponse> Clone(CloneType eCloneType,
54
                                           const bool aQuirkResponse = false);
54
55
55
  static already_AddRefed<InternalResponse>
56
  static already_AddRefed<InternalResponse>
56
  NetworkError(nsresult aRv)
57
  NetworkError(nsresult aRv)
57
  {
58
  {
58
    MOZ_DIAGNOSTIC_ASSERT(NS_FAILED(aRv));
59
    MOZ_DIAGNOSTIC_ASSERT(NS_FAILED(aRv));
59
    RefPtr<InternalResponse> response = new InternalResponse(0, EmptyCString());
60
    RefPtr<InternalResponse> response = new InternalResponse(0, EmptyCString());
60
    ErrorResult result;
61
    ErrorResult result;
61
    response->Headers()->SetGuard(HeadersGuardEnum::Immutable, result);
62
    response->Headers()->SetGuard(HeadersGuardEnum::Immutable, result);
(-)a/dom/fetch/Response.cpp (+40 lines)
Line     Link Here 
 Lines 316-331   Response::Constructor(const GlobalObject Link Here 
316
    }
316
    }
317
  }
317
  }
318
318
319
  r->SetMimeType();
319
  r->SetMimeType();
320
  return r.forget();
320
  return r.forget();
321
}
321
}
322
322
323
already_AddRefed<Response>
323
already_AddRefed<Response>
324
Response::QuirkResponse(JSContext* aCx, nsresult& aRv)
325
{
326
  MOZ_DIAGNOSTIC_ASSERT(aCx);
327
  MOZ_DIAGNOSTIC_ASSERT(!BodyUsed());
328
329
  ErrorResult result;
330
  RefPtr<FetchStreamReader> streamReader;
331
  nsCOMPtr<nsIInputStream> inputStream;
332
333
  JS::Rooted<JSObject*> body(aCx);
334
  MaybeTeeReadableStreamBody(aCx, &body, getter_AddRefs(streamReader),
335
                             getter_AddRefs(inputStream), result);
336
  if (NS_WARN_IF(result.Failed())) {
337
    return nullptr;
338
  }
339
340
  MOZ_ASSERT_IF(body, streamReader);
341
  MOZ_ASSERT_IF(body, inputStream);
342
343
  RefPtr<InternalResponse> ir =
344
    mInternalResponse->Clone(body ? InternalResponse::eDontCloneInputStream
345
                                  : InternalResponse::eCloneInputStream,
346
                             true /* quirkResponse */);
347
348
  RefPtr<Response> response = new Response(mOwner, ir, mSignal);
349
350
  if (body) {
351
    // Maybe we have a body, but we receive null from MaybeTeeReadableStreamBody
352
    // if this body is a native stream.   In this case the InternalResponse will
353
    // have a clone of the native body and the ReadableStream will be created
354
    // lazily if needed.
355
    response->SetReadableStreamBody(aCx, body);
356
    response->mFetchStreamReader = streamReader;
357
    ir->SetBody(inputStream, InternalResponse::UNKNOWN_BODY_SIZE);
358
  }
359
360
  return response.forget();
361
}
362
363
already_AddRefed<Response>
324
Response::Clone(JSContext* aCx, ErrorResult& aRv)
364
Response::Clone(JSContext* aCx, ErrorResult& aRv)
325
{
365
{
326
  if (BodyUsed()) {
366
  if (BodyUsed()) {
327
    aRv.ThrowTypeError<MSG_FETCH_BODY_CONSUMED_ERROR>();
367
    aRv.ThrowTypeError<MSG_FETCH_BODY_CONSUMED_ERROR>();
328
    return nullptr;
368
    return nullptr;
329
  }
369
  }
330
370
331
  RefPtr<FetchStreamReader> streamReader;
371
  RefPtr<FetchStreamReader> streamReader;
(-)a/dom/fetch/Response.h (+3 lines)
Line     Link Here 
 Lines 129-144   public: Link Here 
129
  }
129
  }
130
130
131
  already_AddRefed<Response>
131
  already_AddRefed<Response>
132
  Clone(JSContext* aCx, ErrorResult& aRv);
132
  Clone(JSContext* aCx, ErrorResult& aRv);
133
133
134
  already_AddRefed<Response>
134
  already_AddRefed<Response>
135
  CloneUnfiltered(JSContext* aCx, ErrorResult& aRv);
135
  CloneUnfiltered(JSContext* aCx, ErrorResult& aRv);
136
136
137
  already_AddRefed<Response>
138
  QuirkResponse(JSContext* aCx, nsresult& rv);
139
137
  void
140
  void
138
  SetBody(nsIInputStream* aBody, int64_t aBodySize);
141
  SetBody(nsIInputStream* aBody, int64_t aBodySize);
139
142
140
  already_AddRefed<InternalResponse>
143
  already_AddRefed<InternalResponse>
141
  GetInternalResponse() const;
144
  GetInternalResponse() const;
142
145
143
  AbortSignal*
146
  AbortSignal*
144
  GetSignal() const override
147
  GetSignal() const override
(-)a/dom/workers/ServiceWorkerEvents.cpp (-1 / +6 lines)
Line     Link Here 
 Lines 669-685   RespondWithHandler::ResolvedCallback(JSC Link Here 
669
  }
669
  }
670
670
671
  Telemetry::ScalarAdd(Telemetry::ScalarID::SW_SYNTHESIZED_RES_COUNT, 1);
671
  Telemetry::ScalarAdd(Telemetry::ScalarID::SW_SYNTHESIZED_RES_COUNT, 1);
672
672
673
  if (mRequestMode == RequestMode::Same_origin &&
673
  if (mRequestMode == RequestMode::Same_origin &&
674
      response->Type() == ResponseType::Cors) {
674
      response->Type() == ResponseType::Cors) {
675
    Telemetry::ScalarAdd(Telemetry::ScalarID::SW_CORS_RES_FOR_SO_REQ_COUNT, 1);
675
    Telemetry::ScalarAdd(Telemetry::ScalarID::SW_CORS_RES_FOR_SO_REQ_COUNT, 1);
676
676
677
    // XXXtt: quirkResponse, will be implement in the follow-up patch.
677
    response = response->QuirkResponse(aCx, rv);
678
    if (NS_WARN_IF(NS_FAILED(rv) || !response)) {
679
      return;
680
    }
681
682
    ir = response->GetInternalResponse();
678
  }
683
  }
679
684
680
  // Propagate the URL to the content if the request mode is not "navigate".
685
  // Propagate the URL to the content if the request mode is not "navigate".
681
  // Note that, we only reflect the final URL if the response.redirected is
686
  // Note that, we only reflect the final URL if the response.redirected is
682
  // false. We propagate all the URLs if the response.redirected is true.
687
  // false. We propagate all the URLs if the response.redirected is true.
683
  nsCString responseURL;
688
  nsCString responseURL;
684
  if (mRequestMode != RequestMode::Navigate) {
689
  if (mRequestMode != RequestMode::Navigate) {
685
    responseURL = ir->GetUnfilteredURL();
690
    responseURL = ir->GetUnfilteredURL();

Return to bug 1222008