Chromium Code Reviews| 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/location.h" | 8 #include "base/location.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 1176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1187 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_OpenWindow, | 1187 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_OpenWindow, |
| 1188 OnOpenWindow) | 1188 OnOpenWindow) |
| 1189 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetCachedMetadata, | 1189 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetCachedMetadata, |
| 1190 OnSetCachedMetadata) | 1190 OnSetCachedMetadata) |
| 1191 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ClearCachedMetadata, | 1191 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ClearCachedMetadata, |
| 1192 OnClearCachedMetadata) | 1192 OnClearCachedMetadata) |
| 1193 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToClient, | 1193 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToClient, |
| 1194 OnPostMessageToClient) | 1194 OnPostMessageToClient) |
| 1195 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FocusClient, | 1195 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_FocusClient, |
| 1196 OnFocusClient) | 1196 OnFocusClient) |
| 1197 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_NavigateClient, OnNavigateClient) | |
| 1197 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SkipWaiting, | 1198 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SkipWaiting, |
| 1198 OnSkipWaiting) | 1199 OnSkipWaiting) |
| 1199 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ClaimClients, | 1200 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ClaimClients, |
| 1200 OnClaimClients) | 1201 OnClaimClients) |
| 1201 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_Pong, OnPongFromWorker) | 1202 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_Pong, OnPongFromWorker) |
| 1202 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_StashMessagePort, | 1203 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_StashMessagePort, |
| 1203 OnStashMessagePort) | 1204 OnStashMessagePort) |
| 1204 IPC_MESSAGE_UNHANDLED(handled = false) | 1205 IPC_MESSAGE_UNHANDLED(handled = false) |
| 1205 IPC_END_MESSAGE_MAP() | 1206 IPC_END_MESSAGE_MAP() |
| 1206 return handled; | 1207 return handled; |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1619 if (provider_host->document_url().GetOrigin() != script_url_.GetOrigin()) { | 1620 if (provider_host->document_url().GetOrigin() != script_url_.GetOrigin()) { |
| 1620 // The client does not belong to the same origin as this ServiceWorker, | 1621 // The client does not belong to the same origin as this ServiceWorker, |
| 1621 // possibly due to timing issue or bad message. | 1622 // possibly due to timing issue or bad message. |
| 1622 return; | 1623 return; |
| 1623 } | 1624 } |
| 1624 provider_host->Focus(base::Bind(&ServiceWorkerVersion::OnFocusClientFinished, | 1625 provider_host->Focus(base::Bind(&ServiceWorkerVersion::OnFocusClientFinished, |
| 1625 weak_factory_.GetWeakPtr(), request_id, | 1626 weak_factory_.GetWeakPtr(), request_id, |
| 1626 client_uuid)); | 1627 client_uuid)); |
| 1627 } | 1628 } |
| 1628 | 1629 |
| 1630 void ServiceWorkerVersion::OnNavigateClient(int request_id, | |
| 1631 const std::string& client_uuid, | |
| 1632 const GURL& url) { | |
| 1633 if (!context_) | |
| 1634 return; | |
| 1635 TRACE_EVENT2("ServiceWorker", "ServiceWorkerVersion::OnNavigateClient", | |
| 1636 "Request id", request_id, "Client id", client_uuid); | |
| 1637 ServiceWorkerProviderHost* provider_host = | |
| 1638 context_->GetProviderHostByClientID(client_uuid); | |
| 1639 if (!provider_host) { | |
| 1640 // The client may already have been closed, just ignore. | |
| 1641 return; | |
| 1642 } | |
|
nhiroki
2015/06/23 10:14:37
We need to verify that provider_host's active work
zino
2015/07/07 15:40:36
Maybe done but I'm not sure.
Please correct me.
| |
| 1643 | |
|
nhiroki
2015/06/23 10:14:37
|url| passed from a renderer should be verified be
zino
2015/07/07 15:40:36
Done.
| |
| 1644 provider_host->Navigate( | |
| 1645 url, | |
| 1646 base::Bind(&ServiceWorkerVersion::OnNavigateClientFinished, | |
| 1647 weak_factory_.GetWeakPtr(), request_id, client_uuid, url)); | |
| 1648 } | |
| 1649 | |
| 1629 void ServiceWorkerVersion::OnFocusClientFinished( | 1650 void ServiceWorkerVersion::OnFocusClientFinished( |
| 1630 int request_id, | 1651 int request_id, |
| 1631 const std::string& client_uuid, | 1652 const std::string& client_uuid, |
| 1632 const ServiceWorkerClientInfo& client) { | 1653 const ServiceWorkerClientInfo& client) { |
| 1633 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1654 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1634 | 1655 |
| 1635 if (running_status() != RUNNING) | 1656 if (running_status() != RUNNING) |
| 1636 return; | 1657 return; |
| 1637 | 1658 |
| 1638 ServiceWorkerClientInfo client_info(client); | 1659 ServiceWorkerClientInfo client_info(client); |
| 1639 client_info.client_uuid = client_uuid; | 1660 client_info.client_uuid = client_uuid; |
| 1640 | 1661 |
| 1641 embedded_worker_->SendMessage(ServiceWorkerMsg_FocusClientResponse( | 1662 embedded_worker_->SendMessage(ServiceWorkerMsg_FocusClientResponse( |
| 1642 request_id, client_info)); | 1663 request_id, client_info)); |
| 1643 } | 1664 } |
| 1644 | 1665 |
| 1666 void ServiceWorkerVersion::OnNavigateClientFinished( | |
| 1667 int request_id, | |
| 1668 const std::string& client_uuid, | |
| 1669 const GURL& url, | |
| 1670 const ServiceWorkerClientInfo& client) { | |
| 1671 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 1672 | |
| 1673 if (running_status() != RUNNING) | |
| 1674 return; | |
| 1675 | |
| 1676 ServiceWorkerClientInfo client_info(client); | |
| 1677 client_info.client_uuid = client_uuid; | |
| 1678 | |
| 1679 if (url.GetOrigin() != script_url_.GetOrigin()) { | |
| 1680 client_info = ServiceWorkerClientInfo(); | |
| 1681 } | |
|
nhiroki
2015/06/23 10:14:37
nit: you don't have to wrap a single line with {}
zino
2015/07/07 15:40:36
Done.
| |
| 1682 embedded_worker_->SendMessage( | |
| 1683 ServiceWorkerMsg_NavigateClientResponse(request_id, client_info)); | |
| 1684 } | |
| 1685 | |
| 1645 void ServiceWorkerVersion::OnSkipWaiting(int request_id) { | 1686 void ServiceWorkerVersion::OnSkipWaiting(int request_id) { |
| 1646 skip_waiting_ = true; | 1687 skip_waiting_ = true; |
| 1647 if (status_ != INSTALLED) | 1688 if (status_ != INSTALLED) |
| 1648 return DidSkipWaiting(request_id); | 1689 return DidSkipWaiting(request_id); |
| 1649 | 1690 |
| 1650 if (!context_) | 1691 if (!context_) |
| 1651 return; | 1692 return; |
| 1652 ServiceWorkerRegistration* registration = | 1693 ServiceWorkerRegistration* registration = |
| 1653 context_->GetLiveRegistration(registration_id_); | 1694 context_->GetLiveRegistration(registration_id_); |
| 1654 if (!registration) | 1695 if (!registration) |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2050 return SERVICE_WORKER_ERROR_ABORT; | 2091 return SERVICE_WORKER_ERROR_ABORT; |
| 2051 default: | 2092 default: |
| 2052 return SERVICE_WORKER_ERROR_NETWORK; | 2093 return SERVICE_WORKER_ERROR_NETWORK; |
| 2053 } | 2094 } |
| 2054 } | 2095 } |
| 2055 | 2096 |
| 2056 return default_code; | 2097 return default_code; |
| 2057 } | 2098 } |
| 2058 | 2099 |
| 2059 } // namespace content | 2100 } // namespace content |
| OLD | NEW |