| 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..8e6262694cbc128547a971e4e42eba917ee827ae
|
| --- /dev/null
|
| +++ b/chrome/browser/extensions/api/notification_provider/notification_provider_api.cc
|
| @@ -0,0 +1,197 @@
|
| +// 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() {
|
| +}
|
| +
|
| +bool NotificationProviderNotifyOnClearedFunction::RunAsync() {
|
| + params_ = api::notification_provider::NotifyOnCleared::Params::Create(*args_);
|
| + EXTENSION_FUNCTION_VALIDATE(params_.get());
|
| +
|
| + SendResponse(true);
|
| + return true;
|
| +}
|
| +
|
| +NotificationProviderNotifyOnClickedFunction::
|
| + NotificationProviderNotifyOnClickedFunction() {
|
| +}
|
| +
|
| +NotificationProviderNotifyOnClickedFunction::
|
| + ~NotificationProviderNotifyOnClickedFunction() {
|
| +}
|
| +
|
| +bool NotificationProviderNotifyOnClickedFunction::RunAsync() {
|
| + params_ = api::notification_provider::NotifyOnClicked::Params::Create(*args_);
|
| + EXTENSION_FUNCTION_VALIDATE(params_.get());
|
| +
|
| + SendResponse(true);
|
| + return true;
|
| +}
|
| +
|
| +NotificationProviderNotifyOnButtonClickedFunction::
|
| + NotificationProviderNotifyOnButtonClickedFunction() {
|
| +}
|
| +
|
| +NotificationProviderNotifyOnButtonClickedFunction::
|
| + ~NotificationProviderNotifyOnButtonClickedFunction() {
|
| +}
|
| +
|
| +bool NotificationProviderNotifyOnButtonClickedFunction::RunAsync() {
|
| + params_ =
|
| + api::notification_provider::NotifyOnButtonClicked::Params::Create(*args_);
|
| + EXTENSION_FUNCTION_VALIDATE(params_.get());
|
| +
|
| + SendResponse(true);
|
| + return true;
|
| +}
|
| +
|
| +NotificationProviderNotifyOnPermissionLevelChangedFunction::
|
| + NotificationProviderNotifyOnPermissionLevelChangedFunction() {
|
| +}
|
| +
|
| +NotificationProviderNotifyOnPermissionLevelChangedFunction::
|
| + ~NotificationProviderNotifyOnPermissionLevelChangedFunction() {
|
| +}
|
| +
|
| +bool NotificationProviderNotifyOnPermissionLevelChangedFunction::RunAsync() {
|
| + params_ = api::notification_provider::NotifyOnPermissionLevelChanged::Params::
|
| + Create(*args_);
|
| + EXTENSION_FUNCTION_VALIDATE(params_.get());
|
| +
|
| + SendResponse(true);
|
| + return true;
|
| +}
|
| +
|
| +NotificationProviderNotifyOnShowSettingsFunction::
|
| + NotificationProviderNotifyOnShowSettingsFunction() {
|
| +}
|
| +
|
| +NotificationProviderNotifyOnShowSettingsFunction::
|
| + ~NotificationProviderNotifyOnShowSettingsFunction() {
|
| +}
|
| +
|
| +bool NotificationProviderNotifyOnShowSettingsFunction::RunAsync() {
|
| + params_ =
|
| + api::notification_provider::NotifyOnShowSettings::Params::Create(*args_);
|
| + EXTENSION_FUNCTION_VALIDATE(params_.get());
|
| +
|
| + SendResponse(true);
|
| + return true;
|
| +}
|
| +
|
| +NotificationProviderGetAllNotifiersFunction::
|
| + NotificationProviderGetAllNotifiersFunction() {
|
| +}
|
| +
|
| +NotificationProviderGetAllNotifiersFunction::
|
| + ~NotificationProviderGetAllNotifiersFunction() {
|
| +}
|
| +
|
| +bool NotificationProviderGetAllNotifiersFunction::RunAsync() {
|
| + scoped_ptr<base::DictionaryValue> result(new base::DictionaryValue());
|
| +
|
| + SetResult(result.release());
|
| + SendResponse(true);
|
| + return true;
|
| +}
|
| +
|
| +} // namespace extensions
|
|
|