| Index: src/Notification.cpp | 
| diff --git a/src/Notification.cpp b/src/Notification.cpp | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..fa7064f398438d59ca771ed36d8b361558918685 | 
| --- /dev/null | 
| +++ b/src/Notification.cpp | 
| @@ -0,0 +1,106 @@ | 
| +/* | 
| + * This file is part of Adblock Plus <https://adblockplus.org/>, | 
| + * Copyright (C) 2006-2015 Eyeo GmbH | 
| + * | 
| + * Adblock Plus is free software: you can redistribute it and/or modify | 
| + * it under the terms of the GNU General Public License version 3 as | 
| + * published by the Free Software Foundation. | 
| + * | 
| + * Adblock Plus is distributed in the hope that it will be useful, | 
| + * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
| + * GNU General Public License for more details. | 
| + * | 
| + * You should have received a copy of the GNU General Public License | 
| + * along with Adblock Plus.  If not, see <http://www.gnu.org/licenses/>. | 
| + */ | 
| + | 
| +#include <AdblockPlus/JsValue.h> | 
| +#include <AdblockPlus/JsEngine.h> | 
| +#include <AdblockPlus/Notification.h> | 
| +#include <algorithm> | 
| + | 
| +using namespace AdblockPlus; | 
| + | 
| +namespace | 
| +{ | 
| +  typedef std::pair<NotificationType, std::string> NotificationTypeString; | 
| +  typedef std::vector<NotificationTypeString> NotificationTypes; | 
| +  const NotificationTypes g_notificationTypes = []()->NotificationTypes | 
| +  { | 
| +    NotificationTypes retValue; | 
| +    retValue.emplace_back(std::make_pair(NotificationType::NOTIFICATION_TYPE_QUESTION, "question")); | 
| +    retValue.emplace_back(std::make_pair(NotificationType::NOTIFICATION_TYPE_CRITICAL, "critical")); | 
| +    retValue.emplace_back(std::make_pair(NotificationType::NOTIFICATION_TYPE_INFORMATION, "information")); | 
| +    return retValue; | 
| +  }(); | 
| + | 
| +  NotificationType StringToNotificationType(const std::string& value) | 
| +  { | 
| +    auto ii_notificationType = std::find_if(g_notificationTypes.begin(), g_notificationTypes.end(), | 
| +      [&value](const NotificationTypeString& pair)->bool | 
| +    { | 
| +      return value == pair.second; | 
| +    }); | 
| +    if (ii_notificationType == g_notificationTypes.end()) | 
| +    { | 
| +      return NotificationType::NOTIFICATION_TYPE_INFORMATION; | 
| +    } | 
| +    return ii_notificationType->first; | 
| +  } | 
| +} | 
| + | 
| +Notification::Notification(const JsValuePtr& jsValue, PrivateCtrArg) | 
| +  : JsValue(jsValue) | 
| +{ | 
| +} | 
| + | 
| +NotificationType Notification::GetType() const | 
| +{ | 
| +  return type; | 
| +} | 
| + | 
| +const std::string& Notification::GetTitle() const | 
| +{ | 
| +  return title; | 
| +} | 
| + | 
| +const std::string& Notification::GetMessageString() const | 
| +{ | 
| +  return message; | 
| +} | 
| + | 
| +void Notification::MarkAsShown() | 
| +{ | 
| +  JsValueList params; | 
| +  params.push_back(GetProperty("id")); | 
| +  jsEngine->Evaluate("API.markNotificationAsShown")->Call(params); | 
| +} | 
| + | 
| +NotificationPtr Notification::JsValueToNotification(const JsValuePtr& jsValue) | 
| +{ | 
| +  if(!jsValue || !jsValue->IsObject()) | 
| +  { | 
| +    return NotificationPtr(); | 
| +  } | 
| + | 
| +  auto notification = std::tr1::make_shared<Notification>(jsValue, PrivateCtrArg()); | 
| +  auto jsType = notification->GetProperty("type"); | 
| +  notification->type = StringToNotificationType(jsType ? jsType->AsString() : ""); | 
| + | 
| +  JsValueList params; | 
| +  params.push_back(notification); | 
| +  JsValuePtr func = notification->jsEngine->Evaluate("API.getNotificationTexts"); | 
| +  auto jsTexts = func->Call(params); | 
| +  auto jsTitle = jsTexts->GetProperty("title"); | 
| +  if (jsTitle->IsString()) | 
| +  { | 
| +    notification->title = jsTitle->AsString(); | 
| +  } | 
| +  auto jsMessage = jsTexts->GetProperty("message"); | 
| +  if (jsMessage->IsString()) | 
| +  { | 
| +    notification->message = jsMessage->AsString(); | 
| +  } | 
| +  return notification; | 
| +} | 
|  |