| 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, FrameSecurityLevel::UNINITIALIZED, |
| 61 context, nullptr)); |
| 58 } | 62 } |
| 59 | 63 |
| 60 ServiceWorkerProviderHost::ServiceWorkerProviderHost( | 64 ServiceWorkerProviderHost::ServiceWorkerProviderHost( |
| 61 int render_process_id, | 65 int render_process_id, |
| 62 int route_id, | 66 int route_id, |
| 63 int provider_id, | 67 int provider_id, |
| 64 ServiceWorkerProviderType provider_type, | 68 ServiceWorkerProviderType provider_type, |
| 69 FrameSecurityLevel parent_frame_security_level, |
| 65 base::WeakPtr<ServiceWorkerContextCore> context, | 70 base::WeakPtr<ServiceWorkerContextCore> context, |
| 66 ServiceWorkerDispatcherHost* dispatcher_host) | 71 ServiceWorkerDispatcherHost* dispatcher_host) |
| 67 : client_uuid_(base::GenerateGUID()), | 72 : client_uuid_(base::GenerateGUID()), |
| 68 render_process_id_(render_process_id), | 73 render_process_id_(render_process_id), |
| 69 route_id_(route_id), | 74 route_id_(route_id), |
| 70 render_thread_id_(kDocumentMainThreadId), | 75 render_thread_id_(kDocumentMainThreadId), |
| 71 provider_id_(provider_id), | 76 provider_id_(provider_id), |
| 72 provider_type_(provider_type), | 77 provider_type_(provider_type), |
| 78 parent_frame_security_level_(parent_frame_security_level), |
| 73 context_(context), | 79 context_(context), |
| 74 dispatcher_host_(dispatcher_host), | 80 dispatcher_host_(dispatcher_host), |
| 75 allow_association_(true) { | 81 allow_association_(true) { |
| 76 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_); | 82 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_); |
| 77 | 83 |
| 78 // PlzNavigate | 84 // PlzNavigate |
| 79 CHECK(render_process_id != ChildProcessHost::kInvalidUniqueID || | 85 CHECK(render_process_id != ChildProcessHost::kInvalidUniqueID || |
| 80 IsBrowserSideNavigationEnabled()); | 86 IsBrowserSideNavigationEnabled()); |
| 81 | 87 |
| 82 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) { | 88 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 104 for (const GURL& pattern : associated_patterns_) | 110 for (const GURL& pattern : associated_patterns_) |
| 105 DecreaseProcessReference(pattern); | 111 DecreaseProcessReference(pattern); |
| 106 } | 112 } |
| 107 | 113 |
| 108 int ServiceWorkerProviderHost::frame_id() const { | 114 int ServiceWorkerProviderHost::frame_id() const { |
| 109 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_WINDOW) | 115 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_WINDOW) |
| 110 return route_id_; | 116 return route_id_; |
| 111 return MSG_ROUTING_NONE; | 117 return MSG_ROUTING_NONE; |
| 112 } | 118 } |
| 113 | 119 |
| 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 |
| 114 void ServiceWorkerProviderHost::OnVersionAttributesChanged( | 134 void ServiceWorkerProviderHost::OnVersionAttributesChanged( |
| 115 ServiceWorkerRegistration* registration, | 135 ServiceWorkerRegistration* registration, |
| 116 ChangedVersionAttributesMask changed_mask, | 136 ChangedVersionAttributesMask changed_mask, |
| 117 const ServiceWorkerRegistrationInfo& info) { | 137 const ServiceWorkerRegistrationInfo& info) { |
| 118 if (!get_ready_callback_ || get_ready_callback_->called) | 138 if (!get_ready_callback_ || get_ready_callback_->called) |
| 119 return; | 139 return; |
| 120 if (changed_mask.active_changed() && registration->active_version()) { | 140 if (changed_mask.active_changed() && registration->active_version()) { |
| 121 // Wait until the state change so we don't send the get for ready | 141 // Wait until the state change so we don't send the get for ready |
| 122 // registration complete message before set version attributes message. | 142 // registration complete message before set version attributes message. |
| 123 registration->active_version()->RegisterStatusChangeCallback(base::Bind( | 143 registration->active_version()->RegisterStatusChangeCallback(base::Bind( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 document_url_ = url; | 178 document_url_ = url; |
| 159 } | 179 } |
| 160 | 180 |
| 161 void ServiceWorkerProviderHost::SetTopmostFrameUrl(const GURL& url) { | 181 void ServiceWorkerProviderHost::SetTopmostFrameUrl(const GURL& url) { |
| 162 topmost_frame_url_ = url; | 182 topmost_frame_url_ = url; |
| 163 } | 183 } |
| 164 | 184 |
| 165 void ServiceWorkerProviderHost::SetControllerVersionAttribute( | 185 void ServiceWorkerProviderHost::SetControllerVersionAttribute( |
| 166 ServiceWorkerVersion* version, | 186 ServiceWorkerVersion* version, |
| 167 bool notify_controllerchange) { | 187 bool notify_controllerchange) { |
| 188 CHECK(!version || IsContextSecureForServiceWorker()); |
| 168 if (version == controlling_version_.get()) | 189 if (version == controlling_version_.get()) |
| 169 return; | 190 return; |
| 170 | 191 |
| 171 scoped_refptr<ServiceWorkerVersion> previous_version = controlling_version_; | 192 scoped_refptr<ServiceWorkerVersion> previous_version = controlling_version_; |
| 172 controlling_version_ = version; | 193 controlling_version_ = version; |
| 173 if (version) | 194 if (version) |
| 174 version->AddControllee(this); | 195 version->AddControllee(this); |
| 175 if (previous_version.get()) | 196 if (previous_version.get()) |
| 176 previous_version->RemoveControllee(this); | 197 previous_version->RemoveControllee(this); |
| 177 | 198 |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 Send(new ServiceWorkerMsg_SetControllerServiceWorker( | 664 Send(new ServiceWorkerMsg_SetControllerServiceWorker( |
| 644 render_thread_id_, provider_id(), | 665 render_thread_id_, provider_id(), |
| 645 GetOrCreateServiceWorkerHandle( | 666 GetOrCreateServiceWorkerHandle( |
| 646 associated_registration_->active_version()), | 667 associated_registration_->active_version()), |
| 647 false /* shouldNotifyControllerChange */)); | 668 false /* shouldNotifyControllerChange */)); |
| 648 } | 669 } |
| 649 } | 670 } |
| 650 } | 671 } |
| 651 | 672 |
| 652 } // namespace content | 673 } // namespace content |
| OLD | NEW |