| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 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. |
| 4 |
| 5 #include "chrome/browser/extensions/api/custom_notification_center/custom_notifi
cation_center_api.h" |
| 6 |
| 7 #include "base/callback.h" |
| 8 #include "base/guid.h" |
| 9 #include "base/rand_util.h" |
| 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/common/chrome_version_info.h" |
| 14 #include "extensions/browser/event_router.h" |
| 15 #include "extensions/common/extension.h" |
| 16 #include "extensions/common/features/feature.h" |
| 17 #include "ui/base/layout.h" |
| 18 #include "url/gurl.h" |
| 19 |
| 20 namespace extensions { |
| 21 |
| 22 CustomNotificationCenterEventRouter::CustomNotificationCenterEventRouter( |
| 23 Profile* profile) |
| 24 : profile_(profile) { |
| 25 } |
| 26 |
| 27 CustomNotificationCenterEventRouter::~CustomNotificationCenterEventRouter() { |
| 28 } |
| 29 |
| 30 void CustomNotificationCenterEventRouter::CreateNotification( |
| 31 const std::string& custom_notification_center_id, |
| 32 const std::string& sender_id, |
| 33 const std::string& notification_id, |
| 34 const api::custom_notification_center::NotificationContent& content) { |
| 35 Create(custom_notification_center_id, sender_id, notification_id, content); |
| 36 } |
| 37 |
| 38 void CustomNotificationCenterEventRouter::UpdateNotification( |
| 39 const std::string& custom_notification_center_id, |
| 40 const std::string& sender_id, |
| 41 const std::string& notification_id, |
| 42 const api::custom_notification_center::NotificationContent& content) { |
| 43 Update(custom_notification_center_id, sender_id, notification_id, content); |
| 44 } |
| 45 void CustomNotificationCenterEventRouter::ClearNotification( |
| 46 const std::string& custom_notification_center_id, |
| 47 const std::string& sender_id, |
| 48 const std::string& notification_id) { |
| 49 Clear(custom_notification_center_id, sender_id, notification_id); |
| 50 } |
| 51 |
| 52 void CustomNotificationCenterEventRouter::Create( |
| 53 const std::string& custom_notification_center_id, |
| 54 const std::string& sender_id, |
| 55 const std::string& notification_id, |
| 56 const api::custom_notification_center::NotificationContent& content) { |
| 57 scoped_ptr<base::ListValue> args = |
| 58 api::custom_notification_center::OnCreated::Create( |
| 59 sender_id, notification_id, content); |
| 60 |
| 61 scoped_ptr<Event> event(new Event( |
| 62 api::custom_notification_center::OnCreated::kEventName, args.Pass())); |
| 63 |
| 64 EventRouter::Get(profile_) |
| 65 ->DispatchEventToExtension(custom_notification_center_id, event.Pass()); |
| 66 } |
| 67 |
| 68 void CustomNotificationCenterEventRouter::Update( |
| 69 const std::string& custom_notification_center_id, |
| 70 const std::string& sender_id, |
| 71 const std::string& notification_id, |
| 72 const extensions::api::custom_notification_center::NotificationContent& |
| 73 content) { |
| 74 scoped_ptr<base::ListValue> args = |
| 75 api::custom_notification_center::OnUpdated::Create( |
| 76 sender_id, notification_id, content); |
| 77 |
| 78 scoped_ptr<Event> event(new Event( |
| 79 api::custom_notification_center::OnUpdated::kEventName, args.Pass())); |
| 80 |
| 81 EventRouter::Get(profile_) |
| 82 ->DispatchEventToExtension(custom_notification_center_id, event.Pass()); |
| 83 } |
| 84 |
| 85 void CustomNotificationCenterEventRouter::Clear( |
| 86 const std::string& custom_notification_center_id, |
| 87 const std::string& sender_id, |
| 88 const std::string& notification_id) { |
| 89 scoped_ptr<base::ListValue> args = |
| 90 api::custom_notification_center::OnCleared::Create(sender_id, |
| 91 notification_id); |
| 92 |
| 93 scoped_ptr<Event> event(new Event( |
| 94 api::custom_notification_center::OnCleared::kEventName, args.Pass())); |
| 95 |
| 96 EventRouter::Get(profile_) |
| 97 ->DispatchEventToExtension(custom_notification_center_id, event.Pass()); |
| 98 } |
| 99 |
| 100 CustomNotificationCenterSendOnClearFunction:: |
| 101 CustomNotificationCenterSendOnClearFunction() { |
| 102 } |
| 103 |
| 104 CustomNotificationCenterSendOnClearFunction:: |
| 105 ~CustomNotificationCenterSendOnClearFunction() { |
| 106 } |
| 107 |
| 108 bool CustomNotificationCenterSendOnClearFunction::RunAsync() { |
| 109 params_ = |
| 110 api::custom_notification_center::SendOnClear::Params::Create(*args_); |
| 111 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 112 |
| 113 SendResponse(true); |
| 114 return true; |
| 115 } |
| 116 |
| 117 CustomNotificationCenterSendOnClickFunction:: |
| 118 CustomNotificationCenterSendOnClickFunction() { |
| 119 } |
| 120 |
| 121 CustomNotificationCenterSendOnClickFunction:: |
| 122 ~CustomNotificationCenterSendOnClickFunction() { |
| 123 } |
| 124 |
| 125 bool CustomNotificationCenterSendOnClickFunction::RunAsync() { |
| 126 params_ = |
| 127 api::custom_notification_center::SendOnClick::Params::Create(*args_); |
| 128 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 129 |
| 130 SendResponse(true); |
| 131 return true; |
| 132 } |
| 133 |
| 134 CustomNotificationCenterSendOnButtonClickFunction:: |
| 135 CustomNotificationCenterSendOnButtonClickFunction() { |
| 136 } |
| 137 |
| 138 CustomNotificationCenterSendOnButtonClickFunction:: |
| 139 ~CustomNotificationCenterSendOnButtonClickFunction() { |
| 140 } |
| 141 |
| 142 bool CustomNotificationCenterSendOnButtonClickFunction::RunAsync() { |
| 143 params_ = api::custom_notification_center::SendOnButtonClick::Params::Create( |
| 144 *args_); |
| 145 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 146 |
| 147 SendResponse(true); |
| 148 return true; |
| 149 } |
| 150 |
| 151 CustomNotificationCenterNotifyPermissionLevelChangedFunction:: |
| 152 CustomNotificationCenterNotifyPermissionLevelChangedFunction() { |
| 153 } |
| 154 |
| 155 CustomNotificationCenterNotifyPermissionLevelChangedFunction:: |
| 156 ~CustomNotificationCenterNotifyPermissionLevelChangedFunction() { |
| 157 } |
| 158 |
| 159 bool CustomNotificationCenterNotifyPermissionLevelChangedFunction::RunAsync() { |
| 160 params_ = api::custom_notification_center::NotifyPermissionLevelChanged:: |
| 161 Params::Create(*args_); |
| 162 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| 163 |
| 164 SendResponse(true); |
| 165 return true; |
| 166 } |
| 167 } // namespace extensions |
| OLD | NEW |