Commit 908b82fe authored by Nate Chapin's avatar Nate Chapin Committed by Commit Bot

Support nested workers in devtools

Bug: 829119
Change-Id: Idbc1dd0294174b457989893d11e66237a04c3ea5
Reviewed-on: https://chromium-review.googlesource.com/1005367Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Nate Chapin <japhet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551465}
parent 3a2e44cc
......@@ -438,7 +438,8 @@ void WebDevToolsAgentImpl::Session::InitializeInspectorSession(
inspector_session_->Append(
InspectorApplicationCacheAgent::Create(inspected_frames));
inspector_session_->Append(new InspectorWorkerAgent(inspected_frames));
inspector_session_->Append(
new InspectorWorkerAgent(inspected_frames, nullptr));
tracing_agent_ = new InspectorTracingAgent(agent_, inspected_frames);
inspector_session_->Append(tracing_agent_);
......
......@@ -12,6 +12,7 @@
#include "third_party/blink/renderer/core/inspector/identifiers_factory.h"
#include "third_party/blink/renderer/core/inspector/inspected_frames.h"
#include "third_party/blink/renderer/core/loader/frame_loader.h"
#include "third_party/blink/renderer/core/workers/execution_context_worker_registry.h"
#include "third_party/blink/renderer/core/workers/worker_inspector_proxy.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"
......@@ -117,8 +118,14 @@ void InspectorTracingAgent::EmitMetadataEvents() {
TRACE_EVENT_SCOPE_THREAD, "data",
InspectorTracingStartedInFrame::Data(
session_id_, inspected_frames_->Root()));
for (WorkerInspectorProxy* proxy : WorkerInspectorProxy::AllProxies())
DidStartWorker(proxy, false);
for (LocalFrame* frame : *inspected_frames_) {
for (WorkerInspectorProxy* proxy :
ExecutionContextWorkerRegistry::From(*frame->GetDocument())
->GetWorkerInspectorProxies()) {
DidStartWorker(proxy, false);
}
}
}
void InspectorTracingAgent::RootLayerCleared() {
......
......@@ -32,7 +32,10 @@
#include "base/memory/scoped_refptr.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/inspector/inspected_frames.h"
#include "third_party/blink/renderer/core/workers/execution_context_worker_registry.h"
#include "third_party/blink/renderer/core/workers/worker_global_scope.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
......@@ -49,8 +52,11 @@ static const char kAttachedSessionIds[] = "attachedSessionIds";
int InspectorWorkerAgent::s_last_connection_ = 0;
InspectorWorkerAgent::InspectorWorkerAgent(InspectedFrames* inspected_frames)
: inspected_frames_(inspected_frames) {}
InspectorWorkerAgent::InspectorWorkerAgent(
InspectedFrames* inspected_frames,
WorkerGlobalScope* worker_global_scope)
: inspected_frames_(inspected_frames),
worker_global_scope_(worker_global_scope) {}
InspectorWorkerAgent::~InspectorWorkerAgent() = default;
......@@ -158,12 +164,19 @@ void InspectorWorkerAgent::WorkerTerminated(WorkerInspectorProxy* proxy) {
}
void InspectorWorkerAgent::ConnectToAllProxies() {
for (WorkerInspectorProxy* proxy : WorkerInspectorProxy::AllProxies()) {
// For now we assume this is document. TODO(kinuko): Fix this.
DCHECK(proxy->GetExecutionContext()->IsDocument());
Document* document = ToDocument(proxy->GetExecutionContext());
if (document->GetFrame() &&
inspected_frames_->Contains(document->GetFrame())) {
if (worker_global_scope_) {
for (WorkerInspectorProxy* proxy :
ExecutionContextWorkerRegistry::From(*worker_global_scope_)
->GetWorkerInspectorProxies()) {
ConnectToProxy(proxy, false);
}
return;
}
for (LocalFrame* frame : *inspected_frames_) {
for (WorkerInspectorProxy* proxy :
ExecutionContextWorkerRegistry::From(*frame->GetDocument())
->GetWorkerInspectorProxies()) {
ConnectToProxy(proxy, false);
}
}
......@@ -243,6 +256,7 @@ void InspectorWorkerAgent::DispatchMessageFromWorker(
void InspectorWorkerAgent::Trace(blink::Visitor* visitor) {
visitor->Trace(connected_proxies_);
visitor->Trace(inspected_frames_);
visitor->Trace(worker_global_scope_);
InspectorBaseAgent::Trace(visitor);
}
......
......@@ -41,13 +41,14 @@
namespace blink {
class InspectedFrames;
class WorkerGlobalScope;
class WorkerInspectorProxy;
class CORE_EXPORT InspectorWorkerAgent final
: public InspectorBaseAgent<protocol::Target::Metainfo>,
public WorkerInspectorProxy::PageInspector {
public:
explicit InspectorWorkerAgent(InspectedFrames*);
InspectorWorkerAgent(InspectedFrames*, WorkerGlobalScope*);
~InspectorWorkerAgent() override;
void Trace(blink::Visitor*) override;
......@@ -80,7 +81,10 @@ class CORE_EXPORT InspectorWorkerAgent final
int connection,
const String& message) override;
// This is null while inspecting workers.
Member<InspectedFrames> inspected_frames_;
// This is null while inspecting frames.
Member<WorkerGlobalScope> worker_global_scope_;
HeapHashMap<int, Member<WorkerInspectorProxy>> connected_proxies_;
HashMap<int, String> connection_to_session_id_;
HashMap<String, int> session_id_to_connection_;
......
......@@ -34,6 +34,7 @@
#include "third_party/blink/renderer/core/inspector/InspectorLogAgent.h"
#include "third_party/blink/renderer/core/inspector/InspectorNetworkAgent.h"
#include "third_party/blink/renderer/core/inspector/InspectorTraceEvents.h"
#include "third_party/blink/renderer/core/inspector/InspectorWorkerAgent.h"
#include "third_party/blink/renderer/core/inspector/protocol/Protocol.h"
#include "third_party/blink/renderer/core/inspector/worker_thread_debugger.h"
#include "third_party/blink/renderer/core/loader/worker_fetch_context.h"
......@@ -76,10 +77,14 @@ void WorkerInspectorController::ConnectFrontend(int session_id) {
session->Append(new InspectorLogAgent(thread_->GetConsoleMessageStorage(),
nullptr, session->V8Session()));
if (thread_->GlobalScope()->IsWorkerGlobalScope()) {
DCHECK(ToWorkerGlobalScope(thread_->GlobalScope())->EnsureFetcher());
InspectedFrames* inspected_frames = new InspectedFrames(nullptr);
WorkerGlobalScope* worker_global_scope =
ToWorkerGlobalScope(thread_->GlobalScope());
DCHECK(worker_global_scope->EnsureFetcher());
session->Append(new InspectorNetworkAgent(
new InspectedFrames(nullptr),
ToWorkerGlobalScope(thread_->GlobalScope()), session->V8Session()));
inspected_frames, worker_global_scope, session->V8Session()));
session->Append(
new InspectorWorkerAgent(inspected_frames, worker_global_scope));
}
if (sessions_.IsEmpty())
thread_->GetWorkerBackingThread().BackingThread().AddTaskObserver(this);
......
......@@ -18,6 +18,8 @@ blink_core_sources("workers") {
"dedicated_worker_object_proxy.h",
"dedicated_worker_thread.cc",
"dedicated_worker_thread.h",
"execution_context_worker_registry.cc",
"execution_context_worker_registry.h",
"global_scope_creation_params.cc",
"global_scope_creation_params.h",
"installed_scripts_manager.cc",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/workers/execution_context_worker_registry.h"
namespace blink {
const char ExecutionContextWorkerRegistry::kSupplementName[] =
"ExecutionContextWorkerRegistry";
ExecutionContextWorkerRegistry::ExecutionContextWorkerRegistry(
ExecutionContext& context)
: Supplement<ExecutionContext>(context) {}
ExecutionContextWorkerRegistry* ExecutionContextWorkerRegistry::From(
ExecutionContext& context) {
DCHECK(context.IsContextThread());
ExecutionContextWorkerRegistry* worker_registry =
Supplement<ExecutionContext>::From<ExecutionContextWorkerRegistry>(
context);
if (!worker_registry) {
worker_registry = new ExecutionContextWorkerRegistry(context);
Supplement<ExecutionContext>::ProvideTo(context, worker_registry);
}
return worker_registry;
}
void ExecutionContextWorkerRegistry::AddWorkerInspectorProxy(
WorkerInspectorProxy* proxy) {
proxies_.insert(proxy);
}
void ExecutionContextWorkerRegistry::RemoveWorkerInspectorProxy(
WorkerInspectorProxy* proxy) {
proxies_.erase(proxy);
}
const HeapHashSet<Member<WorkerInspectorProxy>>&
ExecutionContextWorkerRegistry::GetWorkerInspectorProxies() {
return proxies_;
}
void ExecutionContextWorkerRegistry::Trace(Visitor* visitor) {
visitor->Trace(proxies_);
Supplement<ExecutionContext>::Trace(visitor);
}
} // namespace blink
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_WORKERS_EXECUTION_CONTEXT_WORKER_REGISTRY_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_WORKERS_EXECUTION_CONTEXT_WORKER_REGISTRY_H_
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/workers/worker_inspector_proxy.h"
#include "third_party/blink/renderer/platform/supplementable.h"
#include "third_party/blink/renderer/platform/wtf/hash_set.h"
namespace blink {
// Tracks the WorkerInspectorProxy objects created by a given ExecutionContext.
class ExecutionContextWorkerRegistry final
: public GarbageCollectedFinalized<ExecutionContextWorkerRegistry>,
public Supplement<ExecutionContext> {
USING_GARBAGE_COLLECTED_MIXIN(ExecutionContextWorkerRegistry);
public:
static const char kSupplementName[];
static ExecutionContextWorkerRegistry* From(ExecutionContext& context);
void AddWorkerInspectorProxy(WorkerInspectorProxy* proxy);
void RemoveWorkerInspectorProxy(WorkerInspectorProxy* proxy);
const HeapHashSet<Member<WorkerInspectorProxy>>& GetWorkerInspectorProxies();
virtual void Trace(Visitor* visitor);
private:
explicit ExecutionContextWorkerRegistry(ExecutionContext& context);
HeapHashSet<Member<WorkerInspectorProxy>> proxies_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_WORKERS_EXECUTION_CONTEXT_WORKER_REGISTRY_H_
......@@ -11,6 +11,7 @@
#include "third_party/blink/renderer/core/inspector/identifiers_factory.h"
#include "third_party/blink/renderer/core/inspector/worker_inspector_controller.h"
#include "third_party/blink/renderer/core/probe/core_probes.h"
#include "third_party/blink/renderer/core/workers/execution_context_worker_registry.h"
#include "third_party/blink/renderer/core/workers/worker_global_scope.h"
#include "third_party/blink/renderer/core/workers/worker_thread.h"
#include "third_party/blink/renderer/platform/cross_thread_functional.h"
......@@ -19,21 +20,6 @@
namespace blink {
namespace {
static WorkerInspectorProxy::WorkerInspectorProxySet& InspectorProxies() {
DEFINE_STATIC_LOCAL(WorkerInspectorProxy::WorkerInspectorProxySet, proxies,
());
return proxies;
}
} // namespace
const WorkerInspectorProxy::WorkerInspectorProxySet&
WorkerInspectorProxy::AllProxies() {
return InspectorProxies();
}
WorkerInspectorProxy::WorkerInspectorProxy()
: worker_thread_(nullptr), execution_context_(nullptr) {}
......@@ -66,7 +52,9 @@ void WorkerInspectorProxy::WorkerThreadCreated(
worker_thread_ = worker_thread;
execution_context_ = execution_context;
url_ = url.GetString();
InspectorProxies().insert(this);
DCHECK(execution_context_);
ExecutionContextWorkerRegistry::From(*execution_context_)
->AddWorkerInspectorProxy(this);
// We expect everyone starting worker thread to synchronously ask for
// ShouldPauseOnWorkerStart() right before.
bool waiting_for_debugger = false;
......@@ -77,8 +65,8 @@ void WorkerInspectorProxy::WorkerThreadCreated(
void WorkerInspectorProxy::WorkerThreadTerminated() {
if (worker_thread_) {
DCHECK(InspectorProxies().Contains(this));
InspectorProxies().erase(this);
ExecutionContextWorkerRegistry::From(*execution_context_)
->RemoveWorkerInspectorProxy(this);
probe::workerTerminated(execution_context_, this);
}
......
......@@ -57,10 +57,6 @@ class CORE_EXPORT WorkerInspectorProxy final
const String& InspectorId();
WorkerThread* GetWorkerThread() { return worker_thread_; }
using WorkerInspectorProxySet =
PersistentHeapHashSet<WeakMember<WorkerInspectorProxy>>;
static const WorkerInspectorProxySet& AllProxies();
private:
WorkerInspectorProxy();
......
......@@ -66,8 +66,10 @@ SDK.ChildTargetManager = class extends SDK.SDKModel {
* @return {number}
*/
_capabilitiesForType(type) {
if (type === 'worker')
return SDK.Target.Capability.JS | SDK.Target.Capability.Log | SDK.Target.Capability.Network;
if (type === 'worker') {
return SDK.Target.Capability.JS | SDK.Target.Capability.Log | SDK.Target.Capability.Network |
SDK.Target.Capability.Target;
}
if (type === 'service_worker')
return SDK.Target.Capability.Log | SDK.Target.Capability.Network | SDK.Target.Capability.Target;
if (type === 'iframe') {
......
......@@ -1221,7 +1221,7 @@ TestRunner.dumpLoadedModules = function(relativeTo) {
* @return {boolean}
*/
TestRunner.isDedicatedWorker = function(target) {
return target && !target.hasBrowserCapability() && target.hasJSCapability() && !target.hasTargetCapability();
return target && !target.hasBrowserCapability() && target.hasJSCapability() && target.hasLogCapability();
};
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment