Chromium Code Reviews| 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/child/notifications/notification_data_conversions.h" | 5 #include "content/child/notifications/notification_data_conversions.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "third_party/WebKit/public/platform/WebString.h" | 8 #include "third_party/WebKit/public/platform/WebString.h" |
| 9 #include "third_party/WebKit/public/platform/WebURL.h" | 9 #include "third_party/WebKit/public/platform/WebURL.h" |
| 10 #include "third_party/WebKit/public/platform/WebVector.h" | |
| 11 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati onAction.h" | |
| 10 | 12 |
| 11 using blink::WebNotificationData; | 13 using blink::WebNotificationData; |
| 12 | 14 |
| 13 namespace content { | 15 namespace content { |
| 14 | 16 |
| 15 PlatformNotificationData ToPlatformNotificationData( | 17 PlatformNotificationData ToPlatformNotificationData( |
| 16 const WebNotificationData& web_data) { | 18 const WebNotificationData& web_data) { |
| 17 PlatformNotificationData platform_data; | 19 PlatformNotificationData platform_data; |
| 18 platform_data.title = web_data.title; | 20 platform_data.title = web_data.title; |
| 19 platform_data.direction = | 21 platform_data.direction = |
| 20 web_data.direction == WebNotificationData::DirectionLeftToRight | 22 web_data.direction == WebNotificationData::DirectionLeftToRight |
| 21 ? PlatformNotificationData::NotificationDirectionLeftToRight | 23 ? PlatformNotificationData::NotificationDirectionLeftToRight |
| 22 : PlatformNotificationData::NotificationDirectionRightToLeft; | 24 : PlatformNotificationData::NotificationDirectionRightToLeft; |
| 23 platform_data.lang = base::UTF16ToUTF8(web_data.lang); | 25 platform_data.lang = base::UTF16ToUTF8(web_data.lang); |
| 24 platform_data.body = web_data.body; | 26 platform_data.body = web_data.body; |
| 25 platform_data.tag = base::UTF16ToUTF8(web_data.tag); | 27 platform_data.tag = base::UTF16ToUTF8(web_data.tag); |
| 26 platform_data.icon = GURL(web_data.icon.string()); | 28 platform_data.icon = GURL(web_data.icon.string()); |
| 27 platform_data.vibration_pattern.assign(web_data.vibrate.begin(), | 29 platform_data.vibration_pattern.assign(web_data.vibrate.begin(), |
| 28 web_data.vibrate.end()); | 30 web_data.vibrate.end()); |
| 29 platform_data.silent = web_data.silent; | 31 platform_data.silent = web_data.silent; |
| 30 platform_data.data.assign(web_data.data.begin(), web_data.data.end()); | 32 platform_data.data.assign(web_data.data.begin(), web_data.data.end()); |
| 33 platform_data.actions.clear(); | |
|
Peter Beverloo
2015/07/30 17:02:05
This is not necessary - it's a new object.
johnme
2015/07/31 18:21:31
Done.
| |
| 34 platform_data.actions.resize(web_data.actions.size()); | |
| 35 for (size_t i = 0; i < web_data.actions.size(); ++i) { | |
| 36 platform_data.actions[i].action = web_data.actions[i].action; | |
| 37 platform_data.actions[i].title = web_data.actions[i].title; | |
| 38 } | |
| 31 | 39 |
| 32 return platform_data; | 40 return platform_data; |
| 33 } | 41 } |
| 34 | 42 |
| 35 WebNotificationData ToWebNotificationData( | 43 WebNotificationData ToWebNotificationData( |
| 36 const PlatformNotificationData& platform_data) { | 44 const PlatformNotificationData& platform_data) { |
| 37 WebNotificationData web_data; | 45 WebNotificationData web_data; |
| 38 web_data.title = platform_data.title; | 46 web_data.title = platform_data.title; |
| 39 web_data.direction = | 47 web_data.direction = |
| 40 platform_data.direction == | 48 platform_data.direction == |
| 41 PlatformNotificationData::NotificationDirectionLeftToRight | 49 PlatformNotificationData::NotificationDirectionLeftToRight |
| 42 ? WebNotificationData::DirectionLeftToRight | 50 ? WebNotificationData::DirectionLeftToRight |
| 43 : WebNotificationData::DirectionRightToLeft; | 51 : WebNotificationData::DirectionRightToLeft; |
| 44 web_data.lang = blink::WebString::fromUTF8(platform_data.lang); | 52 web_data.lang = blink::WebString::fromUTF8(platform_data.lang); |
| 45 web_data.body = platform_data.body; | 53 web_data.body = platform_data.body; |
| 46 web_data.tag = blink::WebString::fromUTF8(platform_data.tag); | 54 web_data.tag = blink::WebString::fromUTF8(platform_data.tag); |
| 47 web_data.icon = blink::WebURL(platform_data.icon); | 55 web_data.icon = blink::WebURL(platform_data.icon); |
| 48 web_data.vibrate = platform_data.vibration_pattern; | 56 web_data.vibrate = platform_data.vibration_pattern; |
| 49 web_data.silent = platform_data.silent; | 57 web_data.silent = platform_data.silent; |
| 50 web_data.data = platform_data.data; | 58 web_data.data = platform_data.data; |
| 59 blink::WebVector<blink::WebNotificationAction> cleared_and_resized( | |
| 60 platform_data.actions.size()); | |
| 61 web_data.actions.swap(cleared_and_resized); | |
|
Peter Beverloo
2015/07/30 17:02:05
Just use web_data.actions.resize()?
Peter Beverloo
2015/07/30 17:02:05
This is not necessary - it's a new object.
johnme
2015/07/31 18:21:31
WebVector has no resize.
johnme
2015/07/31 18:21:31
Renamed this, to avoid the implication that it's c
| |
| 62 for (size_t i = 0; i < platform_data.actions.size(); ++i) { | |
| 63 web_data.actions[i].action = platform_data.actions[i].action; | |
| 64 web_data.actions[i].title = platform_data.actions[i].title; | |
| 65 } | |
| 51 | 66 |
| 52 return web_data; | 67 return web_data; |
| 53 } | 68 } |
| 54 | 69 |
| 55 } // namespace content | 70 } // namespace content |
| OLD | NEW |