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
3 // found in the LICENSE file.
5 #include "content/child/notifications/notification_data_conversions.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "third_party/WebKit/public/platform/WebString.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/WebNotificationAction.h"
13 using blink::WebNotificationData
;
17 PlatformNotificationData
ToPlatformNotificationData(
18 const WebNotificationData
& web_data
) {
19 PlatformNotificationData platform_data
;
20 platform_data
.title
= web_data
.title
;
22 switch (web_data
.direction
) {
23 case WebNotificationData::DirectionLeftToRight
:
24 platform_data
.direction
=
25 PlatformNotificationData::DIRECTION_LEFT_TO_RIGHT
;
27 case WebNotificationData::DirectionRightToLeft
:
28 platform_data
.direction
=
29 PlatformNotificationData::DIRECTION_RIGHT_TO_LEFT
;
31 case WebNotificationData::DirectionAuto
:
32 platform_data
.direction
=
33 PlatformNotificationData::DIRECTION_AUTO
;
37 platform_data
.lang
= base::UTF16ToUTF8(base::StringPiece16(web_data
.lang
));
38 platform_data
.body
= web_data
.body
;
39 platform_data
.tag
= base::UTF16ToUTF8(base::StringPiece16(web_data
.tag
));
40 platform_data
.icon
= GURL(web_data
.icon
.string());
41 platform_data
.vibration_pattern
.assign(web_data
.vibrate
.begin(),
42 web_data
.vibrate
.end());
43 platform_data
.silent
= web_data
.silent
;
44 platform_data
.data
.assign(web_data
.data
.begin(), web_data
.data
.end());
45 platform_data
.actions
.resize(web_data
.actions
.size());
46 for (size_t i
= 0; i
< web_data
.actions
.size(); ++i
) {
47 platform_data
.actions
[i
].action
=
48 base::UTF16ToUTF8(base::StringPiece16(web_data
.actions
[i
].action
));
49 platform_data
.actions
[i
].title
= web_data
.actions
[i
].title
;
55 WebNotificationData
ToWebNotificationData(
56 const PlatformNotificationData
& platform_data
) {
57 WebNotificationData web_data
;
58 web_data
.title
= platform_data
.title
;
60 switch (platform_data
.direction
) {
61 case PlatformNotificationData::DIRECTION_LEFT_TO_RIGHT
:
62 web_data
.direction
= WebNotificationData::DirectionLeftToRight
;
64 case PlatformNotificationData::DIRECTION_RIGHT_TO_LEFT
:
65 web_data
.direction
= WebNotificationData::DirectionRightToLeft
;
67 case PlatformNotificationData::DIRECTION_AUTO
:
68 web_data
.direction
= WebNotificationData::DirectionAuto
;
72 web_data
.lang
= blink::WebString::fromUTF8(platform_data
.lang
);
73 web_data
.body
= platform_data
.body
;
74 web_data
.tag
= blink::WebString::fromUTF8(platform_data
.tag
);
75 web_data
.icon
= blink::WebURL(platform_data
.icon
);
76 web_data
.vibrate
= platform_data
.vibration_pattern
;
77 web_data
.silent
= platform_data
.silent
;
78 web_data
.data
= platform_data
.data
;
79 blink::WebVector
<blink::WebNotificationAction
> resized(
80 platform_data
.actions
.size());
81 web_data
.actions
.swap(resized
);
82 for (size_t i
= 0; i
< platform_data
.actions
.size(); ++i
) {
83 web_data
.actions
[i
].action
=
84 blink::WebString::fromUTF8(platform_data
.actions
[i
].action
);
85 web_data
.actions
[i
].title
= platform_data
.actions
[i
].title
;
91 } // namespace content