| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_controllee_request_handl
er.h" | 5 #include "content/browser/service_worker/service_worker_controllee_request_handl
er.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "content/browser/service_worker/service_worker_context_core.h" | 8 #include "content/browser/service_worker/service_worker_context_core.h" |
| 9 #include "content/browser/service_worker/service_worker_metrics.h" | 9 #include "content/browser/service_worker/service_worker_metrics.h" |
| 10 #include "content/browser/service_worker/service_worker_provider_host.h" | 10 #include "content/browser/service_worker/service_worker_provider_host.h" |
| 11 #include "content/browser/service_worker/service_worker_registration.h" | 11 #include "content/browser/service_worker/service_worker_registration.h" |
| 12 #include "content/browser/service_worker/service_worker_url_request_job.h" | 12 #include "content/browser/service_worker/service_worker_url_request_job.h" |
| 13 #include "content/browser/service_worker/service_worker_utils.h" | 13 #include "content/browser/service_worker/service_worker_utils.h" |
| 14 #include "content/common/resource_request_body.h" | 14 #include "content/common/resource_request_body.h" |
| 15 #include "content/common/service_worker/service_worker_types.h" | 15 #include "content/common/service_worker/service_worker_types.h" |
| 16 #include "content/public/browser/content_browser_client.h" |
| 17 #include "content/public/common/content_client.h" |
| 16 #include "net/base/load_flags.h" | 18 #include "net/base/load_flags.h" |
| 17 #include "net/base/net_util.h" | 19 #include "net/base/net_util.h" |
| 18 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
| 19 | 21 |
| 20 namespace content { | 22 namespace content { |
| 21 | 23 |
| 22 ServiceWorkerControlleeRequestHandler::ServiceWorkerControlleeRequestHandler( | 24 ServiceWorkerControlleeRequestHandler::ServiceWorkerControlleeRequestHandler( |
| 23 base::WeakPtr<ServiceWorkerContextCore> context, | 25 base::WeakPtr<ServiceWorkerContextCore> context, |
| 24 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 26 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| 25 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, | 27 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 53 else | 55 else |
| 54 provider_host_->active_version()->DeferScheduledUpdate(); | 56 provider_host_->active_version()->DeferScheduledUpdate(); |
| 55 } | 57 } |
| 56 | 58 |
| 57 if (is_main_resource_load_ && provider_host_) | 59 if (is_main_resource_load_ && provider_host_) |
| 58 provider_host_->SetAllowAssociation(true); | 60 provider_host_->SetAllowAssociation(true); |
| 59 } | 61 } |
| 60 | 62 |
| 61 net::URLRequestJob* ServiceWorkerControlleeRequestHandler::MaybeCreateJob( | 63 net::URLRequestJob* ServiceWorkerControlleeRequestHandler::MaybeCreateJob( |
| 62 net::URLRequest* request, | 64 net::URLRequest* request, |
| 63 net::NetworkDelegate* network_delegate) { | 65 net::NetworkDelegate* network_delegate, |
| 66 ResourceContext* resource_context) { |
| 64 if (!context_ || !provider_host_) { | 67 if (!context_ || !provider_host_) { |
| 65 // We can't do anything other than to fall back to network. | 68 // We can't do anything other than to fall back to network. |
| 66 job_ = NULL; | 69 job_ = NULL; |
| 67 return NULL; | 70 return NULL; |
| 68 } | 71 } |
| 69 | 72 |
| 70 // This may get called multiple times for original and redirect requests: | 73 // This may get called multiple times for original and redirect requests: |
| 71 // A. original request case: job_ is null, no previous location info. | 74 // A. original request case: job_ is null, no previous location info. |
| 72 // B. redirect or restarted request case: | 75 // B. redirect or restarted request case: |
| 73 // a) job_ is non-null if the previous location was forwarded to SW. | 76 // a) job_ is non-null if the previous location was forwarded to SW. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 86 | 89 |
| 87 job_ = new ServiceWorkerURLRequestJob(request, | 90 job_ = new ServiceWorkerURLRequestJob(request, |
| 88 network_delegate, | 91 network_delegate, |
| 89 provider_host_, | 92 provider_host_, |
| 90 blob_storage_context_, | 93 blob_storage_context_, |
| 91 request_mode_, | 94 request_mode_, |
| 92 credentials_mode_, | 95 credentials_mode_, |
| 93 request_context_type_, | 96 request_context_type_, |
| 94 frame_type_, | 97 frame_type_, |
| 95 body_); | 98 body_); |
| 99 resource_context_ = resource_context; |
| 100 |
| 96 if (is_main_resource_load_) | 101 if (is_main_resource_load_) |
| 97 PrepareForMainResource(request); | 102 PrepareForMainResource(request); |
| 98 else | 103 else |
| 99 PrepareForSubResource(); | 104 PrepareForSubResource(); |
| 100 | 105 |
| 101 if (job_->ShouldFallbackToNetwork()) { | 106 if (job_->ShouldFallbackToNetwork()) { |
| 102 // If we know we can fallback to network at this point (in case | 107 // If we know we can fallback to network at this point (in case |
| 103 // the storage lookup returned immediately), just return NULL here to | 108 // the storage lookup returned immediately), just return NULL here to |
| 104 // fallback to network. | 109 // fallback to network. |
| 105 job_ = NULL; | 110 job_ = NULL; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 job_->FallbackToNetwork(); | 173 job_->FallbackToNetwork(); |
| 169 TRACE_EVENT_ASYNC_END1( | 174 TRACE_EVENT_ASYNC_END1( |
| 170 "ServiceWorker", | 175 "ServiceWorker", |
| 171 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", | 176 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", |
| 172 job_.get(), | 177 job_.get(), |
| 173 "Status", status); | 178 "Status", status); |
| 174 return; | 179 return; |
| 175 } | 180 } |
| 176 DCHECK(registration.get()); | 181 DCHECK(registration.get()); |
| 177 | 182 |
| 183 if (!GetContentClient()->browser()->AllowServiceWorker( |
| 184 registration->pattern(), |
| 185 provider_host_->topmost_frame_url(), |
| 186 resource_context_)) { |
| 187 job_->FallbackToNetwork(); |
| 188 TRACE_EVENT_ASYNC_END2( |
| 189 "ServiceWorker", |
| 190 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", |
| 191 job_.get(), |
| 192 "Status", status, |
| 193 "Info", "ServiceWorker is blocked"); |
| 194 return; |
| 195 } |
| 196 |
| 178 // Initiate activation of a waiting version. | 197 // Initiate activation of a waiting version. |
| 179 // Usually a register job initiates activation but that | 198 // Usually a register job initiates activation but that |
| 180 // doesn't happen if the browser exits prior to activation | 199 // doesn't happen if the browser exits prior to activation |
| 181 // having occurred. This check handles that case. | 200 // having occurred. This check handles that case. |
| 182 if (registration->waiting_version()) | 201 if (registration->waiting_version()) |
| 183 registration->ActivateWaitingVersionWhenReady(); | 202 registration->ActivateWaitingVersionWhenReady(); |
| 184 | 203 |
| 185 scoped_refptr<ServiceWorkerVersion> active_version = | 204 scoped_refptr<ServiceWorkerVersion> active_version = |
| 186 registration->active_version(); | 205 registration->active_version(); |
| 187 | 206 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 } | 267 } |
| 249 | 268 |
| 250 void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() { | 269 void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() { |
| 251 DCHECK(job_.get()); | 270 DCHECK(job_.get()); |
| 252 DCHECK(context_); | 271 DCHECK(context_); |
| 253 DCHECK(provider_host_->active_version()); | 272 DCHECK(provider_host_->active_version()); |
| 254 job_->ForwardToServiceWorker(); | 273 job_->ForwardToServiceWorker(); |
| 255 } | 274 } |
| 256 | 275 |
| 257 } // namespace content | 276 } // namespace content |
| OLD | NEW |