OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_client_utils.h" | 5 #include "content/browser/service_worker/service_worker_client_utils.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <tuple> | 8 #include <tuple> |
9 | 9 |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 | 95 |
96 int frame_tree_node_id_; | 96 int frame_tree_node_id_; |
97 const OpenURLCallback callback_; | 97 const OpenURLCallback callback_; |
98 | 98 |
99 DISALLOW_COPY_AND_ASSIGN(OpenURLObserver); | 99 DISALLOW_COPY_AND_ASSIGN(OpenURLObserver); |
100 }; | 100 }; |
101 | 101 |
102 ServiceWorkerClientInfo GetWindowClientInfoOnUI( | 102 ServiceWorkerClientInfo GetWindowClientInfoOnUI( |
103 int render_process_id, | 103 int render_process_id, |
104 int render_frame_id, | 104 int render_frame_id, |
105 base::TimeTicks create_time, | |
105 const std::string& client_uuid) { | 106 const std::string& client_uuid) { |
106 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 107 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
107 RenderFrameHostImpl* render_frame_host = | 108 RenderFrameHostImpl* render_frame_host = |
108 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); | 109 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); |
109 if (!render_frame_host) | 110 if (!render_frame_host) |
110 return ServiceWorkerClientInfo(); | 111 return ServiceWorkerClientInfo(); |
111 | 112 |
112 // TODO(mlamouri,michaeln): it is possible to end up collecting information | 113 // TODO(mlamouri,michaeln): it is possible to end up collecting information |
113 // for a frame that is actually being navigated and isn't exactly what we are | 114 // for a frame that is actually being navigated and isn't exactly what we are |
114 // expecting. | 115 // expecting. |
115 return ServiceWorkerClientInfo( | 116 return ServiceWorkerClientInfo( |
116 client_uuid, render_frame_host->GetVisibilityState(), | 117 client_uuid, render_frame_host->GetVisibilityState(), |
117 render_frame_host->IsFocused(), render_frame_host->GetLastCommittedURL(), | 118 render_frame_host->IsFocused(), render_frame_host->GetLastCommittedURL(), |
118 render_frame_host->GetParent() ? REQUEST_CONTEXT_FRAME_TYPE_NESTED | 119 render_frame_host->GetParent() ? REQUEST_CONTEXT_FRAME_TYPE_NESTED |
119 : REQUEST_CONTEXT_FRAME_TYPE_TOP_LEVEL, | 120 : REQUEST_CONTEXT_FRAME_TYPE_TOP_LEVEL, |
120 render_frame_host->frame_tree_node()->last_focus_time(), | 121 render_frame_host->frame_tree_node()->last_focus_time(), create_time, |
121 blink::kWebServiceWorkerClientTypeWindow); | 122 blink::kWebServiceWorkerClientTypeWindow); |
122 } | 123 } |
123 | 124 |
124 ServiceWorkerClientInfo FocusOnUI(int render_process_id, | 125 ServiceWorkerClientInfo FocusOnUI(int render_process_id, |
125 int render_frame_id, | 126 int render_frame_id, |
127 base::TimeTicks create_time, | |
126 const std::string& client_uuid) { | 128 const std::string& client_uuid) { |
127 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 129 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
128 RenderFrameHostImpl* render_frame_host = | 130 RenderFrameHostImpl* render_frame_host = |
129 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); | 131 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); |
130 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 132 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
131 WebContents::FromRenderFrameHost(render_frame_host)); | 133 WebContents::FromRenderFrameHost(render_frame_host)); |
132 | 134 |
133 if (!render_frame_host || !web_contents) | 135 if (!render_frame_host || !web_contents) |
134 return ServiceWorkerClientInfo(); | 136 return ServiceWorkerClientInfo(); |
135 | 137 |
136 FrameTreeNode* frame_tree_node = render_frame_host->frame_tree_node(); | 138 FrameTreeNode* frame_tree_node = render_frame_host->frame_tree_node(); |
137 | 139 |
138 // Focus the frame in the frame tree node, in case it has changed. | 140 // Focus the frame in the frame tree node, in case it has changed. |
139 frame_tree_node->frame_tree()->SetFocusedFrame( | 141 frame_tree_node->frame_tree()->SetFocusedFrame( |
140 frame_tree_node, render_frame_host->GetSiteInstance()); | 142 frame_tree_node, render_frame_host->GetSiteInstance()); |
141 | 143 |
142 // Focus the frame's view to make sure the frame is now considered as focused. | 144 // Focus the frame's view to make sure the frame is now considered as focused. |
143 render_frame_host->GetView()->Focus(); | 145 render_frame_host->GetView()->Focus(); |
144 | 146 |
145 // Move the web contents to the foreground. | 147 // Move the web contents to the foreground. |
146 web_contents->Activate(); | 148 web_contents->Activate(); |
147 | 149 |
148 return GetWindowClientInfoOnUI(render_process_id, render_frame_id, | 150 return GetWindowClientInfoOnUI(render_process_id, render_frame_id, |
149 client_uuid); | 151 create_time, client_uuid); |
150 } | 152 } |
151 | 153 |
152 // This is only called for main frame navigations in OpenWindowOnUI(). | 154 // This is only called for main frame navigations in OpenWindowOnUI(). |
153 void DidOpenURLOnUI(const OpenURLCallback& callback, | 155 void DidOpenURLOnUI(const OpenURLCallback& callback, |
154 WebContents* web_contents) { | 156 WebContents* web_contents) { |
155 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 157 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
156 | 158 |
157 if (!web_contents) { | 159 if (!web_contents) { |
158 BrowserThread::PostTask( | 160 BrowserThread::PostTask( |
159 BrowserThread::IO, FROM_HERE, | 161 BrowserThread::IO, FROM_HERE, |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 context->GetClientProviderHostIterator(origin); | 269 context->GetClientProviderHostIterator(origin); |
268 !it->IsAtEnd(); it->Advance()) { | 270 !it->IsAtEnd(); it->Advance()) { |
269 ServiceWorkerProviderHost* provider_host = it->GetProviderHost(); | 271 ServiceWorkerProviderHost* provider_host = it->GetProviderHost(); |
270 if (provider_host->process_id() != render_process_id || | 272 if (provider_host->process_id() != render_process_id || |
271 provider_host->frame_id() != render_frame_id) { | 273 provider_host->frame_id() != render_frame_id) { |
272 continue; | 274 continue; |
273 } | 275 } |
274 BrowserThread::PostTaskAndReplyWithResult( | 276 BrowserThread::PostTaskAndReplyWithResult( |
275 BrowserThread::UI, FROM_HERE, | 277 BrowserThread::UI, FROM_HERE, |
276 base::Bind(&GetWindowClientInfoOnUI, provider_host->process_id(), | 278 base::Bind(&GetWindowClientInfoOnUI, provider_host->process_id(), |
277 provider_host->route_id(), provider_host->client_uuid()), | 279 provider_host->route_id(), provider_host->create_time(), |
280 provider_host->client_uuid()), | |
278 base::Bind(callback, SERVICE_WORKER_OK)); | 281 base::Bind(callback, SERVICE_WORKER_OK)); |
279 return; | 282 return; |
280 } | 283 } |
281 | 284 |
282 // If here, it means that no provider_host was found, in which case, the | 285 // If here, it means that no provider_host was found, in which case, the |
283 // renderer should still be informed that the window was opened. | 286 // renderer should still be informed that the window was opened. |
284 callback.Run(SERVICE_WORKER_OK, ServiceWorkerClientInfo()); | 287 callback.Run(SERVICE_WORKER_OK, ServiceWorkerClientInfo()); |
285 } | 288 } |
286 | 289 |
287 void AddWindowClient( | 290 void AddWindowClient( |
288 ServiceWorkerProviderHost* host, | 291 ServiceWorkerProviderHost* host, |
289 std::vector<std::tuple<int, int, std::string>>* client_info) { | 292 std::vector<std::tuple<int, int, base::TimeTicks, std::string>>* |
293 client_info) { | |
290 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 294 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
291 if (host->client_type() != blink::kWebServiceWorkerClientTypeWindow) | 295 if (host->client_type() != blink::kWebServiceWorkerClientTypeWindow) |
292 return; | 296 return; |
293 client_info->push_back(std::make_tuple(host->process_id(), host->frame_id(), | 297 client_info->push_back(std::make_tuple(host->process_id(), host->frame_id(), |
298 host->create_time(), | |
294 host->client_uuid())); | 299 host->client_uuid())); |
295 } | 300 } |
296 | 301 |
297 void AddNonWindowClient(ServiceWorkerProviderHost* host, | 302 void AddNonWindowClient(ServiceWorkerProviderHost* host, |
298 const ServiceWorkerClientQueryOptions& options, | 303 const ServiceWorkerClientQueryOptions& options, |
299 ServiceWorkerClients* clients) { | 304 ServiceWorkerClients* clients) { |
300 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 305 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
301 blink::WebServiceWorkerClientType host_client_type = host->client_type(); | 306 blink::WebServiceWorkerClientType host_client_type = host->client_type(); |
302 if (host_client_type == blink::kWebServiceWorkerClientTypeWindow) | 307 if (host_client_type == blink::kWebServiceWorkerClientTypeWindow) |
303 return; | 308 return; |
304 if (options.client_type != blink::kWebServiceWorkerClientTypeAll && | 309 if (options.client_type != blink::kWebServiceWorkerClientTypeAll && |
305 options.client_type != host_client_type) | 310 options.client_type != host_client_type) |
306 return; | 311 return; |
307 | 312 |
308 ServiceWorkerClientInfo client_info( | 313 ServiceWorkerClientInfo client_info( |
309 host->client_uuid(), blink::kWebPageVisibilityStateHidden, | 314 host->client_uuid(), blink::kWebPageVisibilityStateHidden, |
310 false, // is_focused | 315 false, // is_focused |
311 host->document_url(), REQUEST_CONTEXT_FRAME_TYPE_NONE, base::TimeTicks(), | 316 host->document_url(), REQUEST_CONTEXT_FRAME_TYPE_NONE, base::TimeTicks(), |
312 host_client_type); | 317 host->create_time(), host_client_type); |
313 clients->push_back(client_info); | 318 clients->push_back(client_info); |
314 } | 319 } |
315 | 320 |
316 void OnGetWindowClientsOnUI( | 321 void OnGetWindowClientsOnUI( |
317 // The tuple contains process_id, frame_id, client_uuid. | 322 // The tuple contains process_id, frame_id, create_time, client_uuid. |
318 const std::vector<std::tuple<int, int, std::string>>& clients_info, | 323 const std::vector<std::tuple<int, int, base::TimeTicks, std::string>>& |
324 clients_info, | |
319 const GURL& script_url, | 325 const GURL& script_url, |
320 const GetWindowClientsCallback& callback) { | 326 const GetWindowClientsCallback& callback, |
327 std::unique_ptr<ServiceWorkerClients> clients) { | |
321 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 328 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
322 | 329 |
323 std::unique_ptr<ServiceWorkerClients> clients(new ServiceWorkerClients); | |
324 for (const auto& it : clients_info) { | 330 for (const auto& it : clients_info) { |
325 ServiceWorkerClientInfo info = GetWindowClientInfoOnUI( | 331 ServiceWorkerClientInfo info = GetWindowClientInfoOnUI( |
326 std::get<0>(it), std::get<1>(it), std::get<2>(it)); | 332 std::get<0>(it), std::get<1>(it), std::get<2>(it), std::get<3>(it)); |
327 | 333 |
328 // If the request to the provider_host returned an empty | 334 // If the request to the provider_host returned an empty |
329 // ServiceWorkerClientInfo, that means that it wasn't possible to associate | 335 // ServiceWorkerClientInfo, that means that it wasn't possible to associate |
330 // it with a valid RenderFrameHost. It might be because the frame was killed | 336 // it with a valid RenderFrameHost. It might be because the frame was killed |
331 // or navigated in between. | 337 // or navigated in between. |
332 if (info.IsEmpty()) | 338 if (info.IsEmpty()) |
333 continue; | 339 continue; |
334 | 340 |
335 // We can get info for a frame that was navigating end ended up with a | 341 // We can get info for a frame that was navigating end ended up with a |
336 // different URL than expected. In such case, we should make sure to not | 342 // different URL than expected. In such case, we should make sure to not |
337 // expose cross-origin WindowClient. | 343 // expose cross-origin WindowClient. |
338 if (info.url.GetOrigin() != script_url.GetOrigin()) | 344 if (info.url.GetOrigin() != script_url.GetOrigin()) |
339 continue; | 345 continue; |
340 | 346 |
341 clients->push_back(info); | 347 clients->push_back(info); |
342 } | 348 } |
343 | 349 |
344 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 350 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
345 base::Bind(callback, base::Passed(&clients))); | 351 base::Bind(callback, base::Passed(&clients))); |
346 } | 352 } |
347 | 353 |
348 struct ServiceWorkerClientInfoSortMRU { | 354 struct ServiceWorkerClientInfoSort { |
349 bool operator()(const ServiceWorkerClientInfo& a, | 355 bool operator()(const ServiceWorkerClientInfo& a, |
350 const ServiceWorkerClientInfo& b) const { | 356 const ServiceWorkerClientInfo& b) const { |
351 return a.last_focus_time > b.last_focus_time; | 357 if ((a.client_type != b.client_type) && |
358 ((a.client_type == blink::kWebServiceWorkerClientTypeWindow) || | |
359 (b.client_type == blink::kWebServiceWorkerClientTypeWindow))) | |
360 return a.client_type < b.client_type; | |
shimazu
2017/05/29 01:45:13
I feel numerical comparison of enum is a bit scare
xiaofengzhang
2017/06/01 01:00:42
Done. Thanks a lot :-)
| |
361 else if (a.last_focus_time != b.last_focus_time) | |
362 return a.last_focus_time > b.last_focus_time; | |
363 else | |
364 return a.create_time < b.create_time; | |
shimazu
2017/05/29 01:45:13
I think it's better to use '<=' to preserve the or
xiaofengzhang
2017/06/01 01:00:42
It seems "<=" will cause some test failure.
shimazu
2017/06/01 09:50:49
Hmm... I didn't think this change cause crashes. C
shimazu
2017/06/05 01:48:43
Ah, sorry, that's my bad.
C++ Compare requires com
| |
352 } | 365 } |
353 }; | 366 }; |
354 | 367 |
355 void DidGetClients(const ClientsCallback& callback, | 368 void DidGetClients(const ClientsCallback& callback, |
356 ServiceWorkerClients* clients) { | 369 std::unique_ptr<ServiceWorkerClients> clients) { |
357 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 370 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
358 | 371 |
359 // Sort clients so that the most recently active tab is in the front. | 372 std::sort(clients->begin(), clients->end(), ServiceWorkerClientInfoSort()); |
360 std::sort(clients->begin(), clients->end(), ServiceWorkerClientInfoSortMRU()); | |
361 | 373 |
362 callback.Run(clients); | 374 callback.Run(std::move(clients)); |
363 } | 375 } |
364 | 376 |
365 void GetNonWindowClients(const base::WeakPtr<ServiceWorkerVersion>& controller, | 377 void GetNonWindowClients(const base::WeakPtr<ServiceWorkerVersion>& controller, |
366 const ServiceWorkerClientQueryOptions& options, | 378 const ServiceWorkerClientQueryOptions& options, |
367 ServiceWorkerClients* clients) { | 379 const ClientsCallback& callback, |
380 std::unique_ptr<ServiceWorkerClients> clients) { | |
368 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 381 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
369 if (!options.include_uncontrolled) { | 382 if (!options.include_uncontrolled) { |
370 for (auto& controllee : controller->controllee_map()) | 383 for (auto& controllee : controller->controllee_map()) |
371 AddNonWindowClient(controllee.second, options, clients); | 384 AddNonWindowClient(controllee.second, options, clients.get()); |
372 } else if (controller->context()) { | 385 } else if (controller->context()) { |
373 GURL origin = controller->script_url().GetOrigin(); | 386 GURL origin = controller->script_url().GetOrigin(); |
374 for (auto it = controller->context()->GetClientProviderHostIterator(origin); | 387 for (auto it = controller->context()->GetClientProviderHostIterator(origin); |
375 !it->IsAtEnd(); it->Advance()) { | 388 !it->IsAtEnd(); it->Advance()) { |
376 AddNonWindowClient(it->GetProviderHost(), options, clients); | 389 AddNonWindowClient(it->GetProviderHost(), options, clients.get()); |
377 } | 390 } |
378 } | 391 } |
392 DidGetClients(callback, std::move(clients)); | |
379 } | 393 } |
380 | 394 |
381 void DidGetWindowClients(const base::WeakPtr<ServiceWorkerVersion>& controller, | 395 void DidGetWindowClients(const base::WeakPtr<ServiceWorkerVersion>& controller, |
382 const ServiceWorkerClientQueryOptions& options, | 396 const ServiceWorkerClientQueryOptions& options, |
383 const ClientsCallback& callback, | 397 const ClientsCallback& callback, |
384 std::unique_ptr<ServiceWorkerClients> clients) { | 398 std::unique_ptr<ServiceWorkerClients> clients) { |
385 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 399 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
386 if (options.client_type == blink::kWebServiceWorkerClientTypeAll) | 400 if (options.client_type == blink::kWebServiceWorkerClientTypeAll) { |
387 GetNonWindowClients(controller, options, clients.get()); | 401 GetNonWindowClients(controller, options, callback, std::move(clients)); |
388 DidGetClients(callback, clients.get()); | 402 return; |
403 } | |
404 DidGetClients(callback, std::move(clients)); | |
389 } | 405 } |
390 | 406 |
391 void GetWindowClients(const base::WeakPtr<ServiceWorkerVersion>& controller, | 407 void GetWindowClients(const base::WeakPtr<ServiceWorkerVersion>& controller, |
392 const ServiceWorkerClientQueryOptions& options, | 408 const ServiceWorkerClientQueryOptions& options, |
393 const ClientsCallback& callback) { | 409 const ClientsCallback& callback, |
410 std::unique_ptr<ServiceWorkerClients> clients) { | |
394 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 411 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
395 DCHECK(options.client_type == blink::kWebServiceWorkerClientTypeWindow || | 412 DCHECK(options.client_type == blink::kWebServiceWorkerClientTypeWindow || |
396 options.client_type == blink::kWebServiceWorkerClientTypeAll); | 413 options.client_type == blink::kWebServiceWorkerClientTypeAll); |
397 | 414 |
398 std::vector<std::tuple<int, int, std::string>> clients_info; | 415 std::vector<std::tuple<int, int, base::TimeTicks, std::string>> clients_info; |
399 if (!options.include_uncontrolled) { | 416 if (!options.include_uncontrolled) { |
400 for (auto& controllee : controller->controllee_map()) | 417 for (auto& controllee : controller->controllee_map()) { |
shimazu
2017/05/29 01:45:13
Brackets are not necessary here.
xiaofengzhang
2017/06/01 01:00:42
Done. aha, I didn't want to add the brackets here,
| |
401 AddWindowClient(controllee.second, &clients_info); | 418 AddWindowClient(controllee.second, &clients_info); |
419 } | |
402 } else if (controller->context()) { | 420 } else if (controller->context()) { |
403 GURL origin = controller->script_url().GetOrigin(); | 421 GURL origin = controller->script_url().GetOrigin(); |
404 for (auto it = controller->context()->GetClientProviderHostIterator(origin); | 422 for (auto it = controller->context()->GetClientProviderHostIterator(origin); |
405 !it->IsAtEnd(); it->Advance()) { | 423 !it->IsAtEnd(); it->Advance()) { |
406 AddWindowClient(it->GetProviderHost(), &clients_info); | 424 AddWindowClient(it->GetProviderHost(), &clients_info); |
407 } | 425 } |
408 } | 426 } |
409 | 427 |
410 if (clients_info.empty()) { | 428 if (clients_info.empty()) { |
411 DidGetWindowClients(controller, options, callback, | 429 DidGetWindowClients(controller, options, callback, std::move(clients)); |
412 base::WrapUnique(new ServiceWorkerClients)); | |
413 return; | 430 return; |
414 } | 431 } |
415 | 432 |
416 BrowserThread::PostTask( | 433 BrowserThread::PostTask( |
417 BrowserThread::UI, FROM_HERE, | 434 BrowserThread::UI, FROM_HERE, |
418 base::Bind( | 435 base::Bind( |
419 &OnGetWindowClientsOnUI, clients_info, controller->script_url(), | 436 &OnGetWindowClientsOnUI, clients_info, controller->script_url(), |
420 base::Bind(&DidGetWindowClients, controller, options, callback))); | 437 base::Bind(&DidGetWindowClients, controller, options, callback), |
438 base::Passed(&clients))); | |
421 } | 439 } |
422 | 440 |
423 } // namespace | 441 } // namespace |
424 | 442 |
425 void FocusWindowClient(ServiceWorkerProviderHost* provider_host, | 443 void FocusWindowClient(ServiceWorkerProviderHost* provider_host, |
426 const ClientCallback& callback) { | 444 const ClientCallback& callback) { |
427 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 445 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
428 DCHECK_EQ(blink::kWebServiceWorkerClientTypeWindow, | 446 DCHECK_EQ(blink::kWebServiceWorkerClientTypeWindow, |
429 provider_host->client_type()); | 447 provider_host->client_type()); |
430 BrowserThread::PostTaskAndReplyWithResult( | 448 BrowserThread::PostTaskAndReplyWithResult( |
431 BrowserThread::UI, FROM_HERE, | 449 BrowserThread::UI, FROM_HERE, |
432 base::Bind(&FocusOnUI, provider_host->process_id(), | 450 base::Bind(&FocusOnUI, provider_host->process_id(), |
433 provider_host->frame_id(), provider_host->client_uuid()), | 451 provider_host->frame_id(), provider_host->create_time(), |
452 provider_host->client_uuid()), | |
434 callback); | 453 callback); |
435 } | 454 } |
436 | 455 |
437 void OpenWindow(const GURL& url, | 456 void OpenWindow(const GURL& url, |
438 const GURL& script_url, | 457 const GURL& script_url, |
439 int worker_process_id, | 458 int worker_process_id, |
440 const base::WeakPtr<ServiceWorkerContextCore>& context, | 459 const base::WeakPtr<ServiceWorkerContextCore>& context, |
441 const NavigationCallback& callback) { | 460 const NavigationCallback& callback) { |
442 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 461 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
443 BrowserThread::PostTask( | 462 BrowserThread::PostTask( |
(...skipping 25 matching lines...) Expand all Loading... | |
469 blink::WebServiceWorkerClientType client_type = provider_host->client_type(); | 488 blink::WebServiceWorkerClientType client_type = provider_host->client_type(); |
470 DCHECK(client_type == blink::kWebServiceWorkerClientTypeWindow || | 489 DCHECK(client_type == blink::kWebServiceWorkerClientTypeWindow || |
471 client_type == blink::kWebServiceWorkerClientTypeWorker || | 490 client_type == blink::kWebServiceWorkerClientTypeWorker || |
472 client_type == blink::kWebServiceWorkerClientTypeSharedWorker) | 491 client_type == blink::kWebServiceWorkerClientTypeSharedWorker) |
473 << client_type; | 492 << client_type; |
474 | 493 |
475 if (client_type == blink::kWebServiceWorkerClientTypeWindow) { | 494 if (client_type == blink::kWebServiceWorkerClientTypeWindow) { |
476 BrowserThread::PostTaskAndReplyWithResult( | 495 BrowserThread::PostTaskAndReplyWithResult( |
477 BrowserThread::UI, FROM_HERE, | 496 BrowserThread::UI, FROM_HERE, |
478 base::Bind(&GetWindowClientInfoOnUI, provider_host->process_id(), | 497 base::Bind(&GetWindowClientInfoOnUI, provider_host->process_id(), |
479 provider_host->route_id(), provider_host->client_uuid()), | 498 provider_host->route_id(), provider_host->create_time(), |
499 provider_host->client_uuid()), | |
480 callback); | 500 callback); |
481 return; | 501 return; |
482 } | 502 } |
483 | 503 |
484 ServiceWorkerClientInfo client_info( | 504 ServiceWorkerClientInfo client_info( |
485 provider_host->client_uuid(), blink::kWebPageVisibilityStateHidden, | 505 provider_host->client_uuid(), blink::kWebPageVisibilityStateHidden, |
486 false, // is_focused | 506 false, // is_focused |
487 provider_host->document_url(), REQUEST_CONTEXT_FRAME_TYPE_NONE, | 507 provider_host->document_url(), REQUEST_CONTEXT_FRAME_TYPE_NONE, |
488 base::TimeTicks(), provider_host->client_type()); | 508 base::TimeTicks(), provider_host->create_time(), |
509 provider_host->client_type()); | |
489 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 510 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
490 base::Bind(callback, client_info)); | 511 base::Bind(callback, client_info)); |
491 } | 512 } |
492 | 513 |
493 void GetClients(const base::WeakPtr<ServiceWorkerVersion>& controller, | 514 void GetClients(const base::WeakPtr<ServiceWorkerVersion>& controller, |
494 const ServiceWorkerClientQueryOptions& options, | 515 const ServiceWorkerClientQueryOptions& options, |
495 const ClientsCallback& callback) { | 516 const ClientsCallback& callback) { |
496 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 517 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
497 | 518 |
498 ServiceWorkerClients clients; | 519 auto clients = base::MakeUnique<ServiceWorkerClients>(); |
499 if (!controller->HasControllee() && !options.include_uncontrolled) { | 520 if (!controller->HasControllee() && !options.include_uncontrolled) { |
500 DidGetClients(callback, &clients); | 521 DidGetClients(callback, std::move(clients)); |
501 return; | 522 return; |
502 } | 523 } |
503 | 524 |
504 // For Window clients we want to query the info on the UI thread first. | 525 // For Window clients we want to query the info on the UI thread first. |
505 if (options.client_type == blink::kWebServiceWorkerClientTypeWindow || | 526 if (options.client_type == blink::kWebServiceWorkerClientTypeWindow || |
506 options.client_type == blink::kWebServiceWorkerClientTypeAll) { | 527 options.client_type == blink::kWebServiceWorkerClientTypeAll) { |
507 GetWindowClients(controller, options, callback); | 528 GetWindowClients(controller, options, callback, std::move(clients)); |
508 return; | 529 return; |
509 } | 530 } |
510 | 531 |
511 GetNonWindowClients(controller, options, &clients); | 532 GetNonWindowClients(controller, options, callback, std::move(clients)); |
512 DidGetClients(callback, &clients); | |
513 } | 533 } |
514 | 534 |
515 } // namespace service_worker_client_utils | 535 } // namespace service_worker_client_utils |
516 } // namespace content | 536 } // namespace content |
OLD | NEW |