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

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: s/an/a 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
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_fetch_dispatcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 if (!callback.is_null()) 74 if (!callback.is_null())
75 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); 75 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback);
76 } 76 }
77 77
78 WebContents* GetWebContents(int render_process_id, int render_frame_id) { 78 WebContents* GetWebContents(int render_process_id, int render_frame_id) {
79 RenderFrameHost* rfh = 79 RenderFrameHost* rfh =
80 RenderFrameHost::FromID(render_process_id, render_frame_id); 80 RenderFrameHost::FromID(render_process_id, render_frame_id);
81 return WebContents::FromRenderFrameHost(rfh); 81 return WebContents::FromRenderFrameHost(rfh);
82 } 82 }
83 83
84 std::string GetNavigationPreloadDisabledErrorMessage(
85 ServiceWorkerVersion::NavigationPreloadSupportStatus support_status) {
86 switch (support_status) {
87 case ServiceWorkerVersion::NavigationPreloadSupportStatus::SUPPORTED:
88 NOTREACHED();
89 break;
90 case ServiceWorkerVersion::NavigationPreloadSupportStatus::
91 NOT_SUPPORTED_FIELD_TRIAL_STOPPED:
92 return "The Navigation Preload Origin Trial has ended.";
93 case ServiceWorkerVersion::NavigationPreloadSupportStatus::
94 NOT_SUPPORTED_DISABLED_BY_COMMAND_LINE:
95 return "Navigation Preload is disabled by command line flag.";
96 case ServiceWorkerVersion::NavigationPreloadSupportStatus::
97 NOT_SUPPORTED_NO_VALID_ORIGIN_TRIAL_TOKEN:
98 return "The service worker script does not have a valid Navigation "
99 "Preload Origin Trial token.";
100 }
101 NOTREACHED();
102 return "";
103 }
104
84 } // namespace 105 } // namespace
85 106
86 ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost( 107 ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost(
87 int render_process_id, 108 int render_process_id,
88 MessagePortMessageFilter* message_port_message_filter, 109 MessagePortMessageFilter* message_port_message_filter,
89 ResourceContext* resource_context) 110 ResourceContext* resource_context)
90 : BrowserMessageFilter(kFilteredMessageClasses, 111 : BrowserMessageFilter(kFilteredMessageClasses,
91 arraysize(kFilteredMessageClasses)), 112 arraysize(kFilteredMessageClasses)),
92 render_process_id_(render_process_id), 113 render_process_id_(render_process_id),
93 message_port_message_filter_(message_port_message_filter), 114 message_port_message_filter_(message_port_message_filter),
(...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 // https://github.com/w3c/ServiceWorker/issues/920#issuecomment-262212670 731 // https://github.com/w3c/ServiceWorker/issues/920#issuecomment-262212670
711 // TODO(falken): Remove this comment when the spec is updated. 732 // TODO(falken): Remove this comment when the spec is updated.
712 if (!registration->active_version()) { 733 if (!registration->active_version()) {
713 Send(new ServiceWorkerMsg_EnableNavigationPreloadError( 734 Send(new ServiceWorkerMsg_EnableNavigationPreloadError(
714 thread_id, request_id, WebServiceWorkerError::ErrorTypeState, 735 thread_id, request_id, WebServiceWorkerError::ErrorTypeState,
715 std::string(kEnableNavigationPreloadErrorPrefix) + 736 std::string(kEnableNavigationPreloadErrorPrefix) +
716 std::string(kNoActiveWorkerErrorMessage))); 737 std::string(kNoActiveWorkerErrorMessage)));
717 return; 738 return;
718 } 739 }
719 740
741 ServiceWorkerVersion::NavigationPreloadSupportStatus support_status =
742 registration->active_version()->GetNavigationPreloadSupportStatus();
743 if (support_status !=
744 ServiceWorkerVersion::NavigationPreloadSupportStatus::SUPPORTED) {
745 Send(new ServiceWorkerMsg_EnableNavigationPreloadError(
746 thread_id, request_id, WebServiceWorkerError::ErrorTypeAbort,
747 std::string(kEnableNavigationPreloadErrorPrefix) +
748 GetNavigationPreloadDisabledErrorMessage(support_status)));
749 return;
750 }
751
720 std::vector<GURL> urls = {provider_host->document_url(), 752 std::vector<GURL> urls = {provider_host->document_url(),
721 registration->pattern()}; 753 registration->pattern()};
722 if (!ServiceWorkerUtils::AllOriginsMatchAndCanAccessServiceWorkers(urls)) { 754 if (!ServiceWorkerUtils::AllOriginsMatchAndCanAccessServiceWorkers(urls)) {
723 bad_message::ReceivedBadMessage( 755 bad_message::ReceivedBadMessage(
724 this, bad_message::SWDH_ENABLE_NAVIGATION_PRELOAD_INVALID_ORIGIN); 756 this, bad_message::SWDH_ENABLE_NAVIGATION_PRELOAD_INVALID_ORIGIN);
725 return; 757 return;
726 } 758 }
727 759
728 if (!GetContentClient()->browser()->AllowServiceWorker( 760 if (!GetContentClient()->browser()->AllowServiceWorker(
729 registration->pattern(), provider_host->topmost_frame_url(), 761 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 884 // https://github.com/w3c/ServiceWorker/issues/920#issuecomment-262212670
853 // TODO(falken): Remove this comment when the spec is updated. 885 // TODO(falken): Remove this comment when the spec is updated.
854 if (!registration->active_version()) { 886 if (!registration->active_version()) {
855 Send(new ServiceWorkerMsg_SetNavigationPreloadHeaderError( 887 Send(new ServiceWorkerMsg_SetNavigationPreloadHeaderError(
856 thread_id, request_id, WebServiceWorkerError::ErrorTypeState, 888 thread_id, request_id, WebServiceWorkerError::ErrorTypeState,
857 std::string(kSetNavigationPreloadHeaderErrorPrefix) + 889 std::string(kSetNavigationPreloadHeaderErrorPrefix) +
858 std::string(kNoActiveWorkerErrorMessage))); 890 std::string(kNoActiveWorkerErrorMessage)));
859 return; 891 return;
860 } 892 }
861 893
894 ServiceWorkerVersion::NavigationPreloadSupportStatus support_status =
895 registration->active_version()->GetNavigationPreloadSupportStatus();
896 if (support_status !=
897 ServiceWorkerVersion::NavigationPreloadSupportStatus::SUPPORTED) {
898 Send(new ServiceWorkerMsg_SetNavigationPreloadHeaderError(
899 thread_id, request_id, WebServiceWorkerError::ErrorTypeAbort,
900 std::string(kSetNavigationPreloadHeaderErrorPrefix) +
901 GetNavigationPreloadDisabledErrorMessage(support_status)));
902 return;
903 }
862 std::vector<GURL> urls = {provider_host->document_url(), 904 std::vector<GURL> urls = {provider_host->document_url(),
863 registration->pattern()}; 905 registration->pattern()};
864 if (!ServiceWorkerUtils::AllOriginsMatchAndCanAccessServiceWorkers(urls)) { 906 if (!ServiceWorkerUtils::AllOriginsMatchAndCanAccessServiceWorkers(urls)) {
865 bad_message::ReceivedBadMessage( 907 bad_message::ReceivedBadMessage(
866 this, bad_message::SWDH_SET_NAVIGATION_PRELOAD_HEADER_INVALID_ORIGIN); 908 this, bad_message::SWDH_SET_NAVIGATION_PRELOAD_HEADER_INVALID_ORIGIN);
867 return; 909 return;
868 } 910 }
869 911
870 // TODO(falken): Ideally this would match Blink's isValidHTTPHeaderValue. 912 // TODO(falken): Ideally this would match Blink's isValidHTTPHeaderValue.
871 // Chrome's check is less restrictive: it allows non-latin1 characters. 913 // 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) { 1796 if (!handle) {
1755 bad_message::ReceivedBadMessage(this, 1797 bad_message::ReceivedBadMessage(this,
1756 bad_message::SWDH_TERMINATE_BAD_HANDLE); 1798 bad_message::SWDH_TERMINATE_BAD_HANDLE);
1757 return; 1799 return;
1758 } 1800 }
1759 handle->version()->StopWorker( 1801 handle->version()->StopWorker(
1760 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 1802 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
1761 } 1803 }
1762 1804
1763 } // namespace content 1805 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/service_worker/service_worker_fetch_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698