Chromium Code Reviews| 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" |
| 11 #include "content/browser/devtools/service_worker_devtools_agent_host.h" | 11 #include "content/browser/devtools/service_worker_devtools_agent_host.h" |
| 12 #include "content/browser/devtools/service_worker_devtools_manager.h" | 12 #include "content/browser/devtools/service_worker_devtools_manager.h" |
| 13 #include "content/browser/frame_host/frame_tree.h" | 13 #include "content/browser/frame_host/frame_tree.h" |
| 14 #include "content/browser/frame_host/frame_tree_node.h" | 14 #include "content/browser/frame_host/frame_tree_node.h" |
| 15 #include "content/browser/frame_host/render_frame_host_impl.h" | 15 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 16 #include "content/browser/service_worker/service_worker_context_core.h" | 16 #include "content/browser/service_worker/service_worker_context_core.h" |
| 17 #include "content/browser/service_worker/service_worker_context_watcher.h" | 17 #include "content/browser/service_worker/service_worker_context_watcher.h" |
| 18 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 18 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 19 #include "content/browser/service_worker/service_worker_version.h" | 19 #include "content/browser/service_worker/service_worker_version.h" |
| 20 #include "content/public/browser/browser_context.h" | 20 #include "content/public/browser/browser_context.h" |
| 21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/devtools_agent_host.h" | 22 #include "content/public/browser/devtools_agent_host.h" |
| 23 #include "content/public/browser/render_frame_host.h" | 23 #include "content/public/browser/render_frame_host.h" |
| 24 #include "content/public/browser/render_process_host.h" | 24 #include "content/public/browser/render_process_host.h" |
| 25 #include "content/public/browser/storage_partition.h" | 25 #include "content/public/browser/storage_partition.h" |
| 26 #include "content/public/common/push_messaging_status.h" | |
| 26 #include "url/gurl.h" | 27 #include "url/gurl.h" |
| 27 | 28 |
| 28 // Windows headers will redefine SendMessage. | 29 // Windows headers will redefine SendMessage. |
| 29 #ifdef SendMessage | 30 #ifdef SendMessage |
| 30 #undef SendMessage | 31 #undef SendMessage |
| 31 #endif | 32 #endif |
| 32 | 33 |
| 33 namespace content { | 34 namespace content { |
| 34 namespace devtools { | 35 namespace devtools { |
| 35 namespace service_worker { | 36 namespace service_worker { |
| 36 | 37 |
| 37 using Response = DevToolsProtocolClient::Response; | 38 using Response = DevToolsProtocolClient::Response; |
| 38 | 39 |
| 39 namespace { | 40 namespace { |
| 40 | 41 |
| 41 void ResultNoOp(bool success) { | 42 void ResultNoOp(bool success) { |
| 42 } | 43 } |
| 43 void StatusNoOp(ServiceWorkerStatusCode status) { | 44 void StatusNoOp(ServiceWorkerStatusCode status) { |
| 44 } | 45 } |
| 46 void PushDeliveryNoOp(PushDeliveryStatus status) { | |
| 47 } | |
| 45 | 48 |
| 46 const std::string GetVersionRunningStatusString( | 49 const std::string GetVersionRunningStatusString( |
| 47 content::ServiceWorkerVersion::RunningStatus running_status) { | 50 content::ServiceWorkerVersion::RunningStatus running_status) { |
| 48 switch (running_status) { | 51 switch (running_status) { |
| 49 case content::ServiceWorkerVersion::STOPPED: | 52 case content::ServiceWorkerVersion::STOPPED: |
| 50 return kServiceWorkerVersionRunningStatusStopped; | 53 return kServiceWorkerVersionRunningStatusStopped; |
| 51 case content::ServiceWorkerVersion::STARTING: | 54 case content::ServiceWorkerVersion::STARTING: |
| 52 return kServiceWorkerVersionRunningStatusStarting; | 55 return kServiceWorkerVersionRunningStatusStarting; |
| 53 case content::ServiceWorkerVersion::RUNNING: | 56 case content::ServiceWorkerVersion::RUNNING: |
| 54 return kServiceWorkerVersionRunningStatusRunning; | 57 return kServiceWorkerVersionRunningStatusRunning; |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 349 weak_factory_.GetWeakPtr()))); | 352 weak_factory_.GetWeakPtr()))); |
| 350 return Response::OK(); | 353 return Response::OK(); |
| 351 } | 354 } |
| 352 | 355 |
| 353 Response ServiceWorkerHandler::SetDebugOnStart(bool debug_on_start) { | 356 Response ServiceWorkerHandler::SetDebugOnStart(bool debug_on_start) { |
| 354 ServiceWorkerDevToolsManager::GetInstance() | 357 ServiceWorkerDevToolsManager::GetInstance() |
| 355 ->set_debug_service_worker_on_start(debug_on_start); | 358 ->set_debug_service_worker_on_start(debug_on_start); |
| 356 return Response::OK(); | 359 return Response::OK(); |
| 357 } | 360 } |
| 358 | 361 |
| 362 Response ServiceWorkerHandler::DispatchPushEvent( | |
| 363 const std::string& origin, | |
| 364 const std::string& registration_id, | |
| 365 const std::string& data) { | |
| 366 if (!enabled_) | |
| 367 return Response::OK(); | |
| 368 if (!render_frame_host_) | |
| 369 return CreateContextErrorResoponse(); | |
| 370 int64 id = 0; | |
| 371 if (!base::StringToInt64(registration_id, &id)) | |
| 372 return CreateInvalidVersionIdErrorResoponse(); | |
| 373 BrowserContext::DeliverPushMessage( | |
|
pfeldman
2015/04/10 11:55:33
Or lets call it
deliverPushMessage in the protoc
horo
2015/04/10 16:58:33
Done.
| |
| 374 render_frame_host_->GetProcess()->GetBrowserContext(), GURL(origin), id, | |
| 375 data, base::Bind(&PushDeliveryNoOp)); | |
| 376 return Response::OK(); | |
| 377 } | |
| 378 | |
| 359 void ServiceWorkerHandler::OpenNewDevToolsWindow(int process_id, | 379 void ServiceWorkerHandler::OpenNewDevToolsWindow(int process_id, |
| 360 int devtools_agent_route_id) { | 380 int devtools_agent_route_id) { |
| 361 scoped_refptr<DevToolsAgentHostImpl> agent_host( | 381 scoped_refptr<DevToolsAgentHostImpl> agent_host( |
| 362 ServiceWorkerDevToolsManager::GetInstance() | 382 ServiceWorkerDevToolsManager::GetInstance() |
| 363 ->GetDevToolsAgentHostForWorker(process_id, devtools_agent_route_id)); | 383 ->GetDevToolsAgentHostForWorker(process_id, devtools_agent_route_id)); |
| 364 if (!agent_host.get()) | 384 if (!agent_host.get()) |
| 365 return; | 385 return; |
| 366 agent_host->Inspect(render_frame_host_->GetProcess()->GetBrowserContext()); | 386 agent_host->Inspect(render_frame_host_->GetProcess()->GetBrowserContext()); |
| 367 } | 387 } |
| 368 | 388 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 471 return; | 491 return; |
| 472 host->DetachClient(); | 492 host->DetachClient(); |
| 473 client_->WorkerTerminated(WorkerTerminatedParams::Create()-> | 493 client_->WorkerTerminated(WorkerTerminatedParams::Create()-> |
| 474 set_worker_id(host->GetId())); | 494 set_worker_id(host->GetId())); |
| 475 attached_hosts_.erase(it); | 495 attached_hosts_.erase(it); |
| 476 } | 496 } |
| 477 | 497 |
| 478 } // namespace service_worker | 498 } // namespace service_worker |
| 479 } // namespace devtools | 499 } // namespace devtools |
| 480 } // namespace content | 500 } // namespace content |
| OLD | NEW |