Chromium Code Reviews| Index: chrome/browser/extensions/api/notification_provider/notification_provider_api.cc |
| diff --git a/chrome/browser/extensions/api/notification_provider/notification_provider_api.cc b/chrome/browser/extensions/api/notification_provider/notification_provider_api.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..12cdc7b3af33813a7770cfcd89d4c97e01c3f701 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/api/notification_provider/notification_provider_api.cc |
| @@ -0,0 +1,223 @@ |
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/extensions/api/notification_provider/notification_provider_api.h" |
| + |
| +#include "base/callback.h" |
| +#include "base/guid.h" |
| +#include "base/rand_util.h" |
| +#include "base/strings/string_number_conversions.h" |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "chrome/browser/browser_process.h" |
| +#include "chrome/common/chrome_version_info.h" |
| +#include "extensions/browser/event_router.h" |
| +#include "extensions/common/extension.h" |
| +#include "extensions/common/features/feature.h" |
| +#include "ui/base/layout.h" |
| +#include "url/gurl.h" |
| + |
| +namespace extensions { |
| + |
| +NotificationProviderEventRouter::NotificationProviderEventRouter( |
| + Profile* profile) |
| + : profile_(profile) { |
| +} |
| + |
| +NotificationProviderEventRouter::~NotificationProviderEventRouter() { |
| +} |
| + |
| +void NotificationProviderEventRouter::CreateNotification( |
| + const std::string& notification_provider_id, |
| + const std::string& sender_id, |
| + const std::string& notification_id, |
| + const api::notifications::NotificationOptions& options) { |
| + Create(notification_provider_id, sender_id, notification_id, options); |
| +} |
| + |
| +void NotificationProviderEventRouter::UpdateNotification( |
| + const std::string& notification_provider_id, |
| + const std::string& sender_id, |
| + const std::string& notification_id, |
| + const api::notifications::NotificationOptions& options) { |
| + Update(notification_provider_id, sender_id, notification_id, options); |
| +} |
| +void NotificationProviderEventRouter::ClearNotification( |
| + const std::string& notification_provider_id, |
| + const std::string& sender_id, |
| + const std::string& notification_id) { |
| + Clear(notification_provider_id, sender_id, notification_id); |
| +} |
| + |
| +void NotificationProviderEventRouter::Create( |
| + const std::string& notification_provider_id, |
| + const std::string& sender_id, |
| + const std::string& notification_id, |
| + const api::notifications::NotificationOptions& options) { |
| + scoped_ptr<base::ListValue> args = |
| + api::notification_provider::OnCreated::Create( |
| + sender_id, notification_id, options); |
| + |
| + scoped_ptr<Event> event(new Event( |
| + api::notification_provider::OnCreated::kEventName, args.Pass())); |
| + |
| + EventRouter::Get(profile_) |
| + ->DispatchEventToExtension(notification_provider_id, event.Pass()); |
| +} |
| + |
| +void NotificationProviderEventRouter::Update( |
| + const std::string& notification_provider_id, |
| + const std::string& sender_id, |
| + const std::string& notification_id, |
| + const extensions::api::notifications::NotificationOptions& options) { |
| + scoped_ptr<base::ListValue> args = |
| + api::notification_provider::OnUpdated::Create( |
| + sender_id, notification_id, options); |
| + |
| + scoped_ptr<Event> event(new Event( |
| + api::notification_provider::OnUpdated::kEventName, args.Pass())); |
| + |
| + EventRouter::Get(profile_) |
| + ->DispatchEventToExtension(notification_provider_id, event.Pass()); |
| +} |
| + |
| +void NotificationProviderEventRouter::Clear( |
| + const std::string& notification_provider_id, |
| + const std::string& sender_id, |
| + const std::string& notification_id) { |
| + scoped_ptr<base::ListValue> args = |
| + api::notification_provider::OnCleared::Create(sender_id, notification_id); |
| + |
| + scoped_ptr<Event> event(new Event( |
| + api::notification_provider::OnCleared::kEventName, args.Pass())); |
| + |
| + EventRouter::Get(profile_) |
| + ->DispatchEventToExtension(notification_provider_id, event.Pass()); |
| +} |
| + |
| +NotificationProviderNotifyOnClearedFunction:: |
| + NotificationProviderNotifyOnClearedFunction() { |
| +} |
| + |
| +NotificationProviderNotifyOnClearedFunction:: |
| + ~NotificationProviderNotifyOnClearedFunction() { |
| +} |
| + |
| +ExtensionFunction::ResponseAction |
| +NotificationProviderNotifyOnClearedFunction::Run() { |
| + params_ = api::notification_provider::NotifyOnCleared::Params::Create(*args_); |
| + EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| + |
| + base::FundamentalValue* result = new base::FundamentalValue(true); |
|
not at google - send to devlin
2014/07/29 20:09:38
for every function: it's better to use the generat
liyanhou
2014/07/30 17:19:24
Done.
|
| + |
| + return RespondNow(OneArgument(result)); |
| +} |
| + |
| +NotificationProviderNotifyOnClickedFunction:: |
| + NotificationProviderNotifyOnClickedFunction() { |
| +} |
| + |
| +NotificationProviderNotifyOnClickedFunction:: |
| + ~NotificationProviderNotifyOnClickedFunction() { |
| +} |
| + |
| +ExtensionFunction::ResponseAction |
| +NotificationProviderNotifyOnClickedFunction::Run() { |
| + params_ = api::notification_provider::NotifyOnClicked::Params::Create(*args_); |
| + EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| + |
| + base::FundamentalValue* result = new base::FundamentalValue(true); |
| + |
| + return RespondNow(OneArgument(result)); |
| +} |
| + |
| +NotificationProviderNotifyOnButtonClickedFunction:: |
| + NotificationProviderNotifyOnButtonClickedFunction() { |
| +} |
| + |
| +NotificationProviderNotifyOnButtonClickedFunction:: |
| + ~NotificationProviderNotifyOnButtonClickedFunction() { |
| +} |
| + |
| +ExtensionFunction::ResponseAction |
| +NotificationProviderNotifyOnButtonClickedFunction::Run() { |
| + params_ = |
| + api::notification_provider::NotifyOnButtonClicked::Params::Create(*args_); |
| + EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| + |
| + base::FundamentalValue* result = new base::FundamentalValue(true); |
| + |
| + return RespondNow(OneArgument(result)); |
| +} |
| + |
| +NotificationProviderNotifyOnPermissionLevelChangedFunction:: |
| + NotificationProviderNotifyOnPermissionLevelChangedFunction() { |
| +} |
| + |
| +NotificationProviderNotifyOnPermissionLevelChangedFunction:: |
| + ~NotificationProviderNotifyOnPermissionLevelChangedFunction() { |
| +} |
| + |
| +ExtensionFunction::ResponseAction |
| +NotificationProviderNotifyOnPermissionLevelChangedFunction::Run() { |
| + params_ = api::notification_provider::NotifyOnPermissionLevelChanged::Params:: |
| + Create(*args_); |
| + EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| + |
| + base::FundamentalValue* result = new base::FundamentalValue(true); |
| + |
| + return RespondNow(OneArgument(result)); |
| +} |
| + |
| +NotificationProviderNotifyOnShowSettingsFunction:: |
| + NotificationProviderNotifyOnShowSettingsFunction() { |
| +} |
| + |
| +NotificationProviderNotifyOnShowSettingsFunction:: |
| + ~NotificationProviderNotifyOnShowSettingsFunction() { |
| +} |
| + |
| +ExtensionFunction::ResponseAction |
| +NotificationProviderNotifyOnShowSettingsFunction::Run() { |
| + params_ = |
| + api::notification_provider::NotifyOnShowSettings::Params::Create(*args_); |
| + EXTENSION_FUNCTION_VALIDATE(params_.get()); |
| + |
| + base::FundamentalValue* result = new base::FundamentalValue(true); |
| + |
| + return RespondNow(OneArgument(result)); |
| +} |
| + |
| +NotificationProviderGetNotifierFunction:: |
| + NotificationProviderGetNotifierFunction() { |
| +} |
| + |
| +NotificationProviderGetNotifierFunction:: |
| + ~NotificationProviderGetNotifierFunction() { |
| +} |
| + |
| +ExtensionFunction::ResponseAction |
| +NotificationProviderGetNotifierFunction::Run() { |
| + scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue()); |
| + |
| + return RespondNow(OneArgument(result.release())); |
| +} |
| + |
| +NotificationProviderGetAllNotifiersFunction:: |
| + NotificationProviderGetAllNotifiersFunction() { |
| +} |
| + |
| +NotificationProviderGetAllNotifiersFunction:: |
| + ~NotificationProviderGetAllNotifiersFunction() { |
| +} |
| + |
| +ExtensionFunction::ResponseAction |
| +NotificationProviderGetAllNotifiersFunction::Run() { |
| + scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue()); |
| + scoped_ptr<base::ListValue> result(new base::ListValue()); |
| + result->Append(dictionary.release()); |
|
not at google - send to devlin
2014/07/29 20:09:38
for example, here the result could be nicer:
retu
liyanhou
2014/07/30 17:19:25
Done.
|
| + |
| + return RespondNow(OneArgument(result.release())); |
| +} |
| + |
| +} // namespace extensions |