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

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

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