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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/devtools/protocol/service_worker_handler.cc
diff --git a/content/browser/devtools/protocol/service_worker_handler.cc b/content/browser/devtools/protocol/service_worker_handler.cc
index de97cc89a930178a758cb983640bd908b83933f4..3a862405c09a196558cf1ec7bba9bf812c9dde82 100644
--- a/content/browser/devtools/protocol/service_worker_handler.cc
+++ b/content/browser/devtools/protocol/service_worker_handler.cc
@@ -22,6 +22,7 @@
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/storage_partition.h"
+#include "content/public/browser/web_contents.h"
#include "content/public/common/push_messaging_status.h"
#include "url/gurl.h"
@@ -81,6 +82,26 @@ const std::string GetVersionStatusString(
scoped_refptr<ServiceWorkerVersion> CreateVersionDictionaryValue(
const ServiceWorkerVersionInfo& version_info) {
+ std::vector<std::string> clients;
+ for (const auto& client : version_info.clients) {
+ if (client.second.type == SERVICE_WORKER_PROVIDER_FOR_WINDOW) {
+ RenderFrameHostImpl* render_frame_host = RenderFrameHostImpl::FromID(
+ client.second.process_id, client.second.route_id);
+ WebContents* web_contents =
+ WebContents::FromRenderFrameHost(render_frame_host);
+ scoped_refptr<DevToolsAgentHost> agent_host(
+ DevToolsAgentHost::GetOrCreateFor(web_contents));
+ if (agent_host)
+ clients.push_back(agent_host->GetId());
+ } else if (client.second.type ==
+ SERVICE_WORKER_PROVIDER_FOR_SHARED_WORKER) {
+ scoped_refptr<DevToolsAgentHost> agent_host(
+ DevToolsAgentHost::GetForWorker(client.second.process_id,
+ client.second.route_id));
+ if (agent_host)
+ clients.push_back(agent_host->GetId());
+ }
+ }
scoped_refptr<ServiceWorkerVersion> version(
ServiceWorkerVersion::Create()
->set_version_id(base::Int64ToString(version_info.version_id))
@@ -93,7 +114,8 @@ scoped_refptr<ServiceWorkerVersion> CreateVersionDictionaryValue(
->set_script_last_modified(
version_info.script_last_modified.ToDoubleT())
->set_script_response_time(
- version_info.script_response_time.ToDoubleT()));
+ version_info.script_response_time.ToDoubleT())
+ ->set_controlled_clients(clients));
return version;
}
@@ -181,6 +203,27 @@ Response CreateInvalidVersionIdErrorResponse() {
return Response::InternalError("Invalid version ID");
}
+const std::string GetDevToolsAgentHostTypeString(
+ content::DevToolsAgentHost::Type type) {
+ switch (type) {
+ case DevToolsAgentHost::TYPE_WEB_CONTENTS:
+ return "web_contents";
+ case DevToolsAgentHost::TYPE_FRAME:
+ return "frame";
+ case DevToolsAgentHost::TYPE_SHARED_WORKER:
+ return "shared_worker";
+ case DevToolsAgentHost::TYPE_SERVICE_WORKER:
+ return "service_worker";
+ case DevToolsAgentHost::TYPE_EXTERNAL:
+ return "external";
+ case DevToolsAgentHost::TYPE_BROWSER:
+ return "browser";
+ 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.
+ NOTREACHED() << type;
+ }
+ return "";
+}
+
} // namespace
ServiceWorkerHandler::ServiceWorkerHandler()
@@ -397,11 +440,28 @@ Response ServiceWorkerHandler::DeliverPushMessage(
return Response::OK();
}
+// TODO(horo): I will remove it in crrev.com/1143363009.
Response ServiceWorkerHandler::GetTargetInfo(DevToolsCommandId command_id,
const std::string& target_id) {
return Response::InternalError("Not implemented yet");
}
+Response ServiceWorkerHandler::GetTargetInfo(
+ const std::string& target_id,
+ scoped_refptr<TargetInfo>* target_info) {
+ scoped_refptr<DevToolsAgentHost> agent_host(
+ DevToolsAgentHost::GetForId(target_id));
+ if (!agent_host)
+ return Response::InvalidParams("targetId");
+ *target_info =
+ TargetInfo::Create()
+ ->set_id(agent_host->GetId())
+ ->set_type(GetDevToolsAgentHostTypeString(agent_host->GetType()))
+ ->set_title(agent_host->GetTitle())
+ ->set_url(agent_host->GetURL().spec());
+ return Response::OK();
+}
+
Response ServiceWorkerHandler::ActivateTarget(const std::string& target_id) {
scoped_refptr<DevToolsAgentHost> agent_host(
DevToolsAgentHost::GetForId(target_id));

Powered by Google App Engine
This is Rietveld 408576698