Commit 5bfeed4a authored by horo's avatar horo Committed by Commit bot

Check the BrowserContext when ServiceWorkerHandler gets the ServiceWorkerDevToolsAgentHosts

To avoid showing wrong ServiceWorkers which are in another profile in DevTooks window.

BUG=488241

Review URL: https://codereview.chromium.org/1130093009

Cr-Commit-Position: refs/heads/master@{#330049}
parent bb6e4735
......@@ -129,11 +129,14 @@ scoped_refptr<ServiceWorkerDevToolsAgentHost> GetMatchingServiceWorker(
}
ServiceWorkerDevToolsAgentHost::Map GetMatchingServiceWorkers(
BrowserContext* browser_context,
const std::set<GURL>& urls) {
ServiceWorkerDevToolsAgentHost::List agent_hosts;
ServiceWorkerDevToolsManager::GetInstance()->
AddAllAgentHosts(&agent_hosts);
ServiceWorkerDevToolsAgentHost::Map result;
if (!browser_context)
return result;
ServiceWorkerDevToolsAgentHost::List agent_hosts;
ServiceWorkerDevToolsManager::GetInstance()
->AddAllAgentHostsForBrowserContext(browser_context, &agent_hosts);
for (const GURL& url : urls) {
scoped_refptr<ServiceWorkerDevToolsAgentHost> host =
GetMatchingServiceWorker(agent_hosts, url);
......@@ -213,14 +216,16 @@ void ServiceWorkerHandler::UpdateHosts() {
return;
urls_.clear();
BrowserContext* browser_context = nullptr;
if (render_frame_host_) {
render_frame_host_->frame_tree_node()->frame_tree()->ForEach(
base::Bind(&CollectURLs, &urls_));
browser_context = render_frame_host_->GetProcess()->GetBrowserContext();
}
ServiceWorkerDevToolsAgentHost::Map old_hosts = attached_hosts_;
ServiceWorkerDevToolsAgentHost::Map new_hosts =
GetMatchingServiceWorkers(urls_);
GetMatchingServiceWorkers(browser_context, urls_);
for (auto pair : old_hosts) {
if (new_hosts.find(pair.first) == new_hosts.end())
......@@ -463,7 +468,11 @@ void ServiceWorkerHandler::AgentHostClosed(
void ServiceWorkerHandler::WorkerCreated(
ServiceWorkerDevToolsAgentHost* host) {
auto hosts = GetMatchingServiceWorkers(urls_);
BrowserContext* browser_context = nullptr;
if (render_frame_host_)
browser_context = render_frame_host_->GetProcess()->GetBrowserContext();
auto hosts = GetMatchingServiceWorkers(browser_context, urls_);
if (hosts.find(host->GetId()) != hosts.end() && !host->IsAttached() &&
!host->IsPausedForDebugOnStart())
host->PauseForDebugOnStart();
......
......@@ -64,6 +64,17 @@ void ServiceWorkerDevToolsManager::AddAllAgentHosts(
}
}
void ServiceWorkerDevToolsManager::AddAllAgentHostsForBrowserContext(
BrowserContext* browser_context,
ServiceWorkerDevToolsAgentHost::List* result) {
for (auto& worker : workers_) {
if (!worker.second->IsTerminated() &&
worker.second->GetBrowserContext() == browser_context) {
result->push_back(worker.second);
}
}
}
bool ServiceWorkerDevToolsManager::WorkerCreated(
int worker_process_id,
int worker_route_id,
......
......@@ -15,6 +15,7 @@
namespace content {
class BrowserContext;
class DevToolsAgentHostImpl;
class ServiceWorkerDevToolsAgentHost;
class ServiceWorkerContextCore;
......@@ -71,6 +72,9 @@ class CONTENT_EXPORT ServiceWorkerDevToolsManager {
int worker_route_id);
void AddAllAgentHosts(
std::vector<scoped_refptr<ServiceWorkerDevToolsAgentHost>>* result);
void AddAllAgentHostsForBrowserContext(
BrowserContext* browser_context,
std::vector<scoped_refptr<ServiceWorkerDevToolsAgentHost>>* result);
// Returns true when the worker must be paused on start because a DevTool
// window for the same former ServiceWorkerIdentifier is still opened or
......
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