OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 } | 57 } |
58 } | 58 } |
59 | 59 |
60 Notification::Notification(const JsValuePtr& jsValue) | 60 Notification::Notification(const JsValuePtr& jsValue) |
61 : JsValue(jsValue) | 61 : JsValue(jsValue) |
62 { | 62 { |
63 } | 63 } |
64 | 64 |
65 NotificationType Notification::GetType() const | 65 NotificationType Notification::GetType() const |
66 { | 66 { |
67 return type; | 67 return StringToNotificationType(GetProperty("type")->AsString()); |
68 } | 68 } |
69 | 69 |
70 const std::string& Notification::GetTitle() const | 70 NotificationTexts Notification::GetTexts() |
71 { | 71 { |
72 return title; | 72 JsValueList params; |
73 } | 73 params.push_back(shared_from_this()); |
74 | 74 JsValuePtr jsTexts = jsEngine->Evaluate("API.getNotificationTexts")->Call(para
ms); |
75 const std::string& Notification::GetMessageString() const | 75 NotificationTexts notificationTexts; |
76 { | 76 JsValuePtr jsTitle = jsTexts->GetProperty("title"); |
77 return message; | 77 if (jsTitle->IsString()) |
| 78 { |
| 79 notificationTexts.title = jsTitle->AsString(); |
| 80 } |
| 81 JsValuePtr jsMessage = jsTexts->GetProperty("message"); |
| 82 if (jsMessage->IsString()) |
| 83 { |
| 84 notificationTexts.message = jsMessage->AsString(); |
| 85 } |
| 86 return notificationTexts; |
78 } | 87 } |
79 | 88 |
80 std::vector<std::string> Notification::GetLinks() const | 89 std::vector<std::string> Notification::GetLinks() const |
81 { | 90 { |
82 std::vector<std::string> retValue; | 91 std::vector<std::string> retValue; |
83 JsValuePtr jsLinks = GetProperty("links"); | 92 JsValuePtr jsLinks = GetProperty("links"); |
84 if (!jsLinks->IsArray()) | 93 if (!jsLinks->IsArray()) |
85 { | 94 { |
86 return retValue; | 95 return retValue; |
87 } | 96 } |
88 JsValueList urlLinksList = jsLinks->AsList(); | 97 JsValueList urlLinksList = jsLinks->AsList(); |
89 for (JsValueList::const_iterator linkIterator = urlLinksList.begin(); | 98 for (JsValueList::const_iterator linkIterator = urlLinksList.begin(); |
90 linkIterator != urlLinksList.end(); ++linkIterator) | 99 linkIterator != urlLinksList.end(); ++linkIterator) |
91 { | 100 { |
92 retValue.push_back((*linkIterator)->AsString()); | 101 retValue.push_back((*linkIterator)->AsString()); |
93 } | 102 } |
94 return retValue; | 103 return retValue; |
95 } | 104 } |
96 | 105 |
97 void Notification::MarkAsShown() | 106 void Notification::MarkAsShown() |
98 { | 107 { |
99 JsValueList params; | 108 JsValueList params; |
100 params.push_back(GetProperty("id")); | 109 params.push_back(GetProperty("id")); |
101 jsEngine->Evaluate("API.markNotificationAsShown")->Call(params); | 110 jsEngine->Evaluate("API.markNotificationAsShown")->Call(params); |
102 } | |
103 | |
104 NotificationPtr Notification::JsValueToNotification(const JsValuePtr& jsValue) | |
105 { | |
106 if (!jsValue || !jsValue->IsObject()) | |
107 { | |
108 return NotificationPtr(); | |
109 } | |
110 | |
111 NotificationPtr notification(new Notification(jsValue)); | |
112 JsValuePtr jsType = notification->GetProperty("type"); | |
113 notification->type = StringToNotificationType(jsType ? jsType->AsString() : ""
); | |
114 | |
115 JsValueList params; | |
116 params.push_back(notification); | |
117 JsValuePtr func = notification->jsEngine->Evaluate("API.getNotificationTexts")
; | |
118 JsValuePtr jsTexts = func->Call(params); | |
119 JsValuePtr jsTitle = jsTexts->GetProperty("title"); | |
120 if (jsTitle->IsString()) | |
121 { | |
122 notification->title = jsTitle->AsString(); | |
123 } | |
124 JsValuePtr jsMessage = jsTexts->GetProperty("message"); | |
125 if (jsMessage->IsString()) | |
126 { | |
127 notification->message = jsMessage->AsString(); | |
128 } | |
129 return notification; | |
130 } | 111 } |
OLD | NEW |