Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(345)

Side by Side Diff: content/browser/service_worker/service_worker_version.cc

Issue 1007133002: ServiceWorker: Support includeUncontrolled option in clients.matchAll() (1/2, chromium) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 975 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 ServiceWorkerStatusCode status = 986 ServiceWorkerStatusCode status =
987 embedded_worker_->SendMessage(ServiceWorkerMsg_ActivateEvent(request_id)); 987 embedded_worker_->SendMessage(ServiceWorkerMsg_ActivateEvent(request_id));
988 if (status != SERVICE_WORKER_OK) { 988 if (status != SERVICE_WORKER_OK) {
989 activate_callbacks_.Remove(request_id); 989 activate_callbacks_.Remove(request_id);
990 RunSoon(base::Bind(callback, status)); 990 RunSoon(base::Bind(callback, status));
991 } 991 }
992 } 992 }
993 993
994 void ServiceWorkerVersion::OnGetClients( 994 void ServiceWorkerVersion::OnGetClients(
995 int request_id, 995 int request_id,
996 const ServiceWorkerClientQueryOptions& /* options */) { 996 const ServiceWorkerClientQueryOptions& options) {
997 // TODO(kinuko): Handle ClientQueryOptions. (crbug.com/455241, 460415 etc) 997 if (controllee_map_.empty() && options.include_uncontrolled) {
nhiroki 2015/03/16 06:37:58 "controllee_map_.empty() && !options.include_uncon
kinuko 2015/03/20 08:19:39 Done. This is how we need tests for every code...
998 if (controllee_map_.empty()) {
999 if (running_status() == RUNNING) { 998 if (running_status() == RUNNING) {
1000 embedded_worker_->SendMessage( 999 embedded_worker_->SendMessage(
1001 ServiceWorkerMsg_DidGetClients(request_id, 1000 ServiceWorkerMsg_DidGetClients(request_id,
1002 std::vector<ServiceWorkerClientInfo>())); 1001 std::vector<ServiceWorkerClientInfo>()));
1003 } 1002 }
1004 return; 1003 return;
1005 } 1004 }
1006 1005
1007 TRACE_EVENT0("ServiceWorker", 1006 TRACE_EVENT0("ServiceWorker",
1008 "ServiceWorkerVersion::OnGetClients"); 1007 "ServiceWorkerVersion::OnGetClients");
1009 1008
1009 // 4.3.1 matchAll(options)
1010 std::vector<Tuple<int,int,std::string>> clients_info; 1010 std::vector<Tuple<int,int,std::string>> clients_info;
1011 for (auto& controllee : controllee_map_) { 1011 if (!options.include_uncontrolled) {
1012 int process_id = controllee.second->process_id(); 1012 for (auto& controllee : controllee_map_) {
1013 int frame_id = controllee.second->frame_id(); 1013 int process_id = controllee.second->process_id();
1014 const std::string& client_uuid = controllee.first; 1014 int frame_id = controllee.second->frame_id();
1015 1015 const std::string& client_uuid = controllee.first;
1016 clients_info.push_back(MakeTuple(process_id, frame_id, client_uuid)); 1016 clients_info.push_back(MakeTuple(process_id, frame_id, client_uuid));
1017 }
1018 } else {
1019 for (auto it = context_->GetProviderHostIteratorForOrigin(
1020 script_url_.GetOrigin());
1021 !it->IsAtEnd(); it->Advance()) {
1022 ServiceWorkerProviderHost* host = it->GetProviderHost();
1023 clients_info.push_back(
1024 MakeTuple(host->process_id(), host->frame_id(), host->client_uuid()));
nhiroki 2015/03/16 06:37:58 We might need to check host->provider_type() and t
kinuko 2015/03/20 08:19:39 That's a good point, hmm yes it looks like. I chan
1025 }
1017 } 1026 }
1018 1027
1019 BrowserThread::PostTask( 1028 BrowserThread::PostTask(
1020 BrowserThread::UI, FROM_HERE, 1029 BrowserThread::UI, FROM_HERE,
1021 base::Bind(&OnGetClientsFromUI, clients_info, script_url_, 1030 base::Bind(&OnGetClientsFromUI, clients_info, script_url_,
1022 base::Bind(&ServiceWorkerVersion::DidGetClients, 1031 base::Bind(&ServiceWorkerVersion::DidGetClients,
1023 weak_factory_.GetWeakPtr(), 1032 weak_factory_.GetWeakPtr(),
1024 request_id))); 1033 request_id)));
1025 1034
1026 } 1035 }
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 if (running_status() != RUNNING) 1235 if (running_status() != RUNNING)
1227 return; 1236 return;
1228 1237
1229 if (render_process_id == ChildProcessHost::kInvalidUniqueID && 1238 if (render_process_id == ChildProcessHost::kInvalidUniqueID &&
1230 render_frame_id == MSG_ROUTING_NONE) { 1239 render_frame_id == MSG_ROUTING_NONE) {
1231 embedded_worker_->SendMessage(ServiceWorkerMsg_OpenWindowError( 1240 embedded_worker_->SendMessage(ServiceWorkerMsg_OpenWindowError(
1232 request_id, "Something went wrong while trying to open the window.")); 1241 request_id, "Something went wrong while trying to open the window."));
1233 return; 1242 return;
1234 } 1243 }
1235 1244
1236 for (const auto& it : controllee_map_) { 1245 for (auto it =
1237 const ServiceWorkerProviderHost* provider_host = it.second; 1246 context_->GetProviderHostIteratorForOrigin(script_url_.GetOrigin());
1247 !it->IsAtEnd(); it->Advance()) {
1248 ServiceWorkerProviderHost* provider_host = it->GetProviderHost();
1238 if (provider_host->process_id() != render_process_id || 1249 if (provider_host->process_id() != render_process_id ||
1239 provider_host->frame_id() != render_frame_id) { 1250 provider_host->frame_id() != render_frame_id) {
1240 continue; 1251 continue;
1241 } 1252 }
1242 1253 provider_host->GetClientInfo(base::Bind(
1243 // it.second is the client_uuid associated with the provider_host. 1254 &ServiceWorkerVersion::OnOpenWindowFinished, weak_factory_.GetWeakPtr(),
1244 provider_host->GetClientInfo( 1255 request_id, provider_host->client_uuid()));
1245 base::Bind(&ServiceWorkerVersion::OnOpenWindowFinished,
1246 weak_factory_.GetWeakPtr(), request_id, it.first));
1247 return; 1256 return;
1248 } 1257 }
1249 1258
1250 // If here, it means that no provider_host was found, in which case, the 1259 // If here, it means that no provider_host was found, in which case, the
1251 // renderer should still be informed that the window was opened. 1260 // renderer should still be informed that the window was opened.
1252 OnOpenWindowFinished(request_id, std::string(), ServiceWorkerClientInfo()); 1261 OnOpenWindowFinished(request_id, std::string(), ServiceWorkerClientInfo());
1253 } 1262 }
1254 1263
1255 void ServiceWorkerVersion::OnOpenWindowFinished( 1264 void ServiceWorkerVersion::OnOpenWindowFinished(
1256 int request_id, 1265 int request_id,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 TRACE_EVENT_ASYNC_END1("ServiceWorker", 1316 TRACE_EVENT_ASYNC_END1("ServiceWorker",
1308 "ServiceWorkerVersion::OnClearCachedMetadata", 1317 "ServiceWorkerVersion::OnClearCachedMetadata",
1309 callback_id, "result", result); 1318 callback_id, "result", result);
1310 FOR_EACH_OBSERVER(Listener, listeners_, OnCachedMetadataUpdated(this)); 1319 FOR_EACH_OBSERVER(Listener, listeners_, OnCachedMetadataUpdated(this));
1311 } 1320 }
1312 1321
1313 void ServiceWorkerVersion::OnPostMessageToClient( 1322 void ServiceWorkerVersion::OnPostMessageToClient(
1314 const std::string& client_uuid, 1323 const std::string& client_uuid,
1315 const base::string16& message, 1324 const base::string16& message,
1316 const std::vector<TransferredMessagePort>& sent_message_ports) { 1325 const std::vector<TransferredMessagePort>& sent_message_ports) {
1326 if (!context_)
1327 return;
1317 TRACE_EVENT1("ServiceWorker", 1328 TRACE_EVENT1("ServiceWorker",
1318 "ServiceWorkerVersion::OnPostMessageToDocument", 1329 "ServiceWorkerVersion::OnPostMessageToDocument",
1319 "Client id", client_uuid); 1330 "Client id", client_uuid);
1320 auto it = controllee_map_.find(client_uuid); 1331 ServiceWorkerProviderHost* provider_host =
1321 if (it == controllee_map_.end()) { 1332 context_->GetProviderHostByClientID(client_uuid);
1333 if (!provider_host) {
1322 // The client may already have been closed, just ignore. 1334 // The client may already have been closed, just ignore.
1323 return; 1335 return;
1324 } 1336 }
1325 if (it->second->document_url().GetOrigin() != script_url_.GetOrigin()) { 1337 if (provider_host->document_url().GetOrigin() != script_url_.GetOrigin()) {
1326 // The client does not belong to the same origin as this ServiceWorker, 1338 // The client does not belong to the same origin as this ServiceWorker,
1327 // possibly due to timing issue or bad message. 1339 // possibly due to timing issue or bad message.
1328 return; 1340 return;
1329 } 1341 }
1330 it->second->PostMessage(message, sent_message_ports); 1342 provider_host->PostMessage(message, sent_message_ports);
1331 } 1343 }
1332 1344
1333 void ServiceWorkerVersion::OnFocusClient(int request_id, 1345 void ServiceWorkerVersion::OnFocusClient(int request_id,
1334 const std::string& client_uuid) { 1346 const std::string& client_uuid) {
1347 if (!context_)
1348 return;
1335 TRACE_EVENT2("ServiceWorker", 1349 TRACE_EVENT2("ServiceWorker",
1336 "ServiceWorkerVersion::OnFocusClient", 1350 "ServiceWorkerVersion::OnFocusClient",
1337 "Request id", request_id, 1351 "Request id", request_id,
1338 "Client id", client_uuid); 1352 "Client id", client_uuid);
1339 auto it = controllee_map_.find(client_uuid); 1353 ServiceWorkerProviderHost* provider_host =
1340 if (it == controllee_map_.end()) { 1354 context_->GetProviderHostByClientID(client_uuid);
1355 if (!provider_host) {
1341 // The client may already have been closed, just ignore. 1356 // The client may already have been closed, just ignore.
1342 return; 1357 return;
1343 } 1358 }
1344 if (it->second->document_url().GetOrigin() != script_url_.GetOrigin()) { 1359 if (provider_host->document_url().GetOrigin() != script_url_.GetOrigin()) {
1345 // The client does not belong to the same origin as this ServiceWorker, 1360 // The client does not belong to the same origin as this ServiceWorker,
1346 // possibly due to timing issue or bad message. 1361 // possibly due to timing issue or bad message.
1347 return; 1362 return;
1348 } 1363 }
1349 1364 provider_host->Focus(base::Bind(&ServiceWorkerVersion::OnFocusClientFinished,
1350 it->second->Focus( 1365 weak_factory_.GetWeakPtr(), request_id,
1351 base::Bind(&ServiceWorkerVersion::OnFocusClientFinished, 1366 client_uuid));
1352 weak_factory_.GetWeakPtr(),
1353 request_id,
1354 client_uuid));
1355 } 1367 }
1356 1368
1357 void ServiceWorkerVersion::OnFocusClientFinished( 1369 void ServiceWorkerVersion::OnFocusClientFinished(
1358 int request_id, 1370 int request_id,
1359 const std::string& cliend_uuid, 1371 const std::string& cliend_uuid,
1360 const ServiceWorkerClientInfo& client) { 1372 const ServiceWorkerClientInfo& client) {
1361 DCHECK_CURRENTLY_ON(BrowserThread::IO); 1373 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1362 1374
1363 if (running_status() != RUNNING) 1375 if (running_status() != RUNNING)
1364 return; 1376 return;
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
1652 int request_id) { 1664 int request_id) {
1653 callbacks->Remove(request_id); 1665 callbacks->Remove(request_id);
1654 if (is_doomed_) { 1666 if (is_doomed_) {
1655 // The stop should be already scheduled, but try to stop immediately, in 1667 // The stop should be already scheduled, but try to stop immediately, in
1656 // order to release worker resources soon. 1668 // order to release worker resources soon.
1657 StopWorkerIfIdle(); 1669 StopWorkerIfIdle();
1658 } 1670 }
1659 } 1671 }
1660 1672
1661 } // namespace content 1673 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698