OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/api/notifications/notifications_api.h" | 5 #include "chrome/browser/extensions/api/notifications/notifications_api.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 shutdown_notifier_subscription_ = | 149 shutdown_notifier_subscription_ = |
150 ShutdownNotifierFactory::GetInstance()->Get(profile)->Subscribe( | 150 ShutdownNotifierFactory::GetInstance()->Get(profile)->Subscribe( |
151 base::Bind(&NotificationsApiDelegate::Shutdown, | 151 base::Bind(&NotificationsApiDelegate::Shutdown, |
152 base::Unretained(this))); | 152 base::Unretained(this))); |
153 } | 153 } |
154 | 154 |
155 void Close(bool by_user) override { | 155 void Close(bool by_user) override { |
156 EventRouter::UserGestureState gesture = | 156 EventRouter::UserGestureState gesture = |
157 by_user ? EventRouter::USER_GESTURE_ENABLED | 157 by_user ? EventRouter::USER_GESTURE_ENABLED |
158 : EventRouter::USER_GESTURE_NOT_ENABLED; | 158 : EventRouter::USER_GESTURE_NOT_ENABLED; |
159 scoped_ptr<base::ListValue> args(CreateBaseEventArgs()); | 159 std::unique_ptr<base::ListValue> args(CreateBaseEventArgs()); |
160 args->Append(new base::FundamentalValue(by_user)); | 160 args->Append(new base::FundamentalValue(by_user)); |
161 SendEvent(events::NOTIFICATIONS_ON_CLOSED, | 161 SendEvent(events::NOTIFICATIONS_ON_CLOSED, |
162 notifications::OnClosed::kEventName, gesture, std::move(args)); | 162 notifications::OnClosed::kEventName, gesture, std::move(args)); |
163 } | 163 } |
164 | 164 |
165 void Click() override { | 165 void Click() override { |
166 scoped_ptr<base::ListValue> args(CreateBaseEventArgs()); | 166 std::unique_ptr<base::ListValue> args(CreateBaseEventArgs()); |
167 SendEvent(events::NOTIFICATIONS_ON_CLICKED, | 167 SendEvent(events::NOTIFICATIONS_ON_CLICKED, |
168 notifications::OnClicked::kEventName, | 168 notifications::OnClicked::kEventName, |
169 EventRouter::USER_GESTURE_ENABLED, std::move(args)); | 169 EventRouter::USER_GESTURE_ENABLED, std::move(args)); |
170 } | 170 } |
171 | 171 |
172 bool HasClickedListener() override { | 172 bool HasClickedListener() override { |
173 if (!event_router_) | 173 if (!event_router_) |
174 return false; | 174 return false; |
175 | 175 |
176 return event_router_->HasEventListener( | 176 return event_router_->HasEventListener( |
177 notifications::OnClicked::kEventName); | 177 notifications::OnClicked::kEventName); |
178 } | 178 } |
179 | 179 |
180 void ButtonClick(int index) override { | 180 void ButtonClick(int index) override { |
181 scoped_ptr<base::ListValue> args(CreateBaseEventArgs()); | 181 std::unique_ptr<base::ListValue> args(CreateBaseEventArgs()); |
182 args->Append(new base::FundamentalValue(index)); | 182 args->Append(new base::FundamentalValue(index)); |
183 SendEvent(events::NOTIFICATIONS_ON_BUTTON_CLICKED, | 183 SendEvent(events::NOTIFICATIONS_ON_BUTTON_CLICKED, |
184 notifications::OnButtonClicked::kEventName, | 184 notifications::OnButtonClicked::kEventName, |
185 EventRouter::USER_GESTURE_ENABLED, std::move(args)); | 185 EventRouter::USER_GESTURE_ENABLED, std::move(args)); |
186 } | 186 } |
187 | 187 |
188 std::string id() const override { return scoped_id_; } | 188 std::string id() const override { return scoped_id_; } |
189 | 189 |
190 private: | 190 private: |
191 ~NotificationsApiDelegate() override {} | 191 ~NotificationsApiDelegate() override {} |
192 | 192 |
193 void SendEvent(events::HistogramValue histogram_value, | 193 void SendEvent(events::HistogramValue histogram_value, |
194 const std::string& name, | 194 const std::string& name, |
195 EventRouter::UserGestureState user_gesture, | 195 EventRouter::UserGestureState user_gesture, |
196 scoped_ptr<base::ListValue> args) { | 196 std::unique_ptr<base::ListValue> args) { |
197 if (!event_router_) | 197 if (!event_router_) |
198 return; | 198 return; |
199 | 199 |
200 scoped_ptr<Event> event(new Event(histogram_value, name, std::move(args))); | 200 std::unique_ptr<Event> event( |
| 201 new Event(histogram_value, name, std::move(args))); |
201 event->user_gesture = user_gesture; | 202 event->user_gesture = user_gesture; |
202 event_router_->DispatchEventToExtension(extension_id_, std::move(event)); | 203 event_router_->DispatchEventToExtension(extension_id_, std::move(event)); |
203 } | 204 } |
204 | 205 |
205 void Shutdown() { | 206 void Shutdown() { |
206 event_router_ = nullptr; | 207 event_router_ = nullptr; |
207 shutdown_notifier_subscription_.reset(); | 208 shutdown_notifier_subscription_.reset(); |
208 } | 209 } |
209 | 210 |
210 scoped_ptr<base::ListValue> CreateBaseEventArgs() { | 211 std::unique_ptr<base::ListValue> CreateBaseEventArgs() { |
211 scoped_ptr<base::ListValue> args(new base::ListValue()); | 212 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
212 args->Append(new base::StringValue(id_)); | 213 args->Append(new base::StringValue(id_)); |
213 return args; | 214 return args; |
214 } | 215 } |
215 | 216 |
216 scoped_refptr<ChromeAsyncExtensionFunction> api_function_; | 217 scoped_refptr<ChromeAsyncExtensionFunction> api_function_; |
217 | 218 |
218 // Since this class is refcounted it may outlive the profile. We listen for | 219 // Since this class is refcounted it may outlive the profile. We listen for |
219 // profile-keyed service shutdown events and reset to nullptr at that time, | 220 // profile-keyed service shutdown events and reset to nullptr at that time, |
220 // so make sure to check for a valid pointer before use. | 221 // so make sure to check for a valid pointer before use. |
221 EventRouter* event_router_; | 222 EventRouter* event_router_; |
222 | 223 |
223 const std::string extension_id_; | 224 const std::string extension_id_; |
224 const std::string id_; | 225 const std::string id_; |
225 const std::string scoped_id_; | 226 const std::string scoped_id_; |
226 | 227 |
227 scoped_ptr<KeyedServiceShutdownNotifier::Subscription> | 228 std::unique_ptr<KeyedServiceShutdownNotifier::Subscription> |
228 shutdown_notifier_subscription_; | 229 shutdown_notifier_subscription_; |
229 | 230 |
230 DISALLOW_COPY_AND_ASSIGN(NotificationsApiDelegate); | 231 DISALLOW_COPY_AND_ASSIGN(NotificationsApiDelegate); |
231 }; | 232 }; |
232 | 233 |
233 } // namespace | 234 } // namespace |
234 | 235 |
235 bool NotificationsApiFunction::IsNotificationsApiAvailable() { | 236 bool NotificationsApiFunction::IsNotificationsApiAvailable() { |
236 // We need to check this explicitly rather than letting | 237 // We need to check this explicitly rather than letting |
237 // _permission_features.json enforce it, because we're sharing the | 238 // _permission_features.json enforce it, because we're sharing the |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 | 682 |
682 NotificationsGetAllFunction::~NotificationsGetAllFunction() {} | 683 NotificationsGetAllFunction::~NotificationsGetAllFunction() {} |
683 | 684 |
684 bool NotificationsGetAllFunction::RunNotificationsApi() { | 685 bool NotificationsGetAllFunction::RunNotificationsApi() { |
685 NotificationUIManager* notification_ui_manager = | 686 NotificationUIManager* notification_ui_manager = |
686 g_browser_process->notification_ui_manager(); | 687 g_browser_process->notification_ui_manager(); |
687 std::set<std::string> notification_ids = | 688 std::set<std::string> notification_ids = |
688 notification_ui_manager->GetAllIdsByProfileAndSourceOrigin( | 689 notification_ui_manager->GetAllIdsByProfileAndSourceOrigin( |
689 NotificationUIManager::GetProfileID(GetProfile()), extension_->url()); | 690 NotificationUIManager::GetProfileID(GetProfile()), extension_->url()); |
690 | 691 |
691 scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); | 692 std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
692 | 693 |
693 for (std::set<std::string>::iterator iter = notification_ids.begin(); | 694 for (std::set<std::string>::iterator iter = notification_ids.begin(); |
694 iter != notification_ids.end(); iter++) { | 695 iter != notification_ids.end(); iter++) { |
695 result->SetBooleanWithoutPathExpansion( | 696 result->SetBooleanWithoutPathExpansion( |
696 StripScopeFromIdentifier(extension_->id(), *iter), true); | 697 StripScopeFromIdentifier(extension_->id(), *iter), true); |
697 } | 698 } |
698 | 699 |
699 SetResult(result.release()); | 700 SetResult(result.release()); |
700 SendResponse(true); | 701 SendResponse(true); |
701 | 702 |
(...skipping 16 matching lines...) Expand all Loading... |
718 ? api::notifications::PERMISSION_LEVEL_GRANTED | 719 ? api::notifications::PERMISSION_LEVEL_GRANTED |
719 : api::notifications::PERMISSION_LEVEL_DENIED; | 720 : api::notifications::PERMISSION_LEVEL_DENIED; |
720 | 721 |
721 SetResult(new base::StringValue(api::notifications::ToString(result))); | 722 SetResult(new base::StringValue(api::notifications::ToString(result))); |
722 SendResponse(true); | 723 SendResponse(true); |
723 | 724 |
724 return true; | 725 return true; |
725 } | 726 } |
726 | 727 |
727 } // namespace extensions | 728 } // namespace extensions |
OLD | NEW |