OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/renderer/service_worker/service_worker_script_context.h" | 5 #include "content/renderer/service_worker/service_worker_script_context.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "content/child/notifications/notification_data_conversions.h" |
10 #include "content/child/thread_safe_sender.h" | 11 #include "content/child/thread_safe_sender.h" |
11 #include "content/child/webmessageportchannel_impl.h" | 12 #include "content/child/webmessageportchannel_impl.h" |
12 #include "content/common/service_worker/service_worker_messages.h" | 13 #include "content/common/service_worker/service_worker_messages.h" |
13 #include "content/renderer/service_worker/embedded_worker_context_client.h" | 14 #include "content/renderer/service_worker/embedded_worker_context_client.h" |
14 #include "ipc/ipc_message.h" | 15 #include "ipc/ipc_message.h" |
15 #include "third_party/WebKit/public/platform/WebNotificationData.h" | 16 #include "third_party/WebKit/public/platform/WebNotificationData.h" |
16 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" | 17 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" |
17 #include "third_party/WebKit/public/platform/WebServiceWorkerRequest.h" | 18 #include "third_party/WebKit/public/platform/WebServiceWorkerRequest.h" |
18 #include "third_party/WebKit/public/platform/WebString.h" | 19 #include "third_party/WebKit/public/platform/WebString.h" |
19 #include "third_party/WebKit/public/platform/WebURL.h" | 20 #include "third_party/WebKit/public/platform/WebURL.h" |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 | 261 |
261 void ServiceWorkerScriptContext::OnSyncEvent(int request_id) { | 262 void ServiceWorkerScriptContext::OnSyncEvent(int request_id) { |
262 TRACE_EVENT0("ServiceWorker", | 263 TRACE_EVENT0("ServiceWorker", |
263 "ServiceWorkerScriptContext::OnSyncEvent"); | 264 "ServiceWorkerScriptContext::OnSyncEvent"); |
264 proxy_->dispatchSyncEvent(request_id); | 265 proxy_->dispatchSyncEvent(request_id); |
265 } | 266 } |
266 | 267 |
267 void ServiceWorkerScriptContext::OnNotificationClickEvent( | 268 void ServiceWorkerScriptContext::OnNotificationClickEvent( |
268 int request_id, | 269 int request_id, |
269 const std::string& notification_id, | 270 const std::string& notification_id, |
270 const ShowDesktopNotificationHostMsgParams& notification_data) { | 271 const PlatformNotificationData& notification_data) { |
271 TRACE_EVENT0("ServiceWorker", | 272 TRACE_EVENT0("ServiceWorker", |
272 "ServiceWorkerScriptContext::OnNotificationClickEvent"); | 273 "ServiceWorkerScriptContext::OnNotificationClickEvent"); |
273 notification_click_start_timings_[request_id] = base::TimeTicks::Now(); | 274 notification_click_start_timings_[request_id] = base::TimeTicks::Now(); |
274 | |
275 // TODO(peter): Set the appropriate direction once it's been plumbed through. | |
276 // TODO(peter): Store the notification's language and icon URL in the struct. | |
277 blink::WebNotificationData notification( | |
278 blink::WebString(notification_data.title), | |
279 blink::WebNotificationData::DirectionLeftToRight, | |
280 blink::WebString() /* lang */, | |
281 blink::WebString(notification_data.body), | |
282 blink::WebString(notification_data.replace_id), | |
283 blink::WebURL() /* icon_url */); | |
284 | |
285 proxy_->dispatchNotificationClickEvent( | 275 proxy_->dispatchNotificationClickEvent( |
286 request_id, | 276 request_id, |
287 blink::WebString::fromUTF8(notification_id), | 277 blink::WebString::fromUTF8(notification_id), |
288 notification); | 278 ToWebNotificationData(notification_data)); |
289 } | 279 } |
290 | 280 |
291 void ServiceWorkerScriptContext::OnPushEvent(int request_id, | 281 void ServiceWorkerScriptContext::OnPushEvent(int request_id, |
292 const std::string& data) { | 282 const std::string& data) { |
293 TRACE_EVENT0("ServiceWorker", | 283 TRACE_EVENT0("ServiceWorker", |
294 "ServiceWorkerScriptContext::OnPushEvent"); | 284 "ServiceWorkerScriptContext::OnPushEvent"); |
295 push_start_timings_[request_id] = base::TimeTicks::Now(); | 285 push_start_timings_[request_id] = base::TimeTicks::Now(); |
296 proxy_->dispatchPushEvent(request_id, blink::WebString::fromUTF8(data)); | 286 proxy_->dispatchPushEvent(request_id, blink::WebString::fromUTF8(data)); |
297 } | 287 } |
298 | 288 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 pending_skip_waiting_callbacks_.Lookup(request_id); | 373 pending_skip_waiting_callbacks_.Lookup(request_id); |
384 if (!callbacks) { | 374 if (!callbacks) { |
385 NOTREACHED() << "Got stray response: " << request_id; | 375 NOTREACHED() << "Got stray response: " << request_id; |
386 return; | 376 return; |
387 } | 377 } |
388 callbacks->onSuccess(); | 378 callbacks->onSuccess(); |
389 pending_skip_waiting_callbacks_.Remove(request_id); | 379 pending_skip_waiting_callbacks_.Remove(request_id); |
390 } | 380 } |
391 | 381 |
392 } // namespace content | 382 } // namespace content |
OLD | NEW |