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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 } | 237 } |
238 | 238 |
239 Response CreateContextErrorResponse() { | 239 Response CreateContextErrorResponse() { |
240 return Response::InternalError("Could not connect to the context"); | 240 return Response::InternalError("Could not connect to the context"); |
241 } | 241 } |
242 | 242 |
243 Response CreateInvalidVersionIdErrorResponse() { | 243 Response CreateInvalidVersionIdErrorResponse() { |
244 return Response::InternalError("Invalid version ID"); | 244 return Response::InternalError("Invalid version ID"); |
245 } | 245 } |
246 | 246 |
247 const std::string GetDevToolsAgentHostTypeString( | |
248 content::DevToolsAgentHost::Type type) { | |
249 switch (type) { | |
250 case DevToolsAgentHost::TYPE_WEB_CONTENTS: | |
251 return "web_contents"; | |
252 case DevToolsAgentHost::TYPE_FRAME: | |
253 return "frame"; | |
254 case DevToolsAgentHost::TYPE_SHARED_WORKER: | |
255 return "shared_worker"; | |
256 case DevToolsAgentHost::TYPE_SERVICE_WORKER: | |
257 return "service_worker"; | |
258 case DevToolsAgentHost::TYPE_EXTERNAL: | |
259 return "external"; | |
260 case DevToolsAgentHost::TYPE_BROWSER: | |
261 return "browser"; | |
262 } | |
263 NOTREACHED() << type; | |
264 return std::string(); | |
265 } | |
266 | |
267 void DidFindRegistrationForDispatchSyncEventOnIO( | 247 void DidFindRegistrationForDispatchSyncEventOnIO( |
268 scoped_refptr<BackgroundSyncContext> sync_context, | 248 scoped_refptr<BackgroundSyncContext> sync_context, |
269 const std::string& tag, | 249 const std::string& tag, |
270 bool last_chance, | 250 bool last_chance, |
271 ServiceWorkerStatusCode status, | 251 ServiceWorkerStatusCode status, |
272 scoped_refptr<content::ServiceWorkerRegistration> registration) { | 252 scoped_refptr<content::ServiceWorkerRegistration> registration) { |
273 if (status != SERVICE_WORKER_OK || !registration->active_version()) | 253 if (status != SERVICE_WORKER_OK || !registration->active_version()) |
274 return; | 254 return; |
275 BackgroundSyncManager* background_sync_manager = | 255 BackgroundSyncManager* background_sync_manager = |
276 sync_context->background_sync_manager(); | 256 sync_context->background_sync_manager(); |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 Response ServiceWorkerHandler::GetTargetInfo( | 519 Response ServiceWorkerHandler::GetTargetInfo( |
540 const std::string& target_id, | 520 const std::string& target_id, |
541 scoped_refptr<TargetInfo>* target_info) { | 521 scoped_refptr<TargetInfo>* target_info) { |
542 scoped_refptr<DevToolsAgentHost> agent_host( | 522 scoped_refptr<DevToolsAgentHost> agent_host( |
543 DevToolsAgentHost::GetForId(target_id)); | 523 DevToolsAgentHost::GetForId(target_id)); |
544 if (!agent_host) | 524 if (!agent_host) |
545 return Response::InvalidParams("targetId"); | 525 return Response::InvalidParams("targetId"); |
546 *target_info = | 526 *target_info = |
547 TargetInfo::Create() | 527 TargetInfo::Create() |
548 ->set_id(agent_host->GetId()) | 528 ->set_id(agent_host->GetId()) |
549 ->set_type(GetDevToolsAgentHostTypeString(agent_host->GetType())) | 529 ->set_type(agent_host->GetType()) |
550 ->set_title(agent_host->GetTitle()) | 530 ->set_title(agent_host->GetTitle()) |
551 ->set_url(agent_host->GetURL().spec()); | 531 ->set_url(agent_host->GetURL().spec()); |
552 return Response::OK(); | 532 return Response::OK(); |
553 } | 533 } |
554 | 534 |
555 Response ServiceWorkerHandler::ActivateTarget(const std::string& target_id) { | 535 Response ServiceWorkerHandler::ActivateTarget(const std::string& target_id) { |
556 scoped_refptr<DevToolsAgentHost> agent_host( | 536 scoped_refptr<DevToolsAgentHost> agent_host( |
557 DevToolsAgentHost::GetForId(target_id)); | 537 DevToolsAgentHost::GetForId(target_id)); |
558 if (!agent_host) | 538 if (!agent_host) |
559 return Response::InvalidParams("targetId"); | 539 return Response::InvalidParams("targetId"); |
560 agent_host->Activate(); | 540 agent_host->Activate(); |
561 return Response::OK(); | 541 return Response::OK(); |
562 } | 542 } |
563 | 543 |
564 void ServiceWorkerHandler::OpenNewDevToolsWindow(int process_id, | 544 void ServiceWorkerHandler::OpenNewDevToolsWindow(int process_id, |
565 int devtools_agent_route_id) { | 545 int devtools_agent_route_id) { |
566 scoped_refptr<DevToolsAgentHostImpl> agent_host( | 546 scoped_refptr<DevToolsAgentHostImpl> agent_host( |
567 ServiceWorkerDevToolsManager::GetInstance() | 547 ServiceWorkerDevToolsManager::GetInstance() |
568 ->GetDevToolsAgentHostForWorker(process_id, devtools_agent_route_id)); | 548 ->GetDevToolsAgentHostForWorker(process_id, devtools_agent_route_id)); |
569 if (!agent_host.get()) | 549 if (!agent_host.get()) |
570 return; | 550 return; |
571 agent_host->Inspect(render_frame_host_->GetProcess()->GetBrowserContext()); | 551 agent_host->Inspect(); |
572 } | 552 } |
573 | 553 |
574 void ServiceWorkerHandler::OnWorkerRegistrationUpdated( | 554 void ServiceWorkerHandler::OnWorkerRegistrationUpdated( |
575 const std::vector<ServiceWorkerRegistrationInfo>& registrations) { | 555 const std::vector<ServiceWorkerRegistrationInfo>& registrations) { |
576 std::vector<scoped_refptr<ServiceWorkerRegistration>> registration_values; | 556 std::vector<scoped_refptr<ServiceWorkerRegistration>> registration_values; |
577 for (const auto& registration : registrations) { | 557 for (const auto& registration : registrations) { |
578 registration_values.push_back( | 558 registration_values.push_back( |
579 CreateRegistrationDictionaryValue(registration)); | 559 CreateRegistrationDictionaryValue(registration)); |
580 } | 560 } |
581 client_->WorkerRegistrationUpdated( | 561 client_->WorkerRegistrationUpdated( |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 } | 672 } |
693 | 673 |
694 void ServiceWorkerHandler::ClearForceUpdate() { | 674 void ServiceWorkerHandler::ClearForceUpdate() { |
695 if (context_) | 675 if (context_) |
696 context_->SetForceUpdateOnPageLoad(false); | 676 context_->SetForceUpdateOnPageLoad(false); |
697 } | 677 } |
698 | 678 |
699 } // namespace service_worker | 679 } // namespace service_worker |
700 } // namespace devtools | 680 } // namespace devtools |
701 } // namespace content | 681 } // namespace content |
OLD | NEW |