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_watcher.h" | 16 #include "content/browser/service_worker/service_worker_context_watcher.h" |
17 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 17 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
18 #include "content/browser/service_worker/service_worker_version.h" | 18 #include "content/browser/service_worker/service_worker_version.h" |
19 #include "content/public/browser/browser_context.h" | 19 #include "content/public/browser/browser_context.h" |
20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
21 #include "content/public/browser/devtools_agent_host.h" | 21 #include "content/public/browser/devtools_agent_host.h" |
22 #include "content/public/browser/render_frame_host.h" | 22 #include "content/public/browser/render_frame_host.h" |
23 #include "content/public/browser/render_process_host.h" | 23 #include "content/public/browser/render_process_host.h" |
24 #include "content/public/browser/storage_partition.h" | 24 #include "content/public/browser/storage_partition.h" |
25 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 26 #include "content/public/common/push_event_payload.h" |
26 #include "content/public/common/push_messaging_status.h" | 27 #include "content/public/common/push_messaging_status.h" |
27 #include "url/gurl.h" | 28 #include "url/gurl.h" |
28 | 29 |
29 // Windows headers will redefine SendMessage. | 30 // Windows headers will redefine SendMessage. |
30 #ifdef SendMessage | 31 #ifdef SendMessage |
31 #undef SendMessage | 32 #undef SendMessage |
32 #endif | 33 #endif |
33 | 34 |
34 namespace content { | 35 namespace content { |
35 namespace devtools { | 36 namespace devtools { |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 const std::string& origin, | 431 const std::string& origin, |
431 const std::string& registration_id, | 432 const std::string& registration_id, |
432 const std::string& data) { | 433 const std::string& data) { |
433 if (!enabled_) | 434 if (!enabled_) |
434 return Response::OK(); | 435 return Response::OK(); |
435 if (!render_frame_host_) | 436 if (!render_frame_host_) |
436 return CreateContextErrorResponse(); | 437 return CreateContextErrorResponse(); |
437 int64_t id = 0; | 438 int64_t id = 0; |
438 if (!base::StringToInt64(registration_id, &id)) | 439 if (!base::StringToInt64(registration_id, &id)) |
439 return CreateInvalidVersionIdErrorResponse(); | 440 return CreateInvalidVersionIdErrorResponse(); |
| 441 PushEventPayload payload; |
| 442 if (data.size() > 0) |
| 443 payload.setData(data); |
440 BrowserContext::DeliverPushMessage( | 444 BrowserContext::DeliverPushMessage( |
441 render_frame_host_->GetProcess()->GetBrowserContext(), GURL(origin), id, | 445 render_frame_host_->GetProcess()->GetBrowserContext(), GURL(origin), id, |
442 data, base::Bind(&PushDeliveryNoOp)); | 446 payload, base::Bind(&PushDeliveryNoOp)); |
443 return Response::OK(); | 447 return Response::OK(); |
444 } | 448 } |
445 | 449 |
446 Response ServiceWorkerHandler::GetTargetInfo( | 450 Response ServiceWorkerHandler::GetTargetInfo( |
447 const std::string& target_id, | 451 const std::string& target_id, |
448 scoped_refptr<TargetInfo>* target_info) { | 452 scoped_refptr<TargetInfo>* target_info) { |
449 scoped_refptr<DevToolsAgentHost> agent_host( | 453 scoped_refptr<DevToolsAgentHost> agent_host( |
450 DevToolsAgentHost::GetForId(target_id)); | 454 DevToolsAgentHost::GetForId(target_id)); |
451 if (!agent_host) | 455 if (!agent_host) |
452 return Response::InvalidParams("targetId"); | 456 return Response::InvalidParams("targetId"); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 return; | 594 return; |
591 host->DetachClient(); | 595 host->DetachClient(); |
592 client_->WorkerTerminated(WorkerTerminatedParams::Create()-> | 596 client_->WorkerTerminated(WorkerTerminatedParams::Create()-> |
593 set_worker_id(host->GetId())); | 597 set_worker_id(host->GetId())); |
594 attached_hosts_.erase(it); | 598 attached_hosts_.erase(it); |
595 } | 599 } |
596 | 600 |
597 } // namespace service_worker | 601 } // namespace service_worker |
598 } // namespace devtools | 602 } // namespace devtools |
599 } // namespace content | 603 } // namespace content |
OLD | NEW |