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

Side by Side Diff: content/browser/service_worker/service_worker_provider_host.cc

Issue 1149383004: [3/5 chromium] Shows the clients which are controlled by ServiceWorker in DevTools. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: incorporated nhiroki's comment Created 5 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_provider_host.h" 5 #include "content/browser/service_worker/service_worker_provider_host.h"
6 6
7 #include "base/guid.h" 7 #include "base/guid.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "content/browser/frame_host/frame_tree.h" 9 #include "content/browser/frame_host/frame_tree.h"
10 #include "content/browser/frame_host/frame_tree_node.h" 10 #include "content/browser/frame_host/frame_tree_node.h"
(...skipping 13 matching lines...) Expand all
24 #include "content/common/service_worker/service_worker_types.h" 24 #include "content/common/service_worker/service_worker_types.h"
25 #include "content/public/browser/render_frame_host.h" 25 #include "content/public/browser/render_frame_host.h"
26 #include "content/public/browser/render_widget_host_view.h" 26 #include "content/public/browser/render_widget_host_view.h"
27 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
28 #include "content/public/common/child_process_host.h" 28 #include "content/public/common/child_process_host.h"
29 29
30 namespace content { 30 namespace content {
31 31
32 namespace { 32 namespace {
33 33
34 ServiceWorkerClientInfo FocusOnUIThread( 34 ServiceWorkerClientInfo FocusOnUIThread(int render_process_id, int route_id) {
35 int render_process_id,
36 int render_frame_id) {
37 RenderFrameHostImpl* render_frame_host = 35 RenderFrameHostImpl* render_frame_host =
38 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); 36 RenderFrameHostImpl::FromID(render_process_id, route_id);
39 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( 37 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
40 WebContents::FromRenderFrameHost(render_frame_host)); 38 WebContents::FromRenderFrameHost(render_frame_host));
41 39
42 if (!render_frame_host || !web_contents) 40 if (!render_frame_host || !web_contents)
43 return ServiceWorkerClientInfo(); 41 return ServiceWorkerClientInfo();
44 42
45 FrameTreeNode* frame_tree_node = render_frame_host->frame_tree_node(); 43 FrameTreeNode* frame_tree_node = render_frame_host->frame_tree_node();
46 44
47 // Focus the frame in the frame tree node, in case it has changed. 45 // Focus the frame in the frame tree node, in case it has changed.
48 frame_tree_node->frame_tree()->SetFocusedFrame(frame_tree_node); 46 frame_tree_node->frame_tree()->SetFocusedFrame(frame_tree_node);
49 47
50 // Focus the frame's view to make sure the frame is now considered as focused. 48 // Focus the frame's view to make sure the frame is now considered as focused.
51 render_frame_host->GetView()->Focus(); 49 render_frame_host->GetView()->Focus();
52 50
53 // Move the web contents to the foreground. 51 // Move the web contents to the foreground.
54 web_contents->Activate(); 52 web_contents->Activate();
55 53
56 return ServiceWorkerProviderHost::GetWindowClientInfoOnUI(render_process_id, 54 return ServiceWorkerProviderHost::GetWindowClientInfoOnUI(render_process_id,
57 render_frame_id); 55 route_id);
58 } 56 }
59 57
60 } // anonymous namespace 58 } // anonymous namespace
61 59
62 ServiceWorkerProviderHost::OneShotGetReadyCallback::OneShotGetReadyCallback( 60 ServiceWorkerProviderHost::OneShotGetReadyCallback::OneShotGetReadyCallback(
63 const GetRegistrationForReadyCallback& callback) 61 const GetRegistrationForReadyCallback& callback)
64 : callback(callback), 62 : callback(callback),
65 called(false) { 63 called(false) {
66 } 64 }
67 65
68 ServiceWorkerProviderHost::OneShotGetReadyCallback::~OneShotGetReadyCallback() { 66 ServiceWorkerProviderHost::OneShotGetReadyCallback::~OneShotGetReadyCallback() {
69 } 67 }
70 68
71 ServiceWorkerProviderHost::ServiceWorkerProviderHost( 69 ServiceWorkerProviderHost::ServiceWorkerProviderHost(
72 int render_process_id, 70 int render_process_id,
73 int render_frame_id, 71 int route_id,
74 int provider_id, 72 int provider_id,
75 ServiceWorkerProviderType provider_type, 73 ServiceWorkerProviderType provider_type,
76 base::WeakPtr<ServiceWorkerContextCore> context, 74 base::WeakPtr<ServiceWorkerContextCore> context,
77 ServiceWorkerDispatcherHost* dispatcher_host) 75 ServiceWorkerDispatcherHost* dispatcher_host)
78 : client_uuid_(base::GenerateGUID()), 76 : client_uuid_(base::GenerateGUID()),
79 render_process_id_(render_process_id), 77 render_process_id_(render_process_id),
80 render_frame_id_(render_frame_id), 78 route_id_(route_id),
81 render_thread_id_(kDocumentMainThreadId), 79 render_thread_id_(kDocumentMainThreadId),
82 provider_id_(provider_id), 80 provider_id_(provider_id),
83 provider_type_(provider_type), 81 provider_type_(provider_type),
84 context_(context), 82 context_(context),
85 dispatcher_host_(dispatcher_host), 83 dispatcher_host_(dispatcher_host),
86 allow_association_(true) { 84 allow_association_(true) {
87 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_); 85 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_);
88 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_); 86 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_);
89 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) { 87 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_CONTROLLER) {
90 // Actual thread id is set when the service worker context gets started. 88 // Actual thread id is set when the service worker context gets started.
(...skipping 14 matching lines...) Expand all
105 103
106 for (auto& key_registration : matching_registrations_) { 104 for (auto& key_registration : matching_registrations_) {
107 DecreaseProcessReference(key_registration.second->pattern()); 105 DecreaseProcessReference(key_registration.second->pattern());
108 key_registration.second->RemoveListener(this); 106 key_registration.second->RemoveListener(this);
109 } 107 }
110 108
111 for (const GURL& pattern : associated_patterns_) 109 for (const GURL& pattern : associated_patterns_)
112 DecreaseProcessReference(pattern); 110 DecreaseProcessReference(pattern);
113 } 111 }
114 112
113 int ServiceWorkerProviderHost::frame_id() const {
114 if (provider_type_ == SERVICE_WORKER_PROVIDER_FOR_WINDOW)
115 return route_id_;
116 return MSG_ROUTING_NONE;
117 }
118
115 void ServiceWorkerProviderHost::OnVersionAttributesChanged( 119 void ServiceWorkerProviderHost::OnVersionAttributesChanged(
116 ServiceWorkerRegistration* registration, 120 ServiceWorkerRegistration* registration,
117 ChangedVersionAttributesMask changed_mask, 121 ChangedVersionAttributesMask changed_mask,
118 const ServiceWorkerRegistrationInfo& info) { 122 const ServiceWorkerRegistrationInfo& info) {
119 if (!get_ready_callback_ || get_ready_callback_->called) 123 if (!get_ready_callback_ || get_ready_callback_->called)
120 return; 124 return;
121 if (changed_mask.active_changed() && registration->active_version()) { 125 if (changed_mask.active_changed() && registration->active_version()) {
122 // Wait until the state change so we don't send the get for ready 126 // Wait until the state change so we don't send the get for ready
123 // registration complete message before set version attributes message. 127 // registration complete message before set version attributes message.
124 registration->active_version()->RegisterStatusChangeCallback(base::Bind( 128 registration->active_version()->RegisterStatusChangeCallback(base::Bind(
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 Send(new ServiceWorkerMsg_MessageToDocument( 385 Send(new ServiceWorkerMsg_MessageToDocument(
382 kDocumentMainThreadId, provider_id(), 386 kDocumentMainThreadId, provider_id(),
383 message, 387 message,
384 sent_message_ports, 388 sent_message_ports,
385 new_routing_ids)); 389 new_routing_ids));
386 } 390 }
387 391
388 void ServiceWorkerProviderHost::Focus(const GetClientInfoCallback& callback) { 392 void ServiceWorkerProviderHost::Focus(const GetClientInfoCallback& callback) {
389 BrowserThread::PostTaskAndReplyWithResult( 393 BrowserThread::PostTaskAndReplyWithResult(
390 BrowserThread::UI, FROM_HERE, 394 BrowserThread::UI, FROM_HERE,
391 base::Bind(&FocusOnUIThread, 395 base::Bind(&FocusOnUIThread, render_process_id_, route_id_), callback);
392 render_process_id_,
393 render_frame_id_),
394 callback);
395 } 396 }
396 397
397 void ServiceWorkerProviderHost::GetWindowClientInfo( 398 void ServiceWorkerProviderHost::GetWindowClientInfo(
398 const GetClientInfoCallback& callback) const { 399 const GetClientInfoCallback& callback) const {
399 BrowserThread::PostTaskAndReplyWithResult( 400 BrowserThread::PostTaskAndReplyWithResult(
400 BrowserThread::UI, FROM_HERE, 401 BrowserThread::UI, FROM_HERE,
401 base::Bind(&ServiceWorkerProviderHost::GetWindowClientInfoOnUI, 402 base::Bind(&ServiceWorkerProviderHost::GetWindowClientInfoOnUI,
402 render_process_id_, render_frame_id_), 403 render_process_id_, route_id_),
403 callback); 404 callback);
404 } 405 }
405 406
406 // static 407 // static
407 ServiceWorkerClientInfo ServiceWorkerProviderHost::GetWindowClientInfoOnUI( 408 ServiceWorkerClientInfo ServiceWorkerProviderHost::GetWindowClientInfoOnUI(
408 int render_process_id, 409 int render_process_id,
409 int render_frame_id) { 410 int route_id) {
410 RenderFrameHostImpl* render_frame_host = 411 RenderFrameHostImpl* render_frame_host =
411 RenderFrameHostImpl::FromID(render_process_id, render_frame_id); 412 RenderFrameHostImpl::FromID(render_process_id, route_id);
412 if (!render_frame_host) 413 if (!render_frame_host)
413 return ServiceWorkerClientInfo(); 414 return ServiceWorkerClientInfo();
414 415
415 // TODO(mlamouri,michaeln): it is possible to end up collecting information 416 // TODO(mlamouri,michaeln): it is possible to end up collecting information
416 // for a frame that is actually being navigated and isn't exactly what we are 417 // for a frame that is actually being navigated and isn't exactly what we are
417 // expecting. 418 // expecting.
418 return ServiceWorkerClientInfo( 419 return ServiceWorkerClientInfo(
419 render_frame_host->GetVisibilityState(), 420 render_frame_host->GetVisibilityState(),
420 render_frame_host->IsFocused(), 421 render_frame_host->IsFocused(),
421 render_frame_host->GetLastCommittedURL(), 422 render_frame_host->GetLastCommittedURL(),
(...skipping 24 matching lines...) Expand all
446 const GetRegistrationForReadyCallback& callback) { 447 const GetRegistrationForReadyCallback& callback) {
447 if (get_ready_callback_) 448 if (get_ready_callback_)
448 return false; 449 return false;
449 get_ready_callback_.reset(new OneShotGetReadyCallback(callback)); 450 get_ready_callback_.reset(new OneShotGetReadyCallback(callback));
450 ReturnRegistrationForReadyIfNeeded(); 451 ReturnRegistrationForReadyIfNeeded();
451 return true; 452 return true;
452 } 453 }
453 454
454 void ServiceWorkerProviderHost::PrepareForCrossSiteTransfer() { 455 void ServiceWorkerProviderHost::PrepareForCrossSiteTransfer() {
455 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_); 456 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, render_process_id_);
456 DCHECK_NE(MSG_ROUTING_NONE, render_frame_id_); 457 DCHECK_NE(MSG_ROUTING_NONE, route_id_);
457 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_); 458 DCHECK_EQ(kDocumentMainThreadId, render_thread_id_);
458 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_); 459 DCHECK_NE(SERVICE_WORKER_PROVIDER_UNKNOWN, provider_type_);
459 460
460 for (const GURL& pattern : associated_patterns_) 461 for (const GURL& pattern : associated_patterns_)
461 DecreaseProcessReference(pattern); 462 DecreaseProcessReference(pattern);
462 463
463 for (auto& key_registration : matching_registrations_) 464 for (auto& key_registration : matching_registrations_)
464 DecreaseProcessReference(key_registration.second->pattern()); 465 DecreaseProcessReference(key_registration.second->pattern());
465 466
466 if (associated_registration_.get()) { 467 if (associated_registration_.get()) {
467 if (dispatcher_host_) { 468 if (dispatcher_host_) {
468 Send(new ServiceWorkerMsg_DisassociateRegistration( 469 Send(new ServiceWorkerMsg_DisassociateRegistration(
469 render_thread_id_, provider_id())); 470 render_thread_id_, provider_id()));
470 } 471 }
471 } 472 }
472 473
473 render_process_id_ = ChildProcessHost::kInvalidUniqueID; 474 render_process_id_ = ChildProcessHost::kInvalidUniqueID;
474 render_frame_id_ = MSG_ROUTING_NONE; 475 route_id_ = MSG_ROUTING_NONE;
475 render_thread_id_ = kInvalidEmbeddedWorkerThreadId; 476 render_thread_id_ = kInvalidEmbeddedWorkerThreadId;
476 provider_id_ = kInvalidServiceWorkerProviderId; 477 provider_id_ = kInvalidServiceWorkerProviderId;
477 provider_type_ = SERVICE_WORKER_PROVIDER_UNKNOWN; 478 provider_type_ = SERVICE_WORKER_PROVIDER_UNKNOWN;
478 dispatcher_host_ = nullptr; 479 dispatcher_host_ = nullptr;
479 } 480 }
480 481
481 void ServiceWorkerProviderHost::CompleteCrossSiteTransfer( 482 void ServiceWorkerProviderHost::CompleteCrossSiteTransfer(
482 int new_process_id, 483 int new_process_id,
483 int new_frame_id, 484 int new_frame_id,
484 int new_provider_id, 485 int new_provider_id,
485 ServiceWorkerProviderType new_provider_type, 486 ServiceWorkerProviderType new_provider_type,
486 ServiceWorkerDispatcherHost* new_dispatcher_host) { 487 ServiceWorkerDispatcherHost* new_dispatcher_host) {
487 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_); 488 DCHECK_EQ(ChildProcessHost::kInvalidUniqueID, render_process_id_);
488 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, new_process_id); 489 DCHECK_NE(ChildProcessHost::kInvalidUniqueID, new_process_id);
489 DCHECK_NE(MSG_ROUTING_NONE, new_frame_id); 490 DCHECK_NE(MSG_ROUTING_NONE, new_frame_id);
490 491
491 render_process_id_ = new_process_id; 492 render_process_id_ = new_process_id;
492 render_frame_id_ = new_frame_id; 493 route_id_ = new_frame_id;
493 render_thread_id_ = kDocumentMainThreadId; 494 render_thread_id_ = kDocumentMainThreadId;
494 provider_id_ = new_provider_id; 495 provider_id_ = new_provider_id;
495 provider_type_ = new_provider_type; 496 provider_type_ = new_provider_type;
496 dispatcher_host_ = new_dispatcher_host; 497 dispatcher_host_ = new_dispatcher_host;
497 498
498 for (const GURL& pattern : associated_patterns_) 499 for (const GURL& pattern : associated_patterns_)
499 IncreaseProcessReference(pattern); 500 IncreaseProcessReference(pattern);
500 501
501 for (auto& key_registration : matching_registrations_) 502 for (auto& key_registration : matching_registrations_)
502 IncreaseProcessReference(key_registration.second->pattern()); 503 IncreaseProcessReference(key_registration.second->pattern());
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 return context_ != NULL; 651 return context_ != NULL;
651 } 652 }
652 653
653 void ServiceWorkerProviderHost::Send(IPC::Message* message) const { 654 void ServiceWorkerProviderHost::Send(IPC::Message* message) const {
654 DCHECK(dispatcher_host_); 655 DCHECK(dispatcher_host_);
655 DCHECK(IsReadyToSendMessages()); 656 DCHECK(IsReadyToSendMessages());
656 dispatcher_host_->Send(message); 657 dispatcher_host_->Send(message);
657 } 658 }
658 659
659 } // namespace content 660 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698