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

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

Issue 1024383003: Revert of 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
« no previous file with comments | « content/browser/service_worker/service_worker_provider_host.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 978 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 ServiceWorkerStatusCode status = 989 ServiceWorkerStatusCode status =
990 embedded_worker_->SendMessage(ServiceWorkerMsg_ActivateEvent(request_id)); 990 embedded_worker_->SendMessage(ServiceWorkerMsg_ActivateEvent(request_id));
991 if (status != SERVICE_WORKER_OK) { 991 if (status != SERVICE_WORKER_OK) {
992 activate_callbacks_.Remove(request_id); 992 activate_callbacks_.Remove(request_id);
993 RunSoon(base::Bind(callback, status)); 993 RunSoon(base::Bind(callback, status));
994 } 994 }
995 } 995 }
996 996
997 void ServiceWorkerVersion::OnGetClients( 997 void ServiceWorkerVersion::OnGetClients(
998 int request_id, 998 int request_id,
999 const ServiceWorkerClientQueryOptions& options) { 999 const ServiceWorkerClientQueryOptions& /* options */) {
1000 if (controllee_map_.empty() && !options.include_uncontrolled) { 1000 // TODO(kinuko): Handle ClientQueryOptions. (crbug.com/455241, 460415 etc)
1001 if (controllee_map_.empty()) {
1001 if (running_status() == RUNNING) { 1002 if (running_status() == RUNNING) {
1002 embedded_worker_->SendMessage( 1003 embedded_worker_->SendMessage(
1003 ServiceWorkerMsg_DidGetClients(request_id, 1004 ServiceWorkerMsg_DidGetClients(request_id,
1004 std::vector<ServiceWorkerClientInfo>())); 1005 std::vector<ServiceWorkerClientInfo>()));
1005 } 1006 }
1006 return; 1007 return;
1007 } 1008 }
1008 1009
1009 TRACE_EVENT0("ServiceWorker", 1010 TRACE_EVENT0("ServiceWorker",
1010 "ServiceWorkerVersion::OnGetClients"); 1011 "ServiceWorkerVersion::OnGetClients");
1011 1012
1012 // 4.3.1 matchAll(options)
1013 std::vector<Tuple<int,int,std::string>> clients_info; 1013 std::vector<Tuple<int,int,std::string>> clients_info;
1014 if (!options.include_uncontrolled) { 1014 for (auto& controllee : controllee_map_) {
1015 for (auto& controllee : controllee_map_) { 1015 int process_id = controllee.second->process_id();
1016 int process_id = controllee.second->process_id(); 1016 int frame_id = controllee.second->frame_id();
1017 int frame_id = controllee.second->frame_id(); 1017 const std::string& client_uuid = controllee.first;
1018 const std::string& client_uuid = controllee.first; 1018
1019 clients_info.push_back(MakeTuple(process_id, frame_id, client_uuid)); 1019 clients_info.push_back(MakeTuple(process_id, frame_id, client_uuid));
1020 }
1021 } else {
1022 for (auto it =
1023 context_->GetClientProviderHostIterator(script_url_.GetOrigin());
1024 !it->IsAtEnd(); it->Advance()) {
1025 ServiceWorkerProviderHost* host = it->GetProviderHost();
1026 clients_info.push_back(
1027 MakeTuple(host->process_id(), host->frame_id(), host->client_uuid()));
1028 }
1029 } 1020 }
1030 1021
1031 BrowserThread::PostTask( 1022 BrowserThread::PostTask(
1032 BrowserThread::UI, FROM_HERE, 1023 BrowserThread::UI, FROM_HERE,
1033 base::Bind(&OnGetClientsFromUI, clients_info, script_url_, 1024 base::Bind(&OnGetClientsFromUI, clients_info, script_url_,
1034 base::Bind(&ServiceWorkerVersion::DidGetClients, 1025 base::Bind(&ServiceWorkerVersion::DidGetClients,
1035 weak_factory_.GetWeakPtr(), 1026 weak_factory_.GetWeakPtr(),
1036 request_id))); 1027 request_id)));
1037 1028
1038 } 1029 }
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1238 if (running_status() != RUNNING) 1229 if (running_status() != RUNNING)
1239 return; 1230 return;
1240 1231
1241 if (render_process_id == ChildProcessHost::kInvalidUniqueID && 1232 if (render_process_id == ChildProcessHost::kInvalidUniqueID &&
1242 render_frame_id == MSG_ROUTING_NONE) { 1233 render_frame_id == MSG_ROUTING_NONE) {
1243 embedded_worker_->SendMessage(ServiceWorkerMsg_OpenWindowError( 1234 embedded_worker_->SendMessage(ServiceWorkerMsg_OpenWindowError(
1244 request_id, "Something went wrong while trying to open the window.")); 1235 request_id, "Something went wrong while trying to open the window."));
1245 return; 1236 return;
1246 } 1237 }
1247 1238
1248 for (auto it = 1239 for (const auto& it : controllee_map_) {
1249 context_->GetClientProviderHostIterator(script_url_.GetOrigin()); 1240 const ServiceWorkerProviderHost* provider_host = it.second;
1250 !it->IsAtEnd(); it->Advance()) {
1251 ServiceWorkerProviderHost* provider_host = it->GetProviderHost();
1252 if (provider_host->process_id() != render_process_id || 1241 if (provider_host->process_id() != render_process_id ||
1253 provider_host->frame_id() != render_frame_id) { 1242 provider_host->frame_id() != render_frame_id) {
1254 continue; 1243 continue;
1255 } 1244 }
1256 provider_host->GetClientInfo(base::Bind( 1245
1257 &ServiceWorkerVersion::OnOpenWindowFinished, weak_factory_.GetWeakPtr(), 1246 // it.second is the client_uuid associated with the provider_host.
1258 request_id, provider_host->client_uuid())); 1247 provider_host->GetClientInfo(
1248 base::Bind(&ServiceWorkerVersion::OnOpenWindowFinished,
1249 weak_factory_.GetWeakPtr(), request_id, it.first));
1259 return; 1250 return;
1260 } 1251 }
1261 1252
1262 // If here, it means that no provider_host was found, in which case, the 1253 // If here, it means that no provider_host was found, in which case, the
1263 // renderer should still be informed that the window was opened. 1254 // renderer should still be informed that the window was opened.
1264 OnOpenWindowFinished(request_id, std::string(), ServiceWorkerClientInfo()); 1255 OnOpenWindowFinished(request_id, std::string(), ServiceWorkerClientInfo());
1265 } 1256 }
1266 1257
1267 void ServiceWorkerVersion::OnOpenWindowFinished( 1258 void ServiceWorkerVersion::OnOpenWindowFinished(
1268 int request_id, 1259 int request_id,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1319 TRACE_EVENT_ASYNC_END1("ServiceWorker", 1310 TRACE_EVENT_ASYNC_END1("ServiceWorker",
1320 "ServiceWorkerVersion::OnClearCachedMetadata", 1311 "ServiceWorkerVersion::OnClearCachedMetadata",
1321 callback_id, "result", result); 1312 callback_id, "result", result);
1322 FOR_EACH_OBSERVER(Listener, listeners_, OnCachedMetadataUpdated(this)); 1313 FOR_EACH_OBSERVER(Listener, listeners_, OnCachedMetadataUpdated(this));
1323 } 1314 }
1324 1315
1325 void ServiceWorkerVersion::OnPostMessageToClient( 1316 void ServiceWorkerVersion::OnPostMessageToClient(
1326 const std::string& client_uuid, 1317 const std::string& client_uuid,
1327 const base::string16& message, 1318 const base::string16& message,
1328 const std::vector<TransferredMessagePort>& sent_message_ports) { 1319 const std::vector<TransferredMessagePort>& sent_message_ports) {
1329 if (!context_)
1330 return;
1331 TRACE_EVENT1("ServiceWorker", 1320 TRACE_EVENT1("ServiceWorker",
1332 "ServiceWorkerVersion::OnPostMessageToDocument", 1321 "ServiceWorkerVersion::OnPostMessageToDocument",
1333 "Client id", client_uuid); 1322 "Client id", client_uuid);
1334 ServiceWorkerProviderHost* provider_host = 1323 auto it = controllee_map_.find(client_uuid);
1335 context_->GetProviderHostByClientID(client_uuid); 1324 if (it == controllee_map_.end()) {
1336 if (!provider_host) {
1337 // The client may already have been closed, just ignore. 1325 // The client may already have been closed, just ignore.
1338 return; 1326 return;
1339 } 1327 }
1340 if (provider_host->document_url().GetOrigin() != script_url_.GetOrigin()) { 1328 if (it->second->document_url().GetOrigin() != script_url_.GetOrigin()) {
1341 // The client does not belong to the same origin as this ServiceWorker, 1329 // The client does not belong to the same origin as this ServiceWorker,
1342 // possibly due to timing issue or bad message. 1330 // possibly due to timing issue or bad message.
1343 return; 1331 return;
1344 } 1332 }
1345 provider_host->PostMessage(message, sent_message_ports); 1333 it->second->PostMessage(message, sent_message_ports);
1346 } 1334 }
1347 1335
1348 void ServiceWorkerVersion::OnFocusClient(int request_id, 1336 void ServiceWorkerVersion::OnFocusClient(int request_id,
1349 const std::string& client_uuid) { 1337 const std::string& client_uuid) {
1350 if (!context_)
1351 return;
1352 TRACE_EVENT2("ServiceWorker", 1338 TRACE_EVENT2("ServiceWorker",
1353 "ServiceWorkerVersion::OnFocusClient", 1339 "ServiceWorkerVersion::OnFocusClient",
1354 "Request id", request_id, 1340 "Request id", request_id,
1355 "Client id", client_uuid); 1341 "Client id", client_uuid);
1356 ServiceWorkerProviderHost* provider_host = 1342 auto it = controllee_map_.find(client_uuid);
1357 context_->GetProviderHostByClientID(client_uuid); 1343 if (it == controllee_map_.end()) {
1358 if (!provider_host) {
1359 // The client may already have been closed, just ignore. 1344 // The client may already have been closed, just ignore.
1360 return; 1345 return;
1361 } 1346 }
1362 if (provider_host->document_url().GetOrigin() != script_url_.GetOrigin()) { 1347 if (it->second->document_url().GetOrigin() != script_url_.GetOrigin()) {
1363 // The client does not belong to the same origin as this ServiceWorker, 1348 // The client does not belong to the same origin as this ServiceWorker,
1364 // possibly due to timing issue or bad message. 1349 // possibly due to timing issue or bad message.
1365 return; 1350 return;
1366 } 1351 }
1367 provider_host->Focus(base::Bind(&ServiceWorkerVersion::OnFocusClientFinished, 1352
1368 weak_factory_.GetWeakPtr(), request_id, 1353 it->second->Focus(
1369 client_uuid)); 1354 base::Bind(&ServiceWorkerVersion::OnFocusClientFinished,
1355 weak_factory_.GetWeakPtr(),
1356 request_id,
1357 client_uuid));
1370 } 1358 }
1371 1359
1372 void ServiceWorkerVersion::OnFocusClientFinished( 1360 void ServiceWorkerVersion::OnFocusClientFinished(
1373 int request_id, 1361 int request_id,
1374 const std::string& cliend_uuid, 1362 const std::string& cliend_uuid,
1375 const ServiceWorkerClientInfo& client) { 1363 const ServiceWorkerClientInfo& client) {
1376 DCHECK_CURRENTLY_ON(BrowserThread::IO); 1364 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1377 1365
1378 if (running_status() != RUNNING) 1366 if (running_status() != RUNNING)
1379 return; 1367 return;
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
1667 int request_id) { 1655 int request_id) {
1668 callbacks->Remove(request_id); 1656 callbacks->Remove(request_id);
1669 if (is_doomed_) { 1657 if (is_doomed_) {
1670 // The stop should be already scheduled, but try to stop immediately, in 1658 // The stop should be already scheduled, but try to stop immediately, in
1671 // order to release worker resources soon. 1659 // order to release worker resources soon.
1672 StopWorkerIfIdle(); 1660 StopWorkerIfIdle();
1673 } 1661 }
1674 } 1662 }
1675 1663
1676 } // namespace content 1664 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_provider_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698