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

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: 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
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 113ed1c908112f70e2645945d9e22c821fbb226c..f2bbf0127a63b5f4a2ec669479253b2ef22023db 100644
--- a/content/browser/service_worker/service_worker_version.cc
+++ b/content/browser/service_worker/service_worker_version.cc
@@ -993,9 +993,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) {
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...
if (running_status() == RUNNING) {
embedded_worker_->SendMessage(
ServiceWorkerMsg_DidGetClients(request_id,
@@ -1007,13 +1006,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_->GetProviderHostIteratorForOrigin(
+ 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()));
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
+ }
}
BrowserThread::PostTask(
@@ -1233,17 +1242,17 @@ void ServiceWorkerVersion::DidOpenWindow(int request_id,
return;
}
- for (const auto& it : controllee_map_) {
- const ServiceWorkerProviderHost* provider_host = it.second;
+ for (auto it =
+ context_->GetProviderHostIteratorForOrigin(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;
}
@@ -1314,44 +1323,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(

Powered by Google App Engine
This is Rietveld 408576698