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_provider_host.h" | 5 #include "content/browser/service_worker/service_worker_provider_host.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/guid.h" | 9 #include "base/guid.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "content/browser/message_port_message_filter.h" | 12 #include "content/browser/message_port_message_filter.h" |
13 #include "content/browser/service_worker/service_worker_context_core.h" | 13 #include "content/browser/service_worker/service_worker_context_core.h" |
14 #include "content/browser/service_worker/service_worker_context_request_handler.
h" | 14 #include "content/browser/service_worker/service_worker_context_request_handler.
h" |
15 #include "content/browser/service_worker/service_worker_controllee_request_handl
er.h" | 15 #include "content/browser/service_worker/service_worker_controllee_request_handl
er.h" |
16 #include "content/browser/service_worker/service_worker_dispatcher_host.h" | 16 #include "content/browser/service_worker/service_worker_dispatcher_host.h" |
17 #include "content/browser/service_worker/service_worker_handle.h" | 17 #include "content/browser/service_worker/service_worker_handle.h" |
18 #include "content/browser/service_worker/service_worker_registration_handle.h" | 18 #include "content/browser/service_worker/service_worker_registration_handle.h" |
19 #include "content/browser/service_worker/service_worker_version.h" | 19 #include "content/browser/service_worker/service_worker_version.h" |
20 #include "content/common/resource_request_body.h" | 20 #include "content/common/resource_request_body.h" |
21 #include "content/common/service_worker/service_worker_messages.h" | 21 #include "content/common/service_worker/service_worker_messages.h" |
22 #include "content/common/service_worker/service_worker_types.h" | 22 #include "content/common/service_worker/service_worker_types.h" |
23 #include "content/common/service_worker/service_worker_utils.h" | 23 #include "content/common/service_worker/service_worker_utils.h" |
| 24 #include "content/public/browser/content_browser_client.h" |
24 #include "content/public/common/browser_side_navigation_policy.h" | 25 #include "content/public/common/browser_side_navigation_policy.h" |
25 #include "content/public/common/child_process_host.h" | 26 #include "content/public/common/child_process_host.h" |
| 27 #include "content/public/common/content_client.h" |
| 28 #include "content/public/common/origin_util.h" |
26 | 29 |
27 namespace content { | 30 namespace content { |
28 | 31 |
29 namespace { | 32 namespace { |
30 | 33 |
31 // PlzNavigate | 34 // PlzNavigate |
32 // Next ServiceWorkerProviderHost ID for navigations, starts at -2 and keeps | 35 // Next ServiceWorkerProviderHost ID for navigations, starts at -2 and keeps |
33 // going down. | 36 // going down. |
34 int g_next_navigation_provider_id = -2; | 37 int g_next_navigation_provider_id = -2; |
35 | 38 |
(...skipping 11 matching lines...) Expand all Loading... |
47 // static | 50 // static |
48 std::unique_ptr<ServiceWorkerProviderHost> | 51 std::unique_ptr<ServiceWorkerProviderHost> |
49 ServiceWorkerProviderHost::PreCreateNavigationHost( | 52 ServiceWorkerProviderHost::PreCreateNavigationHost( |
50 base::WeakPtr<ServiceWorkerContextCore> context) { | 53 base::WeakPtr<ServiceWorkerContextCore> context) { |
51 CHECK(IsBrowserSideNavigationEnabled()); | 54 CHECK(IsBrowserSideNavigationEnabled()); |
52 // Generate a new browser-assigned id for the host. | 55 // Generate a new browser-assigned id for the host. |
53 int provider_id = g_next_navigation_provider_id--; | 56 int provider_id = g_next_navigation_provider_id--; |
54 return std::unique_ptr<ServiceWorkerProviderHost>( | 57 return std::unique_ptr<ServiceWorkerProviderHost>( |
55 new ServiceWorkerProviderHost( | 58 new ServiceWorkerProviderHost( |
56 ChildProcessHost::kInvalidUniqueID, MSG_ROUTING_NONE, provider_id, | 59 ChildProcessHost::kInvalidUniqueID, MSG_ROUTING_NONE, provider_id, |
57 SERVICE_WORKER_PROVIDER_FOR_WINDOW, context, nullptr)); | 60 SERVICE_WORKER_PROVIDER_FOR_WINDOW, false, context, nullptr)); |
58 } | 61 } |
59 | 62 |
60 ServiceWorkerProviderHost::ServiceWorkerProviderHost( | 63 ServiceWorkerProviderHost::ServiceWorkerProviderHost( |
61 int render_process_id, | 64 int render_process_id, |
62 int route_id, | 65 int route_id, |
63 int provider_id, | 66 int provider_id, |
64 ServiceWorkerProviderType provider_type, | 67 ServiceWorkerProviderType provider_type, |
| 68 bool is_parent_frame_secure, |
65 base::WeakPtr<ServiceWorkerContextCore> context, | 69 base::WeakPtr<ServiceWorkerContextCore> context, |
66 ServiceWorkerDispatcherHost* dispatcher_host) | 70 ServiceWorkerDispatcherHost* dispatcher_host) |
67 : client_uuid_(base::GenerateGUID()), | 71 : client_uuid_(base::GenerateGUID()), |
68 render_process_id_(render_process_id), | 72 render_process_id_(render_process_id), |
69 route_id_(route_id), | 73 route_id_(route_id), |
70 render_thread_id_(kDocumentMainThreadId), | 74 render_thread_id_(kDocumentMainThreadId), |
71 provider_id_(provider_id), | 75 provider_id_(provider_id), |
72 provider_type_(provider_type), | 76 provider_type_(provider_type), |
| 77 is_parent_frame_secure_(is_parent_frame_secure), |
73 context_(context), | 78 context_(context), |
74 dispatcher_host_(dispatcher_host), | 79 dispatcher_host_(dispatcher_host), |
75 allow_association_(true) { | 80 allow_association_(true) { |
76 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_); | 81 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_); |
77 | 82 |
78 // PlzNavigate | 83 // PlzNavigate |
79 CHECK(render_process_id != ChildProcessHost::kInvalidUniqueID || | 84 CHECK(render_process_id != ChildProcessHost::kInvalidUniqueID || |
80 IsBrowserSideNavigationEnabled()); | 85 IsBrowserSideNavigationEnabled()); |
81 | 86 |
82 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) { | 87 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) { |
(...skipping 21 matching lines...) Expand all Loading... |
104 for (const GURL& pattern : associated_patterns_) | 109 for (const GURL& pattern : associated_patterns_) |
105 DecreaseProcessReference(pattern); | 110 DecreaseProcessReference(pattern); |
106 } | 111 } |
107 | 112 |
108 int ServiceWorkerProviderHost::frame_id() const { | 113 int ServiceWorkerProviderHost::frame_id() const { |
109 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_WINDOW) | 114 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_WINDOW) |
110 return route_id_; | 115 return route_id_; |
111 return MSG_ROUTING_NONE; | 116 return MSG_ROUTING_NONE; |
112 } | 117 } |
113 | 118 |
| 119 bool ServiceWorkerProviderHost::IsContextSecureForServiceWorker() const { |
| 120 DCHECK(document_url_.is_valid()); |
| 121 if (!OriginCanAccessServiceWorkers(document_url_)) |
| 122 return false; |
| 123 |
| 124 if (is_parent_frame_secure()) |
| 125 return true; |
| 126 |
| 127 std::set<std::string> schemes; |
| 128 GetContentClient()->browser()->GetSchemesBypassingSecureContextCheckWhitelist( |
| 129 &schemes); |
| 130 return schemes.find(document_url().scheme()) != schemes.end(); |
| 131 } |
| 132 |
114 void ServiceWorkerProviderHost::OnVersionAttributesChanged( | 133 void ServiceWorkerProviderHost::OnVersionAttributesChanged( |
115 ServiceWorkerRegistration* registration, | 134 ServiceWorkerRegistration* registration, |
116 ChangedVersionAttributesMask changed_mask, | 135 ChangedVersionAttributesMask changed_mask, |
117 const ServiceWorkerRegistrationInfo& info) { | 136 const ServiceWorkerRegistrationInfo& info) { |
118 if (!get_ready_callback_ || get_ready_callback_->called) | 137 if (!get_ready_callback_ || get_ready_callback_->called) |
119 return; | 138 return; |
120 if (changed_mask.active_changed() && registration->active_version()) { | 139 if (changed_mask.active_changed() && registration->active_version()) { |
121 // Wait until the state change so we don't send the get for ready | 140 // Wait until the state change so we don't send the get for ready |
122 // registration complete message before set version attributes message. | 141 // registration complete message before set version attributes message. |
123 registration->active_version()->RegisterStatusChangeCallback(base::Bind( | 142 registration->active_version()->RegisterStatusChangeCallback(base::Bind( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 document_url_ = url; | 177 document_url_ = url; |
159 } | 178 } |
160 | 179 |
161 void ServiceWorkerProviderHost::SetTopmostFrameUrl(const GURL& url) { | 180 void ServiceWorkerProviderHost::SetTopmostFrameUrl(const GURL& url) { |
162 topmost_frame_url_ = url; | 181 topmost_frame_url_ = url; |
163 } | 182 } |
164 | 183 |
165 void ServiceWorkerProviderHost::SetControllerVersionAttribute( | 184 void ServiceWorkerProviderHost::SetControllerVersionAttribute( |
166 ServiceWorkerVersion* version, | 185 ServiceWorkerVersion* version, |
167 bool notify_controllerchange) { | 186 bool notify_controllerchange) { |
| 187 CHECK(!version || IsContextSecureForServiceWorker()); |
168 if (version == controlling_version_.get()) | 188 if (version == controlling_version_.get()) |
169 return; | 189 return; |
170 | 190 |
171 scoped_refptr<ServiceWorkerVersion> previous_version = controlling_version_; | 191 scoped_refptr<ServiceWorkerVersion> previous_version = controlling_version_; |
172 controlling_version_ = version; | 192 controlling_version_ = version; |
173 if (version) | 193 if (version) |
174 version->AddControllee(this); | 194 version->AddControllee(this); |
175 if (previous_version.get()) | 195 if (previous_version.get()) |
176 previous_version->RemoveControllee(this); | 196 previous_version->RemoveControllee(this); |
177 | 197 |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 Send(new ServiceWorkerMsg_SetControllerServiceWorker( | 663 Send(new ServiceWorkerMsg_SetControllerServiceWorker( |
644 render_thread_id_, provider_id(), | 664 render_thread_id_, provider_id(), |
645 GetOrCreateServiceWorkerHandle( | 665 GetOrCreateServiceWorkerHandle( |
646 associated_registration_->active_version()), | 666 associated_registration_->active_version()), |
647 false /* shouldNotifyControllerChange */)); | 667 false /* shouldNotifyControllerChange */)); |
648 } | 668 } |
649 } | 669 } |
650 } | 670 } |
651 | 671 |
652 } // namespace content | 672 } // namespace content |
OLD | NEW |