| 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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 | 253 |
| 253 void ServiceWorkerScriptContext::OnSyncEvent(int request_id) { | 254 void ServiceWorkerScriptContext::OnSyncEvent(int request_id) { |
| 254 TRACE_EVENT0("ServiceWorker", | 255 TRACE_EVENT0("ServiceWorker", |
| 255 "ServiceWorkerScriptContext::OnSyncEvent"); | 256 "ServiceWorkerScriptContext::OnSyncEvent"); |
| 256 proxy_->dispatchSyncEvent(request_id); | 257 proxy_->dispatchSyncEvent(request_id); |
| 257 } | 258 } |
| 258 | 259 |
| 259 void ServiceWorkerScriptContext::OnNotificationClickEvent( | 260 void ServiceWorkerScriptContext::OnNotificationClickEvent( |
| 260 int request_id, | 261 int request_id, |
| 261 const std::string& notification_id, | 262 const std::string& notification_id, |
| 262 const ShowDesktopNotificationHostMsgParams& notification_data) { | 263 const PlatformNotificationData& notification_data) { |
| 263 TRACE_EVENT0("ServiceWorker", | 264 TRACE_EVENT0("ServiceWorker", |
| 264 "ServiceWorkerScriptContext::OnNotificationClickEvent"); | 265 "ServiceWorkerScriptContext::OnNotificationClickEvent"); |
| 265 notification_click_start_timings_[request_id] = base::TimeTicks::Now(); | 266 notification_click_start_timings_[request_id] = base::TimeTicks::Now(); |
| 266 | |
| 267 // TODO(peter): Set the appropriate direction once it's been plumbed through. | |
| 268 // TODO(peter): Store the notification's language and icon URL in the struct. | |
| 269 blink::WebNotificationData notification( | |
| 270 blink::WebString(notification_data.title), | |
| 271 blink::WebNotificationData::DirectionLeftToRight, | |
| 272 blink::WebString() /* lang */, | |
| 273 blink::WebString(notification_data.body), | |
| 274 blink::WebString(notification_data.replace_id), | |
| 275 blink::WebURL() /* icon_url */); | |
| 276 | |
| 277 proxy_->dispatchNotificationClickEvent( | 267 proxy_->dispatchNotificationClickEvent( |
| 278 request_id, | 268 request_id, |
| 279 blink::WebString::fromUTF8(notification_id), | 269 blink::WebString::fromUTF8(notification_id), |
| 280 notification); | 270 ToWebNotificationData(notification_data)); |
| 281 } | 271 } |
| 282 | 272 |
| 283 void ServiceWorkerScriptContext::OnPushEvent(int request_id, | 273 void ServiceWorkerScriptContext::OnPushEvent(int request_id, |
| 284 const std::string& data) { | 274 const std::string& data) { |
| 285 TRACE_EVENT0("ServiceWorker", | 275 TRACE_EVENT0("ServiceWorker", |
| 286 "ServiceWorkerScriptContext::OnPushEvent"); | 276 "ServiceWorkerScriptContext::OnPushEvent"); |
| 287 push_start_timings_[request_id] = base::TimeTicks::Now(); | 277 push_start_timings_[request_id] = base::TimeTicks::Now(); |
| 288 proxy_->dispatchPushEvent(request_id, blink::WebString::fromUTF8(data)); | 278 proxy_->dispatchPushEvent(request_id, blink::WebString::fromUTF8(data)); |
| 289 } | 279 } |
| 290 | 280 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 pending_focus_client_callbacks_.Lookup(request_id); | 341 pending_focus_client_callbacks_.Lookup(request_id); |
| 352 if (!callback) { | 342 if (!callback) { |
| 353 NOTREACHED() << "Got stray response: " << request_id; | 343 NOTREACHED() << "Got stray response: " << request_id; |
| 354 return; | 344 return; |
| 355 } | 345 } |
| 356 callback->onSuccess(&result); | 346 callback->onSuccess(&result); |
| 357 pending_focus_client_callbacks_.Remove(request_id); | 347 pending_focus_client_callbacks_.Remove(request_id); |
| 358 } | 348 } |
| 359 | 349 |
| 360 } // namespace content | 350 } // namespace content |
| OLD | NEW |