Chromium Code Reviews| 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/notification_getter/notification_getter_ 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 namespace notification_getter = api::notification_getter; | |
| 23 | |
| 24 NotificationGetterEventRouter::NotificationGetterEventRouter(Profile* profile) | |
| 25 : profile_(profile) { | |
| 26 } | |
| 27 | |
| 28 NotificationGetterEventRouter::~NotificationGetterEventRouter() { | |
| 29 } | |
| 30 | |
| 31 void NotificationGetterEventRouter::CreateNotificationForTest( | |
| 32 const std::string& extension_id, | |
| 33 const std::string& sender_id, | |
| 34 const std::string& notification_id, | |
| 35 const api::notification_getter::NotificationOptions& options) { | |
| 36 Create(extension_id, sender_id, notification_id, options); | |
| 37 } | |
| 38 | |
| 39 void NotificationGetterEventRouter::UpdateNotificationForTest( | |
| 40 const std::string& extension_id, | |
| 41 const std::string& sender_id, | |
| 42 const std::string& notification_id, | |
| 43 const api::notification_getter::NotificationOptions& options) { | |
| 44 Update(extension_id, sender_id, notification_id, options); | |
| 45 } | |
| 46 void NotificationGetterEventRouter::CloseNotificationForTest( | |
| 47 const std::string& extension_id, | |
| 48 const std::string& sender_id, | |
| 49 const std::string& notification_id) { | |
| 50 Close(extension_id, sender_id, notification_id); | |
| 51 } | |
| 52 | |
| 53 void NotificationGetterEventRouter::Create( | |
| 54 const std::string& extension_id, | |
| 55 const std::string& sender_id, | |
| 56 const std::string& notification_id, | |
| 57 const api::notification_getter::NotificationOptions& options) { | |
| 58 scoped_ptr<base::ListValue> args = | |
| 59 api::notification_getter::OnCreated::Create( | |
| 60 sender_id, notification_id, options); | |
| 61 | |
| 62 scoped_ptr<Event> event( | |
| 63 new Event(api::notification_getter::OnCreated::kEventName, args.Pass())); | |
| 64 | |
| 65 EventRouter::Get(profile_) | |
| 66 ->DispatchEventToExtension(extension_id, event.Pass()); | |
|
Pete Williamson
2014/06/30 19:03:48
This seems to be sending the OnCreated event back
liyanhou
2014/07/14 17:44:44
It's sending the event to the new notification cen
| |
| 67 } | |
| 68 | |
| 69 void NotificationGetterEventRouter::Update( | |
| 70 const std::string& extension_id, | |
| 71 const std::string& sender_id, | |
| 72 const std::string& notification_id, | |
| 73 const extensions::api::notification_getter::NotificationOptions& options) { | |
| 74 scoped_ptr<base::ListValue> args = | |
| 75 api::notification_getter::OnUpdated::Create( | |
| 76 sender_id, notification_id, options); | |
| 77 | |
| 78 scoped_ptr<Event> event( | |
| 79 new Event(notification_getter::OnUpdated::kEventName, args.Pass())); | |
| 80 | |
| 81 EventRouter::Get(profile_) | |
| 82 ->DispatchEventToExtension(extension_id, event.Pass()); | |
| 83 } | |
| 84 | |
| 85 void NotificationGetterEventRouter::Close(const std::string& extension_id, | |
| 86 const std::string& sender_id, | |
| 87 const std::string& notification_id) { | |
| 88 scoped_ptr<base::ListValue> args = | |
| 89 api::notification_getter::OnClosed::Create(sender_id, notification_id); | |
| 90 | |
| 91 scoped_ptr<Event> event( | |
| 92 new Event(notification_getter::OnClosed::kEventName, args.Pass())); | |
| 93 | |
| 94 EventRouter::Get(profile_) | |
| 95 ->DispatchEventToExtension(extension_id, event.Pass()); | |
| 96 } | |
| 97 | |
| 98 NotificationGetterSendOnCloseFunction::NotificationGetterSendOnCloseFunction() { | |
| 99 } | |
| 100 | |
| 101 NotificationGetterSendOnCloseFunction:: | |
| 102 ~NotificationGetterSendOnCloseFunction() { | |
| 103 } | |
| 104 | |
| 105 bool NotificationGetterSendOnCloseFunction::RunAsync() { | |
| 106 params_ = api::notification_getter::SendOnClose::Params::Create(*args_); | |
| 107 EXTENSION_FUNCTION_VALIDATE(params_.get()); | |
| 108 | |
| 109 SendResponse(true); | |
| 110 return true; | |
| 111 } | |
| 112 | |
| 113 NotificationGetterSendOnClickFunction::NotificationGetterSendOnClickFunction() { | |
| 114 } | |
| 115 | |
| 116 NotificationGetterSendOnClickFunction:: | |
| 117 ~NotificationGetterSendOnClickFunction() { | |
| 118 } | |
| 119 | |
| 120 bool NotificationGetterSendOnClickFunction::RunAsync() { | |
| 121 params_ = api::notification_getter::SendOnClick::Params::Create(*args_); | |
| 122 EXTENSION_FUNCTION_VALIDATE(params_.get()); | |
| 123 | |
| 124 SendResponse(true); | |
| 125 return true; | |
| 126 } | |
| 127 | |
| 128 NotificationGetterSendOnClickButtonFunction:: | |
| 129 NotificationGetterSendOnClickButtonFunction() { | |
| 130 } | |
| 131 | |
| 132 NotificationGetterSendOnClickButtonFunction:: | |
| 133 ~NotificationGetterSendOnClickButtonFunction() { | |
| 134 } | |
| 135 | |
| 136 bool NotificationGetterSendOnClickButtonFunction::RunAsync() { | |
| 137 params_ = api::notification_getter::SendOnClickButton::Params::Create(*args_); | |
| 138 EXTENSION_FUNCTION_VALIDATE(params_.get()); | |
| 139 | |
| 140 SendResponse(true); | |
| 141 return true; | |
| 142 } | |
| 143 | |
| 144 NotificationGetterNotifyPermissionLevelChangedFunction:: | |
| 145 NotificationGetterNotifyPermissionLevelChangedFunction() { | |
| 146 } | |
| 147 | |
| 148 NotificationGetterNotifyPermissionLevelChangedFunction:: | |
| 149 ~NotificationGetterNotifyPermissionLevelChangedFunction() { | |
| 150 } | |
| 151 | |
| 152 bool NotificationGetterNotifyPermissionLevelChangedFunction::RunAsync() { | |
| 153 params_ = | |
| 154 api::notification_getter::NotifyPermissionLevelChanged::Params::Create( | |
| 155 *args_); | |
| 156 EXTENSION_FUNCTION_VALIDATE(params_.get()); | |
| 157 | |
| 158 SendResponse(true); | |
| 159 return true; | |
| 160 } | |
| 161 } // namespace extensions | |
| OLD | NEW |