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

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: 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 int render_process_id = client.second.process_id;
88 int render_frame_id = client.second.frame_id;
89 int shared_worker_route_id = client.second.shared_worker_route_id;
90 if (render_frame_id != MSG_ROUTING_NONE) {
91 RenderFrameHostImpl* render_frame_host =
92 RenderFrameHostImpl::FromID(render_process_id, render_frame_id);
93 WebContents* web_contents =
94 WebContents::FromRenderFrameHost(render_frame_host);
95 scoped_refptr<DevToolsAgentHost> agent_host(
96 DevToolsAgentHost::GetOrCreateFor(web_contents));
97 if (agent_host) {
98 clients.push_back(agent_host->GetId());
99 }
nhiroki 2015/06/12 02:11:27 nit: {} is not necessary
horo 2015/06/12 04:19:18 Done.
100 } else if (shared_worker_route_id != MSG_ROUTING_NONE) {
101 scoped_refptr<DevToolsAgentHost> agent_host(
102 DevToolsAgentHost::GetForWorker(render_process_id,
103 shared_worker_route_id));
104 if (agent_host) {
105 clients.push_back(agent_host->GetId());
106 }
nhiroki 2015/06/12 02:11:27 ditto.
horo 2015/06/12 04:19:18 Done.
107 }
108 }
84 scoped_refptr<ServiceWorkerVersion> version( 109 scoped_refptr<ServiceWorkerVersion> version(
85 ServiceWorkerVersion::Create() 110 ServiceWorkerVersion::Create()
86 ->set_version_id(base::Int64ToString(version_info.version_id)) 111 ->set_version_id(base::Int64ToString(version_info.version_id))
87 ->set_registration_id( 112 ->set_registration_id(
88 base::Int64ToString(version_info.registration_id)) 113 base::Int64ToString(version_info.registration_id))
89 ->set_script_url(version_info.script_url.spec()) 114 ->set_script_url(version_info.script_url.spec())
90 ->set_running_status( 115 ->set_running_status(
91 GetVersionRunningStatusString(version_info.running_status)) 116 GetVersionRunningStatusString(version_info.running_status))
92 ->set_status(GetVersionStatusString(version_info.status)) 117 ->set_status(GetVersionStatusString(version_info.status))
93 ->set_script_last_modified( 118 ->set_script_last_modified(
94 version_info.script_last_modified.ToDoubleT()) 119 version_info.script_last_modified.ToDoubleT())
95 ->set_script_response_time( 120 ->set_script_response_time(
96 version_info.script_response_time.ToDoubleT())); 121 version_info.script_response_time.ToDoubleT())
122 ->set_controlled_clients(clients));
97 return version; 123 return version;
98 } 124 }
99 125
100 scoped_refptr<ServiceWorkerRegistration> CreateRegistrationDictionaryValue( 126 scoped_refptr<ServiceWorkerRegistration> CreateRegistrationDictionaryValue(
101 const ServiceWorkerRegistrationInfo& registration_info) { 127 const ServiceWorkerRegistrationInfo& registration_info) {
102 scoped_refptr<ServiceWorkerRegistration> registration( 128 scoped_refptr<ServiceWorkerRegistration> registration(
103 ServiceWorkerRegistration::Create() 129 ServiceWorkerRegistration::Create()
104 ->set_registration_id( 130 ->set_registration_id(
105 base::Int64ToString(registration_info.registration_id)) 131 base::Int64ToString(registration_info.registration_id))
106 ->set_scope_url(registration_info.pattern.spec()) 132 ->set_scope_url(registration_info.pattern.spec())
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } 200 }
175 201
176 Response CreateContextErrorResponse() { 202 Response CreateContextErrorResponse() {
177 return Response::InternalError("Could not connect to the context"); 203 return Response::InternalError("Could not connect to the context");
178 } 204 }
179 205
180 Response CreateInvalidVersionIdErrorResponse() { 206 Response CreateInvalidVersionIdErrorResponse() {
181 return Response::InternalError("Invalid version ID"); 207 return Response::InternalError("Invalid version ID");
182 } 208 }
183 209
210 const std::string GetDevToolsAgentHostTypeString(
211 content::DevToolsAgentHost::Type type) {
212 switch (type) {
213 case DevToolsAgentHost::TYPE_WEB_CONTENTS:
214 return "web_contents";
215 case DevToolsAgentHost::TYPE_FRAME:
216 return "frame";
217 case DevToolsAgentHost::TYPE_SHARED_WORKER:
218 return "shared_worker";
219 case DevToolsAgentHost::TYPE_SERVICE_WORKER:
220 return "service_worker";
221 case DevToolsAgentHost::TYPE_EXTERNAL:
222 return "external";
223 case DevToolsAgentHost::TYPE_BROWSER:
224 return "browser";
225 default:
226 NOTREACHED() << type;
227 }
228 return "";
229 }
230
184 } // namespace 231 } // namespace
185 232
186 ServiceWorkerHandler::ServiceWorkerHandler() 233 ServiceWorkerHandler::ServiceWorkerHandler()
187 : enabled_(false), weak_factory_(this) { 234 : enabled_(false), weak_factory_(this) {
188 } 235 }
189 236
190 ServiceWorkerHandler::~ServiceWorkerHandler() { 237 ServiceWorkerHandler::~ServiceWorkerHandler() {
191 Disable(); 238 Disable();
192 } 239 }
193 240
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 return CreateContextErrorResponse(); 437 return CreateContextErrorResponse();
391 int64 id = 0; 438 int64 id = 0;
392 if (!base::StringToInt64(registration_id, &id)) 439 if (!base::StringToInt64(registration_id, &id))
393 return CreateInvalidVersionIdErrorResponse(); 440 return CreateInvalidVersionIdErrorResponse();
394 BrowserContext::DeliverPushMessage( 441 BrowserContext::DeliverPushMessage(
395 render_frame_host_->GetProcess()->GetBrowserContext(), GURL(origin), id, 442 render_frame_host_->GetProcess()->GetBrowserContext(), GURL(origin), id,
396 data, base::Bind(&PushDeliveryNoOp)); 443 data, base::Bind(&PushDeliveryNoOp));
397 return Response::OK(); 444 return Response::OK();
398 } 445 }
399 446
447 // TODO(horo): Remove this.
nhiroki 2015/06/12 02:11:27 nit: bug link
horo 2015/06/12 04:19:18 Done.
400 Response ServiceWorkerHandler::GetTargetInfo(DevToolsCommandId command_id, 448 Response ServiceWorkerHandler::GetTargetInfo(DevToolsCommandId command_id,
401 const std::string& target_id) { 449 const std::string& target_id) {
402 return Response::InternalError("Not implemented yet"); 450 return Response::InternalError("Not implemented yet");
403 } 451 }
404 452
453 Response ServiceWorkerHandler::GetTargetInfo(
454 const std::string& target_id,
455 scoped_refptr<TargetInfo>* target_info) {
456 scoped_refptr<DevToolsAgentHost> agent_host(
457 DevToolsAgentHost::GetForId(target_id));
458 if (!agent_host) {
459 return Response::InvalidParams("targetId");
460 }
nhiroki 2015/06/12 02:11:27 nit: {}
horo 2015/06/12 04:19:18 Done.
461 *target_info =
462 TargetInfo::Create()
463 ->set_id(agent_host->GetId())
464 ->set_type(GetDevToolsAgentHostTypeString(agent_host->GetType()))
465 ->set_title(agent_host->GetTitle())
466 ->set_url(agent_host->GetURL().spec());
467 return Response::OK();
468 }
469
405 Response ServiceWorkerHandler::ActivateTarget(const std::string& target_id) { 470 Response ServiceWorkerHandler::ActivateTarget(const std::string& target_id) {
406 scoped_refptr<DevToolsAgentHost> agent_host( 471 scoped_refptr<DevToolsAgentHost> agent_host(
407 DevToolsAgentHost::GetForId(target_id)); 472 DevToolsAgentHost::GetForId(target_id));
408 if (!agent_host) 473 if (!agent_host)
409 return Response::InvalidParams("targetId"); 474 return Response::InvalidParams("targetId");
410 agent_host->Activate(); 475 agent_host->Activate();
411 return Response::OK(); 476 return Response::OK();
412 } 477 }
413 478
414 void ServiceWorkerHandler::OpenNewDevToolsWindow(int process_id, 479 void ServiceWorkerHandler::OpenNewDevToolsWindow(int process_id,
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 return; 596 return;
532 host->DetachClient(); 597 host->DetachClient();
533 client_->WorkerTerminated(WorkerTerminatedParams::Create()-> 598 client_->WorkerTerminated(WorkerTerminatedParams::Create()->
534 set_worker_id(host->GetId())); 599 set_worker_id(host->GetId()));
535 attached_hosts_.erase(it); 600 attached_hosts_.erase(it);
536 } 601 }
537 602
538 } // namespace service_worker 603 } // namespace service_worker
539 } // namespace devtools 604 } // namespace devtools
540 } // namespace content 605 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698