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 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "content/browser/frame_host/frame_tree_node.h" | 10 #include "content/browser/frame_host/frame_tree_node.h" |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
218 void AddNonWindowClient(ServiceWorkerProviderHost* host, | 218 void AddNonWindowClient(ServiceWorkerProviderHost* host, |
219 const ServiceWorkerClientQueryOptions& options, | 219 const ServiceWorkerClientQueryOptions& options, |
220 ServiceWorkerClients* clients) { | 220 ServiceWorkerClients* clients) { |
221 blink::WebServiceWorkerClientType host_client_type = host->client_type(); | 221 blink::WebServiceWorkerClientType host_client_type = host->client_type(); |
222 if (host_client_type == blink::WebServiceWorkerClientTypeWindow) | 222 if (host_client_type == blink::WebServiceWorkerClientTypeWindow) |
223 return; | 223 return; |
224 if (options.client_type != blink::WebServiceWorkerClientTypeAll && | 224 if (options.client_type != blink::WebServiceWorkerClientTypeAll && |
225 options.client_type != host_client_type) | 225 options.client_type != host_client_type) |
226 return; | 226 return; |
227 | 227 |
228 ServiceWorkerClientInfo client_info(blink::WebPageVisibilityStateHidden, | 228 ServiceWorkerClientInfo client_info( |
229 false, // is_focused | 229 host->client_uuid(), blink::WebPageVisibilityStateHidden, |
230 host->document_url(), | 230 false, // is_focused |
231 REQUEST_CONTEXT_FRAME_TYPE_NONE, | 231 host->document_url(), REQUEST_CONTEXT_FRAME_TYPE_NONE, base::TimeTicks(), |
232 base::TimeTicks(), host_client_type); | 232 host_client_type); |
233 client_info.client_uuid = host->client_uuid(); | |
234 clients->push_back(client_info); | 233 clients->push_back(client_info); |
235 } | 234 } |
236 | 235 |
236 void OnGetWindowClientOnUI( | |
237 int process_id, | |
238 int frame_id, | |
239 const std::string& client_uuid, | |
240 const GURL& script_url, | |
241 const ServiceWorkerProviderHost::GetClientInfoCallback& callback) { | |
242 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
243 | |
244 ServiceWorkerClientInfo info = | |
245 ServiceWorkerProviderHost::GetWindowClientInfoOnUI(process_id, frame_id, | |
246 client_uuid); | |
247 | |
248 if (info.url.GetOrigin() != script_url.GetOrigin()) | |
249 info = ServiceWorkerClientInfo(); | |
250 | |
251 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
252 base::Bind(callback, info)); | |
253 } | |
254 | |
237 void OnGetWindowClientsOnUI( | 255 void OnGetWindowClientsOnUI( |
238 // The tuple contains process_id, frame_id, client_uuid. | 256 // The tuple contains process_id, frame_id, client_uuid. |
239 const std::vector<base::Tuple<int, int, std::string>>& clients_info, | 257 const std::vector<base::Tuple<int, int, std::string>>& clients_info, |
240 const GURL& script_url, | 258 const GURL& script_url, |
241 const GetWindowClientsCallback& callback) { | 259 const GetWindowClientsCallback& callback) { |
242 scoped_ptr<ServiceWorkerClients> clients(new ServiceWorkerClients); | 260 scoped_ptr<ServiceWorkerClients> clients(new ServiceWorkerClients); |
243 | 261 |
244 for (const auto& it : clients_info) { | 262 for (const auto& it : clients_info) { |
245 ServiceWorkerClientInfo info = | 263 ServiceWorkerClientInfo info = |
246 ServiceWorkerProviderHost::GetWindowClientInfoOnUI(base::get<0>(it), | 264 ServiceWorkerProviderHost::GetWindowClientInfoOnUI( |
247 base::get<1>(it)); | 265 base::get<0>(it), base::get<1>(it), base::get<2>(it)); |
248 | 266 |
249 // If the request to the provider_host returned an empty | 267 // If the request to the provider_host returned an empty |
250 // ServiceWorkerClientInfo, that means that it wasn't possible to associate | 268 // ServiceWorkerClientInfo, that means that it wasn't possible to associate |
251 // it with a valid RenderFrameHost. It might be because the frame was killed | 269 // it with a valid RenderFrameHost. It might be because the frame was killed |
252 // or navigated in between. | 270 // or navigated in between. |
253 if (info.IsEmpty()) | 271 if (info.IsEmpty()) |
254 continue; | 272 continue; |
255 | 273 |
256 // We can get info for a frame that was navigating end ended up with a | 274 // We can get info for a frame that was navigating end ended up with a |
257 // different URL than expected. In such case, we should make sure to not | 275 // different URL than expected. In such case, we should make sure to not |
258 // expose cross-origin WindowClient. | 276 // expose cross-origin WindowClient. |
259 if (info.url.GetOrigin() != script_url.GetOrigin()) | 277 if (info.url.GetOrigin() != script_url.GetOrigin()) |
260 continue; | 278 continue; |
261 | 279 |
262 info.client_uuid = base::get<2>(it); | |
263 clients->push_back(info); | 280 clients->push_back(info); |
264 } | 281 } |
265 | 282 |
266 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 283 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
267 base::Bind(callback, base::Passed(&clients))); | 284 base::Bind(callback, base::Passed(&clients))); |
268 } | 285 } |
269 | 286 |
270 struct ServiceWorkerClientInfoSortMRU { | 287 struct ServiceWorkerClientInfoSortMRU { |
271 bool operator()(const ServiceWorkerClientInfo& a, | 288 bool operator()(const ServiceWorkerClientInfo& a, |
272 const ServiceWorkerClientInfo& b) const { | 289 const ServiceWorkerClientInfo& b) const { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 const base::WeakPtr<ServiceWorkerContextCore>& context, | 381 const base::WeakPtr<ServiceWorkerContextCore>& context, |
365 const NavigationCallback& callback) { | 382 const NavigationCallback& callback) { |
366 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 383 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
367 BrowserThread::PostTask( | 384 BrowserThread::PostTask( |
368 BrowserThread::UI, FROM_HERE, | 385 BrowserThread::UI, FROM_HERE, |
369 base::Bind( | 386 base::Bind( |
370 &NavigateClientOnUI, url, script_url, process_id, frame_id, | 387 &NavigateClientOnUI, url, script_url, process_id, frame_id, |
371 base::Bind(&DidNavigate, context, script_url.GetOrigin(), callback))); | 388 base::Bind(&DidNavigate, context, script_url.GetOrigin(), callback))); |
372 } | 389 } |
373 | 390 |
391 void GetClient( | |
392 const base::WeakPtr<ServiceWorkerVersion>& controller, | |
393 const std::string& client_uuid, | |
394 const base::WeakPtr<ServiceWorkerContextCore>& context, | |
395 const ServiceWorkerProviderHost::GetClientInfoCallback& callback) { | |
396 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
397 | |
398 ServiceWorkerProviderHost* provider_host = | |
399 context->GetProviderHostByClientID(client_uuid); | |
400 | |
401 if (!provider_host) { | |
402 // The client may already have been closed, just ignore. | |
403 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
404 base::Bind(callback, ServiceWorkerClientInfo())); | |
405 return; | |
406 } | |
407 | |
408 if (provider_host->client_type() == blink::WebServiceWorkerClientTypeWindow) { | |
409 BrowserThread::PostTask( | |
410 BrowserThread::UI, FROM_HERE, | |
411 base::Bind(&OnGetWindowClientOnUI, provider_host->process_id(), | |
412 provider_host->frame_id(), provider_host->client_uuid(), | |
413 controller->script_url(), callback)); | |
414 return; | |
415 } | |
416 | |
417 if (provider_host->document_url().GetOrigin() != | |
418 controller->script_url().GetOrigin()) { | |
nhiroki
2016/02/17 02:40:28
This origin check should be done before line 408.
jungkees
2016/02/17 14:01:12
I moved this origin check to before line 408 and r
| |
419 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
420 base::Bind(callback, ServiceWorkerClientInfo())); | |
421 return; | |
422 } | |
423 | |
nhiroki
2016/02/17 02:40:28
Can you add DCHECK here?
DCHECK(provider_host->cl
jungkees
2016/02/17 14:01:12
Done.
| |
424 ServiceWorkerClientInfo client_info( | |
425 provider_host->client_uuid(), blink::WebPageVisibilityStateHidden, | |
426 false, // is_focused | |
427 provider_host->document_url(), REQUEST_CONTEXT_FRAME_TYPE_NONE, | |
428 base::TimeTicks(), provider_host->client_type()); | |
429 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
430 base::Bind(callback, client_info)); | |
431 } | |
432 | |
374 void GetClients(const base::WeakPtr<ServiceWorkerVersion>& controller, | 433 void GetClients(const base::WeakPtr<ServiceWorkerVersion>& controller, |
375 const ServiceWorkerClientQueryOptions& options, | 434 const ServiceWorkerClientQueryOptions& options, |
376 const ClientsCallback& callback) { | 435 const ClientsCallback& callback) { |
377 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 436 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
378 | 437 |
379 ServiceWorkerClients clients; | 438 ServiceWorkerClients clients; |
380 if (!controller->HasControllee() && !options.include_uncontrolled) { | 439 if (!controller->HasControllee() && !options.include_uncontrolled) { |
381 DidGetClients(callback, &clients); | 440 DidGetClients(callback, &clients); |
382 return; | 441 return; |
383 } | 442 } |
384 | 443 |
385 // For Window clients we want to query the info on the UI thread first. | 444 // For Window clients we want to query the info on the UI thread first. |
386 if (options.client_type == blink::WebServiceWorkerClientTypeWindow || | 445 if (options.client_type == blink::WebServiceWorkerClientTypeWindow || |
387 options.client_type == blink::WebServiceWorkerClientTypeAll) { | 446 options.client_type == blink::WebServiceWorkerClientTypeAll) { |
388 GetWindowClients(controller, options, callback); | 447 GetWindowClients(controller, options, callback); |
389 return; | 448 return; |
390 } | 449 } |
391 | 450 |
392 GetNonWindowClients(controller, options, &clients); | 451 GetNonWindowClients(controller, options, &clients); |
393 DidGetClients(callback, &clients); | 452 DidGetClients(callback, &clients); |
394 } | 453 } |
395 | 454 |
396 } // namespace service_worker_client_utils | 455 } // namespace service_worker_client_utils |
397 } // namespace content | 456 } // namespace content |
OLD | NEW |