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