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" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 job_ = new ServiceWorkerURLRequestJob(request, | 87 job_ = new ServiceWorkerURLRequestJob(request, |
88 network_delegate, | 88 network_delegate, |
89 provider_host_, | 89 provider_host_, |
90 blob_storage_context_, | 90 blob_storage_context_, |
91 request_mode_, | 91 request_mode_, |
92 credentials_mode_, | 92 credentials_mode_, |
93 request_context_type_, | 93 request_context_type_, |
94 frame_type_, | 94 frame_type_, |
95 body_); | 95 body_); |
96 if (is_main_resource_load_) | 96 if (is_main_resource_load_) |
97 PrepareForMainResource(request->url()); | 97 PrepareForMainResource(request); |
98 else | 98 else |
99 PrepareForSubResource(); | 99 PrepareForSubResource(); |
100 | 100 |
101 if (job_->ShouldFallbackToNetwork()) { | 101 if (job_->ShouldFallbackToNetwork()) { |
102 // If we know we can fallback to network at this point (in case | 102 // If we know we can fallback to network at this point (in case |
103 // the storage lookup returned immediately), just return NULL here to | 103 // the storage lookup returned immediately), just return NULL here to |
104 // fallback to network. | 104 // fallback to network. |
105 job_ = NULL; | 105 job_ = NULL; |
106 return NULL; | 106 return NULL; |
107 } | 107 } |
(...skipping 16 matching lines...) Expand all Loading... |
124 } | 124 } |
125 job_->GetExtraResponseInfo(was_fetched_via_service_worker, | 125 job_->GetExtraResponseInfo(was_fetched_via_service_worker, |
126 was_fallback_required_by_service_worker, | 126 was_fallback_required_by_service_worker, |
127 original_url_via_service_worker, | 127 original_url_via_service_worker, |
128 fetch_start_time, | 128 fetch_start_time, |
129 fetch_ready_time, | 129 fetch_ready_time, |
130 fetch_end_time); | 130 fetch_end_time); |
131 } | 131 } |
132 | 132 |
133 void ServiceWorkerControlleeRequestHandler::PrepareForMainResource( | 133 void ServiceWorkerControlleeRequestHandler::PrepareForMainResource( |
134 const GURL& url) { | 134 const net::URLRequest* request) { |
135 DCHECK(job_.get()); | 135 DCHECK(job_.get()); |
136 DCHECK(context_); | 136 DCHECK(context_); |
137 DCHECK(provider_host_); | 137 DCHECK(provider_host_); |
138 TRACE_EVENT_ASYNC_BEGIN1( | 138 TRACE_EVENT_ASYNC_BEGIN1( |
139 "ServiceWorker", | 139 "ServiceWorker", |
140 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", | 140 "ServiceWorkerControlleeRequestHandler::PrepareForMainResource", |
141 job_.get(), | 141 job_.get(), |
142 "URL", url.spec()); | 142 "URL", request->url().spec()); |
143 // The corresponding provider_host may already have associated a registration | 143 // The corresponding provider_host may already have associated a registration |
144 // in redirect case, unassociate it now. | 144 // in redirect case, unassociate it now. |
145 provider_host_->DisassociateRegistration(); | 145 provider_host_->DisassociateRegistration(); |
146 | 146 |
147 // Also prevent a registrater job for establishing an association to a new | 147 // Also prevent a registrater job for establishing an association to a new |
148 // registration while we're finding an existing registration. | 148 // registration while we're finding an existing registration. |
149 provider_host_->SetAllowAssociation(false); | 149 provider_host_->SetAllowAssociation(false); |
150 | 150 |
151 GURL stripped_url = net::SimplifyUrlForRequest(url); | 151 GURL stripped_url = net::SimplifyUrlForRequest(request->url()); |
152 provider_host_->SetDocumentUrl(stripped_url); | 152 provider_host_->SetDocumentUrl(stripped_url); |
| 153 provider_host_->SetTopmostFrameUrl(request->first_party_for_cookies()); |
153 context_->storage()->FindRegistrationForDocument( | 154 context_->storage()->FindRegistrationForDocument( |
154 stripped_url, | 155 stripped_url, |
155 base::Bind(&self::DidLookupRegistrationForMainResource, | 156 base::Bind(&self::DidLookupRegistrationForMainResource, |
156 weak_factory_.GetWeakPtr())); | 157 weak_factory_.GetWeakPtr())); |
157 } | 158 } |
158 | 159 |
159 void | 160 void |
160 ServiceWorkerControlleeRequestHandler::DidLookupRegistrationForMainResource( | 161 ServiceWorkerControlleeRequestHandler::DidLookupRegistrationForMainResource( |
161 ServiceWorkerStatusCode status, | 162 ServiceWorkerStatusCode status, |
162 const scoped_refptr<ServiceWorkerRegistration>& registration) { | 163 const scoped_refptr<ServiceWorkerRegistration>& registration) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 } | 248 } |
248 | 249 |
249 void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() { | 250 void ServiceWorkerControlleeRequestHandler::PrepareForSubResource() { |
250 DCHECK(job_.get()); | 251 DCHECK(job_.get()); |
251 DCHECK(context_); | 252 DCHECK(context_); |
252 DCHECK(provider_host_->active_version()); | 253 DCHECK(provider_host_->active_version()); |
253 job_->ForwardToServiceWorker(); | 254 job_->ForwardToServiceWorker(); |
254 } | 255 } |
255 | 256 |
256 } // namespace content | 257 } // namespace content |
OLD | NEW |