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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 #include <AdblockPlus/JsValue.h> | 18 #include <AdblockPlus/JsValue.h> |
19 #include <AdblockPlus/JsEngine.h> | 19 #include <AdblockPlus/JsEngine.h> |
| 20 #include "JsContext.h" |
20 #include <AdblockPlus/Notification.h> | 21 #include <AdblockPlus/Notification.h> |
21 #include <algorithm> | 22 #include <algorithm> |
22 | 23 |
23 using namespace AdblockPlus; | 24 using namespace AdblockPlus; |
24 | 25 |
25 namespace | 26 namespace |
26 { | 27 { |
27 typedef std::pair<NotificationType, std::string> NotificationTypeString; | 28 typedef std::pair<NotificationType, std::string> NotificationTypeString; |
28 typedef std::vector<NotificationTypeString> NotificationTypes; | 29 typedef std::vector<NotificationTypeString> NotificationTypes; |
29 NotificationTypes InitNotificationTypes() | 30 NotificationTypes InitNotificationTypes() |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 { | 63 { |
63 } | 64 } |
64 | 65 |
65 NotificationType Notification::GetType() const | 66 NotificationType Notification::GetType() const |
66 { | 67 { |
67 return StringToNotificationType(GetProperty("type")->AsString()); | 68 return StringToNotificationType(GetProperty("type")->AsString()); |
68 } | 69 } |
69 | 70 |
70 NotificationTexts Notification::GetTexts() const | 71 NotificationTexts Notification::GetTexts() const |
71 { | 72 { |
72 JsValuePtr jsTexts = jsEngine->Evaluate("API.getNotificationTexts")->Call(*thi
s); | 73 JsContext context(jsEngine); |
| 74 JsValuePtr jsTexts = context.GetJsEngine().Evaluate("API.getNotificationTexts"
)->Call(*this); |
73 NotificationTexts notificationTexts; | 75 NotificationTexts notificationTexts; |
74 JsValuePtr jsTitle = jsTexts->GetProperty("title"); | 76 JsValuePtr jsTitle = jsTexts->GetProperty("title"); |
75 if (jsTitle->IsString()) | 77 if (jsTitle->IsString()) |
76 { | 78 { |
77 notificationTexts.title = jsTitle->AsString(); | 79 notificationTexts.title = jsTitle->AsString(); |
78 } | 80 } |
79 JsValuePtr jsMessage = jsTexts->GetProperty("message"); | 81 JsValuePtr jsMessage = jsTexts->GetProperty("message"); |
80 if (jsMessage->IsString()) | 82 if (jsMessage->IsString()) |
81 { | 83 { |
82 notificationTexts.message = jsMessage->AsString(); | 84 notificationTexts.message = jsMessage->AsString(); |
(...skipping 13 matching lines...) Expand all Loading... |
96 for (JsValueList::const_iterator linkIterator = urlLinksList.begin(); | 98 for (JsValueList::const_iterator linkIterator = urlLinksList.begin(); |
97 linkIterator != urlLinksList.end(); ++linkIterator) | 99 linkIterator != urlLinksList.end(); ++linkIterator) |
98 { | 100 { |
99 retValue.push_back((*linkIterator)->AsString()); | 101 retValue.push_back((*linkIterator)->AsString()); |
100 } | 102 } |
101 return retValue; | 103 return retValue; |
102 } | 104 } |
103 | 105 |
104 void Notification::MarkAsShown() | 106 void Notification::MarkAsShown() |
105 { | 107 { |
106 jsEngine->Evaluate("API.markNotificationAsShown")->Call(*GetProperty("id")); | 108 JsContext context(jsEngine); |
| 109 context.GetJsEngine().Evaluate("API.markNotificationAsShown")->Call(*GetProper
ty("id")); |
107 } | 110 } |
OLD | NEW |