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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_NOTIFICATIONS_NOTIFICATIONS_API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_NOTIFICATIONS_NOTIFICATIONS_API_H_ 7 8 #include <string> 9 10 #include "base/memory/ref_counted.h" 11 #include "chrome/browser/extensions/api/api_function.h" 12 #include "chrome/common/extensions/api/notifications.h" 13 #include "extensions/browser/extension_function.h" 14 #include "ui/message_center/notification_types.h" 15 16 class Notification; 17 18 namespace extensions { 19 20 class NotificationsApiFunction : public ApiFunction { 21 public: 22 // Whether the current extension and channel allow the API. Public for 23 // testing. 24 bool IsNotificationsApiAvailable(); 25 26 protected: 27 NotificationsApiFunction(); 28 virtual ~NotificationsApiFunction(); 29 30 bool CreateNotification(const std::string& id, 31 api::notifications::NotificationOptions* options); 32 bool UpdateNotification(const std::string& id, 33 api::notifications::NotificationOptions* options, 34 Notification* notification); 35 36 bool IsNotificationsApiEnabled() const; 37 38 bool AreExtensionNotificationsAllowed() const; 39 40 // Returns true if the API function is still allowed to run even when the 41 // notifications for a notifier have been disabled. 42 virtual bool CanRunWhileDisabled() const; 43 44 // Called inside of RunImpl. 45 virtual bool RunNotificationsApi() = 0; 46 47 // UITHreadExtensionFunction: 48 virtual bool RunImpl() OVERRIDE; 49 50 message_center::NotificationType MapApiTemplateTypeToType( 51 api::notifications::TemplateType type); 52 }; 53 54 class NotificationsCreateFunction : public NotificationsApiFunction { 55 public: 56 NotificationsCreateFunction(); 57 58 // NotificationsApiFunction: 59 virtual bool RunNotificationsApi() OVERRIDE; 60 61 protected: 62 virtual ~NotificationsCreateFunction(); 63 64 private: 65 scoped_ptr<api::notifications::Create::Params> params_; 66 67 DECLARE_EXTENSION_FUNCTION("notifications.create", NOTIFICATIONS_CREATE) 68 }; 69 70 class NotificationsUpdateFunction : public NotificationsApiFunction { 71 public: 72 NotificationsUpdateFunction(); 73 74 // NotificationsApiFunction: 75 virtual bool RunNotificationsApi() OVERRIDE; 76 77 protected: 78 virtual ~NotificationsUpdateFunction(); 79 80 private: 81 scoped_ptr<api::notifications::Update::Params> params_; 82 83 DECLARE_EXTENSION_FUNCTION("notifications.update", NOTIFICATIONS_UPDATE) 84 }; 85 86 class NotificationsClearFunction : public NotificationsApiFunction { 87 public: 88 NotificationsClearFunction(); 89 90 // NotificationsApiFunction: 91 virtual bool RunNotificationsApi() OVERRIDE; 92 93 protected: 94 virtual ~NotificationsClearFunction(); 95 96 private: 97 scoped_ptr<api::notifications::Clear::Params> params_; 98 99 DECLARE_EXTENSION_FUNCTION("notifications.clear", NOTIFICATIONS_CLEAR) 100 }; 101 102 class NotificationsGetAllFunction : public NotificationsApiFunction { 103 public: 104 NotificationsGetAllFunction(); 105 106 // NotificationsApiFunction: 107 virtual bool RunNotificationsApi() OVERRIDE; 108 109 protected: 110 virtual ~NotificationsGetAllFunction(); 111 112 private: 113 DECLARE_EXTENSION_FUNCTION("notifications.getAll", NOTIFICATIONS_GET_ALL) 114 }; 115 116 class NotificationsGetPermissionLevelFunction 117 : public NotificationsApiFunction { 118 public: 119 NotificationsGetPermissionLevelFunction(); 120 121 // NotificationsApiFunction: 122 virtual bool CanRunWhileDisabled() const OVERRIDE; 123 virtual bool RunNotificationsApi() OVERRIDE; 124 125 protected: 126 virtual ~NotificationsGetPermissionLevelFunction(); 127 128 private: 129 DECLARE_EXTENSION_FUNCTION("notifications.getPermissionLevel", 130 NOTIFICATIONS_GET_ALL) 131 }; 132 133 } // namespace extensions 134 135 #endif // CHROME_BROWSER_EXTENSIONS_API_NOTIFICATIONS_NOTIFICATIONS_API_H_ 136