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

Side by Side Diff: content/browser/devtools/protocol/service_worker_handler.cc

Issue 1130093009: Check the BrowserContext when ServiceWorkerHandler gets the ServiceWorkerDevToolsAgentHosts (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « no previous file | content/browser/devtools/service_worker_devtools_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 std::string scope = path.substr(0, path.length() - file.length()); 122 std::string scope = path.substr(0, path.length() - file.length());
123 if (scope.length() > best_scope.length()) { 123 if (scope.length() > best_scope.length()) {
124 best_host = host; 124 best_host = host;
125 best_scope = scope; 125 best_scope = scope;
126 } 126 }
127 } 127 }
128 return best_host; 128 return best_host;
129 } 129 }
130 130
131 ServiceWorkerDevToolsAgentHost::Map GetMatchingServiceWorkers( 131 ServiceWorkerDevToolsAgentHost::Map GetMatchingServiceWorkers(
132 BrowserContext* browser_context,
132 const std::set<GURL>& urls) { 133 const std::set<GURL>& urls) {
134 ServiceWorkerDevToolsAgentHost::Map result;
135 if (!browser_context)
136 return result;
133 ServiceWorkerDevToolsAgentHost::List agent_hosts; 137 ServiceWorkerDevToolsAgentHost::List agent_hosts;
134 ServiceWorkerDevToolsManager::GetInstance()-> 138 ServiceWorkerDevToolsManager::GetInstance()
135 AddAllAgentHosts(&agent_hosts); 139 ->AddAllAgentHostsForBrowserContext(browser_context, &agent_hosts);
136 ServiceWorkerDevToolsAgentHost::Map result;
137 for (const GURL& url : urls) { 140 for (const GURL& url : urls) {
138 scoped_refptr<ServiceWorkerDevToolsAgentHost> host = 141 scoped_refptr<ServiceWorkerDevToolsAgentHost> host =
139 GetMatchingServiceWorker(agent_hosts, url); 142 GetMatchingServiceWorker(agent_hosts, url);
140 if (host) 143 if (host)
141 result[host->GetId()] = host; 144 result[host->GetId()] = host;
142 } 145 }
143 return result; 146 return result;
144 } 147 }
145 148
146 bool CollectURLs(std::set<GURL>* urls, FrameTreeNode* tree_node) { 149 bool CollectURLs(std::set<GURL>* urls, FrameTreeNode* tree_node) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 209
207 void ServiceWorkerHandler::SetClient(scoped_ptr<Client> client) { 210 void ServiceWorkerHandler::SetClient(scoped_ptr<Client> client) {
208 client_.swap(client); 211 client_.swap(client);
209 } 212 }
210 213
211 void ServiceWorkerHandler::UpdateHosts() { 214 void ServiceWorkerHandler::UpdateHosts() {
212 if (!enabled_) 215 if (!enabled_)
213 return; 216 return;
214 217
215 urls_.clear(); 218 urls_.clear();
219 BrowserContext* browser_context = nullptr;
216 if (render_frame_host_) { 220 if (render_frame_host_) {
217 render_frame_host_->frame_tree_node()->frame_tree()->ForEach( 221 render_frame_host_->frame_tree_node()->frame_tree()->ForEach(
218 base::Bind(&CollectURLs, &urls_)); 222 base::Bind(&CollectURLs, &urls_));
223 browser_context = render_frame_host_->GetProcess()->GetBrowserContext();
219 } 224 }
220 225
221 ServiceWorkerDevToolsAgentHost::Map old_hosts = attached_hosts_; 226 ServiceWorkerDevToolsAgentHost::Map old_hosts = attached_hosts_;
222 ServiceWorkerDevToolsAgentHost::Map new_hosts = 227 ServiceWorkerDevToolsAgentHost::Map new_hosts =
223 GetMatchingServiceWorkers(urls_); 228 GetMatchingServiceWorkers(browser_context, urls_);
224 229
225 for (auto pair : old_hosts) { 230 for (auto pair : old_hosts) {
226 if (new_hosts.find(pair.first) == new_hosts.end()) 231 if (new_hosts.find(pair.first) == new_hosts.end())
227 ReportWorkerTerminated(pair.second.get()); 232 ReportWorkerTerminated(pair.second.get());
228 } 233 }
229 234
230 for (auto pair : new_hosts) { 235 for (auto pair : new_hosts) {
231 if (old_hosts.find(pair.first) == old_hosts.end()) 236 if (old_hosts.find(pair.first) == old_hosts.end())
232 ReportWorkerCreated(pair.second.get()); 237 ReportWorkerCreated(pair.second.get());
233 } 238 }
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 void ServiceWorkerHandler::AgentHostClosed( 461 void ServiceWorkerHandler::AgentHostClosed(
457 DevToolsAgentHost* host, 462 DevToolsAgentHost* host,
458 bool replaced_with_another_client) { 463 bool replaced_with_another_client) {
459 client_->WorkerTerminated(WorkerTerminatedParams::Create()-> 464 client_->WorkerTerminated(WorkerTerminatedParams::Create()->
460 set_worker_id(host->GetId())); 465 set_worker_id(host->GetId()));
461 attached_hosts_.erase(host->GetId()); 466 attached_hosts_.erase(host->GetId());
462 } 467 }
463 468
464 void ServiceWorkerHandler::WorkerCreated( 469 void ServiceWorkerHandler::WorkerCreated(
465 ServiceWorkerDevToolsAgentHost* host) { 470 ServiceWorkerDevToolsAgentHost* host) {
466 auto hosts = GetMatchingServiceWorkers(urls_); 471 BrowserContext* browser_context = nullptr;
472 if (render_frame_host_)
473 browser_context = render_frame_host_->GetProcess()->GetBrowserContext();
474
475 auto hosts = GetMatchingServiceWorkers(browser_context, urls_);
467 if (hosts.find(host->GetId()) != hosts.end() && !host->IsAttached() && 476 if (hosts.find(host->GetId()) != hosts.end() && !host->IsAttached() &&
468 !host->IsPausedForDebugOnStart()) 477 !host->IsPausedForDebugOnStart())
469 host->PauseForDebugOnStart(); 478 host->PauseForDebugOnStart();
470 } 479 }
471 480
472 void ServiceWorkerHandler::WorkerReadyForInspection( 481 void ServiceWorkerHandler::WorkerReadyForInspection(
473 ServiceWorkerDevToolsAgentHost* host) { 482 ServiceWorkerDevToolsAgentHost* host) {
474 if (ServiceWorkerDevToolsManager::GetInstance() 483 if (ServiceWorkerDevToolsManager::GetInstance()
475 ->debug_service_worker_on_start()) { 484 ->debug_service_worker_on_start()) {
476 // When debug_service_worker_on_start is true, a new DevTools window will 485 // When debug_service_worker_on_start is true, a new DevTools window will
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 return; 517 return;
509 host->DetachClient(); 518 host->DetachClient();
510 client_->WorkerTerminated(WorkerTerminatedParams::Create()-> 519 client_->WorkerTerminated(WorkerTerminatedParams::Create()->
511 set_worker_id(host->GetId())); 520 set_worker_id(host->GetId()));
512 attached_hosts_.erase(it); 521 attached_hosts_.erase(it);
513 } 522 }
514 523
515 } // namespace service_worker 524 } // namespace service_worker
516 } // namespace devtools 525 } // namespace devtools
517 } // namespace content 526 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/devtools/service_worker_devtools_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698