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

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: incorporated falken's comment 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 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_FILELD_TRIAL_STOPPED:
92 return "Navigation Preload field trial is stopped.";
falken 2017/01/13 09:13:20 nit: is "field trial" a term we use in public? May
horo 2017/01/13 09:27:57 Done.
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 "No valid Navigation Preload Orignin Trial token for the script.";
falken 2017/01/13 09:13:20 nit: "Origin" May be good to say "service worker
horo 2017/01/13 09:27:57 Done.
99 }
100 NOTREACHED();
101 return "";
102 }
103
84 } // namespace 104 } // namespace
85 105
86 ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost( 106 ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost(
87 int render_process_id, 107 int render_process_id,
88 MessagePortMessageFilter* message_port_message_filter, 108 MessagePortMessageFilter* message_port_message_filter,
89 ResourceContext* resource_context) 109 ResourceContext* resource_context)
90 : BrowserMessageFilter(kFilteredMessageClasses, 110 : BrowserMessageFilter(kFilteredMessageClasses,
91 arraysize(kFilteredMessageClasses)), 111 arraysize(kFilteredMessageClasses)),
92 render_process_id_(render_process_id), 112 render_process_id_(render_process_id),
93 message_port_message_filter_(message_port_message_filter), 113 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 730 // https://github.com/w3c/ServiceWorker/issues/920#issuecomment-262212670
711 // TODO(falken): Remove this comment when the spec is updated. 731 // TODO(falken): Remove this comment when the spec is updated.
712 if (!registration->active_version()) { 732 if (!registration->active_version()) {
713 Send(new ServiceWorkerMsg_EnableNavigationPreloadError( 733 Send(new ServiceWorkerMsg_EnableNavigationPreloadError(
714 thread_id, request_id, WebServiceWorkerError::ErrorTypeState, 734 thread_id, request_id, WebServiceWorkerError::ErrorTypeState,
715 std::string(kEnableNavigationPreloadErrorPrefix) + 735 std::string(kEnableNavigationPreloadErrorPrefix) +
716 std::string(kNoActiveWorkerErrorMessage))); 736 std::string(kNoActiveWorkerErrorMessage)));
717 return; 737 return;
718 } 738 }
719 739
740 ServiceWorkerVersion::NavigationPreloadSupportStatus support_status =
741 registration->active_version()->GetNavigationPreloadSupportStatus();
742 if (support_status !=
743 ServiceWorkerVersion::NavigationPreloadSupportStatus::SUPPORTED) {
744 Send(new ServiceWorkerMsg_EnableNavigationPreloadError(
745 thread_id, request_id, WebServiceWorkerError::ErrorTypeAbort,
746 std::string(kEnableNavigationPreloadErrorPrefix) +
747 GetNavigationPreloadDisabledErrorMessage(support_status)));
748 return;
749 }
750
720 std::vector<GURL> urls = {provider_host->document_url(), 751 std::vector<GURL> urls = {provider_host->document_url(),
721 registration->pattern()}; 752 registration->pattern()};
722 if (!ServiceWorkerUtils::AllOriginsMatchAndCanAccessServiceWorkers(urls)) { 753 if (!ServiceWorkerUtils::AllOriginsMatchAndCanAccessServiceWorkers(urls)) {
723 bad_message::ReceivedBadMessage( 754 bad_message::ReceivedBadMessage(
724 this, bad_message::SWDH_ENABLE_NAVIGATION_PRELOAD_INVALID_ORIGIN); 755 this, bad_message::SWDH_ENABLE_NAVIGATION_PRELOAD_INVALID_ORIGIN);
725 return; 756 return;
726 } 757 }
727 758
728 if (!GetContentClient()->browser()->AllowServiceWorker( 759 if (!GetContentClient()->browser()->AllowServiceWorker(
729 registration->pattern(), provider_host->topmost_frame_url(), 760 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 883 // https://github.com/w3c/ServiceWorker/issues/920#issuecomment-262212670
853 // TODO(falken): Remove this comment when the spec is updated. 884 // TODO(falken): Remove this comment when the spec is updated.
854 if (!registration->active_version()) { 885 if (!registration->active_version()) {
855 Send(new ServiceWorkerMsg_SetNavigationPreloadHeaderError( 886 Send(new ServiceWorkerMsg_SetNavigationPreloadHeaderError(
856 thread_id, request_id, WebServiceWorkerError::ErrorTypeState, 887 thread_id, request_id, WebServiceWorkerError::ErrorTypeState,
857 std::string(kSetNavigationPreloadHeaderErrorPrefix) + 888 std::string(kSetNavigationPreloadHeaderErrorPrefix) +
858 std::string(kNoActiveWorkerErrorMessage))); 889 std::string(kNoActiveWorkerErrorMessage)));
859 return; 890 return;
860 } 891 }
861 892
893 ServiceWorkerVersion::NavigationPreloadSupportStatus support_status =
894 registration->active_version()->GetNavigationPreloadSupportStatus();
895 if (support_status !=
896 ServiceWorkerVersion::NavigationPreloadSupportStatus::SUPPORTED) {
897 Send(new ServiceWorkerMsg_SetNavigationPreloadHeaderError(
898 thread_id, request_id, WebServiceWorkerError::ErrorTypeAbort,
899 std::string(kSetNavigationPreloadHeaderErrorPrefix) +
900 GetNavigationPreloadDisabledErrorMessage(support_status)));
901 return;
902 }
862 std::vector<GURL> urls = {provider_host->document_url(), 903 std::vector<GURL> urls = {provider_host->document_url(),
863 registration->pattern()}; 904 registration->pattern()};
864 if (!ServiceWorkerUtils::AllOriginsMatchAndCanAccessServiceWorkers(urls)) { 905 if (!ServiceWorkerUtils::AllOriginsMatchAndCanAccessServiceWorkers(urls)) {
865 bad_message::ReceivedBadMessage( 906 bad_message::ReceivedBadMessage(
866 this, bad_message::SWDH_SET_NAVIGATION_PRELOAD_HEADER_INVALID_ORIGIN); 907 this, bad_message::SWDH_SET_NAVIGATION_PRELOAD_HEADER_INVALID_ORIGIN);
867 return; 908 return;
868 } 909 }
869 910
870 // TODO(falken): Ideally this would match Blink's isValidHTTPHeaderValue. 911 // TODO(falken): Ideally this would match Blink's isValidHTTPHeaderValue.
871 // Chrome's check is less restrictive: it allows non-latin1 characters. 912 // 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) { 1795 if (!handle) {
1755 bad_message::ReceivedBadMessage(this, 1796 bad_message::ReceivedBadMessage(this,
1756 bad_message::SWDH_TERMINATE_BAD_HANDLE); 1797 bad_message::SWDH_TERMINATE_BAD_HANDLE);
1757 return; 1798 return;
1758 } 1799 }
1759 handle->version()->StopWorker( 1800 handle->version()->StopWorker(
1760 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); 1801 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
1761 } 1802 }
1762 1803
1763 } // namespace content 1804 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698