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

Unified Diff: content/browser/service_worker/service_worker_client_utils.cc

Issue 1439333002: Service Worker: Add Clients.get(id) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move the origin check lines and update layout tests Created 4 years, 10 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_client_utils.cc
diff --git a/content/browser/service_worker/service_worker_client_utils.cc b/content/browser/service_worker/service_worker_client_utils.cc
index 26ef4d35f181bd9a43c4bb5922c5698da78e6aa3..368c5bdc53d2e979b2f7d9acc6a6ef8a3ea473ba 100644
--- a/content/browser/service_worker/service_worker_client_utils.cc
+++ b/content/browser/service_worker/service_worker_client_utils.cc
@@ -225,15 +225,29 @@ void AddNonWindowClient(ServiceWorkerProviderHost* host,
options.client_type != host_client_type)
return;
- ServiceWorkerClientInfo client_info(blink::WebPageVisibilityStateHidden,
- false, // is_focused
- host->document_url(),
- REQUEST_CONTEXT_FRAME_TYPE_NONE,
- base::TimeTicks(), host_client_type);
- client_info.client_uuid = host->client_uuid();
+ ServiceWorkerClientInfo client_info(
+ host->client_uuid(), blink::WebPageVisibilityStateHidden,
+ false, // is_focused
+ host->document_url(), REQUEST_CONTEXT_FRAME_TYPE_NONE, base::TimeTicks(),
+ host_client_type);
clients->push_back(client_info);
}
+void OnGetWindowClientOnUI(
+ int process_id,
+ int frame_id,
+ const std::string& client_uuid,
+ const ServiceWorkerProviderHost::GetClientInfoCallback& callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+
+ ServiceWorkerClientInfo info =
+ ServiceWorkerProviderHost::GetWindowClientInfoOnUI(process_id, frame_id,
+ client_uuid);
+
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+ base::Bind(callback, info));
+}
+
void OnGetWindowClientsOnUI(
// The tuple contains process_id, frame_id, client_uuid.
const std::vector<base::Tuple<int, int, std::string>>& clients_info,
@@ -243,8 +257,8 @@ void OnGetWindowClientsOnUI(
for (const auto& it : clients_info) {
ServiceWorkerClientInfo info =
- ServiceWorkerProviderHost::GetWindowClientInfoOnUI(base::get<0>(it),
- base::get<1>(it));
+ ServiceWorkerProviderHost::GetWindowClientInfoOnUI(
+ base::get<0>(it), base::get<1>(it), base::get<2>(it));
// If the request to the provider_host returned an empty
// ServiceWorkerClientInfo, that means that it wasn't possible to associate
@@ -259,7 +273,6 @@ void OnGetWindowClientsOnUI(
if (info.url.GetOrigin() != script_url.GetOrigin())
continue;
- info.client_uuid = base::get<2>(it);
clients->push_back(info);
}
@@ -371,6 +384,53 @@ void NavigateClient(const GURL& url,
base::Bind(&DidNavigate, context, script_url.GetOrigin(), callback)));
}
+void GetClient(
+ const base::WeakPtr<ServiceWorkerVersion>& controller,
+ const std::string& client_uuid,
+ const base::WeakPtr<ServiceWorkerContextCore>& context,
+ const ServiceWorkerProviderHost::GetClientInfoCallback& callback) {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+
+ ServiceWorkerProviderHost* provider_host =
+ context->GetProviderHostByClientID(client_uuid);
+
+ if (!provider_host) {
+ // The client may already have been closed, just ignore.
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+ base::Bind(callback, ServiceWorkerClientInfo()));
+ return;
+ }
+
+ if (provider_host->document_url().GetOrigin() !=
+ controller->script_url().GetOrigin()) {
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+ base::Bind(callback, ServiceWorkerClientInfo()));
+ return;
+ }
+
+ if (provider_host->client_type() == blink::WebServiceWorkerClientTypeWindow) {
+ BrowserThread::PostTask(
zino 2016/02/17 18:38:13 Couldn't we use "provider_host->GetWindowClientInf
jungkees 2016/02/18 15:02:20 Yes, that's effectively the same call flow between
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&OnGetWindowClientOnUI, provider_host->process_id(),
+ provider_host->frame_id(), provider_host->client_uuid(),
+ callback));
+ return;
+ }
+
+ DCHECK(provider_host->client_type() ==
+ blink::WebServiceWorkerClientTypeWorker ||
+ provider_host->client_type() ==
+ blink::WebServiceWorkerClientTypeSharedWorker);
+
+ ServiceWorkerClientInfo client_info(
+ provider_host->client_uuid(), blink::WebPageVisibilityStateHidden,
+ false, // is_focused
+ provider_host->document_url(), REQUEST_CONTEXT_FRAME_TYPE_NONE,
+ base::TimeTicks(), provider_host->client_type());
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+ base::Bind(callback, client_info));
+}
+
void GetClients(const base::WeakPtr<ServiceWorkerVersion>& controller,
const ServiceWorkerClientQueryOptions& options,
const ClientsCallback& callback) {

Powered by Google App Engine
This is Rietveld 408576698