Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: content/browser/service_worker/service_worker_url_loader_job.cc

Issue 2982363002: Add support for fallback content for the frame. This includes main and subframes. (Closed)
Patch Set: Address review comments. Add the fallback function as a parameter to LoaderCallback Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/service_worker/service_worker_url_loader_job.h" 5 #include "content/browser/service_worker/service_worker_url_loader_job.h"
6 6
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "content/browser/blob_storage/blob_url_loader_factory.h" 8 #include "content/browser/blob_storage/blob_url_loader_factory.h"
9 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h" 9 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h"
10 #include "content/browser/service_worker/service_worker_version.h" 10 #include "content/browser/service_worker/service_worker_version.h"
(...skipping 25 matching lines...) Expand all
36 36
37 ServiceWorkerURLLoaderJob::~ServiceWorkerURLLoaderJob() {} 37 ServiceWorkerURLLoaderJob::~ServiceWorkerURLLoaderJob() {}
38 38
39 void ServiceWorkerURLLoaderJob::FallbackToNetwork() { 39 void ServiceWorkerURLLoaderJob::FallbackToNetwork() {
40 response_type_ = FALLBACK_TO_NETWORK; 40 response_type_ = FALLBACK_TO_NETWORK;
41 // This could be called multiple times in some cases because we simply 41 // This could be called multiple times in some cases because we simply
42 // call this synchronously here and don't wait for a separate async 42 // call this synchronously here and don't wait for a separate async
43 // StartRequest cue like what URLRequestJob case does. 43 // StartRequest cue like what URLRequestJob case does.
44 // TODO(kinuko): Make sure this is ok or we need to make this async. 44 // TODO(kinuko): Make sure this is ok or we need to make this async.
45 if (!loader_callback_.is_null()) 45 if (!loader_callback_.is_null())
46 std::move(loader_callback_).Run(StartLoaderCallback()); 46 std::move(loader_callback_).Run(StartLoaderCallback(), ResponseFallback());
47 } 47 }
48 48
49 void ServiceWorkerURLLoaderJob::FallbackToNetworkOrRenderer() { 49 void ServiceWorkerURLLoaderJob::FallbackToNetworkOrRenderer() {
50 // TODO(kinuko): Implement this. Now we always fallback to network. 50 // TODO(kinuko): Implement this. Now we always fallback to network.
51 FallbackToNetwork(); 51 FallbackToNetwork();
52 } 52 }
53 53
54 void ServiceWorkerURLLoaderJob::ForwardToServiceWorker() { 54 void ServiceWorkerURLLoaderJob::ForwardToServiceWorker() {
55 response_type_ = FORWARD_TO_SERVICE_WORKER; 55 response_type_ = FORWARD_TO_SERVICE_WORKER;
56 StartRequest(); 56 StartRequest();
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 DeliverErrorResponse(); 244 DeliverErrorResponse();
245 return; 245 return;
246 } 246 }
247 247
248 // Creates a new HttpResponseInfo using the the ServiceWorker script's 248 // Creates a new HttpResponseInfo using the the ServiceWorker script's
249 // HttpResponseInfo to show HTTPS padlock. 249 // HttpResponseInfo to show HTTPS padlock.
250 // TODO(horo): When we support mixed-content (HTTP) no-cors requests from a 250 // TODO(horo): When we support mixed-content (HTTP) no-cors requests from a
251 // ServiceWorker, we have to check the security level of the responses. 251 // ServiceWorker, we have to check the security level of the responses.
252 const net::HttpResponseInfo* main_script_http_info = 252 const net::HttpResponseInfo* main_script_http_info =
253 version->GetMainScriptHttpResponseInfo(); 253 version->GetMainScriptHttpResponseInfo();
254 DCHECK(main_script_http_info); 254 if (main_script_http_info)
ananta 2017/07/27 02:40:25 Was hitting this DCHECK and the subsequent crash l
kinuko 2017/07/27 13:46:27 This should be fixed by my other change- https://c
255 ssl_info_ = main_script_http_info->ssl_info; 255 ssl_info_ = main_script_http_info->ssl_info;
256 256
257 std::move(loader_callback_) 257 std::move(loader_callback_)
258 .Run(base::Bind(&ServiceWorkerURLLoaderJob::StartResponse, 258 .Run(base::Bind(&ServiceWorkerURLLoaderJob::StartResponse,
259 weak_factory_.GetWeakPtr(), response, 259 weak_factory_.GetWeakPtr(), response,
260 base::Passed(std::move(body_as_stream)))); 260 base::Passed(std::move(body_as_stream))),
261 ResponseFallback());
261 } 262 }
262 263
263 void ServiceWorkerURLLoaderJob::StartResponse( 264 void ServiceWorkerURLLoaderJob::StartResponse(
264 const ServiceWorkerResponse& response, 265 const ServiceWorkerResponse& response,
265 blink::mojom::ServiceWorkerStreamHandlePtr body_as_stream, 266 blink::mojom::ServiceWorkerStreamHandlePtr body_as_stream,
266 mojom::URLLoaderRequest request, 267 mojom::URLLoaderRequest request,
267 mojom::URLLoaderClientPtr client) { 268 mojom::URLLoaderClientPtr client) {
268 DCHECK(!binding_.is_bound()); 269 DCHECK(!binding_.is_bound());
269 binding_.Bind(std::move(request)); 270 binding_.Bind(std::move(request));
270 binding_.set_connection_error_handler( 271 binding_.set_connection_error_handler(
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 } 358 }
358 359
359 void ServiceWorkerURLLoaderJob::OnComplete( 360 void ServiceWorkerURLLoaderJob::OnComplete(
360 const ResourceRequestCompletionStatus& status) { 361 const ResourceRequestCompletionStatus& status) {
361 DCHECK_EQ(Status::kSentHeader, status_); 362 DCHECK_EQ(Status::kSentHeader, status_);
362 status_ = Status::kCompleted; 363 status_ = Status::kCompleted;
363 url_loader_client_->OnComplete(status); 364 url_loader_client_->OnComplete(status);
364 } 365 }
365 366
366 } // namespace content 367 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698