| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 ShutdownNotifierFactory::GetInstance()->Get(profile)->Subscribe( | 151 ShutdownNotifierFactory::GetInstance()->Get(profile)->Subscribe( |
| 152 base::Bind(&NotificationsApiDelegate::Shutdown, | 152 base::Bind(&NotificationsApiDelegate::Shutdown, |
| 153 base::Unretained(this))); | 153 base::Unretained(this))); |
| 154 } | 154 } |
| 155 | 155 |
| 156 void Close(bool by_user) override { | 156 void Close(bool by_user) override { |
| 157 EventRouter::UserGestureState gesture = | 157 EventRouter::UserGestureState gesture = |
| 158 by_user ? EventRouter::USER_GESTURE_ENABLED | 158 by_user ? EventRouter::USER_GESTURE_ENABLED |
| 159 : EventRouter::USER_GESTURE_NOT_ENABLED; | 159 : EventRouter::USER_GESTURE_NOT_ENABLED; |
| 160 std::unique_ptr<base::ListValue> args(CreateBaseEventArgs()); | 160 std::unique_ptr<base::ListValue> args(CreateBaseEventArgs()); |
| 161 args->Append(new base::FundamentalValue(by_user)); | 161 args->AppendBoolean(by_user); |
| 162 SendEvent(events::NOTIFICATIONS_ON_CLOSED, | 162 SendEvent(events::NOTIFICATIONS_ON_CLOSED, |
| 163 notifications::OnClosed::kEventName, gesture, std::move(args)); | 163 notifications::OnClosed::kEventName, gesture, std::move(args)); |
| 164 } | 164 } |
| 165 | 165 |
| 166 void Click() override { | 166 void Click() override { |
| 167 std::unique_ptr<base::ListValue> args(CreateBaseEventArgs()); | 167 std::unique_ptr<base::ListValue> args(CreateBaseEventArgs()); |
| 168 SendEvent(events::NOTIFICATIONS_ON_CLICKED, | 168 SendEvent(events::NOTIFICATIONS_ON_CLICKED, |
| 169 notifications::OnClicked::kEventName, | 169 notifications::OnClicked::kEventName, |
| 170 EventRouter::USER_GESTURE_ENABLED, std::move(args)); | 170 EventRouter::USER_GESTURE_ENABLED, std::move(args)); |
| 171 } | 171 } |
| 172 | 172 |
| 173 bool HasClickedListener() override { | 173 bool HasClickedListener() override { |
| 174 if (!event_router_) | 174 if (!event_router_) |
| 175 return false; | 175 return false; |
| 176 | 176 |
| 177 return event_router_->HasEventListener( | 177 return event_router_->HasEventListener( |
| 178 notifications::OnClicked::kEventName); | 178 notifications::OnClicked::kEventName); |
| 179 } | 179 } |
| 180 | 180 |
| 181 void ButtonClick(int index) override { | 181 void ButtonClick(int index) override { |
| 182 std::unique_ptr<base::ListValue> args(CreateBaseEventArgs()); | 182 std::unique_ptr<base::ListValue> args(CreateBaseEventArgs()); |
| 183 args->Append(new base::FundamentalValue(index)); | 183 args->AppendInteger(index); |
| 184 SendEvent(events::NOTIFICATIONS_ON_BUTTON_CLICKED, | 184 SendEvent(events::NOTIFICATIONS_ON_BUTTON_CLICKED, |
| 185 notifications::OnButtonClicked::kEventName, | 185 notifications::OnButtonClicked::kEventName, |
| 186 EventRouter::USER_GESTURE_ENABLED, std::move(args)); | 186 EventRouter::USER_GESTURE_ENABLED, std::move(args)); |
| 187 } | 187 } |
| 188 | 188 |
| 189 std::string id() const override { return scoped_id_; } | 189 std::string id() const override { return scoped_id_; } |
| 190 | 190 |
| 191 private: | 191 private: |
| 192 ~NotificationsApiDelegate() override {} | 192 ~NotificationsApiDelegate() override {} |
| 193 | 193 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 204 event_router_->DispatchEventToExtension(extension_id_, std::move(event)); | 204 event_router_->DispatchEventToExtension(extension_id_, std::move(event)); |
| 205 } | 205 } |
| 206 | 206 |
| 207 void Shutdown() { | 207 void Shutdown() { |
| 208 event_router_ = nullptr; | 208 event_router_ = nullptr; |
| 209 shutdown_notifier_subscription_.reset(); | 209 shutdown_notifier_subscription_.reset(); |
| 210 } | 210 } |
| 211 | 211 |
| 212 std::unique_ptr<base::ListValue> CreateBaseEventArgs() { | 212 std::unique_ptr<base::ListValue> CreateBaseEventArgs() { |
| 213 std::unique_ptr<base::ListValue> args(new base::ListValue()); | 213 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
| 214 args->Append(new base::StringValue(id_)); | 214 args->AppendString(id_); |
| 215 return args; | 215 return args; |
| 216 } | 216 } |
| 217 | 217 |
| 218 scoped_refptr<ChromeAsyncExtensionFunction> api_function_; | 218 scoped_refptr<ChromeAsyncExtensionFunction> api_function_; |
| 219 | 219 |
| 220 // Since this class is refcounted it may outlive the profile. We listen for | 220 // Since this class is refcounted it may outlive the profile. We listen for |
| 221 // profile-keyed service shutdown events and reset to nullptr at that time, | 221 // profile-keyed service shutdown events and reset to nullptr at that time, |
| 222 // so make sure to check for a valid pointer before use. | 222 // so make sure to check for a valid pointer before use. |
| 223 EventRouter* event_router_; | 223 EventRouter* event_router_; |
| 224 | 224 |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 : api::notifications::PERMISSION_LEVEL_DENIED; | 722 : api::notifications::PERMISSION_LEVEL_DENIED; |
| 723 | 723 |
| 724 SetResult(base::MakeUnique<base::StringValue>( | 724 SetResult(base::MakeUnique<base::StringValue>( |
| 725 api::notifications::ToString(result))); | 725 api::notifications::ToString(result))); |
| 726 SendResponse(true); | 726 SendResponse(true); |
| 727 | 727 |
| 728 return true; | 728 return true; |
| 729 } | 729 } |
| 730 | 730 |
| 731 } // namespace extensions | 731 } // namespace extensions |
| OLD | NEW |