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

Unified 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: Add EXPORT 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/service_worker/service_worker_version.cc
diff --git a/content/browser/service_worker/service_worker_version.cc b/content/browser/service_worker/service_worker_version.cc
index b66de89d7b39c8c659293f3e73946562b24875ea..b905698331d3d4d01b5311212bb461031c0329da 100644
--- a/content/browser/service_worker/service_worker_version.cc
+++ b/content/browser/service_worker/service_worker_version.cc
@@ -996,9 +996,8 @@ void ServiceWorkerVersion::DispatchActivateEventAfterStartWorker(
void ServiceWorkerVersion::OnGetClients(
int request_id,
- const ServiceWorkerClientQueryOptions& /* options */) {
- // TODO(kinuko): Handle ClientQueryOptions. (crbug.com/455241, 460415 etc)
- if (controllee_map_.empty()) {
+ const ServiceWorkerClientQueryOptions& options) {
+ if (controllee_map_.empty() && !options.include_uncontrolled) {
if (running_status() == RUNNING) {
embedded_worker_->SendMessage(
ServiceWorkerMsg_DidGetClients(request_id,
@@ -1010,13 +1009,23 @@ void ServiceWorkerVersion::OnGetClients(
TRACE_EVENT0("ServiceWorker",
"ServiceWorkerVersion::OnGetClients");
+ // 4.3.1 matchAll(options)
std::vector<Tuple<int,int,std::string>> clients_info;
- for (auto& controllee : controllee_map_) {
- int process_id = controllee.second->process_id();
- int frame_id = controllee.second->frame_id();
- const std::string& client_uuid = controllee.first;
-
- clients_info.push_back(MakeTuple(process_id, frame_id, client_uuid));
+ if (!options.include_uncontrolled) {
+ for (auto& controllee : controllee_map_) {
+ int process_id = controllee.second->process_id();
+ int frame_id = controllee.second->frame_id();
+ const std::string& client_uuid = controllee.first;
+ clients_info.push_back(MakeTuple(process_id, frame_id, client_uuid));
+ }
+ } else {
+ for (auto it =
+ context_->GetClientProviderHostIterator(script_url_.GetOrigin());
+ !it->IsAtEnd(); it->Advance()) {
+ ServiceWorkerProviderHost* host = it->GetProviderHost();
+ clients_info.push_back(
+ MakeTuple(host->process_id(), host->frame_id(), host->client_uuid()));
+ }
}
BrowserThread::PostTask(
@@ -1236,17 +1245,17 @@ void ServiceWorkerVersion::DidOpenWindow(int request_id,
return;
}
- for (const auto& it : controllee_map_) {
- const ServiceWorkerProviderHost* provider_host = it.second;
+ for (auto it =
+ context_->GetClientProviderHostIterator(script_url_.GetOrigin());
+ !it->IsAtEnd(); it->Advance()) {
+ ServiceWorkerProviderHost* provider_host = it->GetProviderHost();
if (provider_host->process_id() != render_process_id ||
provider_host->frame_id() != render_frame_id) {
continue;
}
-
- // it.second is the client_uuid associated with the provider_host.
- provider_host->GetClientInfo(
- base::Bind(&ServiceWorkerVersion::OnOpenWindowFinished,
- weak_factory_.GetWeakPtr(), request_id, it.first));
+ provider_host->GetClientInfo(base::Bind(
+ &ServiceWorkerVersion::OnOpenWindowFinished, weak_factory_.GetWeakPtr(),
+ request_id, provider_host->client_uuid()));
return;
}
@@ -1317,44 +1326,47 @@ void ServiceWorkerVersion::OnPostMessageToClient(
const std::string& client_uuid,
const base::string16& message,
const std::vector<TransferredMessagePort>& sent_message_ports) {
+ if (!context_)
+ return;
TRACE_EVENT1("ServiceWorker",
"ServiceWorkerVersion::OnPostMessageToDocument",
"Client id", client_uuid);
- auto it = controllee_map_.find(client_uuid);
- if (it == controllee_map_.end()) {
+ ServiceWorkerProviderHost* provider_host =
+ context_->GetProviderHostByClientID(client_uuid);
+ if (!provider_host) {
// The client may already have been closed, just ignore.
return;
}
- if (it->second->document_url().GetOrigin() != script_url_.GetOrigin()) {
+ if (provider_host->document_url().GetOrigin() != script_url_.GetOrigin()) {
// The client does not belong to the same origin as this ServiceWorker,
// possibly due to timing issue or bad message.
return;
}
- it->second->PostMessage(message, sent_message_ports);
+ provider_host->PostMessage(message, sent_message_ports);
}
void ServiceWorkerVersion::OnFocusClient(int request_id,
const std::string& client_uuid) {
+ if (!context_)
+ return;
TRACE_EVENT2("ServiceWorker",
"ServiceWorkerVersion::OnFocusClient",
"Request id", request_id,
"Client id", client_uuid);
- auto it = controllee_map_.find(client_uuid);
- if (it == controllee_map_.end()) {
+ ServiceWorkerProviderHost* provider_host =
+ context_->GetProviderHostByClientID(client_uuid);
+ if (!provider_host) {
// The client may already have been closed, just ignore.
return;
}
- if (it->second->document_url().GetOrigin() != script_url_.GetOrigin()) {
+ if (provider_host->document_url().GetOrigin() != script_url_.GetOrigin()) {
// The client does not belong to the same origin as this ServiceWorker,
// possibly due to timing issue or bad message.
return;
}
-
- it->second->Focus(
- base::Bind(&ServiceWorkerVersion::OnFocusClientFinished,
- weak_factory_.GetWeakPtr(),
- request_id,
- client_uuid));
+ provider_host->Focus(base::Bind(&ServiceWorkerVersion::OnFocusClientFinished,
+ weak_factory_.GetWeakPtr(), request_id,
+ client_uuid));
}
void ServiceWorkerVersion::OnFocusClientFinished(
« 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