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

Side by Side Diff: content/renderer/service_worker/service_worker_context_client.cc

Issue 2812513004: service worker: Clarify the navigation preload network error message. (Closed)
Patch Set: linebreak Created 3 years, 8 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/renderer/service_worker/service_worker_context_client.h" 5 #include "content/renderer/service_worker/service_worker_context_client.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "content/public/renderer/document_state.h" 44 #include "content/public/renderer/document_state.h"
45 #include "content/renderer/devtools/devtools_agent.h" 45 #include "content/renderer/devtools/devtools_agent.h"
46 #include "content/renderer/render_thread_impl.h" 46 #include "content/renderer/render_thread_impl.h"
47 #include "content/renderer/service_worker/embedded_worker_devtools_agent.h" 47 #include "content/renderer/service_worker/embedded_worker_devtools_agent.h"
48 #include "content/renderer/service_worker/embedded_worker_dispatcher.h" 48 #include "content/renderer/service_worker/embedded_worker_dispatcher.h"
49 #include "content/renderer/service_worker/embedded_worker_instance_client_impl.h " 49 #include "content/renderer/service_worker/embedded_worker_instance_client_impl.h "
50 #include "content/renderer/service_worker/service_worker_type_converters.h" 50 #include "content/renderer/service_worker/service_worker_type_converters.h"
51 #include "content/renderer/service_worker/service_worker_type_util.h" 51 #include "content/renderer/service_worker/service_worker_type_util.h"
52 #include "ipc/ipc_message.h" 52 #include "ipc/ipc_message.h"
53 #include "ipc/ipc_message_macros.h" 53 #include "ipc/ipc_message_macros.h"
54 #include "net/base/net_errors.h"
54 #include "net/http/http_response_headers.h" 55 #include "net/http/http_response_headers.h"
55 #include "third_party/WebKit/public/platform/URLConversion.h" 56 #include "third_party/WebKit/public/platform/URLConversion.h"
56 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" 57 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h"
57 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" 58 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
58 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" 59 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
59 #include "third_party/WebKit/public/platform/WebString.h" 60 #include "third_party/WebKit/public/platform/WebString.h"
60 #include "third_party/WebKit/public/platform/WebURLResponse.h" 61 #include "third_party/WebKit/public/platform/WebURLResponse.h"
61 #include "third_party/WebKit/public/platform/modules/background_fetch/WebBackgro undFetchSettledFetch.h" 62 #include "third_party/WebKit/public/platform/modules/background_fetch/WebBackgro undFetchSettledFetch.h"
62 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati onData.h" 63 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati onData.h"
63 #include "third_party/WebKit/public/platform/modules/payments/WebPaymentAppReque st.h" 64 #include "third_party/WebKit/public/platform/modules/payments/WebPaymentAppReque st.h"
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 418
418 void OnStartLoadingResponseBody( 419 void OnStartLoadingResponseBody(
419 mojo::ScopedDataPipeConsumerHandle body) override { 420 mojo::ScopedDataPipeConsumerHandle body) override {
420 DCHECK(!body_.is_valid()); 421 DCHECK(!body_.is_valid());
421 body_ = std::move(body); 422 body_ = std::move(body);
422 MaybeReportResponseToClient(); 423 MaybeReportResponseToClient();
423 } 424 }
424 425
425 void OnComplete(const ResourceRequestCompletionStatus& status) override { 426 void OnComplete(const ResourceRequestCompletionStatus& status) override {
426 if (status.error_code != net::OK) { 427 if (status.error_code != net::OK) {
428 std::string message;
429 std::string unsanitized_message;
430 if (status.error_code == net::ERR_ABORTED) {
431 message =
432 "The service worker navigation preload request was cancelled "
433 "before 'preloadResponse' settled. If you intend to use "
434 "'preloadResponse', use waitUntil() or respondWith() to wait for "
435 "the promise to settle.";
436 } else {
437 message =
438 "The service worker navigation preload request failed with a "
439 "network error.";
440 unsanitized_message =
441 "The service worker navigation preload request failed with network "
442 "error: " +
443 net::ErrorToString(status.error_code) + ".";
444 }
445
427 // This will delete |this|. 446 // This will delete |this|.
428 ReportErrorToClient("Service Worker navigation preload network error."); 447 ReportErrorToClient(message, unsanitized_message);
429 return; 448 return;
430 } 449 }
431 450
432 ServiceWorkerContextClient* client = 451 ServiceWorkerContextClient* client =
433 ServiceWorkerContextClient::ThreadSpecificInstance(); 452 ServiceWorkerContextClient::ThreadSpecificInstance();
434 if (!client) 453 if (!client)
435 return; 454 return;
436 if (response_) { 455 if (response_) {
437 // When the response body from the server is empty, OnComplete() is called 456 // When the response body from the server is empty, OnComplete() is called
438 // without OnStartLoadingResponseBody(). 457 // without OnStartLoadingResponseBody().
(...skipping 12 matching lines...) Expand all
451 ServiceWorkerContextClient* client = 470 ServiceWorkerContextClient* client =
452 ServiceWorkerContextClient::ThreadSpecificInstance(); 471 ServiceWorkerContextClient::ThreadSpecificInstance();
453 if (!client) 472 if (!client)
454 return; 473 return;
455 474
456 client->OnNavigationPreloadResponse( 475 client->OnNavigationPreloadResponse(
457 fetch_event_id_, std::move(response_), 476 fetch_event_id_, std::move(response_),
458 base::MakeUnique<WebDataConsumerHandleImpl>(std::move(body_))); 477 base::MakeUnique<WebDataConsumerHandleImpl>(std::move(body_)));
459 } 478 }
460 479
461 void ReportErrorToClient(const char* error_message) { 480 void ReportErrorToClient(const std::string& message,
481 const std::string& unsanitized_message) {
462 ServiceWorkerContextClient* client = 482 ServiceWorkerContextClient* client =
463 ServiceWorkerContextClient::ThreadSpecificInstance(); 483 ServiceWorkerContextClient::ThreadSpecificInstance();
464 if (!client) 484 if (!client)
465 return; 485 return;
466 // This will delete |this|. 486 // This will delete |this|.
467 client->OnNavigationPreloadError( 487 client->OnNavigationPreloadError(
468 fetch_event_id_, base::MakeUnique<blink::WebServiceWorkerError>( 488 fetch_event_id_, base::MakeUnique<blink::WebServiceWorkerError>(
469 blink::WebServiceWorkerError::kErrorTypeNetwork, 489 blink::WebServiceWorkerError::kErrorTypeNetwork,
470 blink::WebString::FromUTF8(error_message))); 490 blink::WebString::FromUTF8(message),
491 blink::WebString::FromUTF8(unsanitized_message)));
471 } 492 }
472 493
473 const int fetch_event_id_; 494 const int fetch_event_id_;
474 const GURL url_; 495 const GURL url_;
475 mojom::URLLoaderPtr url_loader_; 496 mojom::URLLoaderPtr url_loader_;
476 mojo::Binding<mojom::URLLoaderClient> binding_; 497 mojo::Binding<mojom::URLLoaderClient> binding_;
477 498
478 std::unique_ptr<blink::WebURLResponse> response_; 499 std::unique_ptr<blink::WebURLResponse> response_;
479 mojo::ScopedDataPipeConsumerHandle body_; 500 mojo::ScopedDataPipeConsumerHandle body_;
480 }; 501 };
(...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after
1521 } 1542 }
1522 1543
1523 base::WeakPtr<ServiceWorkerContextClient> 1544 base::WeakPtr<ServiceWorkerContextClient>
1524 ServiceWorkerContextClient::GetWeakPtr() { 1545 ServiceWorkerContextClient::GetWeakPtr() {
1525 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); 1546 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread());
1526 DCHECK(context_); 1547 DCHECK(context_);
1527 return context_->weak_factory.GetWeakPtr(); 1548 return context_->weak_factory.GetWeakPtr();
1528 } 1549 }
1529 1550
1530 } // namespace content 1551 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698