OLD | NEW |
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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 if (!callback.is_null()) | 73 if (!callback.is_null()) |
74 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); | 74 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); |
75 } | 75 } |
76 | 76 |
77 WebContents* GetWebContents(int render_process_id, int render_frame_id) { | 77 WebContents* GetWebContents(int render_process_id, int render_frame_id) { |
78 RenderFrameHost* rfh = | 78 RenderFrameHost* rfh = |
79 RenderFrameHost::FromID(render_process_id, render_frame_id); | 79 RenderFrameHost::FromID(render_process_id, render_frame_id); |
80 return WebContents::FromRenderFrameHost(rfh); | 80 return WebContents::FromRenderFrameHost(rfh); |
81 } | 81 } |
82 | 82 |
83 std::string GetNavigationPreloadDisabledErrorMessage( | |
84 ServiceWorkerVersion::NavigationPreloadSupportStatus support_status) { | |
85 switch (support_status) { | |
86 case ServiceWorkerVersion::NavigationPreloadSupportStatus::SUPPORTED: | |
87 NOTREACHED(); | |
88 break; | |
89 case ServiceWorkerVersion::NavigationPreloadSupportStatus:: | |
90 NOT_SUPPORTED_FIELD_TRIAL_STOPPED: | |
91 return "The Navigation Preload Origin Trial has ended."; | |
92 case ServiceWorkerVersion::NavigationPreloadSupportStatus:: | |
93 NOT_SUPPORTED_DISABLED_BY_COMMAND_LINE: | |
94 return "Navigation Preload is disabled by command line flag."; | |
95 case ServiceWorkerVersion::NavigationPreloadSupportStatus:: | |
96 NOT_SUPPORTED_NO_VALID_ORIGIN_TRIAL_TOKEN: | |
97 return "The service worker script does not have a valid Navigation " | |
98 "Preload Origin Trial token."; | |
99 } | |
100 NOTREACHED(); | |
101 return ""; | |
102 } | |
103 | |
104 } // namespace | 83 } // namespace |
105 | 84 |
106 ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost( | 85 ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost( |
107 int render_process_id, | 86 int render_process_id, |
108 ResourceContext* resource_context) | 87 ResourceContext* resource_context) |
109 : BrowserMessageFilter(kFilteredMessageClasses, | 88 : BrowserMessageFilter(kFilteredMessageClasses, |
110 arraysize(kFilteredMessageClasses)), | 89 arraysize(kFilteredMessageClasses)), |
111 render_process_id_(render_process_id), | 90 render_process_id_(render_process_id), |
112 resource_context_(resource_context), | 91 resource_context_(resource_context), |
113 channel_ready_(false), | 92 channel_ready_(false), |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 // https://github.com/w3c/ServiceWorker/issues/920#issuecomment-262212670 | 695 // https://github.com/w3c/ServiceWorker/issues/920#issuecomment-262212670 |
717 // TODO(falken): Remove this comment when the spec is updated. | 696 // TODO(falken): Remove this comment when the spec is updated. |
718 if (!registration->active_version()) { | 697 if (!registration->active_version()) { |
719 Send(new ServiceWorkerMsg_EnableNavigationPreloadError( | 698 Send(new ServiceWorkerMsg_EnableNavigationPreloadError( |
720 thread_id, request_id, WebServiceWorkerError::kErrorTypeState, | 699 thread_id, request_id, WebServiceWorkerError::kErrorTypeState, |
721 std::string(kEnableNavigationPreloadErrorPrefix) + | 700 std::string(kEnableNavigationPreloadErrorPrefix) + |
722 std::string(kNoActiveWorkerErrorMessage))); | 701 std::string(kNoActiveWorkerErrorMessage))); |
723 return; | 702 return; |
724 } | 703 } |
725 | 704 |
726 ServiceWorkerVersion::NavigationPreloadSupportStatus support_status = | |
727 registration->active_version()->GetNavigationPreloadSupportStatus(); | |
728 if (support_status != | |
729 ServiceWorkerVersion::NavigationPreloadSupportStatus::SUPPORTED) { | |
730 Send(new ServiceWorkerMsg_EnableNavigationPreloadError( | |
731 thread_id, request_id, WebServiceWorkerError::kErrorTypeAbort, | |
732 std::string(kEnableNavigationPreloadErrorPrefix) + | |
733 GetNavigationPreloadDisabledErrorMessage(support_status))); | |
734 return; | |
735 } | |
736 | |
737 std::vector<GURL> urls = {provider_host->document_url(), | 705 std::vector<GURL> urls = {provider_host->document_url(), |
738 registration->pattern()}; | 706 registration->pattern()}; |
739 if (!ServiceWorkerUtils::AllOriginsMatchAndCanAccessServiceWorkers(urls)) { | 707 if (!ServiceWorkerUtils::AllOriginsMatchAndCanAccessServiceWorkers(urls)) { |
740 bad_message::ReceivedBadMessage( | 708 bad_message::ReceivedBadMessage( |
741 this, bad_message::SWDH_ENABLE_NAVIGATION_PRELOAD_INVALID_ORIGIN); | 709 this, bad_message::SWDH_ENABLE_NAVIGATION_PRELOAD_INVALID_ORIGIN); |
742 return; | 710 return; |
743 } | 711 } |
744 | 712 |
745 if (!GetContentClient()->browser()->AllowServiceWorker( | 713 if (!GetContentClient()->browser()->AllowServiceWorker( |
746 registration->pattern(), provider_host->topmost_frame_url(), | 714 registration->pattern(), provider_host->topmost_frame_url(), |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 // https://github.com/w3c/ServiceWorker/issues/920#issuecomment-262212670 | 837 // https://github.com/w3c/ServiceWorker/issues/920#issuecomment-262212670 |
870 // TODO(falken): Remove this comment when the spec is updated. | 838 // TODO(falken): Remove this comment when the spec is updated. |
871 if (!registration->active_version()) { | 839 if (!registration->active_version()) { |
872 Send(new ServiceWorkerMsg_SetNavigationPreloadHeaderError( | 840 Send(new ServiceWorkerMsg_SetNavigationPreloadHeaderError( |
873 thread_id, request_id, WebServiceWorkerError::kErrorTypeState, | 841 thread_id, request_id, WebServiceWorkerError::kErrorTypeState, |
874 std::string(kSetNavigationPreloadHeaderErrorPrefix) + | 842 std::string(kSetNavigationPreloadHeaderErrorPrefix) + |
875 std::string(kNoActiveWorkerErrorMessage))); | 843 std::string(kNoActiveWorkerErrorMessage))); |
876 return; | 844 return; |
877 } | 845 } |
878 | 846 |
879 ServiceWorkerVersion::NavigationPreloadSupportStatus support_status = | |
880 registration->active_version()->GetNavigationPreloadSupportStatus(); | |
881 if (support_status != | |
882 ServiceWorkerVersion::NavigationPreloadSupportStatus::SUPPORTED) { | |
883 Send(new ServiceWorkerMsg_SetNavigationPreloadHeaderError( | |
884 thread_id, request_id, WebServiceWorkerError::kErrorTypeAbort, | |
885 std::string(kSetNavigationPreloadHeaderErrorPrefix) + | |
886 GetNavigationPreloadDisabledErrorMessage(support_status))); | |
887 return; | |
888 } | |
889 std::vector<GURL> urls = {provider_host->document_url(), | 847 std::vector<GURL> urls = {provider_host->document_url(), |
890 registration->pattern()}; | 848 registration->pattern()}; |
891 if (!ServiceWorkerUtils::AllOriginsMatchAndCanAccessServiceWorkers(urls)) { | 849 if (!ServiceWorkerUtils::AllOriginsMatchAndCanAccessServiceWorkers(urls)) { |
892 bad_message::ReceivedBadMessage( | 850 bad_message::ReceivedBadMessage( |
893 this, bad_message::SWDH_SET_NAVIGATION_PRELOAD_HEADER_INVALID_ORIGIN); | 851 this, bad_message::SWDH_SET_NAVIGATION_PRELOAD_HEADER_INVALID_ORIGIN); |
894 return; | 852 return; |
895 } | 853 } |
896 | 854 |
897 // TODO(falken): Ideally this would match Blink's isValidHTTPHeaderValue. | 855 // TODO(falken): Ideally this would match Blink's isValidHTTPHeaderValue. |
898 // Chrome's check is less restrictive: it allows non-latin1 characters. | 856 // Chrome's check is less restrictive: it allows non-latin1 characters. |
(...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1780 if (!handle) { | 1738 if (!handle) { |
1781 bad_message::ReceivedBadMessage(this, | 1739 bad_message::ReceivedBadMessage(this, |
1782 bad_message::SWDH_TERMINATE_BAD_HANDLE); | 1740 bad_message::SWDH_TERMINATE_BAD_HANDLE); |
1783 return; | 1741 return; |
1784 } | 1742 } |
1785 handle->version()->StopWorker( | 1743 handle->version()->StopWorker( |
1786 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 1744 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
1787 } | 1745 } |
1788 | 1746 |
1789 } // namespace content | 1747 } // namespace content |
OLD | NEW |