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

Side by Side Diff: content/browser/devtools/protocol/service_worker_handler.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 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/devtools/protocol/service_worker_handler.h" 5 #include "content/browser/devtools/protocol/service_worker_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/containers/scoped_ptr_hash_map.h" 8 #include "base/containers/scoped_ptr_hash_map.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "content/browser/devtools/service_worker_devtools_agent_host.h" 11 #include "content/browser/devtools/service_worker_devtools_agent_host.h"
12 #include "content/browser/devtools/service_worker_devtools_manager.h" 12 #include "content/browser/devtools/service_worker_devtools_manager.h"
13 #include "content/browser/frame_host/frame_tree.h" 13 #include "content/browser/frame_host/frame_tree.h"
14 #include "content/browser/frame_host/frame_tree_node.h" 14 #include "content/browser/frame_host/frame_tree_node.h"
15 #include "content/browser/frame_host/render_frame_host_impl.h" 15 #include "content/browser/frame_host/render_frame_host_impl.h"
16 #include "content/browser/service_worker/service_worker_context_watcher.h" 16 #include "content/browser/service_worker/service_worker_context_watcher.h"
17 #include "content/browser/service_worker/service_worker_context_wrapper.h" 17 #include "content/browser/service_worker/service_worker_context_wrapper.h"
18 #include "content/browser/service_worker/service_worker_version.h" 18 #include "content/browser/service_worker/service_worker_version.h"
19 #include "content/public/browser/browser_context.h" 19 #include "content/public/browser/browser_context.h"
20 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/devtools_agent_host.h" 21 #include "content/public/browser/devtools_agent_host.h"
22 #include "content/public/browser/render_frame_host.h" 22 #include "content/public/browser/render_frame_host.h"
23 #include "content/public/browser/render_process_host.h" 23 #include "content/public/browser/render_process_host.h"
24 #include "content/public/browser/storage_partition.h" 24 #include "content/public/browser/storage_partition.h"
25 #include "content/public/browser/web_contents.h"
25 #include "content/public/common/push_messaging_status.h" 26 #include "content/public/common/push_messaging_status.h"
26 #include "url/gurl.h" 27 #include "url/gurl.h"
27 28
28 // Windows headers will redefine SendMessage. 29 // Windows headers will redefine SendMessage.
29 #ifdef SendMessage 30 #ifdef SendMessage
30 #undef SendMessage 31 #undef SendMessage
31 #endif 32 #endif
32 33
33 namespace content { 34 namespace content {
34 namespace devtools { 35 namespace devtools {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 case content::ServiceWorkerVersion::ACTIVATED: 75 case content::ServiceWorkerVersion::ACTIVATED:
75 return kServiceWorkerVersionStatusActivated; 76 return kServiceWorkerVersionStatusActivated;
76 case content::ServiceWorkerVersion::REDUNDANT: 77 case content::ServiceWorkerVersion::REDUNDANT:
77 return kServiceWorkerVersionStatusRedundant; 78 return kServiceWorkerVersionStatusRedundant;
78 } 79 }
79 return ""; 80 return "";
80 } 81 }
81 82
82 scoped_refptr<ServiceWorkerVersion> CreateVersionDictionaryValue( 83 scoped_refptr<ServiceWorkerVersion> CreateVersionDictionaryValue(
83 const ServiceWorkerVersionInfo& version_info) { 84 const ServiceWorkerVersionInfo& version_info) {
85 std::vector<std::string> clients;
86 for (const auto& client : version_info.clients) {
87 if (client.second.type == SERVICE_WORKER_PROVIDER_FOR_WINDOW) {
88 RenderFrameHostImpl* render_frame_host = RenderFrameHostImpl::FromID(
89 client.second.process_id, client.second.route_id);
90 WebContents* web_contents =
91 WebContents::FromRenderFrameHost(render_frame_host);
92 scoped_refptr<DevToolsAgentHost> agent_host(
93 DevToolsAgentHost::GetOrCreateFor(web_contents));
94 if (agent_host)
95 clients.push_back(agent_host->GetId());
96 } else if (client.second.type ==
97 SERVICE_WORKER_PROVIDER_FOR_SHARED_WORKER) {
98 scoped_refptr<DevToolsAgentHost> agent_host(
99 DevToolsAgentHost::GetForWorker(client.second.process_id,
100 client.second.route_id));
101 if (agent_host)
102 clients.push_back(agent_host->GetId());
103 }
104 }
84 scoped_refptr<ServiceWorkerVersion> version( 105 scoped_refptr<ServiceWorkerVersion> version(
85 ServiceWorkerVersion::Create() 106 ServiceWorkerVersion::Create()
86 ->set_version_id(base::Int64ToString(version_info.version_id)) 107 ->set_version_id(base::Int64ToString(version_info.version_id))
87 ->set_registration_id( 108 ->set_registration_id(
88 base::Int64ToString(version_info.registration_id)) 109 base::Int64ToString(version_info.registration_id))
89 ->set_script_url(version_info.script_url.spec()) 110 ->set_script_url(version_info.script_url.spec())
90 ->set_running_status( 111 ->set_running_status(
91 GetVersionRunningStatusString(version_info.running_status)) 112 GetVersionRunningStatusString(version_info.running_status))
92 ->set_status(GetVersionStatusString(version_info.status)) 113 ->set_status(GetVersionStatusString(version_info.status))
93 ->set_script_last_modified( 114 ->set_script_last_modified(
94 version_info.script_last_modified.ToDoubleT()) 115 version_info.script_last_modified.ToDoubleT())
95 ->set_script_response_time( 116 ->set_script_response_time(
96 version_info.script_response_time.ToDoubleT())); 117 version_info.script_response_time.ToDoubleT())
118 ->set_controlled_clients(clients));
97 return version; 119 return version;
98 } 120 }
99 121
100 scoped_refptr<ServiceWorkerRegistration> CreateRegistrationDictionaryValue( 122 scoped_refptr<ServiceWorkerRegistration> CreateRegistrationDictionaryValue(
101 const ServiceWorkerRegistrationInfo& registration_info) { 123 const ServiceWorkerRegistrationInfo& registration_info) {
102 scoped_refptr<ServiceWorkerRegistration> registration( 124 scoped_refptr<ServiceWorkerRegistration> registration(
103 ServiceWorkerRegistration::Create() 125 ServiceWorkerRegistration::Create()
104 ->set_registration_id( 126 ->set_registration_id(
105 base::Int64ToString(registration_info.registration_id)) 127 base::Int64ToString(registration_info.registration_id))
106 ->set_scope_url(registration_info.pattern.spec()) 128 ->set_scope_url(registration_info.pattern.spec())
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } 196 }
175 197
176 Response CreateContextErrorResponse() { 198 Response CreateContextErrorResponse() {
177 return Response::InternalError("Could not connect to the context"); 199 return Response::InternalError("Could not connect to the context");
178 } 200 }
179 201
180 Response CreateInvalidVersionIdErrorResponse() { 202 Response CreateInvalidVersionIdErrorResponse() {
181 return Response::InternalError("Invalid version ID"); 203 return Response::InternalError("Invalid version ID");
182 } 204 }
183 205
206 const std::string GetDevToolsAgentHostTypeString(
207 content::DevToolsAgentHost::Type type) {
208 switch (type) {
209 case DevToolsAgentHost::TYPE_WEB_CONTENTS:
210 return "web_contents";
211 case DevToolsAgentHost::TYPE_FRAME:
212 return "frame";
213 case DevToolsAgentHost::TYPE_SHARED_WORKER:
214 return "shared_worker";
215 case DevToolsAgentHost::TYPE_SERVICE_WORKER:
216 return "service_worker";
217 case DevToolsAgentHost::TYPE_EXTERNAL:
218 return "external";
219 case DevToolsAgentHost::TYPE_BROWSER:
220 return "browser";
221 default:
nhiroki 2015/06/12 09:07:47 This switch-case covers all types. Can we delete t
horo 2015/06/12 09:23:47 Done.
222 NOTREACHED() << type;
223 }
224 return "";
225 }
226
184 } // namespace 227 } // namespace
185 228
186 ServiceWorkerHandler::ServiceWorkerHandler() 229 ServiceWorkerHandler::ServiceWorkerHandler()
187 : enabled_(false), weak_factory_(this) { 230 : enabled_(false), weak_factory_(this) {
188 } 231 }
189 232
190 ServiceWorkerHandler::~ServiceWorkerHandler() { 233 ServiceWorkerHandler::~ServiceWorkerHandler() {
191 Disable(); 234 Disable();
192 } 235 }
193 236
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 return CreateContextErrorResponse(); 433 return CreateContextErrorResponse();
391 int64 id = 0; 434 int64 id = 0;
392 if (!base::StringToInt64(registration_id, &id)) 435 if (!base::StringToInt64(registration_id, &id))
393 return CreateInvalidVersionIdErrorResponse(); 436 return CreateInvalidVersionIdErrorResponse();
394 BrowserContext::DeliverPushMessage( 437 BrowserContext::DeliverPushMessage(
395 render_frame_host_->GetProcess()->GetBrowserContext(), GURL(origin), id, 438 render_frame_host_->GetProcess()->GetBrowserContext(), GURL(origin), id,
396 data, base::Bind(&PushDeliveryNoOp)); 439 data, base::Bind(&PushDeliveryNoOp));
397 return Response::OK(); 440 return Response::OK();
398 } 441 }
399 442
443 // TODO(horo): I will remove it in crrev.com/1143363009.
400 Response ServiceWorkerHandler::GetTargetInfo(DevToolsCommandId command_id, 444 Response ServiceWorkerHandler::GetTargetInfo(DevToolsCommandId command_id,
401 const std::string& target_id) { 445 const std::string& target_id) {
402 return Response::InternalError("Not implemented yet"); 446 return Response::InternalError("Not implemented yet");
403 } 447 }
404 448
449 Response ServiceWorkerHandler::GetTargetInfo(
450 const std::string& target_id,
451 scoped_refptr<TargetInfo>* target_info) {
452 scoped_refptr<DevToolsAgentHost> agent_host(
453 DevToolsAgentHost::GetForId(target_id));
454 if (!agent_host)
455 return Response::InvalidParams("targetId");
456 *target_info =
457 TargetInfo::Create()
458 ->set_id(agent_host->GetId())
459 ->set_type(GetDevToolsAgentHostTypeString(agent_host->GetType()))
460 ->set_title(agent_host->GetTitle())
461 ->set_url(agent_host->GetURL().spec());
462 return Response::OK();
463 }
464
405 Response ServiceWorkerHandler::ActivateTarget(const std::string& target_id) { 465 Response ServiceWorkerHandler::ActivateTarget(const std::string& target_id) {
406 scoped_refptr<DevToolsAgentHost> agent_host( 466 scoped_refptr<DevToolsAgentHost> agent_host(
407 DevToolsAgentHost::GetForId(target_id)); 467 DevToolsAgentHost::GetForId(target_id));
408 if (!agent_host) 468 if (!agent_host)
409 return Response::InvalidParams("targetId"); 469 return Response::InvalidParams("targetId");
410 agent_host->Activate(); 470 agent_host->Activate();
411 return Response::OK(); 471 return Response::OK();
412 } 472 }
413 473
414 void ServiceWorkerHandler::OpenNewDevToolsWindow(int process_id, 474 void ServiceWorkerHandler::OpenNewDevToolsWindow(int process_id,
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 return; 591 return;
532 host->DetachClient(); 592 host->DetachClient();
533 client_->WorkerTerminated(WorkerTerminatedParams::Create()-> 593 client_->WorkerTerminated(WorkerTerminatedParams::Create()->
534 set_worker_id(host->GetId())); 594 set_worker_id(host->GetId()));
535 attached_hosts_.erase(it); 595 attached_hosts_.erase(it);
536 } 596 }
537 597
538 } // namespace service_worker 598 } // namespace service_worker
539 } // namespace devtools 599 } // namespace devtools
540 } // namespace content 600 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698