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

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

Issue 2627023002: Introduce Origin-Trial for Service Worker Navigation Preload (Closed)
Patch Set: add LayoutTests Created 3 years, 11 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_dispatcher_host.h" 5 #include "content/browser/service_worker/service_worker_dispatcher_host.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/debug/crash_logging.h" 9 #include "base/debug/crash_logging.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 const char kInvalidStateErrorMessage[] = "The object is in an invalid state."; 58 const char kInvalidStateErrorMessage[] = "The object is in an invalid state.";
59 const char kEnableNavigationPreloadErrorPrefix[] = 59 const char kEnableNavigationPreloadErrorPrefix[] =
60 "Failed to enable or disable navigation preload: "; 60 "Failed to enable or disable navigation preload: ";
61 const char kGetNavigationPreloadStateErrorPrefix[] = 61 const char kGetNavigationPreloadStateErrorPrefix[] =
62 "Failed to get navigation preload state: "; 62 "Failed to get navigation preload state: ";
63 const char kSetNavigationPreloadHeaderErrorPrefix[] = 63 const char kSetNavigationPreloadHeaderErrorPrefix[] =
64 "Failed to set navigation preload header: "; 64 "Failed to set navigation preload header: ";
65 const char kNoActiveWorkerErrorMessage[] = 65 const char kNoActiveWorkerErrorMessage[] =
66 "The registration does not have an active worker."; 66 "The registration does not have an active worker.";
67 const char kDatabaseErrorMessage[] = "Failed to access storage."; 67 const char kDatabaseErrorMessage[] = "Failed to access storage.";
68 const char kFeatureDisabledErrorMessage[] = "This feature is diabled.";
falken 2017/01/13 03:43:41 "disabled" Should we give a more specific error m
horo 2017/01/13 08:41:32 Done.
68 69
69 const uint32_t kFilteredMessageClasses[] = { 70 const uint32_t kFilteredMessageClasses[] = {
70 ServiceWorkerMsgStart, EmbeddedWorkerMsgStart, 71 ServiceWorkerMsgStart, EmbeddedWorkerMsgStart,
71 }; 72 };
72 73
73 void RunSoon(const base::Closure& callback) { 74 void RunSoon(const base::Closure& callback) {
74 if (!callback.is_null()) 75 if (!callback.is_null())
75 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); 76 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback);
76 } 77 }
77 78
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 // https://github.com/w3c/ServiceWorker/issues/920#issuecomment-262212670 711 // https://github.com/w3c/ServiceWorker/issues/920#issuecomment-262212670
711 // TODO(falken): Remove this comment when the spec is updated. 712 // TODO(falken): Remove this comment when the spec is updated.
712 if (!registration->active_version()) { 713 if (!registration->active_version()) {
713 Send(new ServiceWorkerMsg_EnableNavigationPreloadError( 714 Send(new ServiceWorkerMsg_EnableNavigationPreloadError(
714 thread_id, request_id, WebServiceWorkerError::ErrorTypeState, 715 thread_id, request_id, WebServiceWorkerError::ErrorTypeState,
715 std::string(kEnableNavigationPreloadErrorPrefix) + 716 std::string(kEnableNavigationPreloadErrorPrefix) +
716 std::string(kNoActiveWorkerErrorMessage))); 717 std::string(kNoActiveWorkerErrorMessage)));
717 return; 718 return;
718 } 719 }
719 720
721 if (!registration->active_version()->IsNavigationPreloadSupported()) {
722 Send(new ServiceWorkerMsg_EnableNavigationPreloadError(
723 thread_id, request_id, WebServiceWorkerError::ErrorTypeAbort,
724 std::string(kEnableNavigationPreloadErrorPrefix) +
725 std::string(kFeatureDisabledErrorMessage)));
726 return;
727 }
728
720 std::vector<GURL> urls = {provider_host->document_url(), 729 std::vector<GURL> urls = {provider_host->document_url(),
721 registration->pattern()}; 730 registration->pattern()};
722 if (!ServiceWorkerUtils::AllOriginsMatchAndCanAccessServiceWorkers(urls)) { 731 if (!ServiceWorkerUtils::AllOriginsMatchAndCanAccessServiceWorkers(urls)) {
723 bad_message::ReceivedBadMessage( 732 bad_message::ReceivedBadMessage(
724 this, bad_message::SWDH_ENABLE_NAVIGATION_PRELOAD_INVALID_ORIGIN); 733 this, bad_message::SWDH_ENABLE_NAVIGATION_PRELOAD_INVALID_ORIGIN);
725 return; 734 return;
726 } 735 }
727 736
728 if (!GetContentClient()->browser()->AllowServiceWorker( 737 if (!GetContentClient()->browser()->AllowServiceWorker(
729 registration->pattern(), provider_host->topmost_frame_url(), 738 registration->pattern(), provider_host->topmost_frame_url(),
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 // https://github.com/w3c/ServiceWorker/issues/920#issuecomment-262212670 861 // https://github.com/w3c/ServiceWorker/issues/920#issuecomment-262212670
853 // TODO(falken): Remove this comment when the spec is updated. 862 // TODO(falken): Remove this comment when the spec is updated.
854 if (!registration->active_version()) { 863 if (!registration->active_version()) {
855 Send(new ServiceWorkerMsg_SetNavigationPreloadHeaderError( 864 Send(new ServiceWorkerMsg_SetNavigationPreloadHeaderError(
856 thread_id, request_id, WebServiceWorkerError::ErrorTypeState, 865 thread_id, request_id, WebServiceWorkerError::ErrorTypeState,
857 std::string(kSetNavigationPreloadHeaderErrorPrefix) + 866 std::string(kSetNavigationPreloadHeaderErrorPrefix) +
858 std::string(kNoActiveWorkerErrorMessage))); 867 std::string(kNoActiveWorkerErrorMessage)));
859 return; 868 return;
860 } 869 }
861 870
871 if (!registration->active_version()->IsNavigationPreloadSupported()) {
872 Send(new ServiceWorkerMsg_SetNavigationPreloadHeaderError(
873 thread_id, request_id, WebServiceWorkerError::ErrorTypeAbort,
874 std::string(kSetNavigationPreloadHeaderErrorPrefix) +
875 std::string(kFeatureDisabledErrorMessage)));
876 return;
877 }
862 std::vector<GURL> urls = {provider_host->document_url(), 878 std::vector<GURL> urls = {provider_host->document_url(),
863 registration->pattern()}; 879 registration->pattern()};
864 if (!ServiceWorkerUtils::AllOriginsMatchAndCanAccessServiceWorkers(urls)) { 880 if (!ServiceWorkerUtils::AllOriginsMatchAndCanAccessServiceWorkers(urls)) {
865 bad_message::ReceivedBadMessage( 881 bad_message::ReceivedBadMessage(
866 this, bad_message::SWDH_SET_NAVIGATION_PRELOAD_HEADER_INVALID_ORIGIN); 882 this, bad_message::SWDH_SET_NAVIGATION_PRELOAD_HEADER_INVALID_ORIGIN);
867 return; 883 return;
868 } 884 }
869 885
870 // TODO(falken): Ideally this would match Blink's isValidHTTPHeaderValue. 886 // TODO(falken): Ideally this would match Blink's isValidHTTPHeaderValue.
871 // Chrome's check is less restrictive: it allows non-latin1 characters. 887 // Chrome's check is less restrictive: it allows non-latin1 characters.
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after
1754 if (!handle) { 1770 if (!handle) {
1755 bad_message::ReceivedBadMessage(this, 1771 bad_message::ReceivedBadMessage(this,
1756 bad_message::SWDH_TERMINATE_BAD_HANDLE); 1772 bad_message::SWDH_TERMINATE_BAD_HANDLE);
1757 return; 1773 return;
1758 } 1774 }
1759 handle->version()->StopWorker( 1775 handle->version()->StopWorker(
1760 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 1776 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
1761 } 1777 }
1762 1778
1763 } // namespace content 1779 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698