Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/Notification.cpp

Issue 4904655779790848: Issue 1107.update1 - read Notification properties (title, message and type) on the fly (Closed)
Patch Set: Created Jan. 27, 2015, 10:15 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 void Notification::MarkAsShown() 89 void Notification::MarkAsShown()
81 { 90 {
82 JsValueList params; 91 JsValueList params;
83 params.push_back(GetProperty("id")); 92 params.push_back(GetProperty("id"));
84 jsEngine->Evaluate("API.markNotificationAsShown")->Call(params); 93 jsEngine->Evaluate("API.markNotificationAsShown")->Call(params);
85 }
86
87 NotificationPtr Notification::JsValueToNotification(const JsValuePtr& jsValue)
88 {
89 if (!jsValue || !jsValue->IsObject())
90 {
91 return NotificationPtr();
92 }
93
94 NotificationPtr notification(new Notification(jsValue));
95 JsValuePtr jsType = notification->GetProperty("type");
96 notification->type = StringToNotificationType(jsType ? jsType->AsString() : "" );
97
98 JsValueList params;
99 params.push_back(notification);
100 JsValuePtr func = notification->jsEngine->Evaluate("API.getNotificationTexts") ;
101 JsValuePtr jsTexts = func->Call(params);
102 JsValuePtr jsTitle = jsTexts->GetProperty("title");
103 if (jsTitle->IsString())
104 {
105 notification->title = jsTitle->AsString();
106 }
107 JsValuePtr jsMessage = jsTexts->GetProperty("message");
108 if (jsMessage->IsString())
109 {
110 notification->message = jsMessage->AsString();
111 }
112 return notification;
113 } 94 }
OLDNEW
« src/FilterEngine.cpp ('K') | « src/FilterEngine.cpp ('k') | test/Notification.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld