| 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 b905698331d3d4d01b5311212bb461031c0329da..b66de89d7b39c8c659293f3e73946562b24875ea 100644
|
| --- a/content/browser/service_worker/service_worker_version.cc
|
| +++ b/content/browser/service_worker/service_worker_version.cc
|
| @@ -996,8 +996,9 @@
|
|
|
| void ServiceWorkerVersion::OnGetClients(
|
| int request_id,
|
| - const ServiceWorkerClientQueryOptions& options) {
|
| - if (controllee_map_.empty() && !options.include_uncontrolled) {
|
| + const ServiceWorkerClientQueryOptions& /* options */) {
|
| + // TODO(kinuko): Handle ClientQueryOptions. (crbug.com/455241, 460415 etc)
|
| + if (controllee_map_.empty()) {
|
| if (running_status() == RUNNING) {
|
| embedded_worker_->SendMessage(
|
| ServiceWorkerMsg_DidGetClients(request_id,
|
| @@ -1009,23 +1010,13 @@
|
| TRACE_EVENT0("ServiceWorker",
|
| "ServiceWorkerVersion::OnGetClients");
|
|
|
| - // 4.3.1 matchAll(options)
|
| std::vector<Tuple<int,int,std::string>> clients_info;
|
| - 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()));
|
| - }
|
| + 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));
|
| }
|
|
|
| BrowserThread::PostTask(
|
| @@ -1245,17 +1236,17 @@
|
| return;
|
| }
|
|
|
| - for (auto it =
|
| - context_->GetClientProviderHostIterator(script_url_.GetOrigin());
|
| - !it->IsAtEnd(); it->Advance()) {
|
| - ServiceWorkerProviderHost* provider_host = it->GetProviderHost();
|
| + for (const auto& it : controllee_map_) {
|
| + const ServiceWorkerProviderHost* provider_host = it.second;
|
| if (provider_host->process_id() != render_process_id ||
|
| provider_host->frame_id() != render_frame_id) {
|
| continue;
|
| }
|
| - provider_host->GetClientInfo(base::Bind(
|
| - &ServiceWorkerVersion::OnOpenWindowFinished, weak_factory_.GetWeakPtr(),
|
| - request_id, provider_host->client_uuid()));
|
| +
|
| + // 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));
|
| return;
|
| }
|
|
|
| @@ -1326,47 +1317,44 @@
|
| 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);
|
| - ServiceWorkerProviderHost* provider_host =
|
| - context_->GetProviderHostByClientID(client_uuid);
|
| - if (!provider_host) {
|
| + auto it = controllee_map_.find(client_uuid);
|
| + if (it == controllee_map_.end()) {
|
| // The client may already have been closed, just ignore.
|
| return;
|
| }
|
| - if (provider_host->document_url().GetOrigin() != script_url_.GetOrigin()) {
|
| + if (it->second->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;
|
| }
|
| - provider_host->PostMessage(message, sent_message_ports);
|
| + it->second->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);
|
| - ServiceWorkerProviderHost* provider_host =
|
| - context_->GetProviderHostByClientID(client_uuid);
|
| - if (!provider_host) {
|
| + auto it = controllee_map_.find(client_uuid);
|
| + if (it == controllee_map_.end()) {
|
| // The client may already have been closed, just ignore.
|
| return;
|
| }
|
| - if (provider_host->document_url().GetOrigin() != script_url_.GetOrigin()) {
|
| + if (it->second->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;
|
| }
|
| - provider_host->Focus(base::Bind(&ServiceWorkerVersion::OnFocusClientFinished,
|
| - weak_factory_.GetWeakPtr(), request_id,
|
| - client_uuid));
|
| +
|
| + it->second->Focus(
|
| + base::Bind(&ServiceWorkerVersion::OnFocusClientFinished,
|
| + weak_factory_.GetWeakPtr(),
|
| + request_id,
|
| + client_uuid));
|
| }
|
|
|
| void ServiceWorkerVersion::OnFocusClientFinished(
|
|
|