| 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_version.h" | 5 #include "content/browser/service_worker/service_worker_version.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 } | 287 } |
| 288 | 288 |
| 289 base::TimeDelta GetTickDuration(const base::TimeTicks& time) { | 289 base::TimeDelta GetTickDuration(const base::TimeTicks& time) { |
| 290 if (time.is_null()) | 290 if (time.is_null()) |
| 291 return base::TimeDelta(); | 291 return base::TimeDelta(); |
| 292 return base::TimeTicks().Now() - time; | 292 return base::TimeTicks().Now() - time; |
| 293 } | 293 } |
| 294 | 294 |
| 295 void OnGetWindowClientsFromUI( | 295 void OnGetWindowClientsFromUI( |
| 296 // The tuple contains process_id, frame_id, client_uuid. | 296 // The tuple contains process_id, frame_id, client_uuid. |
| 297 const std::vector<Tuple<int, int, std::string>>& clients_info, | 297 const std::vector<base::Tuple<int, int, std::string>>& clients_info, |
| 298 const GURL& script_url, | 298 const GURL& script_url, |
| 299 const GetClientsCallback& callback) { | 299 const GetClientsCallback& callback) { |
| 300 scoped_ptr<ServiceWorkerClients> clients(new ServiceWorkerClients); | 300 scoped_ptr<ServiceWorkerClients> clients(new ServiceWorkerClients); |
| 301 | 301 |
| 302 for (const auto& it : clients_info) { | 302 for (const auto& it : clients_info) { |
| 303 ServiceWorkerClientInfo info = | 303 ServiceWorkerClientInfo info = |
| 304 ServiceWorkerProviderHost::GetWindowClientInfoOnUI(get<0>(it), | 304 ServiceWorkerProviderHost::GetWindowClientInfoOnUI(base::get<0>(it), |
| 305 get<1>(it)); | 305 base::get<1>(it)); |
| 306 | 306 |
| 307 // If the request to the provider_host returned an empty | 307 // If the request to the provider_host returned an empty |
| 308 // ServiceWorkerClientInfo, that means that it wasn't possible to associate | 308 // ServiceWorkerClientInfo, that means that it wasn't possible to associate |
| 309 // it with a valid RenderFrameHost. It might be because the frame was killed | 309 // it with a valid RenderFrameHost. It might be because the frame was killed |
| 310 // or navigated in between. | 310 // or navigated in between. |
| 311 if (info.IsEmpty()) | 311 if (info.IsEmpty()) |
| 312 continue; | 312 continue; |
| 313 | 313 |
| 314 // We can get info for a frame that was navigating end ended up with a | 314 // We can get info for a frame that was navigating end ended up with a |
| 315 // different URL than expected. In such case, we should make sure to not | 315 // different URL than expected. In such case, we should make sure to not |
| 316 // expose cross-origin WindowClient. | 316 // expose cross-origin WindowClient. |
| 317 if (info.url.GetOrigin() != script_url.GetOrigin()) | 317 if (info.url.GetOrigin() != script_url.GetOrigin()) |
| 318 continue; | 318 continue; |
| 319 | 319 |
| 320 info.client_uuid = get<2>(it); | 320 info.client_uuid = base::get<2>(it); |
| 321 clients->push_back(info); | 321 clients->push_back(info); |
| 322 } | 322 } |
| 323 | 323 |
| 324 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 324 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 325 base::Bind(callback, base::Passed(&clients))); | 325 base::Bind(callback, base::Passed(&clients))); |
| 326 } | 326 } |
| 327 | 327 |
| 328 void AddWindowClient(ServiceWorkerProviderHost* host, | 328 void AddWindowClient( |
| 329 std::vector<Tuple<int, int, std::string>>* client_info) { | 329 ServiceWorkerProviderHost* host, |
| 330 std::vector<base::Tuple<int, int, std::string>>* client_info) { |
| 330 if (host->client_type() != blink::WebServiceWorkerClientTypeWindow) | 331 if (host->client_type() != blink::WebServiceWorkerClientTypeWindow) |
| 331 return; | 332 return; |
| 332 client_info->push_back( | 333 client_info->push_back(base::MakeTuple(host->process_id(), host->frame_id(), |
| 333 MakeTuple(host->process_id(), host->frame_id(), host->client_uuid())); | 334 host->client_uuid())); |
| 334 } | 335 } |
| 335 | 336 |
| 336 void AddNonWindowClient(ServiceWorkerProviderHost* host, | 337 void AddNonWindowClient(ServiceWorkerProviderHost* host, |
| 337 const ServiceWorkerClientQueryOptions& options, | 338 const ServiceWorkerClientQueryOptions& options, |
| 338 ServiceWorkerClients* clients) { | 339 ServiceWorkerClients* clients) { |
| 339 blink::WebServiceWorkerClientType host_client_type = host->client_type(); | 340 blink::WebServiceWorkerClientType host_client_type = host->client_type(); |
| 340 if (host_client_type == blink::WebServiceWorkerClientTypeWindow) | 341 if (host_client_type == blink::WebServiceWorkerClientTypeWindow) |
| 341 return; | 342 return; |
| 342 if (options.client_type != blink::WebServiceWorkerClientTypeAll && | 343 if (options.client_type != blink::WebServiceWorkerClientTypeAll && |
| 343 options.client_type != host_client_type) | 344 options.client_type != host_client_type) |
| (...skipping 1378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1722 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated, | 1723 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated, |
| 1723 weak_factory_.GetWeakPtr())); | 1724 weak_factory_.GetWeakPtr())); |
| 1724 } | 1725 } |
| 1725 } | 1726 } |
| 1726 | 1727 |
| 1727 void ServiceWorkerVersion::GetWindowClients( | 1728 void ServiceWorkerVersion::GetWindowClients( |
| 1728 int request_id, | 1729 int request_id, |
| 1729 const ServiceWorkerClientQueryOptions& options) { | 1730 const ServiceWorkerClientQueryOptions& options) { |
| 1730 DCHECK(options.client_type == blink::WebServiceWorkerClientTypeWindow || | 1731 DCHECK(options.client_type == blink::WebServiceWorkerClientTypeWindow || |
| 1731 options.client_type == blink::WebServiceWorkerClientTypeAll); | 1732 options.client_type == blink::WebServiceWorkerClientTypeAll); |
| 1732 std::vector<Tuple<int, int, std::string>> clients_info; | 1733 std::vector<base::Tuple<int, int, std::string>> clients_info; |
| 1733 if (!options.include_uncontrolled) { | 1734 if (!options.include_uncontrolled) { |
| 1734 for (auto& controllee : controllee_map_) | 1735 for (auto& controllee : controllee_map_) |
| 1735 AddWindowClient(controllee.second, &clients_info); | 1736 AddWindowClient(controllee.second, &clients_info); |
| 1736 } else { | 1737 } else { |
| 1737 for (auto it = | 1738 for (auto it = |
| 1738 context_->GetClientProviderHostIterator(script_url_.GetOrigin()); | 1739 context_->GetClientProviderHostIterator(script_url_.GetOrigin()); |
| 1739 !it->IsAtEnd(); it->Advance()) { | 1740 !it->IsAtEnd(); it->Advance()) { |
| 1740 AddWindowClient(it->GetProviderHost(), &clients_info); | 1741 AddWindowClient(it->GetProviderHost(), &clients_info); |
| 1741 } | 1742 } |
| 1742 } | 1743 } |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2018 return SERVICE_WORKER_ERROR_ABORT; | 2019 return SERVICE_WORKER_ERROR_ABORT; |
| 2019 default: | 2020 default: |
| 2020 return SERVICE_WORKER_ERROR_NETWORK; | 2021 return SERVICE_WORKER_ERROR_NETWORK; |
| 2021 } | 2022 } |
| 2022 } | 2023 } |
| 2023 | 2024 |
| 2024 return default_code; | 2025 return default_code; |
| 2025 } | 2026 } |
| 2026 | 2027 |
| 2027 } // namespace content | 2028 } // namespace content |
| OLD | NEW |