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