| OLD | NEW |
| 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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 | 243 |
| 244 ServiceWorkerHandler::~ServiceWorkerHandler() { | 244 ServiceWorkerHandler::~ServiceWorkerHandler() { |
| 245 Disable(); | 245 Disable(); |
| 246 } | 246 } |
| 247 | 247 |
| 248 void ServiceWorkerHandler::SetRenderFrameHost( | 248 void ServiceWorkerHandler::SetRenderFrameHost( |
| 249 RenderFrameHostImpl* render_frame_host) { | 249 RenderFrameHostImpl* render_frame_host) { |
| 250 render_frame_host_ = render_frame_host; | 250 render_frame_host_ = render_frame_host; |
| 251 // Do not call UpdateHosts yet, wait for load to commit. | 251 // Do not call UpdateHosts yet, wait for load to commit. |
| 252 if (!render_frame_host) { | 252 if (!render_frame_host) { |
| 253 ClearForceUpdate(); | 253 ClearOverrides(); |
| 254 context_ = nullptr; | 254 context_ = nullptr; |
| 255 return; | 255 return; |
| 256 } | 256 } |
| 257 StoragePartition* partition = BrowserContext::GetStoragePartition( | 257 StoragePartition* partition = BrowserContext::GetStoragePartition( |
| 258 render_frame_host->GetProcess()->GetBrowserContext(), | 258 render_frame_host->GetProcess()->GetBrowserContext(), |
| 259 render_frame_host->GetSiteInstance()); | 259 render_frame_host->GetSiteInstance()); |
| 260 DCHECK(partition); | 260 DCHECK(partition); |
| 261 context_ = static_cast<ServiceWorkerContextWrapper*>( | 261 context_ = static_cast<ServiceWorkerContextWrapper*>( |
| 262 partition->GetServiceWorkerContext()); | 262 partition->GetServiceWorkerContext()); |
| 263 } | 263 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 UpdateHosts(); | 320 UpdateHosts(); |
| 321 return Response::OK(); | 321 return Response::OK(); |
| 322 } | 322 } |
| 323 | 323 |
| 324 Response ServiceWorkerHandler::Disable() { | 324 Response ServiceWorkerHandler::Disable() { |
| 325 if (!enabled_) | 325 if (!enabled_) |
| 326 return Response::OK(); | 326 return Response::OK(); |
| 327 enabled_ = false; | 327 enabled_ = false; |
| 328 | 328 |
| 329 ServiceWorkerDevToolsManager::GetInstance()->RemoveObserver(this); | 329 ServiceWorkerDevToolsManager::GetInstance()->RemoveObserver(this); |
| 330 ClearForceUpdate(); | 330 ClearOverrides(); |
| 331 for (const auto& pair : attached_hosts_) | 331 for (const auto& pair : attached_hosts_) |
| 332 pair.second->DetachClient(); | 332 pair.second->DetachClient(); |
| 333 attached_hosts_.clear(); | 333 attached_hosts_.clear(); |
| 334 DCHECK(context_watcher_); | 334 DCHECK(context_watcher_); |
| 335 context_watcher_->Stop(); | 335 context_watcher_->Stop(); |
| 336 context_watcher_ = nullptr; | 336 context_watcher_ = nullptr; |
| 337 return Response::OK(); | 337 return Response::OK(); |
| 338 } | 338 } |
| 339 | 339 |
| 340 Response ServiceWorkerHandler::SendMessage( | 340 Response ServiceWorkerHandler::SendMessage( |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 if (!base::StringToInt64(version_id, &id)) | 407 if (!base::StringToInt64(version_id, &id)) |
| 408 return CreateInvalidVersionIdErrorResponse(); | 408 return CreateInvalidVersionIdErrorResponse(); |
| 409 BrowserThread::PostTask( | 409 BrowserThread::PostTask( |
| 410 BrowserThread::IO, FROM_HERE, | 410 BrowserThread::IO, FROM_HERE, |
| 411 base::Bind(&GetDevToolsRouteInfoOnIO, context_, id, | 411 base::Bind(&GetDevToolsRouteInfoOnIO, context_, id, |
| 412 base::Bind(&ServiceWorkerHandler::OpenNewDevToolsWindow, | 412 base::Bind(&ServiceWorkerHandler::OpenNewDevToolsWindow, |
| 413 weak_factory_.GetWeakPtr()))); | 413 weak_factory_.GetWeakPtr()))); |
| 414 return Response::OK(); | 414 return Response::OK(); |
| 415 } | 415 } |
| 416 | 416 |
| 417 Response ServiceWorkerHandler::SetForceUpdateOnPageLoad( | 417 Response ServiceWorkerHandler::SetUpdateOnPageLoad( |
| 418 bool force_update_on_page_load) { | 418 bool update_on_page_load) { |
| 419 if (!context_) | 419 if (!context_) |
| 420 return CreateContextErrorResponse(); | 420 return CreateContextErrorResponse(); |
| 421 context_->SetForceUpdateOnPageLoad(force_update_on_page_load); | 421 context_->SetUpdateOnPageLoadForDevTools(update_on_page_load); |
| 422 return Response::OK(); | 422 return Response::OK(); |
| 423 } | 423 } |
| 424 | 424 |
| 425 Response ServiceWorkerHandler::SetFallbackToNetwork( |
| 426 bool fall_back) { |
| 427 if (!context_) |
| 428 return CreateContextErrorResponse(); |
| 429 context_->SetFallbackToNetworkForDevTools(fall_back); |
| 430 return Response::OK(); |
| 431 } |
| 432 |
| 425 Response ServiceWorkerHandler::DeliverPushMessage( | 433 Response ServiceWorkerHandler::DeliverPushMessage( |
| 426 const std::string& origin, | 434 const std::string& origin, |
| 427 const std::string& registration_id, | 435 const std::string& registration_id, |
| 428 const std::string& data) { | 436 const std::string& data) { |
| 429 if (!enabled_) | 437 if (!enabled_) |
| 430 return Response::OK(); | 438 return Response::OK(); |
| 431 if (!render_frame_host_) | 439 if (!render_frame_host_) |
| 432 return CreateContextErrorResponse(); | 440 return CreateContextErrorResponse(); |
| 433 int64_t id = 0; | 441 int64_t id = 0; |
| 434 if (!base::StringToInt64(registration_id, &id)) | 442 if (!base::StringToInt64(registration_id, &id)) |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 ServiceWorkerDevToolsAgentHost* host) { | 589 ServiceWorkerDevToolsAgentHost* host) { |
| 582 auto it = attached_hosts_.find(host->GetId()); | 590 auto it = attached_hosts_.find(host->GetId()); |
| 583 if (it == attached_hosts_.end()) | 591 if (it == attached_hosts_.end()) |
| 584 return; | 592 return; |
| 585 host->DetachClient(); | 593 host->DetachClient(); |
| 586 client_->WorkerTerminated(WorkerTerminatedParams::Create()-> | 594 client_->WorkerTerminated(WorkerTerminatedParams::Create()-> |
| 587 set_worker_id(host->GetId())); | 595 set_worker_id(host->GetId())); |
| 588 attached_hosts_.erase(it); | 596 attached_hosts_.erase(it); |
| 589 } | 597 } |
| 590 | 598 |
| 591 void ServiceWorkerHandler::ClearForceUpdate() { | 599 void ServiceWorkerHandler::ClearOverrides() { |
| 592 if (context_) | 600 if (context_) { |
| 593 context_->SetForceUpdateOnPageLoad(false); | 601 context_->SetUpdateOnPageLoadForDevTools(false); |
| 602 context_->SetFallbackToNetworkForDevTools(false); |
| 603 } |
| 594 } | 604 } |
| 595 | 605 |
| 596 } // namespace service_worker | 606 } // namespace service_worker |
| 597 } // namespace devtools | 607 } // namespace devtools |
| 598 } // namespace content | 608 } // namespace content |
| OLD | NEW |